/****************************************************************************** * * Copyright (c) 2017-2019 by Löwenware Ltd * Please, refer LICENSE file for legal information * ******************************************************************************/ /** * @file interface.h * @author Ilja Kartašov * @brief Interface header file for AISL SDK modules * * @see https://lowenware.com/aisl/ */ #ifndef AISL_SDK_MODS_INTERFACE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA #define AISL_SDK_MODS_INTERFACE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA #include #define AISLX_MOD_INIT(MOD, END_POINT) \ do { \ ((aislx_mod_t) mod)->end_point = END_POINT; \ ((aislx_mod_t) mod)->ep_length = strlen(END_POINT); \ ((aislx_mod_t) mod)->on_stream_event = MOD##_on_event; \ ((aislx_mod_t) mod)->ctx_size = sizeof(struct context); \ } while(0) \ /** @brief AISL mod structure pointer */ typedef struct aislx_mod * aislx_mod_t; /** @brief Pointer to AISL stream event observer */ typedef aisl_status_t (* aislx_mod_observer_t)(aislx_mod_t mod, aisl_evt_t const evt); /** @brief Root level AISL mod's structure */ struct aislx_mod { const char * end_point; /**< Root mod's URL or NULL */ aislx_mod_observer_t on_event; /**< Mod's stream event observer */ size_t ctx_size; /**< Mod's context size */ uint8_t ep_length; /**< Mod's context size */ }; /** @brief Root level ASIL mod's context structure */ struct aislx_mod_ctx { aislx_mod_t mod; /**< Mod's pointer */ }; /** @brief Root level ASIL mod's context structure pointer */ typedef struct aislx_mod_ctx * aislx_mod_ctx_t; /** @brief Allocates zeroed #aislx_mod_t context * @param mod an instance of #aislx_mod_t * @return pointer to newly allocated #aisl_mox_ctx_t */ aislx_mod_ctx_t aislx_mod_ctx_new(aislx_mod_t mod); /** @brief Frees previosly allocated #aislx_mod_ctx_t * @param ctx an instance of mod's context structure * */ void aislx_mod_ctx_free(aislx_mod_ctx_t ctx); /** @brief Wrapper function that calles mod's observer * @param mod an instance of #aislx_mod_t * @param evt an AISL stream event * @return AISL_SUCCESS if event handled, AISL_IDLE if event not handled or an * error code */ aisl_status_t aislx_mod_on_event(aislx_mod_t mod, aisl_evt_t const evt); #endif /* !AISL_SDK_MODS_INTERFACE_H */