]> git.ozlabs.org Git - petitboot/blob - ui/common/discover-client.h
ui/common: Add discover_client_enumerate to re-add device data
[petitboot] / ui / common / discover-client.h
1 #ifndef _DISCOVER_CLIENT_H
2 #define _DISCOVER_CLIENT_H
3
4 #include <types/types.h>
5 #include <waiter/waiter.h>
6
7 struct discover_client;
8
9 struct pb_boot_data {
10         char *image;
11         char *initrd;
12         char *dtb;
13         char *args;
14 };
15
16 /**
17  * struct discover_client_ops - Application supplied client info.
18  * @device_add: PB_PROTOCOL_ACTION_ADD event callback.
19  * @device_remove: PB_PROTOCOL_ACTION_REMOVE event callback.
20  * @cb_arg: Client managed convenience variable passed to callbacks.
21  *
22  * The discover client holds talloc references to the devices (and the
23  * devices' boot options), so callbacks may store boot options and devices
24  * as long as the client remains allocated.
25  *
26  * The boot_status and system_info structs are allocated by the client,
27  * and will be free()ed after the callback is invoked. If the callback
28  * stores these structures for usage beyond the duration of the callback,
29  * it must talloc_steal() them.
30  */
31
32 struct discover_client_ops {
33         int (*device_add)(struct device *device, void *arg);
34         int (*boot_option_add)(struct device *dev, struct boot_option *option,
35                         void *arg);
36         void (*device_remove)(struct device *device, void *arg);
37         void (*update_status)(struct boot_status *status, void *arg);
38         void (*update_sysinfo)(struct system_info *sysinfo, void *arg);
39         void (*update_config)(struct config *sysinfo, void *arg);
40         void *cb_arg;
41 };
42
43 struct discover_client *discover_client_init(struct waitset *waitset,
44         const struct discover_client_ops *ops, void *cb_arg);
45
46 void discover_client_destroy(struct discover_client *client);
47
48 /**
49  * Get the number of devices that the discover client has stored. This
50  * is the set of devices that have been added and not removed
51  *
52  * @param client The discover client
53  * @return       The number of devices that have been added.
54  */
55 int discover_client_device_count(struct discover_client *client);
56
57 /**
58  * Get the device at a specific index.
59  * @param client A pointer to the discover client
60  * @param index  The index of the device to retrieve
61  * @return       The device at the specified index, or NULL if none exists
62  */
63 struct device *discover_client_get_device(struct discover_client *client,
64                 int index);
65
66 /* Tell the discover server to boot an image
67  * @param client A pointer to the discover client
68  * @param boot_command The command to boot
69  */
70 int discover_client_boot(struct discover_client *client,
71                 const struct device *device,
72                 const struct boot_option *boot_option,
73                 const struct pb_boot_data *data);
74
75 /* Tell the discover server to cancel the default boot option, if any
76  */
77 int discover_client_cancel_default(struct discover_client *client);
78
79 /* Tell the discover server to reinitialise */
80 int discover_client_send_reinit(struct discover_client *client);
81
82 /* Send new configuration data to the discover server */
83 int discover_client_send_config(struct discover_client *client,
84                 struct config *config);
85
86 /* Re-enumerate the collected devices & boot options, calling ops->device_add
87  * and ops->boot_option_add on each.
88  */
89 void discover_client_enumerate(struct discover_client *client);
90 #endif