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,
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,
}
}
+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)
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)
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,
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)
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,
}
}
+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)
{
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,
#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"
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;
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,
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;
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");
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,
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);
#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,