]> git.ozlabs.org Git - petitboot/blob - ui/test/discover-test.c
ui/ncurses/nc-widgets: Unify select key
[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 void print_sysinfo(struct system_info *sysinfo,
86         void __attribute__((unused)) *arg)
87 {
88         unsigned int i;
89
90         printf("sysinfo:\n");
91         printf("\ttype:     %s\n", sysinfo->type);
92         printf("\tid:       %s\n", sysinfo->identifier);
93
94         if (sysinfo->n_interfaces == 0)
95                 printf("\tno interfaces.\n");
96         else
97                 printf("\tinterfaces:\n");
98
99         for (i = 0; i < sysinfo->n_interfaces; i++) {
100                 struct interface_info *if_info = sysinfo->interfaces[i];
101                 uint8_t *m = if_info->hwaddr;
102
103                 printf("\t\tname:   %s\n", if_info->name);
104
105                 if (if_info->hwaddr_size == 6)
106                         printf("\t\tmac:    %02x:%02x:%02x:%02x:%02x:%02x\n",
107                                         m[0], m[1], m[2], m[3], m[4], m[5]);
108                 else
109                         printf("\t\tmac:    unknown hwaddr size %d\n",
110                                         if_info->hwaddr_size);
111         }
112 }
113
114 static struct discover_client_ops client_ops = {
115         .device_add = print_device_add,
116         .boot_option_add = print_boot_option_add,
117         .device_remove = print_device_remove,
118         .update_status = print_status,
119         .update_sysinfo = print_sysinfo,
120 };
121
122 int main(void)
123 {
124         struct discover_client *client;
125         struct waitset *waitset;
126
127         waitset = waitset_create(NULL);
128
129         client = discover_client_init(waitset, &client_ops, NULL);
130         if (!client)
131                 return -1;
132
133         for (;;) {
134                 int rc;
135
136                 rc = waiter_poll(waitset);
137                 if (rc)
138                         break;
139         }
140
141         return 0;
142 }