Documentation
Includes
tuya_iot_config.h
#include "tuya_iot_config.h"
tuya_os_adapter.h
#include "tuya_os_adapter.h"
tuya_base_utilities.h
#include "tuya_base_utilities.h"
base_event_info.h
#include "base_event_info.h"
Macros
Marco __BASE_EVENT_H__
#define __BASE_EVENT_H__
Marco EVENT_NAME_MAX_LEN
#define EVENT_NAME_MAX_LEN (16) // move to tuya_iot_config.h. use kconfig config. default is 16
Marco EVENT_DESC_MAX_LEN
#define EVENT_DESC_MAX_LEN (32)
Functions
Func ty_event_init
int ty_event_init(void);
Func ty_publish_event
int ty_publish_event(const char* name, void *data);
Func ty_subscribe_event
int ty_subscribe_event(const char *name, const char *desc, const event_subscribe_cb cb, SUBSCRIBE_TYPE_E type);
Func ty_unsubscribe_event
int ty_unsubscribe_event(const char *name, const char *desc, event_subscribe_cb cb);
Vars
Consts
Types
Typedefs
Typedef SUBSCRIBE_TYPE_E
typedef BYTE_T SUBSCRIBE_TYPE_E;
#define SUBSCRIBE_TYPE_NORMAL 0 // normal type, dispatch by the subscribe order, remove when unsubscribe
#define SUBSCRIBE_TYPE_EMERGENCY 1 // emergency type, dispatch first, remove when unsubscribe
#define SUBSCRIBE_TYPE_ONETIME 2 // one time type, dispatch by the subscribe order, remove after first time dispath
Typedef event_raw_data_t;
typedef struct {
int type; // the data type
int len; // the data length
char value[0]; // the data content
}event_raw_data_t;
Typedef event_subscribe_cb
typedef int (*event_subscribe_cb)(void *data);
Typedef subscribe_node_t;
typedef struct {
char name[EVENT_NAME_MAX_LEN+1]; // name, used to record the the event info
char desc[EVENT_DESC_MAX_LEN+1]; // description, used to record the subscribe info
SUBSCRIBE_TYPE_E type; // the subscribe type
event_subscribe_cb cb; // the subscribe callback function
struct tuya_list_head node; // list node, used to attch to the event node
}subscribe_node_t;
Typedef event_node_t;
typedef struct {
MUTEX_HANDLE mutex; // mutex, protection the event publish and subscribe
char name[EVENT_NAME_MAX_LEN+1]; // name, the event name
struct tuya_list_head node; // list node, used to attach to the event manage module
struct tuya_list_head subscribe_root; // subscibe root, used to manage the subscriber
}event_node_t;
Typedef event_manage_t;
typedef struct {
int inited;
MUTEX_HANDLE mutex; // mutex, used to protection event manage node
int event_cnt; // current event number
struct tuya_list_head event_root; // event root, used to manage the event
struct tuya_list_head free_subscribe_root; // free subscriber list, used to manage the subscribe which not found the event
}event_manage_t;