µEvLoop
A fast and lightweight event loop aimed at embedded platforms in C99.
event.h
Go to the documentation of this file.
1 
5 #ifndef UEL_EVENT_H
6 #define UEL_EVENT_H
7 
9 #include <stdint.h>
10 #include <stdbool.h>
12 
13 #include "uevloop/utils/closure.h"
15 
18  UEL_CLOSURE_EVENT,
19  UEL_TIMER_EVENT,
20  UEL_SIGNAL_EVENT,
21  UEL_SIGNAL_LISTENER_EVENT,
22  UEL_OBSERVER_EVENT
23 };
26 
27 
30  UEL_TIMER_RUNNING,
31  UEL_TIMER_PAUSED,
32  UEL_TIMER_CANCELLED
33 };
36 
37 
57 typedef struct event uel_event_t;
58 struct event {
60  uel_closure_t closure;
61  void *value;
62  bool repeating;
63 
67 
69  struct uel_event_timer {
73  uint32_t due_time;
74  uint16_t timeout;
76  } timer;
77 
80  uintptr_t value;
81  uel_llist_t *listeners;
82  } signal;
83 
89  bool unlistened;
90  } listener;
91 
94  volatile uintptr_t *condition_var;
95  uintptr_t last_value;
96  bool cancelled;
98  } observer;
99  } detail;
100 };
101 
111  uel_event_t *event,
112  uel_closure_t *closure,
113  void *value,
114  bool repeating
115 );
116 
125  uel_event_t *event,
126  uintptr_t signal,
127  uel_llist_t *listeners,
128  void *params
129 );
130 
138 void uel_event_config_signal_listener(uel_event_t *event, uel_closure_t *closure, bool repeating);
139 
149  uel_event_t *event,
150  uel_closure_t *closure,
151  volatile uintptr_t *condition_var,
152  bool repeating
153 );
154 
159 void uel_event_observer_cancel(uel_event_t *event);
160 
174  uel_event_t *event,
175  uint16_t timeout_in_ms,
176  bool repeating,
177  bool immediate,
178  uel_closure_t *closure,
179  void *value,
180  uint32_t current_time
181 );
182 
187 void uel_event_timer_pause(uel_event_t *event);
188 
193 void uel_event_timer_resume(uel_event_t *event);
194 
199 void uel_event_timer_cancel(uel_event_t *event);
200 
201 #endif /* UEL_EVENT_H */
linked-list.h
Defines a simple implementation of linked lists and functions to manipulate it.
event::uel_event_detail::uel_event_signal::listeners
uel_llist_t * listeners
Reference to the signal listeners.
Definition: event.h:81
event::uel_event_detail::uel_event_signal::value
uintptr_t value
The integer value that identifies this signal.
Definition: event.h:80
event::value
void * value
The value the closure should be invoked with.
Definition: event.h:61
event::uel_event_detail::uel_event_listener::unlistened
bool unlistened
Definition: event.h:89
event::uel_event_detail::uel_event_observer::last_value
uintptr_t last_value
Definition: event.h:95
closure.h
Defines closures, objects that bind functions to creating and calling contexts.
uel_event_timer_pause
void uel_event_timer_pause(uel_event_t *event)
Pauses a timer event.
event
Events are special messages passed around the core. They represent tasks to be run at some point by t...
Definition: event.h:58
event::type
uel_event_type_t type
The type of the event, as defined by uel_event_type_t
Definition: event.h:59
event::uel_event_detail::signal
struct event::uel_event_detail::uel_event_signal signal
The emission information of this event. Relevant only for signals.
uel_event_timer_status_t
enum uel_event_timer_status uel_event_timer_status_t
Alias to the uel_event_timer_status.
Definition: event.h:35
uel_event_timer_cancel
void uel_event_timer_cancel(uel_event_t *event)
Cancels a timer event.
event::uel_event_detail::uel_event_observer::condition_var
volatile uintptr_t * condition_var
The address of a volatile value to observe.
Definition: event.h:94
event::detail
union event::uel_event_detail detail
Represents speciffic detail on a event depending on its type.
uel_event_type_t
enum uel_event_type uel_event_type_t
Alias to the uel_event_type enum.
Definition: event.h:25
event::uel_event_detail::uel_event_listener
Contains the context of a particular signal listener.
Definition: event.h:85
uel_event_observer_cancel
void uel_event_observer_cancel(uel_event_t *event)
Cancels an observer.
uel_event_config_signal
void uel_event_config_signal(uel_event_t *event, uintptr_t signal, uel_llist_t *listeners, void *params)
Configures a signal event.
event::uel_event_detail
Definition: event.h:66
event::uel_event_detail::listener
struct event::uel_event_detail::uel_event_listener listener
The listening information of this event. Relevant only for signal listeners.
uel_event_config_timer
void uel_event_config_timer(uel_event_t *event, uint16_t timeout_in_ms, bool repeating, bool immediate, uel_closure_t *closure, void *value, uint32_t current_time)
Configures a timer event.
uel_event_config_observer
void uel_event_config_observer(uel_event_t *event, uel_closure_t *closure, volatile uintptr_t *condition_var, bool repeating)
Configures an observer event.
event::uel_event_detail::uel_event_timer::due_time
uint32_t due_time
The value the system timer must be at when this event's closure should be invoked....
Definition: event.h:73
event::uel_event_detail::uel_event_timer::status
uel_event_timer_status_t status
Current timer status.
Definition: event.h:75
event::repeating
bool repeating
Marks whether the event should be discarded after processing.
Definition: event.h:62
event::uel_event_detail::uel_event_signal
Contains information related to an emitted signal.
Definition: event.h:79
event::uel_event_detail::uel_event_timer
Contains information suitable for scheduling an event at the scheduler.
Definition: event.h:69
event::uel_event_detail::uel_event_observer::cancelled
bool cancelled
Whether this observer has been cancelled and is awaiting for destruction.
Definition: event.h:97
event::uel_event_detail::timer
struct event::uel_event_detail::uel_event_timer timer
The scheduling information of this event. Relevant only for timers.
uel_event_timer_resume
void uel_event_timer_resume(uel_event_t *event)
Resumes a paused timer event.
uel_event_config_closure
void uel_event_config_closure(uel_event_t *event, uel_closure_t *closure, void *value, bool repeating)
Configures a closure event.
uel_event_type
uel_event_type
Possible types of events understood by the core.
Definition: event.h:17
event::uel_event_detail::uel_event_observer
Contains the reference to an observer variable.
Definition: event.h:93
event::closure
uel_closure_t closure
The closure to be invoked a.k.a. the action to be run.
Definition: event.h:60
event::uel_event_detail::observer
struct event::uel_event_detail::uel_event_observer observer
The observing information of this event. Relevant only for observers.
uel_event_timer_status
uel_event_timer_status
Possible statuses for a timer event.
Definition: event.h:29
uel_event_config_signal_listener
void uel_event_config_signal_listener(uel_event_t *event, uel_closure_t *closure, bool repeating)
Configures a signal listener event.
event::uel_event_detail::uel_event_timer::timeout
uint16_t timeout
Holds the interval between two executions of the timer.
Definition: event.h:74