X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=7e5819c5bd972d8284a9f70ac1c9eb1efbb9d0bb;hp=90d92968bd024fd5e7dd38ada6c8eb9a2840abab;hb=812761a1f8ff94e4913529840b905360ff843fc4;hpb=9057583b8b37d07eb9af2fd48674f1732fecda17 diff --git a/discover/device-handler.c b/discover/device-handler.c index 90d9296..7e5819c 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" @@ -24,18 +26,8 @@ struct device_handler { struct device *devices; int n_devices; -}; - -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 list contexts; }; struct mount_map { @@ -43,7 +35,6 @@ struct mount_map { char *mount_point; }; -static struct list contexts; static struct boot_option options[] = { { @@ -60,11 +51,10 @@ 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, +int device_handler_get_current_devices( + struct device_handler *handler __attribute__((unused)), struct device **devices) { @@ -280,11 +270,12 @@ static int umount_device(struct discover_context *ctx) return 0; } -static struct discover_context *find_context(const char *id) +static struct discover_context *find_context(struct device_handler *handler, + const char *id) { struct discover_context *ctx; - list_for_each_entry(&contexts, ctx, list) { + list_for_each_entry(&handler->contexts, ctx, list) { if (!strcmp(ctx->id, id)) return ctx; } @@ -311,7 +302,7 @@ static int handle_add_event(struct device_handler *handler, int rc; /* create our context */ - ctx = talloc(NULL, struct discover_context); + ctx = talloc(handler, struct discover_context); ctx->event = event; ctx->mount_path = NULL; ctx->links = NULL; @@ -334,10 +325,19 @@ static int handle_add_event(struct device_handler *handler, return 0; } - list_add(&contexts, &ctx->list); - + 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; } @@ -346,10 +346,12 @@ static int handle_remove_event(struct device_handler *handler, { struct discover_context *ctx; - ctx = find_context(event->device); + ctx = find_context(handler, event->device); if (!ctx) return 0; + discover_server_notify_remove(handler->server, ctx->device); + talloc_free(ctx); return 0; @@ -376,26 +378,31 @@ 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(&contexts); + 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; } -void device_handler_destroy(struct device_handler *devices) +void device_handler_destroy(struct device_handler *handler) { - struct discover_context *ctx, *n; - - talloc_free(devices); - - list_for_each_entry_safe(&contexts, ctx, n, list) - talloc_free(ctx); + talloc_free(handler); }