SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
event.h
Go to the documentation of this file.
1 
8 #ifndef __SOLAR_CAPTURE_EVENT_H__
9 #define __SOLAR_CAPTURE_EVENT_H__
10 
11 #include <sys/epoll.h>
12 
13 struct sc_attr;
14 struct sc_thread;
15 struct sc_callback;
16 
24 typedef void (sc_callback_handler_fn)(struct sc_callback*, void* event_info);
25 
26 
33 struct sc_callback {
34  void* cb_private;
36  struct sc_dlist cb_link;
37 };
38 
39 
58 extern int sc_callback_alloc(struct sc_callback** cb_out,
59  const struct sc_attr* attr,
60  struct sc_thread* thread);
61 
62 
70 extern void sc_callback_free(struct sc_callback* cb);
71 
72 
78 static inline int sc_callback_is_active(const struct sc_callback* cb)
79 {
80  return cb->cb_link.next != &cb->cb_link;
81 }
82 
83 
91 static inline void sc_callback_remove(struct sc_callback* cb)
92 {
93  sc_dlist_remove(&cb->cb_link);
94  sc_dlist_init(&cb->cb_link);
95 }
96 
97 
110 extern void sc_callback_on_idle(struct sc_callback* cb);
111 
112 
135 extern int sc_epoll_ctl(struct sc_thread* thread, int op, int fd,
136  unsigned events, struct sc_callback* cb);
137 
138 
139 #endif /* __SOLAR_CAPTURE_EVENT_H__ */
140 
static void sc_dlist_init(struct sc_dlist *list)
Initialise a pre-allocated sc_dlist to be an empty doubly linked list.
Definition: dlist.h:107
void( sc_callback_handler_fn)(struct sc_callback *, void *event_info)
A callback handler function.
Definition: event.h:24
Attribute object.
sc_callback_handler_fn * cb_handler_fn
Definition: event.h:35
static void sc_dlist_remove(struct sc_dlist *l)
Remove an item from the list.
Definition: dlist.h:145
Doubly linked list pointers.
Definition: dlist.h:60
static void sc_callback_remove(struct sc_callback *cb)
Unregister a callback object from its event source.
Definition: event.h:91
int sc_callback_alloc(struct sc_callback **cb_out, const struct sc_attr *attr, struct sc_thread *thread)
Allocate a callback object instance.
struct sc_dlist * next
Definition: dlist.h:62
void sc_callback_on_idle(struct sc_callback *cb)
Request a callback when the thread is idle.
static int sc_callback_is_active(const struct sc_callback *cb)
Returns true if a callback object is active.
Definition: event.h:78
void sc_callback_free(struct sc_callback *cb)
Free a callback object instance.
int sc_epoll_ctl(struct sc_thread *thread, int op, int fd, unsigned events, struct sc_callback *cb)
Request a callback when the thread is idle.
void * cb_private
Definition: event.h:34
A callback object.
Definition: event.h:33