libamxp
1.4.0
Patterns C Implementation
|
Data Structures | |
struct | _amxp_signal |
Structure containing the signal information. More... | |
Typedefs | |
typedef struct _amxp_signal | amxp_signal_t |
Structure containing the signal information. More... | |
Functions | |
int | amxp_sigmngr_emit_signal (const amxp_signal_mngr_t *const sig_mngr, const char *name, const amxc_var_t *const data) |
Emits a signal. More... | |
int | amxp_sigmngr_deferred_call (amxp_signal_mngr_t *const sig_mngr, amxp_deferred_fn_t fn, const amxc_var_t *const data, void *priv) |
Defers a function call. More... | |
int | amxp_sigmngr_enable (amxp_signal_mngr_t *const sig_mngr, bool enable) |
Enables or disables the signal manager. More... | |
int | amxp_sigmngr_suspend (amxp_signal_mngr_t *const sig_mngr) |
Suspends the handling of signals for the signal manager. More... | |
int | amxp_sigmngr_resume (amxp_signal_mngr_t *const sig_mngr) |
Resumes the handling of signals for the signal manager. More... | |
int | amxp_signal_new (amxp_signal_mngr_t *sig_mngr, amxp_signal_t **signal, const char *name) |
Constructor function, creates a new signal. More... | |
int | amxp_signal_delete (amxp_signal_t **signal) |
Destructor function, deletes a signal. More... | |
void | amxp_signal_trigger (amxp_signal_t *const signal, const amxc_var_t *const data) |
Triggers a signal. More... | |
int | amxp_signal_emit (const amxp_signal_t *const signal, const amxc_var_t *const data) |
Emits a signal. More... | |
int | amxp_signal_read (void) |
Reads from the amxp signal file descriptor. More... | |
int | amxp_signal_fd (void) |
Gets the amxp signal file descriptor. More... | |
int | amxp_signal_disconnect_all (amxp_signal_t *const signal) |
Disconnects all slots from the signal. More... | |
const char * | amxp_signal_name (const amxp_signal_t *const signal) |
Gets the name of the signal. More... | |
bool | amxp_signal_has_slots (const amxp_signal_t *const signal) |
Checks if the signal has slots conencted. More... | |
When a signal is triggered, all callback functions (slots) that are connected are called immediately. When a signal is emitted, it will be triggered after reading from the amxp signal file descriptor. It is recommended to implement an eventloop.
A signal is a name to which slots (callback functions) can connect.
typedef struct _amxp_signal amxp_signal_t |
Structure containing the signal information.
int amxp_sigmngr_deferred_call | ( | amxp_signal_mngr_t *const | sig_mngr, |
amxp_deferred_fn_t | fn, | ||
const amxc_var_t *const | data, | ||
void * | priv | ||
) |
Defers a function call.
Adds a function call to the singal queue. This function will be called at the moment the queue is being handled. Using deferred function calls it is possible to make synchronous functions behave asynchronously.
When sig_mngr is NULL, the function call is added to the queue of global signal manager.
The function will be called when reading the amxp signal file descriptor using function amxp_signal_read.
To be able to use this method it is recommended to implement an eventloop.
sig_mngr | pointer to the sig_mngr pointer. Will be set to NULL |
fn | the deferred function |
data | the data that is passed to the function. |
priv | some pointer to private data |
Definition at line 536 of file amxp_signal.c.
int amxp_sigmngr_emit_signal | ( | const amxp_signal_mngr_t *const | sig_mngr, |
const char * | name, | ||
const amxc_var_t *const | data | ||
) |
Emits a signal.
Searches the signal manager for the given signal and emits the signal. This function is basically the same as calling amxp_sigmngr_find_signal and amxp_signal_emit in sequence.
When sig_mngr is NULL, the signal is searched in the global signal manager.
When no signal is found with the given name, this function fails.
The signal will be triggered when reading the amxp signal file descriptor using function amxp_signal_read.
To be able to use this method it is recommended to implement an eventloop.
sig_mngr | ponter to the sig_mngr pointer. Will be set to NULL |
name | the name of the signal |
data | the data that is passed to all the slots. |
Definition at line 514 of file amxp_signal.c.
int amxp_sigmngr_enable | ( | amxp_signal_mngr_t *const | sig_mngr, |
bool | enable | ||
) |
Enables or disables the signal manager.
When a signal manager is disabled, all emitted signals or triggered signals are discarded, including the signal data.
sig_mngr | pointer to the signal manager. Use NULL for the global signal manager. |
enable | when true signal emitting and triggering is enabled, when false emitting and triggering of signals is blocked for this signal manager. |
Definition at line 561 of file amxp_signal.c.
int amxp_sigmngr_resume | ( | amxp_signal_mngr_t *const | sig_mngr | ) |
Resumes the handling of signals for the signal manager.
When a signal manager is resumed, all queued signals will be handled by the eventloop.
After resuming a signal manager it will be possible to trigger signals again.
When the signal manager was not suspended this functions returns a none-zero value.
sig_mngr | pointer to the signal manager. Use NULL for the global signal manager. |
Definition at line 595 of file amxp_signal.c.
int amxp_sigmngr_suspend | ( | amxp_signal_mngr_t *const | sig_mngr | ) |
Suspends the handling of signals for the signal manager.
When a signal manager is suspended, all emitted signals are queued but not handled until the signal manager is resumed with amxp_sigmngr_resume.
When a signal manager is suspended, all triggered signals are dropped including the signal data.
When the signal manager was already suspended this functions returns a none-zero value.
sig_mngr | pointer to the signal manager. Use NULL for the global signal manager. |
Definition at line 571 of file amxp_signal.c.
int amxp_signal_delete | ( | amxp_signal_t ** | signal | ) |
Destructor function, deletes a signal.
All connected slots will be automatically disconnected.
The signal is removed from the signal manager it was added to.
signal | pointer to the pointer that wil point to the new allocated signal. |
Definition at line 669 of file amxp_signal.c.
int amxp_signal_disconnect_all | ( | amxp_signal_t *const | signal | ) |
Disconnects all slots from the signal.
signal | pointer to the signal structure. |
Definition at line 806 of file amxp_signal.c.
int amxp_signal_emit | ( | const amxp_signal_t *const | signal, |
const amxc_var_t *const | data | ||
) |
Emits a signal.
The signal will be triggered when reading the amxp signal file descriptor using function amxp_signal_read.
To be able to use this method it is recommended to implement an eventloop.
signal | pointer to the signal structure. |
data | the data that will be passed to all slots. |
Definition at line 742 of file amxp_signal.c.
int amxp_signal_fd | ( | void | ) |
Gets the amxp signal file descriptor.
Definition at line 841 of file amxp_signal.c.
bool amxp_signal_has_slots | ( | const amxp_signal_t *const | signal | ) |
Checks if the signal has slots conencted.
signal | pointer to the signal structure. |
Definition at line 821 of file amxp_signal.c.
const char* amxp_signal_name | ( | const amxp_signal_t *const | signal | ) |
Gets the name of the signal.
signal | pointer to the signal structure. |
Definition at line 817 of file amxp_signal.c.
int amxp_signal_new | ( | amxp_signal_mngr_t * | sig_mngr, |
amxp_signal_t ** | signal, | ||
const char * | name | ||
) |
Constructor function, creates a new signal.
Creates a new signal and adds it to the given signal manager. If sig_mngr is NULL, the signal is added to the global signal manager.
sig_mngr | pointer to signal manager where the signal must be added |
signal | pointer to the pointer that wil point to the new allocated signal |
name | name of the signal |
Definition at line 620 of file amxp_signal.c.
int amxp_signal_read | ( | void | ) |
Reads from the amxp signal file descriptor.
Each signal that was emitted will be read from the file descriptor and triggered. This is usefull when you want to do a full stack unwind before triggering the slots.
To be able to use this method it is recommended to implement an eventloop.
Definition at line 769 of file amxp_signal.c.
void amxp_signal_trigger | ( | amxp_signal_t *const | signal, |
const amxc_var_t *const | data | ||
) |
Triggers a signal.
All slots connected to the signal will be called. When a private data pointer was given at the time of the connect, the private data is passed to the slot.
The signal name and the signal data are passed to all the connected slots as well.
signal | pointer to the signal structure. |
data | the data that will be passed to all slots. |
Definition at line 691 of file amxp_signal.c.