Event handling operations.
More...
#include <event.h>
#include <logging.h>
#include <scheduler.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Go to the source code of this file.
|
event_loop_t * | event_loop_get () |
|
int | event_loop_put (event_loop_t *event_loop, event_t *e) |
|
event_t * | event_loop_take (event_loop_t *event_loop) |
|
event_t * | event_init (void(*func)(scheduler_t *, void *), void *arg, char *name, char *source_name, uint16_t source_line) |
|
void | event_destroy (event_t *e) |
| Free any memory associated with an event. More...
|
|
void | event_loop_destroy () |
| Frees any memory associated with the event queue. More...
|
|
void | event_signal_ext (void *func, void *args, char *name, char *s_name, uint16_t s_line) |
|
int | event_loop_enter (scheduler_t *scheduler, void(*update_call)(scheduler_t *), void(*signal_call)(scheduler_t *)) |
| Enters the event loop. More...
|
|
void | event_loop_terminate () |
| Stops the event loop from executing. More...
|
|
Event handling operations.
Definition in file event.c.
◆ event_destroy()
Free any memory associated with an event.
- Parameters
-
Definition at line 165 of file event.c.
◆ event_init()
event_t* event_init |
( |
void(*)(scheduler_t *, void *) |
func, |
|
|
void * |
arg, |
|
|
char * |
name, |
|
|
char * |
source_name, |
|
|
uint16_t |
source_line |
|
) |
| |
Allocates and initializes a new event. An event consists of a function and the arguments for that function. The arguments for the function should be taken in by the function as a sinlge void* and then parsed inside the function. This interface provides a simple and generic interface for getting a function to be called within the main thread.
- Parameters
-
func | the function to call when the event is executed |
arg | the arguements for the function. |
name | name of the event |
source_name | source file name creating the event |
source_line | line number of the source file creating the event |
- Returns
- the new event wrapper for the function and arguments
Definition at line 147 of file event.c.
◆ event_loop_destroy()
void event_loop_destroy |
( |
| ) |
|
Frees any memory associated with the event queue.
Any events that are in the queue when this gets called will be freed as well.
Definition at line 179 of file event.c.
◆ event_loop_enter()
Enters the event loop.
This function will not return until another threads chooses to terminate the event loop. Essentially this function should not return until the program is ready to exit. There should also only be one thread working on this part of the event loop.
- Parameters
-
scheduler | scheduler reference to to be notified |
update_call | a function that is called every time an event is processed |
signal_call | a function that is called once a second |
- Returns
- this function will return an error code: 0x0: successful execution 0x1: attempt to enter a loop that is occupied
Definition at line 221 of file event.c.
◆ event_loop_get()
There is only one instance of an event loop in any program. This function will control access to that event loop. If the event loop hasn't been created yet, it will create and return the event loop. If it has been created, this function will simple return it to the caller. This first call to this function should be made from the thread that will be running the event loop.
This is to prevent confusion on if the event loop has been created.
- Returns
Definition at line 48 of file event.c.
◆ event_loop_put()
puts a new item into the event queue. The event queue acts as a circular, concurrent queue, and as a result this function must correct synchronize on the queue to prevent race conditions. This will lock the queue, and wait if the queue is full.
- Parameters
-
event_loop | the event loop to add the event to |
e | the event to put into the event loop |
- Returns
- true if the item was succesfully added, false otherwise
Definition at line 75 of file event.c.
◆ event_loop_take()
Takes the next item out of the queue. The event queue acts as a circular, concurrent queue, and as a result this function must correctly synchronize on the queue to prevent race conditions. This will lock the queue, and wait if the queue is full.
- Parameters
-
- Returns
- the next event in the event loop, NULL if the event loop has ended
Definition at line 90 of file event.c.
◆ event_loop_terminate()
void event_loop_terminate |
( |
| ) |
|
Stops the event loop from executing.
This will wake up any threads that are waiting on either a push into the event loop, or are trying to take from the event loop and the put() and take() functions will return errors.
Definition at line 275 of file event.c.
◆ event_signal_ext()
void event_signal_ext |
( |
void * |
func, |
|
|
void * |
args, |
|
|
char * |
name, |
|
|
char * |
s_name, |
|
|
uint16_t |
s_line |
|
) |
| |
public interface for creating new events. Simple call this function, with the first argument being a function pointer ( void(*)(void*) ) and the second being the arguments for the function.
- Parameters
-
func | |
args | |
name | name of the event |
s_name | source file name creating the event |
s_line | line number of the source file creating the event |
Definition at line 200 of file event.c.
◆ el_created
Flag used to check if the event loop has been created
Definition at line 35 of file event.c.
◆ vl_singleton
The event loop is a singleton, this is the only actual event loop
Definition at line 29 of file event.c.