1 #ifndef _DISCOVER_CLIENT_H
2 #define _DISCOVER_CLIENT_H
4 #include <types/types.h>
5 #include <waiter/waiter.h>
7 struct discover_client;
18 * struct discover_client_ops - Application supplied client info.
19 * @device_add: PB_PROTOCOL_ACTION_ADD event callback.
20 * @device_remove: PB_PROTOCOL_ACTION_REMOVE event callback.
21 * @cb_arg: Client managed convenience variable passed to callbacks.
23 * The discover client holds talloc references to the devices (and the
24 * devices' boot options), so callbacks may store boot options and devices
25 * as long as the client remains allocated.
27 * The status and system_info structs are allocated by the client,
28 * and will be free()ed after the callback is invoked. If the callback
29 * stores these structures for usage beyond the duration of the callback,
30 * it must talloc_steal() them.
33 struct discover_client_ops {
34 int (*device_add)(struct device *device, void *arg);
35 int (*boot_option_add)(struct device *dev, struct boot_option *option,
37 void (*device_remove)(struct device *device, void *arg);
38 void (*update_status)(struct status *status, void *arg);
39 void (*update_sysinfo)(struct system_info *sysinfo, void *arg);
40 void (*update_config)(struct config *sysinfo, void *arg);
44 struct discover_client *discover_client_init(struct waitset *waitset,
45 const struct discover_client_ops *ops, void *cb_arg);
47 void discover_client_destroy(struct discover_client *client);
50 * Get the number of devices that the discover client has stored. This
51 * is the set of devices that have been added and not removed
53 * @param client The discover client
54 * @return The number of devices that have been added.
56 int discover_client_device_count(struct discover_client *client);
59 * Get the device at a specific index.
60 * @param client A pointer to the discover client
61 * @param index The index of the device to retrieve
62 * @return The device at the specified index, or NULL if none exists
64 struct device *discover_client_get_device(struct discover_client *client,
67 /* Tell the discover server to boot an image
68 * @param client A pointer to the discover client
69 * @param boot_command The command to boot
71 int discover_client_boot(struct discover_client *client,
72 const struct device *device,
73 const struct boot_option *boot_option,
74 const struct pb_boot_data *data);
76 /* Tell the discover server to cancel the default boot option, if any
78 int discover_client_cancel_default(struct discover_client *client);
80 /* Tell the discover server to reinitialise */
81 int discover_client_send_reinit(struct discover_client *client);
83 /* Send new configuration data to the discover server */
84 int discover_client_send_config(struct discover_client *client,
85 struct config *config);
87 /* Re-enumerate the collected devices & boot options, calling ops->device_add
88 * and ops->boot_option_add on each.
90 void discover_client_enumerate(struct discover_client *client);
92 /* Send url to config to the discover server */
93 int discover_client_send_url(struct discover_client *client, char *url);