Introduce pollers
Handlers may way to poll on multiple file descriptors. This change
introduces pollers, which are registered with:
console_register_poller(), which provides a function to call when a
specified fd has pollable events.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/console-server.h b/console-server.h
index ec77102..38cddef 100644
--- a/console-server.h
+++ b/console-server.h
@@ -1,9 +1,10 @@
-struct console;
-
#include <poll.h>
#include <stdint.h>
+struct console;
+
+/* handler API */
enum {
HANDLER_OK = 0,
HANDLER_EXIT,
@@ -13,10 +14,6 @@
const char *name;
int (*init)(struct handler *handler,
struct console *console);
- int (*init_poll)(struct handler *hander,
- struct pollfd *pollfd);
- int (*poll_event)(struct handler *handler,
- int events);
int (*data_in)(struct handler *handler,
uint8_t *buf, size_t len);
void (*fini)(struct handler *handler);
@@ -33,6 +30,24 @@
int console_data_out(struct console *console, const uint8_t *data, size_t len);
+/* poller API */
+struct poller;
+
+enum poller_ret {
+ POLLER_OK = 0,
+ POLLER_REMOVE,
+ POLLER_EXIT,
+};
+
+typedef enum poller_ret (*poller_fn_t)(struct handler *handler,
+ int revents, void *data);
+
+struct poller *console_register_poller(struct console *console,
+ struct handler *handler, poller_fn_t poller_fn,
+ int fd, int events, void *data);
+
+void console_unregister_poller(struct console *console, struct poller *poller);
+
/* utils */
int write_buf_to_fd(int fd, const uint8_t *buf, size_t len);