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,
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,
}
}
+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)
"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)
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;
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;
void *idle_handler_user_data;
uint32_t is_loaded : 1;
- uint32_t is_shown : 1;
uint32_t should_force_text_mode : 1;
};
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 ();
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,
ply_boot_splash_update_progress (splash);
}
- splash->is_shown = true;
+ splash->mode = mode;
return true;
}
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);
}
ply_terminal_set_mode (terminal, PLY_TERMINAL_MODE_TEXT);
}
- splash->is_shown = false;
+ splash->mode = PLY_BOOT_SPLASH_MODE_INVALID;
if (splash->loop != NULL)
{
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);
}
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)
{
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,
#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"
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;
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,
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;
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");
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,
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);
#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,