]> git.ozlabs.org Git - petitboot/blobdiff - discover/discover-server.c
discover: parse boot message from incoming ACTION_BOOT messages
[petitboot] / discover / discover-server.c
index 21e15da4c84e64219134274996ec9d09106cf2ba..76d03d1c10159924a3a73cf096d57827dd9ca31b 100644 (file)
@@ -29,6 +29,7 @@ struct discover_server {
 };
 
 struct client {
+       struct discover_server *server;
        struct list_item list;
        int fd;
 };
@@ -126,7 +127,34 @@ static int write_remove_message(struct discover_server *server,
        return client_write_message(server, client, message);
 }
 
-static int discover_server_process(void *arg)
+static int discover_server_process_message(void *arg)
+{
+       struct pb_protocol_message *message;
+       struct boot_command *boot_command;
+       struct client *client = arg;
+
+       message = pb_protocol_read_message(client, client->fd);
+
+       if (!message)
+               return 0;
+
+       if (message->action != PB_PROTOCOL_ACTION_BOOT) {
+               pb_log("%s: invalid action %d\n", __func__, message->action);
+               return 0;
+       }
+
+       boot_command = pb_protocol_deserialise_boot_command(client, message);
+       if (!boot_command) {
+               pb_log("%s: no boot command?", __func__);
+               return 0;
+       }
+
+       /* todo: pass boot_command to client->server->device_handler */
+
+       return 0;
+}
+
+static int discover_server_process_connection(void *arg)
 {
        struct discover_server *server = arg;
        struct client *client;
@@ -146,6 +174,7 @@ static int discover_server_process(void *arg)
        talloc_set_destructor(client, client_destructor);
 
        client->fd = fd;
+       client->server = server;
 
        /* send existing devices to client */
        n_devices = device_handler_get_device_count(server->device_handler);
@@ -156,6 +185,9 @@ static int discover_server_process(void *arg)
                write_add_message(server, client, device);
        }
 
+       waiter_register(server->waitset, client->fd, WAIT_IN,
+                       discover_server_process_message, client);
+
        return 0;
 }
 
@@ -222,7 +254,7 @@ struct discover_server *discover_server_init(struct waitset *waitset)
        }
 
        server->waiter = waiter_register(server->waitset, server->socket,
-                       WAIT_IN, discover_server_process, server);
+                       WAIT_IN, discover_server_process_connection, server);
 
        return server;