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