From: Richard Hughes Date: Fri, 8 Jun 2012 08:09:52 +0000 (+0100) Subject: main: add a system-update command that can pass update progress to the daemon X-Git-Tag: 0.8.6~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cef67c3f5d55080629ab2c249db59466ab0eebe8;p=thirdparty%2Fplymouth.git main: add a system-update command that can pass update progress to the daemon https://bugs.freedesktop.org/show_bug.cgi?id=50876 --- diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index 73650f65..56458ceb 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -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, diff --git a/src/client/ply-boot-client.h b/src/client/ply-boot-client.h index 4e7607a1..24939f76 100644 --- a/src/client/ply-boot-client.h +++ b/src/client/ply-boot-client.h @@ -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, diff --git a/src/client/plymouth.c b/src/client/plymouth.c index 245e4e5e..e00208d1 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -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) diff --git a/src/libply-splash-core/ply-boot-splash-plugin.h b/src/libply-splash-core/ply-boot-splash-plugin.h index b2957125..2d73d661 100644 --- a/src/libply-splash-core/ply-boot-splash-plugin.h +++ b/src/libply-splash-core/ply-boot-splash-plugin.h @@ -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, diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 46162963..d82d610c 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -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) diff --git a/src/libply-splash-core/ply-boot-splash.h b/src/libply-splash-core/ply-boot-splash.h index 8c66a7fc..a79e9396 100644 --- a/src/libply-splash-core/ply-boot-splash.h +++ b/src/libply-splash-core/ply-boot-splash.h @@ -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, diff --git a/src/main.c b/src/main.c index 3187153a..08e0cc34 100644 --- a/src/main.c +++ b/src/main.c @@ -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, diff --git a/src/ply-boot-protocol.h b/src/ply-boot-protocol.h index b5ac69ba..23dfc8da 100644 --- a/src/ply-boot-protocol.h +++ b/src/ply-boot-protocol.h @@ -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" diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index e027eed4..f15ade78 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -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, diff --git a/src/ply-boot-server.h b/src/ply-boot-server.h index f522ccb1..b885a81f 100644 --- a/src/ply-boot-server.h +++ b/src/ply-boot-server.h @@ -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,