]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
main: add a change-mode command to be able to switch the splash mode at runtime
authorRichard Hughes <richard@hughsie.com>
Thu, 7 Jun 2012 16:01:53 +0000 (17:01 +0100)
committerRay Strode <rstrode@redhat.com>
Fri, 8 Jun 2012 22:14:40 +0000 (18:14 -0400)
https://bugs.freedesktop.org/show_bug.cgi?id=50847

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/main.c
src/ply-boot-protocol.h
src/ply-boot-server.c
src/ply-boot-server.h

index 5d3965d5cc215798698b76351e9048ea106fa8a3..73650f65573da887343db406df1bad12c3d298d9 100644 (file)
@@ -547,6 +547,19 @@ ply_boot_client_update_daemon (ply_boot_client_t                  *client,
                                  status, handler, failed_handler, user_data);
 }
 
+void
+ply_boot_client_change_mode (ply_boot_client_t                  *client,
+                             const char                         *new_mode,
+                             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_CHANGE_MODE,
+                                 new_mode, handler, failed_handler, user_data);
+}
+
 void
 ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t                  *client,
                                             const char                         *root_dir,
index ca6f37a0da5907231334abfaa24f4ec9e37773aa..4e7607a131eea71193d996495c5240ca16d70560 100644 (file)
@@ -58,6 +58,11 @@ void ply_boot_client_update_daemon (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_change_mode (ply_boot_client_t                  *client,
+                                  const char                         *new_mode,
+                                  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 72574180cd135c284245e76e818ec01c2fc39e15..245e4e5e5e6c8c2d8cfd1e212f5dac9067284919 100644 (file)
@@ -863,6 +863,53 @@ on_update_request (state_t    *state,
     }
 }
 
+static void
+on_change_mode_request (state_t    *state,
+                        const char *command)
+{
+  bool boot_up;
+  bool shutdown;
+  bool updates;
+
+  boot_up = false;
+  shutdown = false;
+  updates = false;
+  ply_command_parser_get_command_options (state->command_parser,
+                                          command,
+                                          "boot-up", &boot_up,
+                                          "shutdown", &shutdown,
+                                          "updates", &updates,
+                                          NULL);
+
+  if (boot_up)
+    {
+      ply_boot_client_change_mode (state->client, "boot-up",
+                                   (ply_boot_client_response_handler_t)
+                                   on_success,
+                                   (ply_boot_client_response_handler_t)
+                                   on_failure, state);
+
+    }
+  else if (shutdown)
+    {
+      ply_boot_client_change_mode (state->client, "shutdown",
+                                   (ply_boot_client_response_handler_t)
+                                   on_success,
+                                   (ply_boot_client_response_handler_t)
+                                   on_failure, state);
+
+    }
+  else if (updates)
+    {
+      ply_boot_client_change_mode (state->client, "updates",
+                                   (ply_boot_client_response_handler_t)
+                                   on_success,
+                                   (ply_boot_client_response_handler_t)
+                                   on_failure, state);
+
+    }
+}
+
 int
 main (int    argc,
       char **argv)
@@ -899,6 +946,18 @@ main (int    argc,
                                   "wait", "Wait for boot daemon to quit", PLY_COMMAND_OPTION_TYPE_FLAG,
                                   NULL);
 
+  ply_command_parser_add_command (state.command_parser,
+                                  "change-mode", "Change the operation mode",
+                                  (ply_command_handler_t)
+                                  on_change_mode_request, &state,
+                                  "boot-up", "Starting the system up",
+                                  PLY_COMMAND_OPTION_TYPE_FLAG,
+                                  "shutdown", "Shutting the system down",
+                                  PLY_COMMAND_OPTION_TYPE_FLAG,
+                                  "updates", "Applying updates",
+                                  PLY_COMMAND_OPTION_TYPE_FLAG,
+                                  NULL);
+
   ply_command_parser_add_command (state.command_parser,
                                   "update", "Tell daemon about boot status changes",
                                   (ply_command_handler_t)
index 107bf9901c0f3aced97d509d38ded3de192f14b9..b29571258afe8ee0d4962f41ae1465aea8e25d83 100644 (file)
@@ -39,6 +39,7 @@ typedef enum
   PLY_BOOT_SPLASH_MODE_BOOT_UP,
   PLY_BOOT_SPLASH_MODE_SHUTDOWN,
   PLY_BOOT_SPLASH_MODE_UPDATES,
+  PLY_BOOT_SPLASH_MODE_INVALID
 } ply_boot_splash_mode_t;
 
 typedef struct _ply_boot_splash_plugin ply_boot_splash_plugin_t;
index a84910d07abc16361e3e8a64a942da5a4d812701..46162963046c93b0b22e8fff9b3b5f6c834fc5b8 100644 (file)
@@ -58,6 +58,7 @@ struct _ply_boot_splash
   ply_module_handle_t *module_handle;
   const ply_boot_splash_plugin_interface_t *plugin_interface;
   ply_boot_splash_plugin_t *plugin;
+  ply_boot_splash_mode_t mode;
   ply_keyboard_t *keyboard;
   ply_buffer_t *boot_buffer;
   ply_trigger_t *idle_trigger;
@@ -73,7 +74,6 @@ struct _ply_boot_splash
   void *idle_handler_user_data;
 
   uint32_t is_loaded : 1;
-  uint32_t is_shown : 1;
   uint32_t should_force_text_mode : 1;
 };
 
