]> git.ozlabs.org Git - petitboot/commitdiff
config: Implement config messages
authorJeremy Kerr <jk@ozlabs.org>
Fri, 18 Oct 2013 02:31:03 +0000 (10:31 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 13 Nov 2013 09:27:51 +0000 (17:27 +0800)
On client connect, send a PB_PROTOCOL_ACTION_CONFIG message.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/discover-server.c
discover/discover-server.h
test/parser/handler.c
ui/common/discover-client.c
ui/common/discover-client.h

index 41a4fde130a69567020f96bbfe477264a5041e1a..bd631f61bf86eac57c76dbfb8dfcb43476ad741a 100644 (file)
@@ -10,6 +10,7 @@
 #include <sys/un.h>
 #include <asm/byteorder.h>
 
 #include <sys/un.h>
 #include <asm/byteorder.h>
 
+#include <pb-config/pb-config.h>
 #include <talloc/talloc.h>
 #include <waiter/waiter.h>
 #include <log/log.h>
 #include <talloc/talloc.h>
 #include <waiter/waiter.h>
 #include <log/log.h>
@@ -190,6 +191,24 @@ static int write_system_info_message(struct discover_server *server,
        return client_write_message(server, client, message);
 }
 
        return client_write_message(server, client, message);
 }
 
+static int write_config_message(struct discover_server *server,
+               struct client *client, const struct config *config)
+{
+       struct pb_protocol_message *message;
+       int len;
+
+       len = pb_protocol_config_len(config);
+
+       message = pb_protocol_create_message(client,
+                       PB_PROTOCOL_ACTION_CONFIG, len);
+       if (!message)
+               return -1;
+
+       pb_protocol_serialise_config(config, message->payload, len);
+
+       return client_write_message(server, client, message);
+}
+
 static int discover_server_process_message(void *arg)
 {
        struct pb_protocol_message *message;
 static int discover_server_process_message(void *arg)
 {
        struct pb_protocol_message *message;
@@ -263,6 +282,11 @@ static int discover_server_process_connection(void *arg)
        if (rc)
                return 0;
 
        if (rc)
                return 0;
 
+       /* send config to client */
+       rc = write_config_message(server, client, config_get());
+       if (rc)
+               return 0;
+
        /* send existing devices to client */
        n_devices = device_handler_get_device_count(server->device_handler);
        for (i = 0; i < n_devices; i++) {
        /* send existing devices to client */
        n_devices = device_handler_get_device_count(server->device_handler);
        for (i = 0; i < n_devices; i++) {
@@ -332,6 +356,15 @@ void discover_server_notify_system_info(struct discover_server *server,
                write_system_info_message(server, client, sysinfo);
 }
 
                write_system_info_message(server, client, sysinfo);
 }
 
+void discover_server_notify_config(struct discover_server *server,
+               const struct config *config)
+{
+       struct client *client;
+
+       list_for_each_entry(&server->clients, client, list)
+               write_config_message(server, client, config);
+}
+
 void discover_server_set_device_source(struct discover_server *server,
                struct device_handler *handler)
 {
 void discover_server_set_device_source(struct discover_server *server,
                struct device_handler *handler)
 {
index d22fb3845717be5aca95fde226f008ebf93eeb8c..97f53b92165c52aacea82eb071ddbd3f6d54e099 100644 (file)
@@ -9,6 +9,7 @@ struct boot_option;
 struct boot_status;
 struct system_info;
 struct device;
 struct boot_status;
 struct system_info;
 struct device;
+struct config;
 
 struct discover_server *discover_server_init(struct waitset *waitset);
 
 
 struct discover_server *discover_server_init(struct waitset *waitset);
 
@@ -27,4 +28,6 @@ void discover_server_notify_boot_status(struct discover_server *server,
                struct boot_status *status);
 void discover_server_notify_system_info(struct discover_server *server,
                const struct system_info *sysinfo);
                struct boot_status *status);
 void discover_server_notify_system_info(struct discover_server *server,
                const struct system_info *sysinfo);
+void discover_server_notify_config(struct discover_server *server,
+               const struct config *config);
 #endif /* _DISCOVER_SERVER_H */
 #endif /* _DISCOVER_SERVER_H */
index d9057eb56c60fd5bff19e937e80a4bf43abd0ab6..97ae3885a16f55eb088e0137c2f68893c0a29bb6 100644 (file)
@@ -36,6 +36,13 @@ void discover_server_notify_boot_status(struct discover_server *server,
        (void)status;
 }
 
        (void)status;
 }
 
+void discover_server_notify_config(struct discover_server *server,
+               struct config *config)
+{
+       (void)server;
+       (void)config;
+}
+
 void parser_init(void)
 {
 }
 void parser_init(void)
 {
 }
index fea8c573c7d18516657dca663c94525164a1ccda..de210bd785bd940af1a27eac7784dc6c87133529 100644 (file)
@@ -126,6 +126,13 @@ static void update_sysinfo(struct discover_client *client,
        talloc_free(sysinfo);
 }
 
        talloc_free(sysinfo);
 }
 
+static void update_config(struct discover_client *client,
+               struct config *config)
+{
+       if (client->ops.update_config)
+               client->ops.update_config(config, client->ops.cb_arg);
+}
+
 static int discover_client_process(void *arg)
 {
        struct discover_client *client = arg;
 static int discover_client_process(void *arg)
 {
        struct discover_client *client = arg;
@@ -133,6 +140,7 @@ static int discover_client_process(void *arg)
        struct system_info *sysinfo;
        struct boot_status *status;
        struct boot_option *opt;
        struct system_info *sysinfo;
        struct boot_status *status;
        struct boot_option *opt;
+       struct config *config;
        struct device *dev;
        char *dev_id;
        int rc;
        struct device *dev;
        char *dev_id;
        int rc;
@@ -194,6 +202,16 @@ static int discover_client_process(void *arg)
                }
                update_sysinfo(client, sysinfo);
                break;
                }
                update_sysinfo(client, sysinfo);
                break;
+       case PB_PROTOCOL_ACTION_CONFIG:
+               config = talloc_zero(ctx, struct config);
+
+               rc = pb_protocol_deserialise_config(config, message);
+               if (rc) {
+                       pb_log("%s: invalid config message?\n", __func__);
+                       return 0;
+               }
+               update_config(client, config);
+               break;
        default:
                pb_log("%s: unknown action %d\n", __func__, message->action);
        }
        default:
                pb_log("%s: unknown action %d\n", __func__, message->action);
        }
index feca63b9eac324c2fd77a6005eda2979c25cf3fc..6aa0432d7a67b2d4fc3774901283b5d852c51881 100644 (file)
@@ -27,6 +27,7 @@ struct discover_client_ops {
        void (*device_remove)(struct device *device, void *arg);
        void (*update_status)(struct boot_status *status, void *arg);
        void (*update_sysinfo)(struct system_info *sysinfo, void *arg);
        void (*device_remove)(struct device *device, void *arg);
        void (*update_status)(struct boot_status *status, void *arg);
        void (*update_sysinfo)(struct system_info *sysinfo, void *arg);
+       void (*update_config)(struct config *sysinfo, void *arg);
        void *cb_arg;
 };
 
        void *cb_arg;
 };