]> git.ozlabs.org Git - petitboot/blob - ui/test/discover-test.c
ui/ncurses: Use tty name in default log filename
[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_ANY:
16                 return "any";
17         case DEVICE_TYPE_UNKNOWN:
18                 return "unknown";
19         }
20         return "invalid";
21 }
22
23 static int print_device_add(struct device *device,
24         void __attribute__((unused)) *arg)
25 {
26         struct boot_option *opt;
27
28         printf("new device:\n");
29         printf("\tid:   %s\n", device->id);
30         printf("\ttype: %s\n", device_type_string(device->type));
31         printf("\tname: %s\n", device->name);
32         printf("\tdesc: %s\n", device->description);
33         printf("\ticon: %s\n", device->icon_file);
34
35         printf("\tboot options:\n");
36         list_for_each_entry(&device->boot_options, opt, list) {
37                 printf("\t\tid:   %s\n", opt->id);
38                 printf("\t\tname: %s\n", opt->name);
39                 printf("\t\tdesc: %s\n", opt->description);
40                 printf("\t\ticon: %s\n", opt->icon_file);
41                 printf("\t\tboot: %s\n", opt->boot_image_file);
42                 printf("\t\tinit: %s\n", opt->initrd_file);
43                 printf("\t\tdtb:  %s\n", opt->dtb_file);
44                 printf("\t\targs: %s\n", opt->boot_args);
45         }
46
47         return 0;
48 }
49
50 static int print_boot_option_add(struct device *dev,
51                 struct boot_option *opt,
52                 void __attribute__((unused)) *arg)
53 {
54         printf("new boot option (dev: %s):\n", dev->id);
55         printf("\tdev id: %s\n", opt->device_id);
56         printf("\tid:     %s\n", opt->id);
57         printf("\tname:   %s\n", opt->name);
58         printf("\tdesc:   %s\n", opt->description);
59         printf("\ticon:   %s\n", opt->icon_file);
60         printf("\tboot:   %s\n", opt->boot_image_file);
61         printf("\tinit:   %s\n", opt->initrd_file);
62         printf("\targs:   %s\n", opt->boot_args);
63         printf("\tdefault:%d\n", opt->is_default);
64
65         return 0;
66 }
67
68 static void print_device_remove(struct device *device,
69         void __attribute__((unused)) *arg)
70 {
71         printf("removed device:\n");
72         printf("\tid:   %s\n", device->id);
73         printf("\tname: %s\n", device->name);
74 }
75
76 static void print_status(struct boot_status *status,
77         void __attribute__((unused)) *arg)
78 {
79         printf("status:\n");
80         printf("\ttype:     %d\n", status->type);
81         printf("\tmessage:  %s\n", status->message);
82         printf("\tdetail:   %s\n", status->detail);
83         printf("\tprogress: %d\n", status->progress);
84
85 }
86
87 static void print_sysinfo(struct system_info *sysinfo,
88         void __attribute__((unused)) *arg)
89 {
90         unsigned int i;
91
92         printf("sysinfo:\n");
93         printf("\ttype:     %s\n", sysinfo->type);
94         printf("\tid:       %s\n", sysinfo->identifier);
95
96         if (sysinfo->n_interfaces == 0)
97                 printf("\tno interfaces.\n");
98         else
99                 printf("\tinterfaces:\n");
100
101         for (i = 0; i < sysinfo->n_interfaces; i++) {
102                 struct interface_info *if_info = sysinfo->interfaces[i];
103                 uint8_t *m = if_info->hwaddr;
104
105                 printf("\t\tname:   %s\n", if_info->name);
106
107                 if (if_info->hwaddr_size == 6)
108                         printf("\t\tmac:    %02x:%02x:%02x:%02x:%02x:%02x\n",
109                                         m[0], m[1], m[2], m[3], m[4], m[5]);
110                 else
111                         printf("\t\tmac:    unknown hwaddr size %d\n",
112                                         if_info->hwaddr_size);
113         }
114 }
115
116 static struct discover_client_ops client_ops = {
117         .device_add = print_device_add,
118         .boot_option_add = print_boot_option_add,
119         .device_remove = print_device_remove,
120         .update_status = print_status,
121         .update_sysinfo = print_sysinfo,
122 };
123
124 int main(void)
125 {
126         struct discover_client *client;
127         struct waitset *waitset;
128
129         waitset = waitset_create(NULL);
130
131         client = discover_client_init(waitset, &client_ops, NULL);
132         if (!client)
133                 return -1;
134
135         for (;;) {
136                 int rc;
137
138                 rc = waiter_poll(waitset);
139                 if (rc)
140                         break;
141         }
142
143         return 0;
144 }