From: Richard Hughes Date: Thu, 7 Jun 2012 16:01:53 +0000 (+0100) Subject: main: add a change-mode command to be able to switch the splash mode at runtime X-Git-Tag: 0.8.6~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0880f04eabfcd0783a261f351be80938d4bcbf3b;p=thirdparty%2Fplymouth.git main: add a change-mode command to be able to switch the splash mode at runtime https://bugs.freedesktop.org/show_bug.cgi?id=50847 --- diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index 5d3965d5..73650f65 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -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, diff --git a/src/client/ply-boot-client.h b/src/client/ply-boot-client.h index ca6f37a0..4e7607a1 100644 --- a/src/client/ply-boot-client.h +++ b/src/client/ply-boot-client.h @@ -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, diff --git a/src/client/plymouth.c b/src/client/plymouth.c index 72574180..245e4e5e 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -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) diff --git a/src/libply-splash-core/ply-boot-splash-plugin.h b/src/libply-splash-core/ply-boot-splash-plugin.h index 107bf990..b2957125 100644 --- a/src/libply-splash-core/ply-boot-splash-plugin.h +++ b/src/libply-splash-core/ply-boot-splash-plugin.h @@ -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; diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index a84910d0..46162963 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -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); } diff --git a/src/main.c b/src/main.c index b9daf69f..3187153a 100644 --- a/src/main.c +++ b/src/main.c @@ -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, diff --git a/src/ply-boot-protocol.h b/src/ply-boot-protocol.h index 11aa1fb8..b5ac69ba 100644 --- a/src/ply-boot-protocol.h +++ b/src/ply-boot-protocol.h @@ -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" diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index 90a3e7b9..e027eed4 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -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, diff --git a/src/ply-boot-server.h b/src/ply-boot-server.h index f4d2174b..f522ccb1 100644 --- a/src/ply-boot-server.h +++ b/src/ply-boot-server.h @@ -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,