From ff7293bba1fd4cdf54bb90bd1b7a38dd393fee69 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Wed, 1 Feb 2017 16:11:43 +1100 Subject: discover: Handle and track plugin_options Track plugin_options in the device_handler. Plugins can be added with device_handler_add_plugin_option() and accessed via device_handler_get_plugin(). Extend discover_server to support the new 'add' and 'remove' pb-protocol actions and advertise new plugins to connecting clients. Signed-off-by: Samuel Mendoza-Jonas --- discover/discover-server.c | 61 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'discover/discover-server.c') diff --git a/discover/discover-server.c b/discover/discover-server.c index a3087b3..e2e87ca 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -139,6 +139,39 @@ static int write_boot_option_add_message(struct discover_server *server, return client_write_message(server, client, message); } +static int write_plugin_option_add_message(struct discover_server *server, + struct client *client, const struct plugin_option *opt) +{ + struct pb_protocol_message *message; + int len; + + len = pb_protocol_plugin_option_len(opt); + + message = pb_protocol_create_message(client, + PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD, len); + if (!message) + return -1; + + pb_protocol_serialise_plugin_option(opt, message->payload, len); + + return client_write_message(server, client, message); +} + +static int write_plugins_remove_message(struct discover_server *server, + struct client *client) +{ + struct pb_protocol_message *message; + + message = pb_protocol_create_message(client, + PB_PROTOCOL_ACTION_PLUGINS_REMOVE, 0); + if (!message) + return -1; + + /* No payload so nothing to serialise */ + + return client_write_message(server, client, message); +} + static int write_device_remove_message(struct discover_server *server, struct client *client, char *dev_id) { @@ -284,7 +317,7 @@ static int discover_server_process_connection(void *arg) { struct discover_server *server = arg; struct statuslog_entry *entry; - int fd, rc, i, n_devices; + int fd, rc, i, n_devices, n_plugins; struct client *client; /* accept the incoming connection */ @@ -339,6 +372,15 @@ static int discover_server_process_connection(void *arg) list_for_each_entry(&server->status, entry, list) write_boot_status_message(server, client, entry->status); + /* send installed plugins to client */ + n_plugins = device_handler_get_plugin_count(server->device_handler); + for (i = 0; i < n_plugins; i++) { + const struct plugin_option *plugin; + + plugin = device_handler_get_plugin(server->device_handler, i); + write_plugin_option_add_message(server, client, plugin); + } + return 0; } @@ -416,6 +458,23 @@ void discover_server_notify_config(struct discover_server *server, write_config_message(server, client, config); } +void discover_server_notify_plugin_option_add(struct discover_server *server, + struct plugin_option *opt) +{ + struct client *client; + + list_for_each_entry(&server->clients, client, list) + write_plugin_option_add_message(server, client, opt); +} + +void discover_server_notify_plugins_remove(struct discover_server *server) +{ + struct client *client; + + list_for_each_entry(&server->clients, client, list) + write_plugins_remove_message(server, client); +} + void discover_server_set_device_source(struct discover_server *server, struct device_handler *handler) { -- cgit v1.2.1