]> git.ozlabs.org Git - petitboot/blob - ui/test/discover-test.c
ui/test: print default status of boot options
[petitboot] / ui / test / discover-test.c
1
2 #include <stdio.h>
3
4 #include "ui/common/discover-client.h"
5
6 static int print_device_add(struct device *device,
7         void __attribute__((unused)) *arg)
8 {
9         struct boot_option *opt;
10
11         printf("new device:\n");
12         printf("\tid:   %s\n", device->id);
13         printf("\tname: %s\n", device->name);
14         printf("\tdesc: %s\n", device->description);
15         printf("\ticon: %s\n", device->icon_file);
16
17         printf("\tboot options:\n");
18         list_for_each_entry(&device->boot_options, opt, list) {
19                 printf("\t\tid:   %s\n", opt->id);
20                 printf("\t\tname: %s\n", opt->name);
21                 printf("\t\tdesc: %s\n", opt->description);
22                 printf("\t\ticon: %s\n", opt->icon_file);
23                 printf("\t\tboot: %s\n", opt->boot_image_file);
24                 printf("\t\tinit: %s\n", opt->initrd_file);
25                 printf("\t\targs: %s\n", opt->boot_args);
26         }
27
28         return 0;
29 }
30
31 static int print_boot_option_add(struct device *dev,
32                 struct boot_option *opt,
33                 void __attribute__((unused)) *arg)
34 {
35         printf("new boot option (dev: %s):\n", dev->id);
36         printf("\tdev id: %s\n", opt->device_id);
37         printf("\tid:     %s\n", opt->id);
38         printf("\tname:   %s\n", opt->name);
39         printf("\tdesc:   %s\n", opt->description);
40         printf("\ticon:   %s\n", opt->icon_file);
41         printf("\tboot:   %s\n", opt->boot_image_file);
42         printf("\tinit:   %s\n", opt->initrd_file);
43         printf("\targs:   %s\n", opt->boot_args);
44         printf("\tdefault:%d\n", opt->is_default);
45
46         return 0;
47 }
48
49 static void print_device_remove(struct device *device,
50         void __attribute__((unused)) *arg)
51 {
52         printf("removed device:\n");
53         printf("\tid:   %s\n", device->id);
54         printf("\tname: %s\n", device->name);
55 }
56
57 static void print_status(struct boot_status *status,
58         void __attribute__((unused)) *arg)
59 {
60         printf("status:\n");
61         printf("\ttype:     %d\n", status->type);
62         printf("\tmessage:  %s\n", status->message);
63         printf("\tdetail:   %s\n", status->detail);
64         printf("\tprogress: %d\n", status->progress);
65
66 }
67
68 static struct discover_client_ops client_ops = {
69         .device_add = print_device_add,
70         .boot_option_add = print_boot_option_add,
71         .device_remove = print_device_remove,
72         .update_status = print_status,
73 };
74
75 int main(void)
76 {
77         struct discover_client *client;
78         struct waitset *waitset;
79
80         waitset = waitset_create(NULL);
81
82         client = discover_client_init(waitset, &client_ops, NULL);
83         if (!client)
84                 return -1;
85
86         for (;;) {
87                 int rc;
88
89                 rc = waiter_poll(waitset);
90                 if (rc)
91                         break;
92         }
93
94         return 0;
95 }