summaryrefslogtreecommitdiffstats
path: root/ui/test/discover-test.c
blob: f3e7dd8cfc5b177595fedfd9a1ff9815c1dea3b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

#include <stdio.h>

#include "ui/common/discover-client.h"

static const char *device_type_string(enum device_type type)
{
	switch (type) {
	case DEVICE_TYPE_DISK:
		return "disk";
	case DEVICE_TYPE_USB:
		return "usb";
	case DEVICE_TYPE_NETWORK:
		return "network";
	case DEVICE_TYPE_OPTICAL:
		return "optical";
	case DEVICE_TYPE_ANY:
		return "any";
	case DEVICE_TYPE_UNKNOWN:
		return "unknown";
	}
	return "invalid";
}

static int print_device_add(struct device *device,
	void __attribute__((unused)) *arg)
{
	struct boot_option *opt;

	printf("new device:\n");
	printf("\tid:   %s\n", device->id);
	printf("\ttype: %s\n", device_type_string(device->type));
	printf("\tname: %s\n", device->name);
	printf("\tdesc: %s\n", device->description);
	printf("\ticon: %s\n", device->icon_file);

	printf("\tboot options:\n");
	list_for_each_entry(&device->boot_options, opt, list) {
		printf("\t\tid:   %s\n", opt->id);
		printf("\t\tname: %s\n", opt->name);
		printf("\t\tdesc: %s\n", opt->description);
		printf("\t\ticon: %s\n", opt->icon_file);
		printf("\t\tboot: %s\n", opt->boot_image_file);
		printf("\t\tinit: %s\n", opt->initrd_file);
		printf("\t\tdtb:  %s\n", opt->dtb_file);
		printf("\t\targs: %s\n", opt->boot_args);
	}

	return 0;
}

static int print_boot_option_add(struct device *dev,
		struct boot_option *opt,
		void __attribute__((unused)) *arg)
{
	printf("new boot option (dev: %s):\n", dev->id);
	printf("\tdev id: %s\n", opt->device_id);
	printf("\tid:     %s\n", opt->id);
	printf("\tname:   %s\n", opt->name);
	printf("\tdesc:   %s\n", opt->description);
	printf("\ticon:   %s\n", opt->icon_file);
	printf("\tboot:   %s\n", opt->boot_image_file);
	printf("\tinit:   %s\n", opt->initrd_file);
	printf("\targs:   %s\n", opt->boot_args);
	printf("\tdefault:%d\n", opt->is_default);

	return 0;
}

static void print_device_remove(struct device *device,
	void __attribute__((unused)) *arg)
{
	printf("removed device:\n");
	printf("\tid:   %s\n", device->id);
	printf("\tname: %s\n", device->name);
}

static void print_status(struct status *status,
	void __attribute__((unused)) *arg)
{
	printf("status:\n");
	printf("\ttype:     %d\n", status->type);
	printf("\tmessage:  %s\n", status->message);

}

static void print_sysinfo(struct system_info *sysinfo,
	void __attribute__((unused)) *arg)
{
	unsigned int i;

	printf("sysinfo:\n");
	printf("\ttype:     %s\n", sysinfo->type);
	printf("\tid:       %s\n", sysinfo->identifier);

	if (sysinfo->n_interfaces == 0)
		printf("\tno interfaces.\n");
	else
		printf("\tinterfaces:\n");

	for (i = 0; i < sysinfo->n_interfaces; i++) {
		struct interface_info *if_info = sysinfo->interfaces[i];
		uint8_t *m = if_info->hwaddr;

		printf("\t\tname:   %s\n", if_info->name);

		if (if_info->hwaddr_size == 6)
			printf("\t\tmac:    %02x:%02x:%02x:%02x:%02x:%02x\n",
					m[0], m[1], m[2], m[3], m[4], m[5]);
		else
			printf("\t\tmac:    unknown hwaddr size %d\n",
					if_info->hwaddr_size);
	}
}

static struct discover_client_ops client_ops = {
	.device_add = print_device_add,
	.boot_option_add = print_boot_option_add,
	.device_remove = print_device_remove,
	.update_status = print_status,
	.update_sysinfo = print_sysinfo,
};

int main(void)
{
	struct discover_client *client;
	struct waitset *waitset;

	waitset = waitset_create(NULL);

	client = discover_client_init(waitset, &client_ops, NULL);
	if (!client)
		return -1;

	for (;;) {
		int rc;

		rc = waiter_poll(waitset);
		if (rc)
			break;
	}

	return 0;
}
OpenPOWER on IntegriCloud