main: add a system-update command that can pass update progress to the daemon

https://bugs.freedesktop.org/show_bug.cgi?id=50876
This commit is contained in:
Richard Hughes 2012-06-08 09:09:52 +01:00 committed by Ray Strode
parent 0880f04eab
commit cef67c3f5d
10 changed files with 133 additions and 0 deletions

View 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,

View 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,

View 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)

View 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,

View 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)

View 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,

View 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,

View 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"

View 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,

View 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,