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
19 const FuriEventLoopContract* contract;
20 void* object;
22
23 // Callback and context
25 void* callback_context;
26
27 // Waiting list
28 ILIST_INTERFACE(WaitingList, struct 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 void*, /* 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} FuriEventLoopProcessStatus;
64
65typedef enum {
66 FuriEventLoopStateStopped,
67 FuriEventLoopStateIdle,
68 FuriEventLoopStateProcessing,
69} FuriEventLoopState;
70
71typedef struct {
73 void* context;
75
76LIST_DUAL_PUSH_DEF(PendingQueue, FuriEventLoopPendingQueueItem, M_POD_OPLIST)
77
79 // Only works if all operations are done from the same thread
80 FuriThreadId thread_id;
81
82 // Poller state
83 volatile FuriEventLoopState state;
84
85 // Event handling
86 FuriEventLoopTree_t tree;
87 WaitingList_t waiting_list;
88
89 // Active timer list
90 TimerList_t timer_list;
91 // Timer request queue
92 TimerQueue_t timer_queue;
93 // Pending callback queue
94 PendingQueue_t pending_queue;
95 // Tick event
97};
Furi Event Loop.
void(* FuriEventLoopPendingCallback)(void *context)
Timer callback type for functions to be called in a deferred manner.
Definition event_loop.h:101
FuriEventLoopEvent
Event Loop events.
Definition event_loop.h:24
bool(* FuriEventLoopMessageQueueCallback)(FuriMessageQueue *queue, void *context)
Callback type for message queue.
Definition event_loop.h:132
Definition event_loop_link_i.h:26
Definition event_loop_i.h:78
Definition event_loop_i.h:14
Definition event_loop_i.h:71
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