45a4c7489719adc3f26fc106e7bef34096540e16
[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\tdtb:  %s\n", opt->dtb_file);
26                 printf("\t\targs: %s\n", opt->boot_args);
27         }
28
29         return 0;
30 }
31
32 static int print_boot_option_add(struct device *dev,
33                 struct boot_option *opt,
34                 void __attribute__((unused)) *arg)
35 {
36         printf("new boot option (dev: %s):\n", dev->id);
37         printf("\tdev id: %s\n", opt->device_id);
38         printf("\tid:     %s\n", opt->id);
39         printf("\tname:   %s\n", opt->name);
40         printf("\tdesc:   %s\n", opt->description);
41         printf("\ticon:   %s\n", opt->icon_file);
42         printf("\tboot:   %s\n", opt->boot_image_file);
43         printf("\tinit:   %s\n", opt->initrd_file);
44         printf("\targs:   %s\n", opt->boot_args);
45         printf("\tdefault:%d\n", opt->is_default);
46
47         return 0;
48 }
49
50 static void print_device_remove(struct device *device,
51         void __attribute__((unused)) *arg)
52 {
53         printf("removed device:\n");
54         printf("\tid:   %s\n", device->id);
55         printf("\tname: %s\n", device->name);
56 }
57
58 static void print_status(struct boot_status *status,
59         void __attribute__((unused)) *arg)
60 {
61         printf("status:\n");
62         printf("\ttype:     %d\n", status->type);
63         printf("\tmessage:  %s\n", status->message);
64         printf("\tdetail:   %s\n", status->detail);
65         printf("\tprogress: %d\n", status->progress);
66
67 }
68
69 static struct discover_client_ops client_ops = {
70         .device_add = print_device_add,
71         .boot_option_add = print_boot_option_add,
72         .device_remove = print_device_remove,
73         .update_status = print_status,
74 };
75
76 int main(void)
77 {
78         struct discover_client *client;
79         struct waitset *waitset;
80
81         waitset = waitset_create(NULL);
82
83         client = discover_client_init(waitset, &client_ops, NULL);
84         if (!client)
85                 return -1;
86
87         for (;;) {
88                 int rc;
89
90                 rc = waiter_poll(waitset);
91                 if (rc)
92                         break;
93         }
94
95         return 0;
96 }