@@ -97,7 +97,7 @@ ply_boot_splash_new (const char     *theme_path,
   splash->theme_path = strdup (theme_path);
   splash->plugin_dir = strdup (plugin_dir);
   splash->module_handle = NULL;
-  splash->is_shown = false;
+  splash->mode = PLY_BOOT_SPLASH_MODE_INVALID;
 
   splash->boot_buffer = boot_buffer;
   splash->pixel_displays = ply_list_new ();
@@ -564,17 +564,25 @@ ply_boot_splash_show (ply_boot_splash_t *splash,
                       ply_boot_splash_mode_t mode)
 {
   assert (splash != NULL);
+  assert (mode != PLY_BOOT_SPLASH_MODE_INVALID);
   assert (splash->module_handle != NULL);
   assert (splash->loop != NULL);
-
-  if (splash->is_shown)
-    return true;
-
   assert (splash->plugin_interface != NULL);
   assert (splash->plugin != NULL);
   assert (splash->plugin_interface->show_splash_screen != NULL);
 
-  ply_trace ("showing splash screen\n");
+  if (splash->mode == mode)
+    {
+      ply_trace ("already set same splash screen mode");
+      return true;
+    }
+  else if (splash->mode != PLY_BOOT_SPLASH_MODE_INVALID)
+    {
+      splash->plugin_interface->hide_splash_screen (splash->plugin,
+                                                    splash->loop);
+    }
+
+  ply_trace ("showing splash screen");
   if (!splash->plugin_interface->show_splash_screen (splash->plugin,
                                                      splash->loop,
                                                      splash->boot_buffer,
@@ -592,7 +600,7 @@ ply_boot_splash_show (ply_boot_splash_t *splash,
       ply_boot_splash_update_progress (splash);
     }
 
-  splash->is_shown = true;
+  splash->mode = mode;
   return true;
 }
 
@@ -605,7 +613,7 @@ ply_boot_splash_update_status (ply_boot_splash_t *splash,
   assert (splash->plugin_interface != NULL);
   assert (splash->plugin != NULL);
   assert (splash->plugin_interface->update_status != NULL);
-  assert (splash->is_shown);
+  assert (splash->mode != PLY_BOOT_SPLASH_MODE_INVALID);
 
   splash->plugin_interface->update_status (splash->plugin, status);
 }
@@ -659,7 +667,7 @@ ply_boot_splash_hide (ply_boot_splash_t *splash)
         ply_terminal_set_mode (terminal, PLY_TERMINAL_MODE_TEXT);
     }
 
-  splash->is_shown = false;
+  splash->mode = PLY_BOOT_SPLASH_MODE_INVALID;
 
   if (splash->loop != NULL)
     {
@@ -682,6 +690,7 @@ void ply_boot_splash_display_message (ply_boot_splash_t             *splash,
   assert (splash != NULL);
   assert (splash->plugin_interface != NULL);
   assert (splash->plugin != NULL);
+
   if (splash->plugin_interface->display_message != NULL)
     splash->plugin_interface->display_message (splash->plugin, message);
 }
index b9daf69ff60ffc835399dbaaeb68d320e61afeee..3187153a99a3180ff9ba627adc8f23c9331244b2 100644 (file)
@@ -181,6 +181,33 @@ on_update (state_t     *state,
                                    status);
 }
 
+static void
+on_change_mode (state_t     *state,
+                const char  *mode)
+{
+  if (state->boot_splash == NULL)
+    {
+      ply_trace ("no splash set");
+      return;
+    }
+
+  ply_trace ("updating mode to '%s'", mode);
+  if (strcmp (mode, "boot-up") == 0)
+    state->mode = PLY_BOOT_SPLASH_MODE_BOOT_UP;
+  else if (strcmp (mode, "shutdown") == 0)
+    state->mode = PLY_BOOT_SPLASH_MODE_SHUTDOWN;
+  else if (strcmp (mode, "updates") == 0)
+    state->mode = PLY_BOOT_SPLASH_MODE_UPDATES;
+  else
+    return;
+
+  if (!ply_boot_splash_show (state->boot_splash, state->mode))
+    {
+      ply_trace ("failed to update splash");
+      return;
+    }
+}
+
 static void
 show_messages (state_t *state)
 {
@@ -1228,6 +1255,7 @@ start_boot_server (state_t *state)
   ply_boot_server_t *server;
 
   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_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 11aa1fb810fae9140d3ff483ef259193906d7f31..b5ac69ba8c29927c5ad97c8f21ef4d056d7b1824 100644 (file)
@@ -26,6 +26,7 @@
 #define PLY_BOOT_PROTOCOL_OLD_ABSTRACT_SOCKET_PATH "/ply-boot-protocol"
 #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_INITIALIZED "S"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_DEACTIVATE "D"
 #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_REACTIVATE "r"
index 90a3e7b9197090da175cea8eab1395dd5e07ffbd..e027eed45230e60794886f2578418c1b3cf7d8ae 100644 (file)
@@ -58,6 +58,7 @@ struct _ply_boot_server
   int socket_fd;
 
   ply_boot_server_update_handler_t update_handler;
+  ply_boot_server_change_mode_handler_t change_mode_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;
@@ -82,6 +83,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_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,
@@ -109,6 +111,7 @@ ply_boot_server_new (ply_boot_server_update_handler_t  update_handler,
   server->loop = NULL;
   server->is_listening = false;
   server->update_handler = update_handler;
+  server->change_mode_handler = change_mode_handler;
   server->ask_for_password_handler = ask_for_password_handler;
   server->ask_question_handler = ask_question_handler;
   server->display_message_handler = display_message_handler;
@@ -419,6 +422,20 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection)
       free (command);
       return;
     }
+  else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_CHANGE_MODE) == 0)
+    {
+      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");
+
+      ply_trace ("got change mode notification");
+      if (server->change_mode_handler != NULL)
+        server->change_mode_handler (server->user_data, argument, server);
+      free (argument);
+      free (command);
+      return;
+    }
   else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_SYSTEM_INITIALIZED) == 0)
     {
       ply_trace ("got system initialized notification");
@@ -931,6 +948,7 @@ main (int    argc,
   loop = ply_event_loop_new ();
 
   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_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 f4d2174bf9d0633c17f4ab3f6925503af2413b8a..f522ccb180bfc29af93822a223da91f8446a7c65 100644 (file)
@@ -36,6 +36,10 @@ typedef void (* ply_boot_server_update_handler_t) (void              *user_data,
                                                    const char        *status,
                                                    ply_boot_server_t *server);
 
+typedef void (* ply_boot_server_change_mode_handler_t) (void              *user_data,
+                                                        const char        *mode,
+                                                        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);
@@ -97,6 +101,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_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,