Flipper Zero Firmware
Loading...
Searching...
No Matches
event_loop.h File Reference

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 struct FuriMessageQueue FuriMessageQueue
 Anonymous message queue type.
 
typedef bool(* FuriEventLoopMessageQueueCallback) (FuriMessageQueue *queue, void *context)
 Callback type for message queue.
 

Enumerations

enum  FuriEventLoopEvent { FuriEventLoopEventOut , FuriEventLoopEventIn }
 Event Loop events. More...
 

Functions

FuriEventLoopfuri_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_message_queue_subscribe (FuriEventLoop *instance, FuriMessageQueue *message_queue, FuriEventLoopEvent event, FuriEventLoopMessageQueueCallback callback, void *context)
 Subscribe to message queue events.
 
void furi_event_loop_message_queue_unsubscribe (FuriEventLoop *instance, FuriMessageQueue *message_queue)
 Unsubscribe from message queue.
 

Detailed Description

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 Documentation

◆ FuriEventLoopMessageQueueCallback

typedef bool(* FuriEventLoopMessageQueueCallback) (FuriMessageQueue *queue, void *context)

Callback type for message queue.

Parameters
queueThe queue that triggered event
contextThe context that was provided on furi_event_loop_message_queue_subscribe call
Returns
true if event was processed, false if we need to delay processing

◆ FuriEventLoopPendingCallback

typedef void(* FuriEventLoopPendingCallback) (void *context)

Timer callback type for functions to be called in a deferred manner.

Parameters
[in,out]contextpointer to a user-specific object that was provided during furi_event_loop_pend_callback() call

◆ FuriEventLoopTickCallback

typedef void(* FuriEventLoopTickCallback) (void *context)

Tick callback type.

Parameters
contextThe context for callback

Enumeration Type Documentation

◆ FuriEventLoopEvent

Event Loop events.

Enumerator
FuriEventLoopEventOut 

On departure: item was retrieved from container, flag reset, etc...

FuriEventLoopEventIn 

On arrival: item was inserted into container, flag set, etc...

Function Documentation

◆ furi_event_loop_alloc()

FuriEventLoop * furi_event_loop_alloc ( void )

Allocate Event Loop instance.

Couple things to keep in mind:

  • You can have 1 event_loop per 1 thread
  • You can not use event_loop instance in the other thread
  • Do not use blocking API to query object delegated to Event Loop
Returns
The Event Loop instance

◆ furi_event_loop_free()

void furi_event_loop_free ( FuriEventLoop * instance)

Free Event Loop instance.

Parameters
instanceThe Event Loop instance

◆ furi_event_loop_message_queue_subscribe()

void furi_event_loop_message_queue_subscribe ( FuriEventLoop * instance,
FuriMessageQueue * message_queue,
FuriEventLoopEvent event,
FuriEventLoopMessageQueueCallback callback,
void * context )

Subscribe to message queue events.

Warning
you can only have one subscription for one event type.
Parameters
instanceThe Event Loop instance
message_queueThe message queue to add
[in]eventThe Event Loop event to trigger on
[in]callbackThe callback to call on event
contextThe context for callback

◆ furi_event_loop_message_queue_unsubscribe()

void furi_event_loop_message_queue_unsubscribe ( FuriEventLoop * instance,
FuriMessageQueue * message_queue )

Unsubscribe from message queue.

Parameters
instanceThe Event Loop instance
message_queueThe message queue

◆ furi_event_loop_pend_callback()

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.

Parameters
[in,out]instancepointer to the current FuriEventLoop instance
[in]callbackpointer to the callback to be executed when previous commands have been processed
[in,out]contextpointer to a user-specific object (will be passed to the callback)

◆ furi_event_loop_run()

void furi_event_loop_run ( FuriEventLoop * instance)

Continuously poll for events.

Can be stopped with furi_event_loop_stop

Parameters
instanceThe Event Loop instance

◆ furi_event_loop_stop()

void furi_event_loop_stop ( FuriEventLoop * instance)

Stop Event Loop instance.

Parameters
instanceThe Event Loop instance

◆ furi_event_loop_tick_set()

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.

Parameters
instanceThe Event Loop instance
[in]intervalThe tick interval
[in]callbackThe callback to call
contextThe context for callback