]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
main: add a system-update command that can pass update progress to the daemon
authorRichard Hughes <richard@hughsie.com>
Fri, 8 Jun 2012 08:09:52 +0000 (09:09 +0100)
committerRay Strode <rstrode@redhat.com>
Fri, 8 Jun 2012 22:47:41 +0000 (18:47 -0400)
https://bugs.freedesktop.org/show_bug.cgi?id=50876

src/client/ply-boot-client.c
src/client/ply-boot-client.h
src/client/plymouth.c
src/libply-splash-core/ply-boot-splash-plugin.h
src/libply-splash-core/ply-boot-splash.c
src/libply-splash-core/ply-boot-splash.h
src/main.c
src/ply-boot-protocol.h
src/ply-boot-server.c
src/ply-boot-server.h

index 73650f65573da887343db406df1bad12c3d298d9..56458cebcfd662974316146372ebb0f666e76c43 100644 (file)
@@ -560,6 +560,19 @@ ply_boot_client_change_mode (ply_boot_client_t                  *client,
                                  new_mode, handler, failed_handler, user_data);
 }
 
+void
+ply_boot_client_system_update (ply_boot_client_t                  *client,
+                               const char                         *progress,
+                               ply_boot_client_response_handler_t  handler,
+                               ply_boot_client_response_handler_t  failed_handler,
+                               void                               *user_data)
+{
+  assert (client != NULL);
+
+  ply_boot_client_queue_request (client, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_UPDATE,
+                                 progress, handler, failed_handler, user_data);
+}
+
 void
 ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t                  *client,
                                             const char                         *root_dir,
index 4e7607a131eea71193d996495c5240ca16d70560..24939f766f93ecefec0e90061241b1c121bfb5db 100644 (file)
@@ -63,6 +63,11 @@ void ply_boot_client_change_mode (ply_boot_client_t                  *client,
                                   ply_boot_client_response_handler_t  handler,
                                   ply_boot_client_response_handler_t  failed_handler,
                                   void                               *user_data);
+void ply_boot_client_system_update (ply_boot_client_t                  *client,
+                                    const char                         *progress,
+                                    ply_boot_client_response_handler_t  handler,
+                                    ply_boot_client_response_handler_t  failed_handler,
+                                    void                               *user_data);
 void ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t                  *client,
                                                  const char                         *chroot_dir,
                                                  ply_boot_client_response_handler_t  handler,
index 245e4e5e5e6c8c2d8cfd1e212f5dac9067284919..e00208d171b59c184307b6135561bfd0e486686b 100644 (file)
@@ -910,6 +910,39 @@ on_change_mode_request (state_t    *state,
     }
 }
 
+static void
+on_system_update_request (state_t    *state,
+                          const char *command)
+{
+  int progress;
+
+  progress = 0;
+  ply_command_parser_get_command_options (state->command_parser,
+                                          command,
+                                          "progress", &progress,
+                                          NULL);
+
+  if (progress >= 0 && progress <= 100)
+    {
+      char *progress_string = NULL;
+
+      asprintf (&progress_string, "%d", progress);
+
+      ply_boot_client_system_update (state->client,
+                                     progress_string,
+                                     (ply_boot_client_response_handler_t)
+                                     on_success,
+                                     (ply_boot_client_response_handler_t)
+                                     on_failure, state);
+      free (progress_string);
+    }
+  else
+    {
+      ply_error ("couldn't set invalid percentage: %i", progress);
+      ply_event_loop_exit (state->loop, 1);
+    }
+}
+
 int
 main (int    argc,
       char **argv)
@@ -958,6 +991,14 @@ main (int    argc,
                                   PLY_COMMAND_OPTION_TYPE_FLAG,
                                   NULL);
 
