事件管理系统,允许基于事件 ID 注册和触发回调函数。 Event management system that allows registration and triggering of callbacks based on event IDs.
More...
#include <event.hpp>
|
struct | Block |
| 用于存储事件回调的数据结构。 Data structure for storing event callbacks. More...
|
|
|
| Event () |
| 构造函数,初始化用于存储事件的红黑树。 Constructs an Event object with an empty red-black tree for event storage.
|
|
void | Register (uint32_t event, const Callback &cb) |
| 为特定事件注册回调函数。 Registers a callback function for a specific event.
|
|
void | Active (uint32_t event) |
| 触发与特定事件关联的所有回调函数(非中断上下文)。 Triggers all callbacks associated with a specific event (non-interrupt context).
|
|
void | ActiveFromCallback (CallbackList list, uint32_t event) |
| 从回调函数中触发与特定事件关联的所有回调函数。 Triggers all callbacks associated with a specific event (interrupt context).
|
|
CallbackList | GetList (uint32_t event) |
| 获取指定事件的回调链表指针(必须在非中断上下文中调用)。 Returns the callback list pointer for the given event (must be called outside ISR).
|
|
void | Bind (Event &sources, uint32_t source_event, uint32_t target_event) |
| 将源事件绑定到当前事件实例中的目标事件。 Binds an event from a source Event instance to a target event in the current instance.
|
|
事件管理系统,允许基于事件 ID 注册和触发回调函数。 Event management system that allows registration and triggering of callbacks based on event IDs.
Definition at line 17 of file event.hpp.
◆ Callback
◆ CallbackList
回调链表指针类型,用于事件触发时从 ISR 中安全调用。 Pointer to the callback list, safe to use in ISR after acquired in non-interrupt context.
Definition at line 27 of file event.hpp.
◆ Event()
构造函数,初始化用于存储事件的红黑树。 Constructs an Event object with an empty red-black tree for event storage.
Definition at line 7 of file event.cpp.
8 :
rbt_([](
const uint32_t &a,
const uint32_t &b)
9 { return static_cast<int>(a) - static_cast<int>(b); })
10{
11}
◆ Active()
void Event::Active |
( |
uint32_t | event | ) |
|
触发与特定事件关联的所有回调函数(非中断上下文)。 Triggers all callbacks associated with a specific event (non-interrupt context).
- Parameters
-
event | 要激活的事件 ID。 The event ID to activate. |
Definition at line 30 of file event.cpp.
31{
33 if (!list)
34 {
35 return;
36 }
37
38 auto foreach_fun = [=](Block &block)
39 {
40 block.cb.Run(false, event);
41 return ErrorCode::OK;
42 };
43
45}
链表实现,用于存储和管理数据节点。 A linked list implementation for storing and managing data nodes.
ErrorCode Foreach(Func func)
遍历链表中的每个节点,并应用回调函数。 Iterates over each node in the list and applies a callback function.
Node< Data > * Search(const Key &key)
搜索红黑树中的节点 (Search for a node in the Red-Black Tree).
用于存储事件回调的数据结构。 Data structure for storing event callbacks.
◆ ActiveFromCallback()
void Event::ActiveFromCallback |
( |
CallbackList | list, |
|
|
uint32_t | event ) |
从回调函数中触发与特定事件关联的所有回调函数。 Triggers all callbacks associated with a specific event (interrupt context).
- Parameters
-
list | 在非回调函数中获取的事件回调链表指针。 The event callback list pointer obtained from the non-callback function. |
event | 要激活的事件 ID。 The event ID to activate. |
Definition at line 47 of file event.cpp.
48{
49 if (!list)
50 {
51 return;
52 }
53
54 auto foreach_fun = [=](Block &block)
55 {
56 block.cb.Run(true, event);
57 return ErrorCode::OK;
58 };
59
60 list->Foreach<Block>(foreach_fun);
61}
◆ Bind()
void Event::Bind |
( |
Event & | sources, |
|
|
uint32_t | source_event, |
|
|
uint32_t | target_event ) |
将源事件绑定到当前事件实例中的目标事件。 Binds an event from a source Event instance to a target event in the current instance.
- Parameters
-
sources | 包含原始事件的源 Event 实例。 The source Event instance. |
source_event | 源事件实例中的事件 ID。 The source event ID. |
target_event | 当前实例中的目标事件 ID。 The target event ID in this instance. |
Definition at line 75 of file event.cpp.
76{
77 struct BindBlock
78 {
80 uint32_t event;
81 };
82
83 auto block = new BindBlock{this, target_event};
84
85 auto bind_fun = [](bool in_isr, BindBlock *block, uint32_t event)
86 {
87 UNUSED(event);
88 UNUSED(in_isr);
89 block->target->ActiveFromCallback(block->target->GetList(block->event), block->event);
90 };
91
93
95}
static Callback Create(FunType fun, ArgType arg)
事件管理系统,允许基于事件 ID 注册和触发回调函数。 Event management system that allows registration and triggering of callba...
void Register(uint32_t event, const Callback &cb)
为特定事件注册回调函数。 Registers a callback function for a specific event.
◆ GetList()
获取指定事件的回调链表指针(必须在非中断上下文中调用)。 Returns the callback list pointer for the given event (must be called outside ISR).
- Parameters
-
event | 要查询的事件 ID。 The event ID to search. |
- Returns
- 回调链表指针,如果未注册则主动创建。 The callback list pointer, if not registered, it is actively created.
Definition at line 63 of file event.cpp.
64{
66 if (!node)
67 {
70 node = list;
71 }
72 return &node->data_;
73}
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
void Insert(BaseNode &node, KeyType &&key)
在树中插入新节点 (Insert a new node into the tree).
◆ Register()
void Event::Register |
( |
uint32_t | event, |
|
|
const Callback & | cb ) |
为特定事件注册回调函数。 Registers a callback function for a specific event.
- Parameters
-
event | 要注册回调的事件 ID。 The event ID to register the callback for. |
cb | 事件触发时执行的回调函数。 The callback function to be executed when the event occurs. |
Definition at line 13 of file event.cpp.
14{
16
17 if (!list)
18 {
21 }
22
24
25 node->
data_.event = event;
27 list->data_.Add(*node);
28}
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...
Data data_
存储的数据。 The stored data.
◆ rbt_
RBTree<uint32_t> LibXR::Event::rbt_ |
|
private |
用于管理已注册事件的红黑树。 Red-black tree for managing registered events.
Definition at line 96 of file event.hpp.
The documentation for this class was generated from the following files: