Flipper Zero Firmware
Loading...
Searching...
No Matches
event_loop_i.h
1#pragma once
2
3#include "event_loop.h"
4#include "event_loop_link_i.h"
5#include "event_loop_timer_i.h"
6#include "event_loop_tick_i.h"
7
8#include <m-list.h>
9#include <m-bptree.h>
10#include <m-i-list.h>
11
12#include "thread.h"
13
15 // Source
16 FuriEventLoop* owner;
17
18 // Tracking item
20 FuriEventLoopObject* object;
21 const FuriEventLoopContract* contract;
22
23 // Callback and context
25 void* callback_context;
26
27 // Waiting list
28 ILIST_INTERFACE(WaitingList, FuriEventLoopItem);
29};
30
31ILIST_DEF(WaitingList, FuriEventLoopItem, M_POD_OPLIST)
32
33/* Event Loop RB tree */
34#define FURI_EVENT_LOOP_TREE_RANK (4)
35
36BPTREE_DEF2( // NOLINT
37 FuriEventLoopTree,
38 FURI_EVENT_LOOP_TREE_RANK,
39 FuriEventLoopObject*, /* pointer to object we track */
40 M_PTR_OPLIST,
41 FuriEventLoopItem*, /* pointer to the FuriEventLoopItem */
42 M_PTR_OPLIST)
43
44#define M_OPL_FuriEventLoopTree_t() BPTREE_OPLIST(FuriEventLoopTree, M_POD_OPLIST)
45
46#define FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX (2)
47
48typedef enum {
49 FuriEventLoopFlagEvent = (1 << 0),
50 FuriEventLoopFlagStop = (1 << 1),
51 FuriEventLoopFlagTimer = (1 << 2),
52 FuriEventLoopFlagPending = (1 << 3),
53} FuriEventLoopFlag;
54
55#define FuriEventLoopFlagAll \
56 (FuriEventLoopFlagEvent | FuriEventLoopFlagStop | FuriEventLoopFlagTimer | \
57 FuriEventLoopFlagPending)
58
59typedef enum {
60 FuriEventLoopProcessStatusComplete,
61 FuriEventLoopProcessStatusIncomplete,
62 FuriEventLoopProcessStatusAgain,
63 FuriEventLoopProcessStatusFreeLater,
64} FuriEventLoopProcessStatus;
65
66typedef enum {
67 FuriEventLoopStateStopped,
68 FuriEventLoopStateIdle,
69 FuriEventLoopStateProcessing,
70} FuriEventLoopState;
71
72typedef struct {
74 void* context;
76
77LIST_DUAL_PUSH_DEF(PendingQueue, FuriEventLoopPendingQueueItem, M_POD_OPLIST)
78
80 // Only works if all operations are done from the same thread
81 FuriThreadId thread_id;
82
83 // Poller state
84 volatile FuriEventLoopState state;
85
86 // Event handling
87 FuriEventLoopTree_t tree;
88 WaitingList_t waiting_list;
89
90 // Active timer list
91 TimerList_t timer_list;
92 // Timer request queue
93 TimerQueue_t timer_queue;
94 // Pending callback queue
95 PendingQueue_t pending_queue;
96 // Tick event
98};
Furi Event Loop.
void(* FuriEventLoopPendingCallback)(void *context)
Timer callback type for functions to be called in a deferred manner.
Definition event_loop.h:174
FuriEventLoopEvent
Enumeration of event types, flags and masks.
Definition event_loop.h:32
bool(* FuriEventLoopEventCallback)(FuriEventLoopObject *object, void *context)
Callback type for event loop events.
Definition event_loop.h:203
Definition event_loop_link_i.h:27
Definition event_loop_i.h:79
Definition event_loop_i.h:14
Definition event_loop_i.h:72
Definition event_loop_tick_i.h:5
Furi: Furi Thread API.
void * FuriThreadId
Unique thread identifier type (used by the OS kernel).
Definition thread.h:55