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

Event handling operations. More...

#include <scheduler.h>
Include dependency graph for event.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  event_t
 
struct  event_loop
 
struct  arg_int
 

Macros

#define EVENT_LOOP_SIZE   1024
 
#define event_signal(func, args)   event_signal_ext(func, args, #func, __FILE__, __LINE__)
 

Typedefs

typedef struct event_loop event_loop_t
 
typedef void(* event_function) (scheduler_t *, void *)
 

Functions

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...
 
int event_loop_put (event_loop_t *event_loop, event_t *event)
 
event_tevent_loop_take (event_loop_t *event_loop)
 
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(*)(scheduler_t *), void(*)(scheduler_t *))
 Enters the event loop. More...
 
void event_loop_terminate ()
 Stops the event loop from executing. More...
 

Detailed Description

Event handling operations.

Definition in file event.h.

Typedef Documentation

◆ event_loop_t

typedef struct event_loop event_loop_t

internal structure for the event loop

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_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.