FOSSology  4.4.0
Open Source License Compliance by Open Source Software
event.c File Reference

Event handling operations. More...

#include <event.h>
#include <logging.h>
#include <scheduler.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for event.c:

Go to the source code of this file.

Functions

event_loop_tevent_loop_get ()
 
int event_loop_put (event_loop_t *event_loop, event_t *e)
 
event_tevent_loop_take (event_loop_t *event_loop)
 
event_tevent_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...
 

Variables

event_loop_t vl_singleton
 
int el_created = 0
 

Detailed Description

Event handling operations.

Definition in file event.c.

Function Documentation

◆ event_destroy()

void event_destroy ( event_t e)

Free any memory associated with an event.

Parameters
ethe event to destroy

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
functhe function to call when the event is executed
argthe arguements for the function.
namename of the event
source_namesource file name creating the event
source_lineline 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()

int event_loop_enter ( scheduler_t scheduler,
void(*)(scheduler_t *)  update_call,
void(*)(scheduler_t *)  signal_call 
)

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
schedulerscheduler reference to to be notified
update_calla function that is called every time an event is processed
signal_calla 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()

event_loop_t* 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()

int event_loop_put ( event_loop_t event_loop,
event_t e 
)

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_loopthe event loop to add the event to
ethe 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()

event_t* event_loop_take ( event_loop_t event_loop)

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
event_loopthe event loop to get the event out of
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
namename of the event
s_namesource file name creating the event
s_lineline number of the source file creating the event

Definition at line 200 of file event.c.

Variable Documentation

◆ el_created

int el_created = 0

Flag used to check if the event loop has been created

Definition at line 35 of file event.c.

◆ vl_singleton

event_loop_t vl_singleton

The event loop is a singleton, this is the only actual event loop

Definition at line 29 of file event.c.