X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=8d3e877ad2379b661379a13fa28998127b3e5ecc;hp=98194ad46cea86434b9fdf8217b8876106cbbe16;hb=9793f862467407e83aa5b5a2cc35c25de9bae17b;hpb=01ed46e3e38a06120736d77c210ed0b165b0c7ce diff --git a/discover/device-handler.c b/discover/device-handler.c index 98194ad..8d3e877 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -11,6 +11,8 @@ #include #include "device-handler.h" +#include "discover-server.h" +#include "parser.h" #include "udev.h" #include "log.h" #include "paths.h" @@ -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; @@ -61,8 +51,6 @@ static struct device device = { .name = "meep", .description = "meep description", .icon_file = "meep.png", - .n_options = 1, - .options = options, }; int device_handler_get_current_devices(struct device_handler *handler, @@ -337,9 +325,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; } @@ -352,6 +349,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; @@ -378,16 +377,26 @@ int device_handler_event(struct device_handler *handler, struct device_handler *device_handler_init(struct discover_server *server) { struct device_handler *handler; + unsigned int i; handler = talloc(NULL, struct device_handler); handler->devices = NULL; handler->n_devices = 0; + handler->server = server; list_init(&handler->contexts); /* set up our mount point base */ mkdir_recursive(mount_base()); + /* setup out test objects */ + list_init(&device.boot_options); + + for (i = 0; i < sizeof(options) / sizeof(options[0]); i++) + list_add(&device.boot_options, &options[i].list); + + parser_init(); + return handler; }