kiba-engine
Data Structures | Macros | Typedefs | Functions | Variables
event.c File Reference

Event system implementation. More...

#include <kiba/core/event.h>
#include <kiba/core/log.h>
#include <kiba/core/memory.h>
Include dependency graph for event.c:

Go to the source code of this file.

Data Structures

struct  registered_listener
 
struct  registered_listener_list
 
struct  event_system_state
 

Macros

#define MAX_EVENT_LISTENER   512
 Maximum number of listeners per event code.
 

Typedefs

typedef struct registered_listener registered_listener
 
typedef struct registered_listener_list registered_listener_list
 
typedef struct event_system_state event_system_state
 

Functions

b8 event_initialize (void)
 Initialize the event system. More...
 
void event_shutdown (void)
 Shutdown event system. More...
 
b8 event_register (u16 event_code, void *listener, on_event_function on_event, b8 append)
 Register a callback for a particular event type. More...
 
b8 event_unregister (u16 event_code, void *listener, on_event_function on_event)
 Unregister a callback for a particular event type. More...
 
b8 event_fire (u16 event_code, void *sender, event_context context)
 Fire an event. More...
 

Variables

event_system_state event_state
 

Detailed Description

Event system implementation.

Definition in file event.c.

Typedef Documentation

◆ event_system_state

State of the event system.

◆ registered_listener

Struct to store listener data with its callback.

◆ registered_listener_list

Custom fixed length array to store registered_listener.

Function Documentation

◆ event_fire()

b8 event_fire ( u16  event_code,
void *  sender,
event_context  context 
)

Fire an event.

The event system will propagate the event to all registered listeners.

Parameters
event_codethe code of the event being fired
sendercustom sender data which will be forwarded into the listeners' callbacks
contextcontextual data for the event being fired
Returns
true if a registered listener handled the event, false otherwise

Definition at line 81 of file event.c.

◆ event_initialize()

b8 event_initialize ( void  )

Initialize the event system.

Prepares the internal state to process and forward events. Must be called once before using the event system.

Returns
false if an error occurred, true if succesful

Definition at line 40 of file event.c.

Here is the call graph for this function:

◆ event_register()

b8 event_register ( u16  event_code,
void *  listener,
on_event_function  on_event,
b8  append 
)

Register a callback for a particular event type.

Parameters
event_codethe event code to listen for
listenercustom data which will be passed to the callback when it is called
on_eventthe callback to be called by the event system
appendregister at the end of the priority list (true) or at the beginning (false)
Returns
true if the callback was registered successfully, false otherwise

Definition at line 47 of file event.c.

Here is the call graph for this function:

◆ event_shutdown()

void event_shutdown ( void  )

Shutdown event system.

Definition at line 45 of file event.c.

◆ event_unregister()

b8 event_unregister ( u16  event_code,
void *  listener,
on_event_function  on_event 
)

Unregister a callback for a particular event type.

Parameters
event_codethe event code to unregister from
listenercustom data originally passed to the event_register call
on_eventthe callback to be unregistered
Returns
true if the callback was unregistered successfully, false otherwise (e.g. not found)

Definition at line 67 of file event.c.

Here is the call graph for this function:

Variable Documentation

◆ event_state

event_system_state event_state

Internal event system state.

Definition at line 38 of file event.c.