Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Fields
sol_mainloop_source_type Struct Reference

Structure representing the type of a source of mainloop events. More...

#include <sol-mainloop.h>

Data Fields

uint16_t api_version
 must match SOL_MAINLOOP_SOURCE_TYPE_API_VERSION at runtime. More...
 
bool(* check )(void *data)
 Function to be called to check if there are events to be dispatched. More...
 
void(* dispatch )(void *data)
 Function to be called during main loop iterations if prepare() or check() returns true. More...
 
void(* dispose )(void *data)
 Function to be called when the source is deleted. More...
 
bool(* get_next_timeout )(void *data, struct timespec *timeout)
 Function to be called to query the next timeout for the next event in this source. More...
 
bool(* prepare )(void *data)
 Function to be called to prepare to check for events. More...
 

Detailed Description

Structure representing the type of a source of mainloop events.

Field Documentation

uint16_t sol_mainloop_source_type::api_version

must match SOL_MAINLOOP_SOURCE_TYPE_API_VERSION at runtime.

bool(* sol_mainloop_source_type::check)(void *data)

Function to be called to check if there are events to be dispatched.

If returns true, then there are events to be dispatched and dispatch() should be called.

A source can implement the traditional main loop primitives:

  • idler: return true.
  • timeout: return true if timeouts expired.
  • fd: return true if fds are ready.

Must not be NULL.

void(* sol_mainloop_source_type::dispatch)(void *data)

Function to be called during main loop iterations if prepare() or check() returns true.

Must not be NULL.

void(* sol_mainloop_source_type::dispose)(void *data)

Function to be called when the source is deleted.

It is called when the source is explicitly deleted using sol_mainloop_del_source() or when sol_shutdown() is called.

May be NULL.

bool(* sol_mainloop_source_type::get_next_timeout)(void *data, struct timespec *timeout)

Function to be called to query the next timeout for the next event in this source.

If returns true, then timeout must be set to the next timeout to expire in this source. Soletta's main loop will gather all timeouts from external sources and internal (registered with sol_timeout_add()) and will schedule a timer interruption to the one that happens sooner, sleeping until then if there are no known events such as in prepare(), or idlers registered with sol_idle_add().

If returns false, then may sleep forever as no events are expected.

A source can implement the traditional main loop primitives:

  • idler: return false.
  • timeout: return true and set timeout.
  • fd: return false.

May be NULL, in this case return false is assumed.

bool(* sol_mainloop_source_type::prepare)(void *data)

Function to be called to prepare to check for events.

This function will be called before Soletta's main loop query for its own events. In Linux/POSIX, it will be called before poll(). A source may convert its internal monitored resources to Soletta's at this moment, such as issuing sol_timeout_add() or sol_fd_add().

If returns true, then there are events to be dispatched right away. This will have dispatch() to be called, even if check() returns false. This will not let the main loop to sleep or block while it wait for events, as the source's events must be dispatched as soon as possible.

A source can implement the traditional main loop primitives:

  • idler: return true.
  • timeout: return false and implement get_next_timeout().
  • fd: return false.

May be NULL, in this case return false is assumed.


The documentation for this struct was generated from the following file: