Furi Event Loop. More...
#include "base.h"
Go to the source code of this file.
Typedefs | |
typedef struct FuriEventLoop | FuriEventLoop |
Anonymous message queue type. | |
typedef void(* | FuriEventLoopTickCallback) (void *context) |
Tick callback type. | |
typedef void(* | FuriEventLoopPendingCallback) (void *context) |
Timer callback type for functions to be called in a deferred manner. | |
typedef void | FuriEventLoopObject |
typedef void(* | FuriEventLoopEventCallback) (FuriEventLoopObject *object, void *context) |
Callback type for event loop events. | |
typedef struct FuriMessageQueue | FuriMessageQueue |
Opaque message queue type. | |
typedef struct FuriStreamBuffer | FuriStreamBuffer |
Opaque stream buffer type. | |
typedef struct FuriSemaphore | FuriSemaphore |
Opaque semaphore type. | |
typedef struct FuriMutex | FuriMutex |
Opaque mutex type. | |
Enumerations | |
enum | FuriEventLoopEvent { FuriEventLoopEventIn = 0x00000001U , FuriEventLoopEventOut = 0x00000002U , FuriEventLoopEventMask = 0x00000003U , FuriEventLoopEventFlagEdge = 0x00000004U , FuriEventLoopEventFlagOnce = 0x00000008U , FuriEventLoopEventFlagMask = 0xFFFFFFFCU , FuriEventLoopEventReserved = UINT32_MAX } |
Enumeration of event types, flags and masks. More... | |
Functions | |
FuriEventLoop * | furi_event_loop_alloc (void) |
Allocate Event Loop instance. | |
void | furi_event_loop_free (FuriEventLoop *instance) |
Free Event Loop instance. | |
void | furi_event_loop_run (FuriEventLoop *instance) |
Continuously poll for events. | |
void | furi_event_loop_stop (FuriEventLoop *instance) |
Stop Event Loop instance. | |
void | furi_event_loop_tick_set (FuriEventLoop *instance, uint32_t interval, FuriEventLoopTickCallback callback, void *context) |
Set Event Loop tick callback. | |
void | furi_event_loop_pend_callback (FuriEventLoop *instance, FuriEventLoopPendingCallback callback, void *context) |
Call a function when all preceding timer commands are processed. | |
void | furi_event_loop_subscribe_event_flag (FuriEventLoop *instance, FuriEventFlag *event_flag, FuriEventLoopEvent event, FuriEventLoopEventCallback callback, void *context) |
Subscribe to event flag events. | |
void | furi_event_loop_subscribe_message_queue (FuriEventLoop *instance, FuriMessageQueue *message_queue, FuriEventLoopEvent event, FuriEventLoopEventCallback callback, void *context) |
Subscribe to message queue events. | |
void | furi_event_loop_subscribe_stream_buffer (FuriEventLoop *instance, FuriStreamBuffer *stream_buffer, FuriEventLoopEvent event, FuriEventLoopEventCallback callback, void *context) |
Subscribe to stream buffer events. | |
void | furi_event_loop_subscribe_semaphore (FuriEventLoop *instance, FuriSemaphore *semaphore, FuriEventLoopEvent event, FuriEventLoopEventCallback callback, void *context) |
Subscribe to semaphore events. | |
void | furi_event_loop_subscribe_mutex (FuriEventLoop *instance, FuriMutex *mutex, FuriEventLoopEvent event, FuriEventLoopEventCallback callback, void *context) |
Subscribe to mutex events. | |
void | furi_event_loop_unsubscribe (FuriEventLoop *instance, FuriEventLoopObject *object) |
Unsubscribe from events (common) | |
bool | furi_event_loop_is_subscribed (FuriEventLoop *instance, FuriEventLoopObject *object) |
Checks if the loop is subscribed to an object of any kind. | |
Furi Event Loop.
This module is designed to handle application event loop in fully asynchronous, reactive nature. On the low level this modules is inspired by epoll/kqueue concept, on the high level by asyncio event loop. This module is trying to best fit into Furi OS, so we don't provide any compatibility with other event driven APIs. But programming concepts are the same, except some runtime limitations from our side.
typedef void(* FuriEventLoopEventCallback) (FuriEventLoopObject *object, void *context) |
Callback type for event loop events.
object | The object that triggered the event |
context | The context that was provided upon subscription |
typedef void(* FuriEventLoopPendingCallback) (void *context) |
Timer callback type for functions to be called in a deferred manner.
[in,out] | context | pointer to a user-specific object that was provided during furi_event_loop_pend_callback() call |
typedef void(* FuriEventLoopTickCallback) (void *context) |
Tick callback type.
context | The context for callback |
enum FuriEventLoopEvent |
Enumeration of event types, flags and masks.
Only one event direction (In or Out) can be used per subscription. An object can have no more than one subscription for each direction.
Additional flags that modify the behaviour can be set using the bitwise OR operation (see flag description).
FuriEventLoop * furi_event_loop_alloc | ( | void | ) |
Allocate Event Loop instance.
Couple things to keep in mind:
void furi_event_loop_free | ( | FuriEventLoop * | instance | ) |
Free Event Loop instance.
instance | The Event Loop instance |
bool furi_event_loop_is_subscribed | ( | FuriEventLoop * | instance, |
FuriEventLoopObject * | object ) |
Checks if the loop is subscribed to an object of any kind.
instance | Event Loop instance |
object | Object to check |
void furi_event_loop_pend_callback | ( | FuriEventLoop * | instance, |
FuriEventLoopPendingCallback | callback, | ||
void * | context ) |
Call a function when all preceding timer commands are processed.
This function may be useful to call another function when the event loop has been started.
[in,out] | instance | pointer to the current FuriEventLoop instance |
[in] | callback | pointer to the callback to be executed when previous commands have been processed |
[in,out] | context | pointer to a user-specific object (will be passed to the callback) |
void furi_event_loop_run | ( | FuriEventLoop * | instance | ) |
Continuously poll for events.
Can be stopped with furi_event_loop_stop
instance | The Event Loop instance |
void furi_event_loop_stop | ( | FuriEventLoop * | instance | ) |
Stop Event Loop instance.
instance | The Event Loop instance |
void furi_event_loop_subscribe_event_flag | ( | FuriEventLoop * | instance, |
FuriEventFlag * | event_flag, | ||
FuriEventLoopEvent | event, | ||
FuriEventLoopEventCallback | callback, | ||
void * | context ) |
Subscribe to event flag events.
instance | The Event Loop instance | |
event_flag | The event flag to add | |
[in] | event | The Event Loop event to trigger on |
[in] | callback | The callback to call on event |
context | The context for callback |
Subscribe to event flag events.
void furi_event_loop_subscribe_message_queue | ( | FuriEventLoop * | instance, |
FuriMessageQueue * | message_queue, | ||
FuriEventLoopEvent | event, | ||
FuriEventLoopEventCallback | callback, | ||
void * | context ) |
Subscribe to message queue events.
instance | The Event Loop instance | |
message_queue | The message queue to add | |
[in] | event | The Event Loop event to trigger on |
[in] | callback | The callback to call on event |
context | The context for callback |
void furi_event_loop_subscribe_mutex | ( | FuriEventLoop * | instance, |
FuriMutex * | mutex, | ||
FuriEventLoopEvent | event, | ||
FuriEventLoopEventCallback | callback, | ||
void * | context ) |
Subscribe to mutex events.
instance | The Event Loop instance | |
mutex | The mutex to add | |
[in] | event | The Event Loop event to trigger on |
[in] | callback | The callback to call on event |
context | The context for callback |
void furi_event_loop_subscribe_semaphore | ( | FuriEventLoop * | instance, |
FuriSemaphore * | semaphore, | ||
FuriEventLoopEvent | event, | ||
FuriEventLoopEventCallback | callback, | ||
void * | context ) |
Subscribe to semaphore events.
instance | The Event Loop instance | |
semaphore | The semaphore to add | |
[in] | event | The Event Loop event to trigger on |
[in] | callback | The callback to call on event |
context | The context for callback |
void furi_event_loop_subscribe_stream_buffer | ( | FuriEventLoop * | instance, |
FuriStreamBuffer * | stream_buffer, | ||
FuriEventLoopEvent | event, | ||
FuriEventLoopEventCallback | callback, | ||
void * | context ) |
Subscribe to stream buffer events.
instance | The Event Loop instance | |
stream_buffer | The stream buffer to add | |
[in] | event | The Event Loop event to trigger on |
[in] | callback | The callback to call on event |
context | The context for callback |
void furi_event_loop_tick_set | ( | FuriEventLoop * | instance, |
uint32_t | interval, | ||
FuriEventLoopTickCallback | callback, | ||
void * | context ) |
Set Event Loop tick callback.
Tick callback is called periodically after specified inactivity time. It acts like a low-priority timer: it will only fire if there is time left after processing the synchronization primitives and the regular timers. Therefore, it is not monotonic: ticks will be skipped if the event loop is busy.
instance | The Event Loop instance | |
[in] | interval | The tick interval |
[in] | callback | The callback to call |
context | The context for callback |
void furi_event_loop_unsubscribe | ( | FuriEventLoop * | instance, |
FuriEventLoopObject * | object ) |
Unsubscribe from events (common)
instance | The Event Loop instance |
object | The object to unsubscribe from |
Unsubscribe from events (common)