TuyaOS
base_event.h
浏览该文件的文档.
1
11#ifndef __BASE_EVENT_H__
12#define __BASE_EVENT_H__
13
14#include "tuya_iot_config.h"
15#include "tuya_os_adapter.h"
16#include "tuya_base_utilities.h"
17#include "base_event_info.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
27#ifndef EVENT_NAME_MAX_LEN
28#define EVENT_NAME_MAX_LEN (16) // move to tuya_iot_config.h. use kconfig config. default is 16
29#endif
30
35#define EVENT_DESC_MAX_LEN (32)
36
41typedef BYTE_T SUBSCRIBE_TYPE_E;
42#define SUBSCRIBE_TYPE_NORMAL 0 // normal type, dispatch by the subscribe order, remove when unsubscribe
43#define SUBSCRIBE_TYPE_EMERGENCY 1 // emergency type, dispatch first, remove when unsubscribe
44#define SUBSCRIBE_TYPE_ONETIME 2 // one time type, dispatch by the subscribe order, remove after first time dispath
45
50typedef struct {
51 int type; // the data type
52 int len; // the data length
53 char value[0]; // the data content
55
60typedef int (*event_subscribe_cb)(void *data);
61
66typedef struct {
67 char name[EVENT_NAME_MAX_LEN + 1]; // name, used to record the the event info
68 char desc[EVENT_DESC_MAX_LEN + 1]; // description, used to record the subscribe info
69 SUBSCRIBE_TYPE_E type; // the subscribe type
70 event_subscribe_cb cb; // the subscribe callback function
71 struct tuya_list_head node; // list node, used to attch to the event node
73
78typedef struct {
79 MUTEX_HANDLE mutex; // mutex, protection the event publish and subscribe
80
81 char name[EVENT_NAME_MAX_LEN + 1]; // name, the event name
82 struct tuya_list_head node; // list node, used to attach to the event manage module
83 struct tuya_list_head subscribe_root; // subscibe root, used to manage the subscriber
85
90typedef struct {
91 int inited;
92 MUTEX_HANDLE mutex; // mutex, used to protection event manage node
93 int event_cnt; // current event number
94 struct tuya_list_head event_root; // event root, used to manage the event
95 struct tuya_list_head free_subscribe_root; // free subscriber list, used to manage the subscribe which not found the event
97
104
112int ty_publish_event(const char* name, void *data);
113
123int ty_subscribe_event(const char *name, const char *desc, const event_subscribe_cb cb, SUBSCRIBE_TYPE_E type);
124
133int ty_unsubscribe_event(const char *name, const char *desc, event_subscribe_cb cb);
134
135#ifdef __cplusplus
136}
137#endif /* __cplusplus */
138
139#endif /*__BASE_EVENT_H__ */
140
141
int(* event_subscribe_cb)(void *data)
event subscribe callback function type
Definition: base_event.h:60
int ty_event_init(void)
event initialization
int ty_publish_event(const char *name, void *data)
: publish event
BYTE_T SUBSCRIBE_TYPE_E
subscriber type
Definition: base_event.h:41
#define EVENT_DESC_MAX_LEN
max length of event description
Definition: base_event.h:35
int ty_unsubscribe_event(const char *name, const char *desc, event_subscribe_cb cb)
: unsubscribe event
int ty_subscribe_event(const char *name, const char *desc, const event_subscribe_cb cb, SUBSCRIBE_TYPE_E type)
: subscribe event
#define EVENT_NAME_MAX_LEN
max length of event name
Definition: base_event.h:28
tuya simple event module
the event manage node
Definition: base_event.h:90
the event node
Definition: base_event.h:78
the event dispatch raw data
Definition: base_event.h:50
the subscirbe node
Definition: base_event.h:66
tuya utilities module
Common process - Initialization