mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-08 16:10:59 +00:00
API change -- Remove first ctx argument and add event mask to callback
There really does not exist a good reason for us sending a `uev_ctx_t *` pointer as the first argument to event callbacks. If the callback needs to reference the context, it can find the ctx pointer in the `uev_t *w`. This patch removes the first argument from all callbacks and also fixes a slight bug in that the event loop never returned the actual event that triggered the callback! Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
9e7f6865fc
commit
1f9558059a
6 files changed
+30
-24
No files matched your search
@@ -61,15 +61,16 @@ details, see [this article][4] at [lwn.net](http://lwn.net).
|
||||
API
|
||||
---
|
||||
|
||||
Here is the interface to [libuEv]. It handles three different types of
|
||||
events: I/O (files, sockets, message queues, etc.), timers, and signals.
|
||||
The C interface to [libuEv] is very simple. It handles three different
|
||||
types of events: I/O (files, sockets, message queues, etc.), timers, and
|
||||
signals. With a slight caveat on signals
|
||||
|
||||
```C
|
||||
/* Callback example, arg is passed from watcher's *_init()
|
||||
* w->fd holds the file descriptor, events is set by libuEv
|
||||
* to indicate if any of UEV_READ and/or UEV_WRITE is ready.
|
||||
*/
|
||||
void callback (uev_ctx_t *ctx, uev_t *w, void *arg, int events);
|
||||
void callback (uev_t *w, void *arg, int events);
|
||||
|
||||
/* Event loop functions, notice use of flags! */
|
||||
int uev_init (uev_ctx_t *ctx);
|
||||
@@ -111,10 +112,10 @@ file descriptor to monitor, and an event callback function, by calling
|
||||
the event type's `_init()` function with the `uev_ctx_t` context.
|
||||
|
||||
```C
|
||||
void cleanup_exit(uev_ctx_t *ctx, uev_t *w, void *arg, int events)
|
||||
void cleanup_exit(uev_t *w, void *arg, int events)
|
||||
{
|
||||
/* Graceful exit, with optional cleanup ... */
|
||||
uev_exit(ctx);
|
||||
uev_exit(w->ctx);
|
||||
}
|
||||
|
||||
uev_t termw;
|
||||
@@ -186,7 +187,7 @@ struct js_event {
|
||||
uint8_t number; /* axis/button number */
|
||||
} e;
|
||||
|
||||
static void joystick_cb(uev_ctx_t *ctx, uev_t *w, void *arg, int events)
|
||||
static void joystick_cb(uev_t *w, void *arg, int events)
|
||||
{
|
||||
read (w->fd, &e, sizeof(e));
|
||||
|
||||
|
||||
Reference in new issue
Block a user