struct list progress;
unsigned int n_progress;
+
+ struct plugin_option **plugins;
+ unsigned int n_plugins;
};
static int mount_device(struct discover_device *dev);
return handler->devices[index];
}
+/**
+ * device_handler_get_plugin_count - Get the count of current handler plugins.
+ */
+int device_handler_get_plugin_count(const struct device_handler *handler)
+{
+ return handler->n_plugins;
+}
+
+/**
+ * discover_handler_get_plugin - Get a handler plugin by index.
+ */
+const struct plugin_option *device_handler_get_plugin(
+ const struct device_handler *handler, unsigned int index)
+{
+ if (index >= handler->n_plugins) {
+ assert(0 && "bad index");
+ return NULL;
+ }
+
+ return handler->plugins[index];
+}
+
struct network *device_handler_get_network(
const struct device_handler *handler)
{
handler->ramdisks = NULL;
handler->n_ramdisks = 0;
+ /* drop any known plugins */
+ for (i = 0; i < handler->n_plugins; i++)
+ talloc_free(handler->plugins[i]);
+ talloc_free(handler->plugins);
+ handler->plugins = NULL;
+ handler->n_plugins = 0;
+
+ discover_server_notify_plugins_remove(handler->server);
+
device_handler_reinit_sources(handler);
}
}
}
+void device_handler_add_plugin_option(struct device_handler *handler,
+ struct plugin_option *opt)
+{
+ struct plugin_option *tmp;
+ unsigned int i;
+
+ for (i = 0; i < handler->n_plugins; i++) {
+ tmp = handler->plugins[i];
+ /* If both id and version match, ignore */
+ if (strncmp(opt->id, tmp->id, strlen(opt->id)) == 0 &&
+ strncmp(opt->version, tmp->version,
+ strlen(opt->version) == 0)) {
+ pb_log("discover: Plugin '%s' already exists, ignoring\n",
+ opt->id);
+ return;
+ }
+ }
+
+ handler->plugins = talloc_realloc(handler, handler->plugins,
+ struct plugin_option *, handler->n_plugins + 1);
+ if (!handler->plugins) {
+ pb_log("Failed to allocate memory for new plugin\n");
+ handler->n_plugins = 0;
+ return;
+ }
+
+ handler->plugins[handler->n_plugins++] = opt;
+ discover_server_notify_plugin_option_add(handler->server, opt);
+}
+
static void device_handler_update_lang(const char *lang)
{
const char *cur_lang;
int device_handler_get_device_count(const struct device_handler *handler);
const struct discover_device *device_handler_get_device(
const struct device_handler *handler, unsigned int index);
+int device_handler_get_plugin_count(const struct device_handler *handler);
+const struct plugin_option *device_handler_get_plugin(
+ const struct device_handler *handler, unsigned int index);
struct network *device_handler_get_network(
const struct device_handler *handler);
struct discover_device *dev);
void discover_context_add_boot_option(struct discover_context *ctx,
struct discover_boot_option *opt);
+void device_handler_add_plugin_option(struct device_handler *handler,
+ struct plugin_option *opt);
int device_handler_user_event(struct device_handler *handler,
struct event *event);
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)
{
{
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 */
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;
}
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)
{
struct device_handler;
struct boot_option;
struct status;
+struct plugin_option;
+struct boot_status;
struct system_info;
struct device;
struct config;
const struct system_info *sysinfo);
void discover_server_notify_config(struct discover_server *server,
const struct config *config);
+void discover_server_notify_plugin_option_add(struct discover_server *server,
+ struct plugin_option *option);
+void discover_server_notify_plugins_remove(struct discover_server *server);
#endif /* _DISCOVER_SERVER_H */
test/parser/utils.c \
test/parser/handler.c \
test/parser/network.c \
+ test/parser/user-event.c \
test/parser/parser-test.h \
discover/yaboot-parser.c \
discover/kboot-parser.c \
#include "device-handler.h"
struct network;
+struct client;
typedef void (*boot_status_fn)(void *arg, struct status *);
void pending_network_jobs_cancel(void)
{
}
+
+void discover_server_notify_plugins_remove(struct discover_server *server)
+{
+ (void)server;
+}
--- /dev/null
+
+#include <assert.h>
+
+#include <types/types.h>
+
+struct device_handler;
+
+void device_handler_add_plugin_option(struct device_handler *handler,
+ struct plugin_option *opt)
+{
+ (void)handler;
+ (void)opt;
+}