]> git.ozlabs.org Git - petitboot/commitdiff
discover: Consolidate user events by device ID
authorJeremy Kerr <jk@ozlabs.org>
Mon, 11 Mar 2013 06:07:36 +0000 (14:07 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 16 Apr 2013 03:41:46 +0000 (11:41 +0800)
Currently, we assume all user events are for a new device. This means
that we can never add boot options to an existing device.

This change tries to find an existing (matching by ID) device before
creating a new one in the user event add path.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/device-handler.c
discover/event-parser.c
discover/parser.h
ui/test/discover-test.c

index ab27b51b2eaf764d98a37b7df3185dd49d46a20b..4ba7405f2de73f29ded296340ec310104393a8d6 100644 (file)
@@ -347,23 +347,25 @@ static int handle_add_user_event(struct device_handler *handler,
 
        assert(event->device);
 
 
        assert(event->device);
 
-       device = talloc_zero(handler, struct device);
+       device = device_handler_find(handler, event->device);
 
 
-       if (!device)
-               goto fail;
+       if (!device) {
+               device = talloc_zero(handler, struct device);
 
 
-       device->id = talloc_strdup(device, event->device);
-       list_init(&device->boot_options);
+               if (!device)
+                       goto fail;
 
 
-       parse_user_event(device, event);
+               device->id = talloc_strdup(device, event->device);
+               list_init(&device->boot_options);
 
 
-       discover_server_notify_device_add(handler->server, device);
+               /* add device to handler device array */
+               device_handler_add(handler, device);
 
 
-       list_for_each_entry(&device->boot_options, opt, list)
-               discover_server_notify_boot_option_add(handler->server, opt);
+               discover_server_notify_device_add(handler->server, device);
+       }
 
 
-       /* add device to handler device array */
-       device_handler_add(handler, device);
+       opt = parse_user_event(device, event);
+       discover_server_notify_boot_option_add(handler->server, opt);
 
        return 0;
 
 
        return 0;
 
index 1eec5c9cd410ca55f7a90a33f987e82a83a06c7d..c09c5babc27a1e44d642c31f523688b55b652ff4 100644 (file)
@@ -13,7 +13,7 @@
  * Understands params: name, image, args.
  */
 
  * Understands params: name, image, args.
  */
 
-int parse_user_event(struct device *device, struct event *event)
+struct boot_option *parse_user_event(struct device *device, struct event *event)
 {
        struct boot_option *opt;
        const char *p;
 {
        struct boot_option *opt;
        const char *p;
@@ -54,9 +54,9 @@ int parse_user_event(struct device *device, struct event *event)
 
        device_add_boot_option(device, opt);
 
 
        device_add_boot_option(device, opt);
 
-       return 0;
+       return opt;
 
 fail:
        talloc_free(opt);
 
 fail:
        talloc_free(opt);
-       return -1;
+       return NULL;
 }
 }
index 589c6ff20de188409e5d04daedd81507fa76f469..a80d1b5b8df43ccf4cee400ce125395212446025 100644 (file)
@@ -21,6 +21,7 @@ enum generic_icon_type {
 void parser_init(void);
 
 void iterate_parsers(struct discover_context *ctx);
 void parser_init(void);
 
 void iterate_parsers(struct discover_context *ctx);
-int parse_user_event(struct device *device, struct event *event);
+struct boot_option *parse_user_event(struct device *device,
+               struct event *event);
 
 #endif /* _PARSER_H */
 
 #endif /* _PARSER_H */
index ae43b1e524b30421e694ed4fee4d04dcb309a8b3..8f7c2c22a9709bccb991a7b0d2fdd10ac1389c5d 100644 (file)
@@ -28,6 +28,23 @@ static int print_device_add(struct device *device,
        return 0;
 }
 
        return 0;
 }
 
+static int print_boot_option_add(struct device *dev,
+               struct boot_option *opt,
+               void __attribute__((unused)) *arg)
+{
+       printf("new boot option (dev: %s):\n", dev->id);
+       printf("\tdev id: %s\n", opt->device_id);
+       printf("\tid:     %s\n", opt->id);
+       printf("\tname:   %s\n", opt->name);
+       printf("\tdesc:   %s\n", opt->description);
+       printf("\ticon:   %s\n", opt->icon_file);
+       printf("\tboot:   %s\n", opt->boot_image_file);
+       printf("\tinit:   %s\n", opt->initrd_file);
+       printf("\targs:   %s\n", opt->boot_args);
+
+       return 0;
+}
+
 static void print_device_remove(struct device *device,
        void __attribute__((unused)) *arg)
 {
 static void print_device_remove(struct device *device,
        void __attribute__((unused)) *arg)
 {
@@ -38,6 +55,7 @@ static void print_device_remove(struct device *device,
 
 static struct discover_client_ops client_ops = {
        .device_add = print_device_add,
 
 static struct discover_client_ops client_ops = {
        .device_add = print_device_add,
+       .boot_option_add = print_boot_option_add,
        .device_remove = print_device_remove,
 };
 
        .device_remove = print_device_remove,
 };