X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdiscover-server.c;h=34d82be828cc623bb7e5f12b949a72c23953c052;hp=a3087b3335d423fa1e01fc25ab6bfe705a23933f;hb=3917e88b838001b13a19fc6ea01d08b08c0770ca;hpb=75c97cfd449b2bac8e61af1017a83bdf43f5e8fe diff --git a/discover/discover-server.c b/discover/discover-server.c index a3087b3..34d82be 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -139,6 +140,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) { @@ -213,6 +247,7 @@ static int write_config_message(struct discover_server *server, static int discover_server_process_message(void *arg) { + struct autoboot_option *autoboot_opt; struct pb_protocol_message *message; struct boot_command *boot_command; struct client *client = arg; @@ -235,7 +270,7 @@ static int discover_server_process_message(void *arg) rc = pb_protocol_deserialise_boot_command(boot_command, message); if (rc) { - pb_log("%s: no boot command?", __func__); + pb_log_fn("no boot command?\n"); return 0; } @@ -256,7 +291,7 @@ static int discover_server_process_message(void *arg) rc = pb_protocol_deserialise_config(config, message); if (rc) { - pb_log("%s: no config?", __func__); + pb_log_fn("no config?\n"); return 0; } @@ -271,8 +306,29 @@ static int discover_server_process_message(void *arg) url, NULL, NULL); break; + case PB_PROTOCOL_ACTION_PLUGIN_INSTALL: + url = pb_protocol_deserialise_string((void *) client, message); + + device_handler_install_plugin(client->server->device_handler, + url); + break; + + case PB_PROTOCOL_ACTION_TEMP_AUTOBOOT: + autoboot_opt = talloc_zero(client, struct autoboot_option); + rc = pb_protocol_deserialise_temp_autoboot(autoboot_opt, + message); + if (rc) { + pb_log("can't parse temporary autoboot message\n"); + return 0; + } + + device_handler_apply_temp_autoboot( + client->server->device_handler, + autoboot_opt); + break; + default: - pb_log("%s: invalid action %d\n", __func__, message->action); + pb_log_fn("invalid action %d\n", message->action); return 0; } @@ -284,7 +340,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 +395,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 +481,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) {