X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdiscover-server.c;h=a3087b3335d423fa1e01fc25ab6bfe705a23933f;hp=1765074ecd675038ddc75bf3bc997f4951b925cb;hb=75c97cfd449b2bac8e61af1017a83bdf43f5e8fe;hpb=c14b12980885edd035322cd3bc87efff444c39b1 diff --git a/discover/discover-server.c b/discover/discover-server.c index 1765074..a3087b3 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -28,6 +28,7 @@ struct discover_server { struct waitset *waitset; struct waiter *waiter; struct list clients; + struct list status; struct device_handler *device_handler; }; @@ -157,7 +158,7 @@ static int write_device_remove_message(struct discover_server *server, } static int write_boot_status_message(struct discover_server *server, - struct client *client, const struct boot_status *status) + struct client *client, const struct status *status) { struct pb_protocol_message *message; int len; @@ -216,6 +217,7 @@ static int discover_server_process_message(void *arg) struct boot_command *boot_command; struct client *client = arg; struct config *config; + char *url; int rc; message = pb_protocol_read_message(client, client->fd); @@ -245,6 +247,10 @@ static int discover_server_process_message(void *arg) device_handler_cancel_default(client->server->device_handler); break; + case PB_PROTOCOL_ACTION_REINIT: + device_handler_reinit(client->server->device_handler); + break; + case PB_PROTOCOL_ACTION_CONFIG: config = talloc_zero(client, struct config); @@ -258,6 +264,13 @@ static int discover_server_process_message(void *arg) config); break; + case PB_PROTOCOL_ACTION_ADD_URL: + url = pb_protocol_deserialise_string((void *) client, message); + + device_handler_process_url(client->server->device_handler, + url, NULL, NULL); + break; + default: pb_log("%s: invalid action %d\n", __func__, message->action); return 0; @@ -270,11 +283,12 @@ static int discover_server_process_message(void *arg) static int discover_server_process_connection(void *arg) { struct discover_server *server = arg; + struct statuslog_entry *entry; int fd, rc, i, n_devices; struct client *client; /* accept the incoming connection */ - fd = accept(server->socket, NULL, 0); + fd = accept(server->socket, NULL, NULL); if (fd < 0) { pb_log("accept: %s\n", strerror(errno)); return 0; @@ -321,6 +335,10 @@ static int discover_server_process_connection(void *arg) } } + /* send status backlog to client */ + list_for_each_entry(&server->status, entry, list) + write_boot_status_message(server, client, entry->status); + return 0; } @@ -354,10 +372,28 @@ void discover_server_notify_device_remove(struct discover_server *server, } void discover_server_notify_boot_status(struct discover_server *server, - struct boot_status *status) + struct status *status) { + struct statuslog_entry *entry; struct client *client; + /* Duplicate the status struct to add to the backlog */ + entry = talloc(server, struct statuslog_entry); + if (!entry) { + pb_log("Failed to allocated saved status!\n"); + } else { + entry->status = talloc(entry, struct status); + if (entry->status) { + entry->status->type = status->type; + entry->status->message = talloc_strdup(entry->status, + status->message); + entry->status->backlog = true; + list_add_tail(&server->status, &entry->list); + } else { + talloc_free(entry); + } + } + list_for_each_entry(&server->clients, client, list) write_boot_status_message(server, client, status); } @@ -398,6 +434,7 @@ struct discover_server *discover_server_init(struct waitset *waitset) server->waiter = NULL; server->waitset = waitset; list_init(&server->clients); + list_init(&server->status); unlink(PB_SOCKET_PATH);