X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=8a4930e1efd565d8487f88875b26774adddcc882;hp=1f8938f295b322e68b2df19fb7eeadd8146b1ca1;hb=dcab4e022083fecf221bebf9d6cdbb30b4b33c4d;hpb=b118597194815910897ccf86d77b8b5a066adf5a diff --git a/discover/device-handler.c b/discover/device-handler.c index 1f8938f..8a4930e 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -8,11 +8,13 @@ #include #include +#include #include #include "device-handler.h" +#include "discover-server.h" +#include "parser.h" #include "udev.h" -#include "log.h" #include "paths.h" #define MOUNT_BIN "/bin/mount" @@ -28,18 +30,6 @@ struct device_handler { struct list contexts; }; -struct discover_context { - char *id; - char *device_path; - char *mount_path; - struct udev_event *event; - struct device *device; - char **links; - int n_links; - - struct list_item list; -}; - struct mount_map { char *device_path; char *mount_point; @@ -63,8 +53,9 @@ static struct device device = { .icon_file = "meep.png", }; -int device_handler_get_current_devices(struct device_handler *handler, - struct device **devices) +int device_handler_get_current_devices( + struct device_handler *handler __attribute__((unused)), + const struct device **devices) { *devices = &device; @@ -335,9 +326,18 @@ static int handle_add_event(struct device_handler *handler, } list_add(&handler->contexts, &ctx->list); - talloc_set_destructor(ctx, destroy_context); + /* set up the top-level device */ + ctx->device = talloc_zero(ctx, struct device); + ctx->device->id = talloc_strdup(ctx->device, ctx->id); + list_init(&ctx->device->boot_options); + + /* run the parsers */ + iterate_parsers(ctx); + + discover_server_notify_add(handler->server, ctx->device); + return 0; } @@ -350,6 +350,8 @@ static int handle_remove_event(struct device_handler *handler, if (!ctx) return 0; + discover_server_notify_remove(handler->server, ctx->device); + talloc_free(ctx); return 0; @@ -376,11 +378,12 @@ int device_handler_event(struct device_handler *handler, struct device_handler *device_handler_init(struct discover_server *server) { struct device_handler *handler; - int i; + unsigned int i; handler = talloc(NULL, struct device_handler); handler->devices = NULL; handler->n_devices = 0; + handler->server = server; list_init(&handler->contexts); @@ -393,6 +396,8 @@ struct device_handler *device_handler_init(struct discover_server *server) for (i = 0; i < sizeof(options) / sizeof(options[0]); i++) list_add(&device.boot_options, &options[i].list); + parser_init(); + return handler; }