]> git.ozlabs.org Git - petitboot/blobdiff - ui/twin/pbt-client.c
ui/common: Free message on return
[petitboot] / ui / twin / pbt-client.c
index c664740d04e726025fa56d5319c0d99a7d8cdb22..a4ad0e926f35155f4e2557a62a6f3138d9a304ed 100644 (file)
@@ -19,7 +19,6 @@
 #include "config.h"
 #endif
 
 #include "config.h"
 #endif
 
-#define _GNU_SOURCE
 #include <assert.h>
 #include <string.h>
 
 #include <assert.h>
 #include <string.h>
 
@@ -30,6 +29,7 @@
 #include "log/log.h"
 #include "talloc/talloc.h"
 #include "waiter/waiter.h"
 #include "log/log.h"
 #include "talloc/talloc.h"
 #include "waiter/waiter.h"
+#include "process/process.h"
 #include "ui/common/discover-client.h"
 
 static struct pb_opt_data *pbt_opt_data_from_item(struct pbt_item *item)
 #include "ui/common/discover-client.h"
 
 static struct pb_opt_data *pbt_opt_data_from_item(struct pbt_item *item)
@@ -57,13 +57,13 @@ static int pbt_client_boot(struct pbt_item *item)
        int result;
        struct pb_opt_data *opt_data = pbt_opt_data_from_item(item);
 
        int result;
        struct pb_opt_data *opt_data = pbt_opt_data_from_item(item);
 
