63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
/******************************************************************************
|
|
*
|
|
* Copyright (c) 2017-2019 by Löwenware Ltd
|
|
* Please, refer LICENSE file for legal information
|
|
*
|
|
******************************************************************************/
|
|
|
|
/**
|
|
* @file interface.h
|
|
* @author Ilja Kartašov <ik@lowenware.com>
|
|
* @brief Interface header file for AISL SDK modules
|
|
*
|
|
* @see https://lowenware.com/aisl/
|
|
*/
|
|
|
|
#ifndef MODULE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA
|
|
#define MODULE_H_1AEFECA5_9341_431B_8194_EA0C2E76B5EA
|
|
|
|
#include <aisl/aisl.h>
|
|
|
|
#define AX_MODULE_INIT(MOD, END_POINT) \
|
|
do { \
|
|
((AxModule) mod)->end_point = END_POINT; \
|
|
((AxModule) mod)->ep_length = strlen(END_POINT); \
|
|
((AxModule) mod)->on_event = (AxObserver)MOD##_on_event; \
|
|
((AxModule) mod)->ctx_size = sizeof (struct context); \
|
|
} while(0) \
|
|
|
|
#define AX_MODULE(x) ((AxModule)x)
|
|
|
|
/** @brief AISL module structure pointer
|
|
*/
|
|
typedef struct ax_module * AxModule;
|
|
|
|
|
|
/** @brief Pointer to AISL stream event observer
|
|
*/
|
|
typedef AislStatus
|
|
(* AxObserver)(AxModule mod, const struct aisl_evt *evt);
|
|
|
|
|
|
|
|
/** @brief Root level AISL mod's structure
|
|
*/
|
|
struct ax_module {
|
|
const char *end_point; /**< Root mod's URL or NULL */
|
|
AxObserver on_event; /**< Mod's stream event observer */
|
|
size_t ctx_size; /**< Mod's context size */
|
|
uint8_t ep_length; /**< End-Point length */
|
|
};
|
|
|
|
|
|
/** @brief Wrapper function that calles mod's observer
|
|
* @param mod an instance of AxModule#
|
|
* @param evt an AISL stream event
|
|
* @return AISL_SUCCESS if event handled, AISL_IDLE if event not handled or an
|
|
* error code
|
|
*/
|
|
AislStatus
|
|
ax_module_on_event(AxModule mod, const struct aisl_evt *evt);
|
|
|
|
#endif /* !MODULE;_H */
|