Skip to content

Message Queue

Derek Jamison edited this page Apr 29, 2023 · 12 revisions

The FuriMessageQueue is typically used in an application for communicating events.

typedef enum {
    MyEventTypeKey,
} MyEventType;

typedef struct {
    MyEventType type; // The reason for this event.
    InputEvent input; // This data is specific to keypress data.
    // TODO: Add additional properties that are helpful for your events.
} MyEvent;

Allocate a queue.

FuriMessageQueue* queue = furi_message_queue_alloc(8, sizeof(MyEvent));

Dequeue messages in a loop until you get done event.

MyEvent event;
bool keep_processing = true;
while (keep_processing) {
   if(furi_message_queue_get(queue, &event, FuriWaitForever) == FuriStatusOk) {
      // Process the event, set keep_processing to false if this is the done event.
   }
}

Free the queue when your application is exiting.

furi_message_queue_free(queue);
Clone this wiki locally