-       pb_log("%s: %s\n", __func__, pbt_item_name(item));
+       pb_debug("%s: %s\n", __func__, pbt_item_name(item));
 
        pbt_frame_status_printf(&item->pbt_client->frame, "Booting %s...",
                pbt_item_name(item));
 
        result = discover_client_boot(item->pbt_client->discover_client,
 
        pbt_frame_status_printf(&item->pbt_client->frame, "Booting %s...",
                pbt_item_name(item));
 
        result = discover_client_boot(item->pbt_client->discover_client,
-                       opt_data->dev, opt_data->opt, opt_data->bd);
+                       NULL, opt_data->opt, opt_data->bd);
 
        if (result) {
                pb_log("%s: failed: %s\n", __func__, opt_data->bd->image);
 
        if (result) {
                pb_log("%s: failed: %s\n", __func__, opt_data->bd->image);
@@ -83,101 +83,91 @@ static int pbt_client_on_edit(struct pbt_item *item)
 static int pbt_device_add(struct device *dev, struct pbt_client *client)
 {
        struct pbt_frame *const frame = &client->frame;
 static int pbt_device_add(struct device *dev, struct pbt_client *client)
 {
        struct pbt_frame *const frame = &client->frame;
-       struct pbt_item *device_item;
-       struct boot_option *opt;
+       struct pbt_item *item;
        struct pbt_quad q;
        const char *icon_file;
        struct pbt_quad q;
        const char *icon_file;
-       struct pbt_item *selected_item = NULL;
 
 
-       pb_log("%s: %p %s: n_options %d\n", __func__, dev, dev->id,
+       pb_debug("%s: %p %s: n_options %d\n", __func__, dev, dev->id,
                dev->n_options);
 
        pb_protocol_dump_device(dev, "", pb_log_get_stream());
 
                dev->n_options);
 
        pb_protocol_dump_device(dev, "", pb_log_get_stream());
 
-       /* device_item */
-
        // FIXME: check for existing dev->id
 
        icon_file = dev->icon_file ? dev->icon_file : pbt_icon_chooser(dev->id);
 
        // FIXME: check for existing dev->id
 
        icon_file = dev->icon_file ? dev->icon_file : pbt_icon_chooser(dev->id);
 
-       device_item = pbt_item_create_reduced(frame->top_menu, dev->id,
+       item = pbt_item_create_reduced(frame->top_menu, dev->id,
                frame->top_menu->n_items, icon_file);
 
                frame->top_menu->n_items, icon_file);
 
-       if (!device_item)
-               goto fail_device_item_create;
+       if (!item)
+               return -1;
 
 
-       device_item->pb_device = dev;
+       item->pb_device = dev;
+       dev->ui_info = item;
        frame->top_menu->n_items++;
 
        /* sub_menu */
        frame->top_menu->n_items++;
 
        /* sub_menu */
-
        q.x = frame->top_menu->window->pixmap->width;
        q.y = 0;
        q.width = frame->top_menu->scr->tscreen->width - q.x;
        q.height = frame->top_menu->scr->tscreen->height;
 
        q.x = frame->top_menu->window->pixmap->width;
        q.y = 0;
        q.width = frame->top_menu->scr->tscreen->width - q.x;
        q.height = frame->top_menu->scr->tscreen->height;
 
-       device_item->sub_menu = pbt_menu_create(device_item, dev->id,
+       item->sub_menu = pbt_menu_create(item, dev->id,
                frame->top_menu->scr, frame->top_menu, &q,
                &frame->top_menu->layout);
                frame->top_menu->scr, frame->top_menu, &q,
                &frame->top_menu->layout);
-       if (!device_item->sub_menu)
-               goto fail_sub_menu_create;
+       if (!item->sub_menu)
+               return -1;
+
+       pbt_menu_show(frame->top_menu, 1);
+
+       return 0;
+}
+
+static int pbt_boot_option_add(struct device *dev, struct boot_option *opt,
+               struct pbt_client *client)
+{
+       struct pbt_item *opt_item, *device_item;
+       struct pb_opt_data *opt_data;
 
 
-       list_for_each_entry(&dev->boot_options, opt, list) {
-               struct pbt_item *i;
-               struct pb_opt_data *opt_data;
+       device_item = dev->ui_info;
 
 
-               i = pbt_item_create(device_item->sub_menu,
+       opt_item = pbt_item_create(device_item->sub_menu,
                        opt->id, device_item->sub_menu->n_items++,
                        opt->icon_file, opt->name, opt->description);
 
                        opt->id, device_item->sub_menu->n_items++,
                        opt->icon_file, opt->name, opt->description);
 
-               if (!i) {
-                       assert(0);
-                       break;
-               }
-
-               i->pb_opt = opt;
-               i->pbt_client = client;
-               i->on_execute = pbt_client_boot;
-               i->on_edit = pbt_client_on_edit;
-
-               i->data = opt_data = talloc(i, struct pb_opt_data);
-               opt_data->name = opt->name;
-               opt_data->bd = talloc(i, struct pb_boot_data);
-               opt_data->bd->image = talloc_strdup(opt_data->bd,
-                       opt->boot_image_file);
-               opt_data->bd->initrd = talloc_strdup(opt_data->bd,
-                       opt->initrd_file);
-               opt_data->bd->args = talloc_strdup(opt_data->bd,
-                       opt->boot_args);
-               opt_data->dev = dev;
-               opt_data->opt = opt;
-               opt_data->opt_hash = pb_opt_hash(dev, opt);
-
-               /* Select the first item as default. */
-
-               if (!selected_item)
-                       selected_item = i;
-
-               /* If this is the default_item select it and start timer. */
-
-               if (opt_data->opt_hash
-                       == device_item->sub_menu->default_item_hash) {
-                       selected_item = i;
-                       ui_timer_kick(&client->signal_data.timer);
-               }
+       opt_item->pb_opt = opt;
+       opt_item->pbt_client = client;
+       opt_item->on_execute = pbt_client_boot;
+       opt_item->on_edit = pbt_client_on_edit;
+
+       opt_item->data = opt_data = talloc(opt_item, struct pb_opt_data);
+       opt_data->name = opt->name;
+       opt_data->bd = talloc(opt_item, struct pb_boot_data);
+       opt_data->bd->image = talloc_strdup(opt_data->bd,
+               opt->boot_image_file);
+       opt_data->bd->initrd = talloc_strdup(opt_data->bd,
+               opt->initrd_file);
+       opt_data->bd->dtb = talloc_strdup(opt_data->bd,
+               opt->dtb_file);
+       opt_data->bd->args = talloc_strdup(opt_data->bd,
+               opt->boot_args);
+       opt_data->opt = opt;
+       opt_data->opt_hash = pb_opt_hash(dev, opt);
+
+       /* If this is the default_item select it and start timer. */
+       if (opt_data->opt_hash == device_item->sub_menu->default_item_hash) {
+               device_item->selected_item = opt_item;
+               pbt_menu_set_selected(device_item->sub_menu, opt_item);
+               ui_timer_kick(&client->signal_data.timer);
        }
 
        }
 
-       pbt_menu_set_selected(device_item->sub_menu, selected_item);
+       /* Select the first item as default. */
+       if (!device_item->selected_item)
+               pbt_menu_set_selected(device_item->sub_menu, opt_item);
 
 
-       pbt_menu_show(frame->top_menu, 1);
        twin_screen_update(client->frame.scr->tscreen);
 
        return 0;
        twin_screen_update(client->frame.scr->tscreen);
 
        return 0;
-
-fail_sub_menu_create:
-fail_device_item_create:
-       assert(0);
-       return -1;
 }
 
 static void pbt_device_remove(struct device *dev, struct pbt_client *client)
 }
 
 static void pbt_device_remove(struct device *dev, struct pbt_client *client)
@@ -190,7 +180,7 @@ static void pbt_device_remove(struct device *dev, struct pbt_client *client)
        struct pbt_item *next_item;
        struct pbt_item *i;
 
        struct pbt_item *next_item;
        struct pbt_item *i;
 
-       pb_log("%s: %p %s: n_options %d\n", __func__, dev, dev->id,
+       pb_debug("%s: %p %s: n_options %d\n", __func__, dev, dev->id,
                dev->n_options);
 
        pb_protocol_dump_device(dev, "", pb_log_get_stream());
                dev->n_options);
 
        pb_protocol_dump_device(dev, "", pb_log_get_stream());
@@ -248,12 +238,13 @@ static void pbt_device_remove(struct device *dev, struct pbt_client *client)
 
 static struct discover_client_ops pbt_client_ops = {
        .device_add = (void *)pbt_device_add,
 
 static struct discover_client_ops pbt_client_ops = {
        .device_add = (void *)pbt_device_add,
+       .boot_option_add = (void *)pbt_boot_option_add,
        .device_remove = (void *)pbt_device_remove,
 };
 
 static void pbt_client_destructor(struct pbt_client *client)
 {
        .device_remove = (void *)pbt_device_remove,
 };
 
 static void pbt_client_destructor(struct pbt_client *client)
 {
-       pb_log("%s\n", __func__);
+       pb_debug("%s\n", __func__);
 
        // move to screen twin_x11_destroy(twin_ctx);
        talloc_free(client->discover_client);
 
        // move to screen twin_x11_destroy(twin_ctx);
        talloc_free(client->discover_client);
@@ -261,8 +252,7 @@ static void pbt_client_destructor(struct pbt_client *client)
 }
 
 struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
 }
 
 struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
-       unsigned int width, unsigned int height,
-       int start_deamon, int dry_run)
+       unsigned int width, unsigned int height, int start_deamon)
 {
        struct pbt_client *pbt_client;
        unsigned int i;
 {
        struct pbt_client *pbt_client;
        unsigned int i;
@@ -279,8 +269,9 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
 
        pbt_client->waitset = waitset_create(pbt_client);
 
 
        pbt_client->waitset = waitset_create(pbt_client);
 
+       process_init(pbt_client, pbt_client->waitset, false);
+
        pbt_client->sig = "pbt_client";
        pbt_client->sig = "pbt_client";
-       pbt_client->dry_run = dry_run;
        pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset,
                        backend, width, height, NULL, NULL);
 
        pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset,
                        backend, width, height, NULL, NULL);
 
@@ -306,7 +297,7 @@ retry_start:
 
                start_deamon = 0;
 
 
                start_deamon = 0;
 
-               result = pb_start_daemon();
+               result = pb_start_daemon(pbt_client);
 
                if (!result)
                        goto retry_start;
 
                if (!result)
                        goto retry_start;