TuyaOS
base_event.h
浏览该文件的文档.
1
11#ifndef __BASE_EVENT_H__
12#define __BASE_EVENT_H__
13
14#include "tuya_iot_config.h"
15
16#include "tuya_base_utilities.h"
17#include "base_event_info.h"
18#include "tal_mutex.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
28#ifndef EVENT_NAME_MAX_LEN
29#define EVENT_NAME_MAX_LEN (16) // move to tuya_iot_config.h. use kconfig config. default is 16
30#endif
31
36#define EVENT_DESC_MAX_LEN (32)
37
42typedef BYTE_T SUBSCRIBE_TYPE_E;
43#define SUBSCRIBE_TYPE_NORMAL 0 // normal type, dispatch by the subscribe order, remove when unsubscribe
44#define SUBSCRIBE_TYPE_EMERGENCY 1 // emergency type, dispatch first, remove when unsubscribe
45#define SUBSCRIBE_TYPE_ONETIME 2 // one time type, dispatch by the subscribe order, remove after first time dispath
46
51typedef struct {
52 INT_T type; // the data type
53 INT_T len; // the data length
54 CHAR_T value[0]; // the data content
56
61typedef INT_T(*EVENT_SUBSCRIBE_CB)(VOID_T *data);
62
67typedef struct {
68 CHAR_T name[EVENT_NAME_MAX_LEN + 1]; // name, used to record the the event info
69 CHAR_T desc[EVENT_DESC_MAX_LEN + 1]; // description, used to record the subscribe info
70 SUBSCRIBE_TYPE_E type; // the subscribe type
71 EVENT_SUBSCRIBE_CB cb; // the subscribe callback function
72 struct tuya_list_head node; // list node, used to attch to the event node
74
79typedef struct {
80 MUTEX_HANDLE mutex; // mutex, protection the event publish and subscribe
81
82 CHAR_T name[EVENT_NAME_MAX_LEN + 1]; // name, the event name
83 struct tuya_list_head node; // list node, used to attach to the event manage module
84 struct tuya_list_head subscribe_root; // subscibe root, used to manage the subscriber
85
86 EVENT_SUBSCRIBE_CB last_cb; //used to debug which cb is blocked
88
93typedef struct {
94 INT_T inited;
95 MUTEX_HANDLE mutex; // mutex, used to protection event manage node
96 INT_T event_cnt; // current event number
97 struct tuya_list_head event_root; // event root, used to manage the event
98 struct tuya_list_head free_subscribe_root; // free subscriber list, used to manage the subscribe which not found the event
100
106OPERATE_RET ty_event_init(VOID);
107
115OPERATE_RET ty_publish_event(CONST CHAR_T* name, VOID_T *data);
116
126OPERATE_RET ty_subscribe_event(CONST CHAR_T *name, CONST CHAR_T *desc, CONST EVENT_SUBSCRIBE_CB cb, SUBSCRIBE_TYPE_E type);
127
136OPERATE_RET ty_unsubscribe_event(CONST CHAR_T *name, CONST CHAR_T *desc, EVENT_SUBSCRIBE_CB cb);
137
138#ifdef __cplusplus
139}
140#endif /* __cplusplus */
141
142#endif /*__BASE_EVENT_H__ */
143
144
OPERATE_RET ty_subscribe_event(CONST CHAR_T *name, CONST CHAR_T *desc, CONST EVENT_SUBSCRIBE_CB cb, SUBSCRIBE_TYPE_E type)
: subscribe event
OPERATE_RET ty_event_init(VOID)
event initialization
BYTE_T SUBSCRIBE_TYPE_E
subscriber type
Definition: base_event.h:42
#define EVENT_DESC_MAX_LEN
max length of event description
Definition: base_event.h:36
OPERATE_RET ty_publish_event(CONST CHAR_T *name, VOID_T *data)
: publish event
OPERATE_RET ty_unsubscribe_event(CONST CHAR_T *name, CONST CHAR_T *desc, EVENT_SUBSCRIBE_CB cb)
: unsubscribe event
INT_T(* EVENT_SUBSCRIBE_CB)(VOID_T *data)
event subscribe callback function type
Definition: base_event.h:61
#define EVENT_NAME_MAX_LEN
max length of event name
Definition: base_event.h:29
tuya simple event module
the event manage node
Definition: base_event.h:93
the event node
Definition: base_event.h:79
the event dispatch raw data
Definition: base_event.h:51
the subscirbe node
Definition: base_event.h:67
Common process - adapter the mutex api provide by OS
tuya utilities module