µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
Data Structures | Typedefs | Functions
signal.h File Reference

Defines signals and relays, structures used to communicate asynchronously between distant parts of the application. More...

#include "uevloop/utils/linked-list.h"
#include "uevloop/utils/closure.h"
#include "uevloop/utils/promise.h"
#include "uevloop/system/containers/system-pools.h"
#include "uevloop/system/containers/system-queues.h"
#include "uevloop/system/event.h"
Include dependency graph for signal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  uel_signal_relay_t
 Contains a signal vector and operates on in. More...
 

Typedefs

typedef uintptr_t uel_signal_t
 
typedef struct uel_event_listener * uel_signal_listener_t
 Defines a reference type suitable to manipulate the actual listener event's context.
 

Functions

void uel_signal_relay_init (uel_signal_relay_t *relay, uel_syspools_t *pools, uel_sysqueues_t *queues, uel_llist_t *buffer, uintptr_t width)
 Initialises a signal relay. More...
 
uel_signal_listener_t uel_signal_listen (uel_signal_t signal, uel_signal_relay_t *relay, uel_closure_t *closure)
 Attaches a listener closure to some signal at a particular relay. More...
 
uel_signal_listener_t uel_signal_listen_once (uel_signal_t signal, uel_signal_relay_t *relay, uel_closure_t *closure)
 Attaches a listener closure to some signal at a particular relay. The listener closure will be invoked only once. More...
 
void uel_signal_unlisten (uel_signal_listener_t listener)
 Marks a signal listener as expired. When its corresponding signal is emitted, this listener's closure will not be invoked and the listener will be destroyed. More...
 
void uel_signal_emit (uel_signal_t signal, uel_signal_relay_t *relay, void *params)
 Emits a signal at the supplied relay. Any closure listening to this signal will be asynchronously invoked. More...
 
uel_signal_listener_t uel_signal_resolve_promise (uel_signal_t signal, uel_signal_relay_t *relay, uel_promise_t *promise)
 Attaches a non-repeating listener that resolves the provided promise upon emission. More...
 
uel_signal_listener_t uel_signal_reject_promise (uel_signal_t signal, uel_signal_relay_t *relay, uel_promise_t *promise)
 Attaches a non-repeating listener that rejects the provided promise upon emission. More...
 

Detailed Description

Defines signals and relays, structures used to communicate asynchronously between distant parts of the application.

Typedef Documentation

◆ uel_signal_t

Any signal is defined as an unsigned integer type. This means that any signal type is only valid within the scope defined by the relay designed to respond to said signal.

Function Documentation

◆ uel_signal_emit()

void uel_signal_emit ( uel_signal_t  signal,
uel_signal_relay_t *  relay,
void *  params 
)

Emits a signal at the supplied relay. Any closure listening to this signal will be asynchronously invoked.

Parameters
signalThe signal to be emitted
relayThe relay where the signal is registered
paramsThe parameters supplied to the listener's closure when it is invoked.

◆ uel_signal_listen()

uel_signal_listener_t uel_signal_listen ( uel_signal_t  signal,
uel_signal_relay_t *  relay,
uel_closure_t *  closure 
)

Attaches a listener closure to some signal at a particular relay.

Parameters
signalThe signal to be listened for
relayThe relay where the listener will be registered
closureThe closure to be invoked when the signal is emitted. The closure will be invoked with whatever parameters are supplied during emission.
Returns
Returns a listener that references this particular operation

◆ uel_signal_listen_once()

uel_signal_listener_t uel_signal_listen_once ( uel_signal_t  signal,
uel_signal_relay_t *  relay,
uel_closure_t *  closure 
)

Attaches a listener closure to some signal at a particular relay. The listener closure will be invoked only once.

Parameters
signalThe signal to be listened for
relayThe relay where the listener will be registered
closureThe closure to be invoked when the signal is emitted. The closure will be invoked with whatever parameters are supplied during emission.
Returns
Returns a listener that references this particular operation

◆ uel_signal_reject_promise()

uel_signal_listener_t uel_signal_reject_promise ( uel_signal_t  signal,
uel_signal_relay_t *  relay,
uel_promise_t *  promise 
)

Attaches a non-repeating listener that rejects the provided promise upon emission.

Parameters
signalThe signal to be listened for
relayThe relay where the signal is registered
promiseThe promise to be rejected upon signal emission
Returns
The listener associated with this operation

◆ uel_signal_relay_init()

void uel_signal_relay_init ( uel_signal_relay_t *  relay,
uel_syspools_t *  pools,
uel_sysqueues_t *  queues,
uel_llist_t *  buffer,
uintptr_t  width 
)

Initialises a signal relay.

Parameters
relayThe signal relay object to be initialised
poolsThe system's internal pools
queuesThe system's internal queues
bufferThe buffer that will be used to store listeners registered at this relay. Must be the number of signals bound to this relay wide.
widthThe number of signals bound to this relay.

◆ uel_signal_resolve_promise()

uel_signal_listener_t uel_signal_resolve_promise ( uel_signal_t  signal,
uel_signal_relay_t *  relay,
uel_promise_t *  promise 
)

Attaches a non-repeating listener that resolves the provided promise upon emission.

Parameters
signalThe signal to be listened for
relayThe relay where the signal is registered
promiseThe promise to be resolved upon signal emission
Returns
The listener associated with this operation

◆ uel_signal_unlisten()

void uel_signal_unlisten ( uel_signal_listener_t  listener)

Marks a signal listener as expired. When its corresponding signal is emitted, this listener's closure will not be invoked and the listener will be destroyed.

  • Parameters
    listenerThe listener that identifies the listen operation to be undone