console-server: allow separate handler instances
Currently, each handler (socket-handler, tty-handler and log-handler)
provides a statically-allocated instance of a handler, which gets
initialized for a console through the ->init callback.
We have upcoming changes that may create more than one console object,
in which case means we will need multiple instances of each handler
type.
This change splits the handler type from the handler instance; the
former is now struct handler_type, with struct handler being the
instance. Handler modules define a (const) struct handler_type, and
->init() now returns a newly-allocated instance of a handler of that
type.
This allows multiple handlers of each type.
Because the handler instances are allocated by type->init, we now
require both ->init and ->fini to be present on registered handlers.
We no longer need the `bool active` member of the handler, as instances
are always active.
Change-Id: Id97f15bd6445e17786f5883b849de8559c5ea434
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
diff --git a/console-dbus.c b/console-dbus.c
index dd53908..91d99c7 100644
--- a/console-dbus.c
+++ b/console-dbus.c
@@ -33,22 +33,25 @@
static void tty_change_baudrate(struct console *console)
{
- struct handler *handler;
int i;
int rc;
tty_init_termios(console);
for (i = 0; i < console->n_handlers; i++) {
+ const struct handler_type *type;
+ struct handler *handler;
+
handler = console->handlers[i];
- if (!handler->baudrate) {
+ type = handler->type;
+ if (!type->baudrate) {
continue;
}
- rc = handler->baudrate(handler, console->tty.uart.baud);
+ rc = type->baudrate(handler, console->tty.uart.baud);
if (rc) {
warnx("Can't set terminal baudrate for handler %s",
- handler->name);
+ type->name);
}
}
}