libamxrt
0.4.2
Ambiorix Run Time Library
|
Functions | |
int | amxrt_el_create (void) |
Creates and initializes all needed event loop components. More... | |
int | amxrt_el_start (void) |
Starts the event loop. More... | |
int | amxrt_el_stop (void) |
Stops the event loop. More... | |
int | amxrt_el_destroy (void) |
Cleans-up the event loop components. More... | |
A default ambiorix eventloop can be created using the event loop functions in this library. The eventloop is implemented using libevent.
In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider" (that generally blocks the request until an event has arrived), then calls the relevant event handler ("dispatches the event"). The event loop is also sometimes referred to as the message dispatcher, message loop, message pump, or run loop.
The event-loop may be used in conjunction with a reactor, if the event provider follows the file interface, which can be selected or 'polled' (the Unix system call, not actual polling). The event loop almost always operates asynchronously with the message originator.
When the event loop forms the central control flow construct of a program, as it often does, it may be termed the main loop or main event loop. This title is appropriate, because such an event loop is at the highest level of control within the program.
When the function amxrt_el_create is called all ambiorix file descriptors (fds) are added to the eventloop for monitoring (for read), some system signals are added for monitoring.
The system signals that are monitored are:
Extra system signals can be enabled using amxp_syssig_enable, or a htable list can be passed to the function amxrt_enable_syssigs. This will cause that the system signals are captured and converted to ambiorix signals. To handle them connect callback functions to them using amxp_slot_connect.
By default all opened sockets (opened with amxrt_connect) are added to the event-loop as well.
The ambiorix signals will be handled in the event loop as well. Ambiorix signals can be created using amxp_signal_emit.
For more information about ambiorix signals see libamxp.
int amxrt_el_create | ( | void | ) |
Creates and initializes all needed event loop components.
It is recommended to first open all needed sockets (like connections to the used bus systems), register the data model (if any), enable all system signals that needs to be handled before creating the event loop components.
Definition at line 253 of file amxrt_el_libevent.c.
int amxrt_el_destroy | ( | void | ) |
Cleans-up the event loop components.
When the event loop is not needed anymore, all it's components must be deleted and removed. Typically this is done just before exiting the application.
Definition at line 313 of file amxrt_el_libevent.c.
int amxrt_el_start | ( | void | ) |
Starts the event loop.
This function will start the event loop. The event loop will be "waiting" for events and if one is received, it will be dispatched (correct callback functions are called).
The event loop will keep running until amxrt_el_stop is called, that is: this function will not return until the event loop is stopped.
IF the event loop fails to start the function returns immediately.
Definition at line 291 of file amxrt_el_libevent.c.
int amxrt_el_stop | ( | void | ) |
Stops the event loop.
This function will stop the event loop.
When the event loop is stopped no events will be dispatched any more.
After stopping the event loop it can be restarted by calling amxrt_el_start.
Typically an event loop is started once, and keeps on running for the complete lifetime of the application.
Definition at line 305 of file amxrt_el_libevent.c.