All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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#include "event_loop_thread_flag_interface.h"
8
9#include <m-list.h>
10#include <m-bptree.h>
11#include <m-i-list.h>
12
13#include "thread.h"
14#include "thread_i.h"
15
17 // Source
18 FuriEventLoop* owner;
19
20 // Tracking item
22 FuriEventLoopObject* object;
23 const FuriEventLoopContract* contract;
24
25 // Callback and context
27 void* callback_context;
28
29 // Waiting list
30 ILIST_INTERFACE(WaitingList, FuriEventLoopItem);
31};
32
33ILIST_DEF(WaitingList, FuriEventLoopItem, M_POD_OPLIST)
34
35/* Event Loop RB tree */
36#define FURI_EVENT_LOOP_TREE_RANK (4)
37
38BPTREE_DEF2( // NOLINT
39 FuriEventLoopTree,
40 FURI_EVENT_LOOP_TREE_RANK,
41 FuriEventLoopObject*, /* pointer to object we track */
42 M_PTR_OPLIST,
43 FuriEventLoopItem*, /* pointer to the FuriEventLoopItem */
44 M_PTR_OPLIST)
45
46#define M_OPL_FuriEventLoopTree_t() BPTREE_OPLIST(FuriEventLoopTree, M_POD_OPLIST)
47
48#define FURI_EVENT_LOOP_FLAG_NOTIFY_INDEX (2)
49
50typedef enum {
51 FuriEventLoopFlagEvent = (1 << 0),
52 FuriEventLoopFlagStop = (1 << 1),
53 FuriEventLoopFlagTimer = (1 << 2),
54 FuriEventLoopFlagPending = (1 << 3),
55 FuriEventLoopFlagThreadFlag = (1 << 4),
56} FuriEventLoopFlag;
57
58#define FuriEventLoopFlagAll \
59 (FuriEventLoopFlagEvent | FuriEventLoopFlagStop | FuriEventLoopFlagTimer | \
60 FuriEventLoopFlagPending | FuriEventLoopFlagThreadFlag)
61
62typedef enum {
63 FuriEventLoopProcessStatusComplete,
64 FuriEventLoopProcessStatusIncomplete,
65 FuriEventLoopProcessStatusFreeLater,
66} FuriEventLoopProcessStatus;
67
68typedef enum {
69 FuriEventLoopStateStopped,
70 FuriEventLoopStateRunning,
71} FuriEventLoopState;
72
73typedef struct {
75 void* context;
77
78LIST_DUAL_PUSH_DEF(PendingQueue, FuriEventLoopPendingQueueItem, M_POD_OPLIST)
79
81 // Only works if all operations are done from the same thread
82 FuriThreadId thread_id;
83
84 // Poller state
85 volatile FuriEventLoopState state;
86 volatile FuriEventLoopItem* current_item;
87
88 // Event handling
89 FuriEventLoopTree_t tree;
90 WaitingList_t waiting_list;
91
92 // Active timer list
93 TimerList_t timer_list;
94 // Timer request queue
95 TimerQueue_t timer_queue;
96 // Pending callback queue
97 PendingQueue_t pending_queue;
98 // Tick event
100
101 // Thread flags callback
102 bool are_thread_flags_subscribed;
103 FuriEventLoopThreadFlagsCallback thread_flags_callback;
104 void* thread_flags_callback_context;
105};
Furi Event Loop.
void(* FuriEventLoopPendingCallback)(void *context)
Timer callback type for functions to be called in a deferred manner.
Definition event_loop.h:177
FuriEventLoopEvent
Enumeration of event types, flags and masks.
Definition event_loop.h:35
void(* FuriEventLoopEventCallback)(FuriEventLoopObject *object, void *context)
Callback type for event loop events.
Definition event_loop.h:204
void(* FuriEventLoopThreadFlagsCallback)(void *context)
Callback type for event loop thread flag events.
Definition event_loop.h:210
Definition event_loop_link_i.h:27
Definition event_loop_i.h:80
Definition event_loop_i.h:16
Definition event_loop_i.h:73
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:56