#include <sys/un.h>
#include <asm/byteorder.h>
+#include <pb-config/pb-config.h>
#include <talloc/talloc.h>
#include <waiter/waiter.h>
#include <log/log.h>
return client_write_message(server, client, message);
}
+static int write_config_message(struct discover_server *server,
+ struct client *client, const struct config *config)
+{
+ struct pb_protocol_message *message;
+ int len;
+
+ len = pb_protocol_config_len(config);
+
+ message = pb_protocol_create_message(client,
+ PB_PROTOCOL_ACTION_CONFIG, len);
+ if (!message)
+ return -1;
+
+ pb_protocol_serialise_config(config, message->payload, len);
+
+ return client_write_message(server, client, message);
+}
+
static int discover_server_process_message(void *arg)
{
struct pb_protocol_message *message;
if (rc)
return 0;
+ /* send config to client */
+ rc = write_config_message(server, client, config_get());
+ if (rc)
+ return 0;
+
/* send existing devices to client */
n_devices = device_handler_get_device_count(server->device_handler);
for (i = 0; i < n_devices; i++) {
write_system_info_message(server, client, sysinfo);
}
+void discover_server_notify_config(struct discover_server *server,
+ const struct config *config)
+{
+ struct client *client;
+
+ list_for_each_entry(&server->clients, client, list)
+ write_config_message(server, client, config);
+}
+
void discover_server_set_device_source(struct discover_server *server,
struct device_handler *handler)
{
struct boot_status;
struct system_info;
struct device;
+struct config;
struct discover_server *discover_server_init(struct waitset *waitset);
struct boot_status *status);
void discover_server_notify_system_info(struct discover_server *server,
const struct system_info *sysinfo);
+void discover_server_notify_config(struct discover_server *server,
+ const struct config *config);
#endif /* _DISCOVER_SERVER_H */
talloc_free(sysinfo);
}
+static void update_config(struct discover_client *client,
+ struct config *config)
+{
+ if (client->ops.update_config)
+ client->ops.update_config(config, client->ops.cb_arg);
+}
+
static int discover_client_process(void *arg)
{
struct discover_client *client = arg;
struct system_info *sysinfo;
struct boot_status *status;
struct boot_option *opt;
+ struct config *config;
struct device *dev;
char *dev_id;
int rc;
}
update_sysinfo(client, sysinfo);
break;
+ case PB_PROTOCOL_ACTION_CONFIG:
+ config = talloc_zero(ctx, struct config);
+
+ rc = pb_protocol_deserialise_config(config, message);
+ if (rc) {
+ pb_log("%s: invalid config message?\n", __func__);
+ return 0;
+ }
+ update_config(client, config);
+ break;
default:
pb_log("%s: unknown action %d\n", __func__, message->action);
}