+  ply_command_parser_add_command (state.command_parser,
+                                  "system-update", "Tell the daemon about updates progress",
+                                  (ply_command_handler_t)
+                                  on_system_update_request, &state,
+                                  "progress", "The percentage progress of the updates",
+                                  PLY_COMMAND_OPTION_TYPE_INTEGER,
+                                  NULL);
+
   ply_command_parser_add_command (state.command_parser,
                                   "update", "Tell daemon about boot status changes",
                                   (ply_command_handler_t)
index b29571258afe8ee0d4962f41ae1465aea8e25d83..2d73d6612c11879257c8305ef47ab33b14594d15 100644 (file)
@@ -65,6 +65,8 @@ typedef struct
                                ply_event_loop_t         *loop,
                                ply_buffer_t             *boot_buffer,
                                ply_boot_splash_mode_t    mode);
+  void (* system_update) (ply_boot_splash_plugin_t *plugin,
+                          int                       progress);
   void (* update_status) (ply_boot_splash_plugin_t *plugin,
                           const char               *status);
   void (* on_boot_output) (ply_boot_splash_plugin_t *plugin,
index 46162963046c93b0b22e8fff9b3b5f6c834fc5b8..d82d610c2d81e6c8087fdcfd7e315c395a7b2ecf 100644 (file)
@@ -604,6 +604,23 @@ ply_boot_splash_show (ply_boot_splash_t *splash,
   return true;
 }
 
+bool
+ply_boot_splash_system_update (ply_boot_splash_t *splash,
+                               int                progress)
+{
+  assert (splash != NULL);
+  assert (splash->module_handle != NULL);
+  assert (splash->loop != NULL);
+  assert (splash->plugin_interface != NULL);
+  assert (splash->plugin != NULL);
+  assert (splash->plugin_interface->system_update != NULL);
+
+  ply_trace ("updating system %i%%", progress);
+  splash->plugin_interface->system_update (splash->plugin,
+                                           progress);
+  return true;
+}
+
 void
 ply_boot_splash_update_status (ply_boot_splash_t *splash,
                                const char        *status)
index 8c66a7fc7b035137a7efc33b9a19e03eeae3b01c..a79e9396eed9f00c7de536b3fb1648c7abecb190 100644 (file)
@@ -62,6 +62,8 @@ void ply_boot_splash_remove_text_display (ply_boot_splash_t   *splash,
 void ply_boot_splash_free (ply_boot_splash_t *splash);
 bool ply_boot_splash_show (ply_boot_splash_t *splash,
                            ply_boot_splash_mode_t mode);
+bool ply_boot_splash_system_update (ply_boot_splash_t *splash,
+                                    int                progress);
 void ply_boot_splash_update_status (ply_boot_splash_t *splash,
                                     const char        *status);
 void ply_boot_splash_update_output (ply_boot_splash_t *splash,
index 3187153a99a3180ff9ba627adc8f23c9331244b2..08e0cc3485a971dc63f69b89d9612b509209d9af 100644 (file)
@@ -208,6 +208,24 @@ on_change_mode (state_t     *state,
     }
 }
 
+static void
+on_system_update (state_t     *state,
+                  int          progress)
+{
+  if (state->boot_splash == NULL)
+    {
+      ply_trace ("no splash set");
+      return;
+    }
+
+  ply_trace ("setting system update to '%i'", progress);
+  if (!ply_boot_splash_system_update (state->boot_splash, progress))
+    {
+      ply_trace ("failed to update splash");
+      return;
+    }
+}
+
 static void
 show_messages (state_t *state)
 {
@@ -1256,6 +1274,7 @@ start_boot_server (state_t *state)
 
   server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update,
                                 (ply_boot_server_change_mode_handler_t) on_change_mode,
+                                (ply_boot_server_system_update_handler_t) on_system_update,
                                 (ply_boot_server_ask_for_password_handler_t) on_ask_for_password,
                                 (ply_boot_server_ask_question_handler_t) on_ask_question,
                                 (ply_boot_server_display_message_handler_t) on_display_message,
index b5ac69ba8c29927c5ad97c8f21ef4d056d7b1824..23dfc8da88bd8ce6af254924ee75d42ad5c37dd5 100644 (file)
@@ -27,6 +27,7 @@
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_PING "P"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_UPDATE "U"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_CHANGE_MODE "C"
+#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_UPDATE "u"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_INITIALIZED "S"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_DEACTIVATE "D"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_REACTIVATE "r"
index e027eed45230e60794886f2578418c1b3cf7d8ae..f15ade78332be8efe94835fd7dfbc5ade87abd2c 100644 (file)
@@ -59,6 +59,7 @@ struct _ply_boot_server
 
   ply_boot_server_update_handler_t update_handler;
   ply_boot_server_change_mode_handler_t change_mode_handler;
+  ply_boot_server_system_update_handler_t system_update_handler;
   ply_boot_server_newroot_handler_t newroot_handler;
   ply_boot_server_system_initialized_handler_t system_initialized_handler;
   ply_boot_server_error_handler_t error_handler;
@@ -84,6 +85,7 @@ struct _ply_boot_server
 ply_boot_server_t *
 ply_boot_server_new (ply_boot_server_update_handler_t  update_handler,
                      ply_boot_server_change_mode_handler_t  change_mode_handler,
+                     ply_boot_server_system_update_handler_t  system_update_handler,
                      ply_boot_server_ask_for_password_handler_t ask_for_password_handler,
                      ply_boot_server_ask_question_handler_t ask_question_handler,
                      ply_boot_server_display_message_handler_t display_message_handler,
@@ -112,6 +114,7 @@ ply_boot_server_new (ply_boot_server_update_handler_t  update_handler,
   server->is_listening = false;
   server->update_handler = update_handler;
   server->change_mode_handler = change_mode_handler;
+  server->system_update_handler = system_update_handler;
   server->ask_for_password_handler = ask_for_password_handler;
   server->ask_question_handler = ask_question_handler;
   server->display_message_handler = display_message_handler;
@@ -436,6 +439,30 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection)
       free (command);
       return;
     }
+  else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_UPDATE) == 0)
+    {
+      long int value;
+      char *endptr = NULL;
+
+      value = strtol (argument, &endptr, 10);
+      if (endptr == NULL || *endptr != '\0' || value < 0 || value > 100)
+        {
+          ply_error ("failed to parse percentage %s", argument);
+          value = 0;
+        }
+
+      ply_trace ("got system-update notification %li%%", value);
+      if (!ply_write (connection->fd,
+                      PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK,
+                      strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK)))
+        ply_trace ("could not finish writing update reply: %m");
+
+      if (server->system_update_handler != NULL)
+        server->system_update_handler (server->user_data, value, server);
+      free (argument);
+      free (command);
+      return;
+    }
   else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_INITIALIZED) == 0)
     {
       ply_trace ("got system initialized notification");
@@ -949,6 +976,7 @@ main (int    argc,
 
   server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update,
                                 (ply_boot_server_change_mode_handler_t) on_change_mode,
+                                (ply_boot_server_system_update_handler_t) on_system_update,
                                 (ply_boot_server_ask_for_password_handler_t) on_ask_for_password,
                                 (ply_boot_server_ask_question_handler_t) on_ask_question,
                                 (ply_boot_server_display_message_handler_t) on_display_message,
index f522ccb180bfc29af93822a223da91f8446a7c65..b885a81fd8a91c1fa5db7fd9a14172ac1a83a429 100644 (file)
@@ -40,6 +40,10 @@ typedef void (* ply_boot_server_change_mode_handler_t) (void              *user_
                                                         const char        *mode,
                                                         ply_boot_server_t *server);
 
+typedef void (* ply_boot_server_system_update_handler_t) (void              *user_data,
+                                                          int                progress,
+                                                          ply_boot_server_t *server);
+
 typedef void (* ply_boot_server_newroot_handler_t) (void              *user_data,
                                                     const char        *root_dir,
                                                     ply_boot_server_t *server);
@@ -102,6 +106,7 @@ typedef bool (* ply_boot_server_has_active_vt_handler_t) (void              *use
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
 ply_boot_server_t *ply_boot_server_new (ply_boot_server_update_handler_t update_handler,
                                         ply_boot_server_change_mode_handler_t change_mode_handler,
+                                        ply_boot_server_system_update_handler_t system_update_handler,
                                         ply_boot_server_ask_for_password_handler_t ask_for_password_handler,
                                         ply_boot_server_ask_question_handler_t ask_question_handler,
                                         ply_boot_server_display_message_handler_t display_message_handler,