[PATCH 7/9] add a message display method
william.jon.mccann at gmail.com
william.jon.mccann at gmail.com
Mon Feb 23 12:35:55 PST 2009
From: William Jon McCann <jmccann at redhat.com>
Useful for showing messages like "Shutting down..." etc. A plugin
may choose not to support this feature.
---
src/client/ply-boot-client.c | 14 ++++++++
src/client/ply-boot-client.h | 5 +++
src/client/plymouth.c | 10 +++++-
src/libplybootsplash/ply-boot-splash-plugin.h | 2 +
src/main.c | 10 ++++++
src/plugins/splash/text/plugin.c | 42 +++++++++++++++++++++++++
src/ply-boot-protocol.h | 1 +
src/ply-boot-server.c | 16 +++++++++
src/ply-boot-server.h | 4 ++
src/ply-boot-splash.c | 9 +++++
src/ply-boot-splash.h | 2 +
11 files changed, 114 insertions(+), 1 deletions(-)
diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c
index 7354d3a..ca96bcd 100644
--- a/src/client/ply-boot-client.c
+++ b/src/client/ply-boot-client.c
@@ -530,6 +530,20 @@ ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t *
}
void
+ply_boot_client_tell_daemon_to_display_message (ply_boot_client_t *client,
+ const char *message,
+ ply_boot_client_response_handler_t handler,
+ ply_boot_client_response_handler_t failed_handler,
+ void *user_data)
+{
+ assert (client != NULL);
+ assert (message != NULL);
+
+ ply_boot_client_queue_request (client, PLY_BOOT_PROTOCOL_REQUEST_TYPE_MESSAGE,
+ message, handler, failed_handler, user_data);
+}
+
+void
ply_boot_client_tell_daemon_system_is_initialized (ply_boot_client_t *client,
ply_boot_client_response_handler_t handler,
ply_boot_client_response_handler_t failed_handler,
diff --git a/src/client/ply-boot-client.h b/src/client/ply-boot-client.h
index cca9feb..43684ac 100644
--- a/src/client/ply-boot-client.h
+++ b/src/client/ply-boot-client.h
@@ -63,6 +63,11 @@ void ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t
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_display_message (ply_boot_client_t *client,
+ const char *message,
+ ply_boot_client_response_handler_t handler,
+ ply_boot_client_response_handler_t failed_handler,
+ void *user_data);
void ply_boot_client_ask_daemon_for_password (ply_boot_client_t *client,
const char *prompt,
ply_boot_client_answer_handler_t handler,
diff --git a/src/client/plymouth.c b/src/client/plymouth.c
index 60e86fb..fd8f948 100644
--- a/src/client/plymouth.c
+++ b/src/client/plymouth.c
@@ -596,7 +596,7 @@ main (int argc,
{
state_t state = { 0 };
bool should_help, should_quit, should_ping, should_sysinit, should_ask_for_password, should_show_splash, should_hide_splash, should_wait, should_be_verbose, report_error;
- char *status, *chroot_dir, *ignore_keystroke;
+ char *status, *chroot_dir, *ignore_keystroke, *message;
int exit_code;
exit_code = 0;
@@ -619,6 +619,7 @@ main (int argc,
"ask-for-password", "Ask user for password", PLY_COMMAND_OPTION_TYPE_FLAG,
"ignore-keystroke", "Remove sensitivity to a keystroke", PLY_COMMAND_OPTION_TYPE_STRING,
"update", "Tell boot daemon an update about boot progress", PLY_COMMAND_OPTION_TYPE_STRING,
+ "message", "Tell boot daemon to display a message", PLY_COMMAND_OPTION_TYPE_STRING,
"details", "Tell boot daemon there were errors during boot", PLY_COMMAND_OPTION_TYPE_FLAG,
"wait", "Wait for boot daemon to quit", PLY_COMMAND_OPTION_TYPE_FLAG,
NULL);
@@ -706,6 +707,7 @@ main (int argc,
"sysinit", &should_sysinit,
"show-splash", &should_show_splash,
"hide-splash", &should_hide_splash,
+ "message", &message,
"ask-for-password", &should_ask_for_password,
"ignore-keystroke", &ignore_keystroke,
"update", &status,
@@ -784,6 +786,12 @@ main (int argc,
on_success,
(ply_boot_client_response_handler_t)
on_failure, &state);
+ else if (message != NULL)
+ ply_boot_client_tell_daemon_to_display_message (state.client, message,
+ (ply_boot_client_response_handler_t)
+ on_success,
+ (ply_boot_client_response_handler_t)
+ on_failure, &state);
else if (should_ask_for_password)
{
password_answer_state_t answer_state = { 0 };
diff --git a/src/libplybootsplash/ply-boot-splash-plugin.h b/src/libplybootsplash/ply-boot-splash-plugin.h
index 9361955..5eca3b3 100644
--- a/src/libplybootsplash/ply-boot-splash-plugin.h
+++ b/src/libplybootsplash/ply-boot-splash-plugin.h
@@ -58,6 +58,8 @@ typedef struct
void (* hide_splash_screen) (ply_boot_splash_plugin_t *plugin,
ply_event_loop_t *loop);
void (* display_normal) (ply_boot_splash_plugin_t *plugin);
+ void (* display_message) (ply_boot_splash_plugin_t *plugin,
+ const char *message);
void (* display_password) (ply_boot_splash_plugin_t *plugin,
const char *prompt,
int bullets);
diff --git a/src/main.c b/src/main.c
index 44ac147..62085b2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -203,6 +203,14 @@ on_ask_question (state_t *state,
}
static void
+on_display_message (state_t *state,
+ const char *message)
+{
+ if (state->boot_splash != NULL)
+ ply_boot_splash_display_message (state->boot_splash, message);
+}
+
+static void
on_watch_for_keystroke (state_t *state,
const char *keys,
ply_trigger_t *trigger)
@@ -639,6 +647,7 @@ start_boot_server (state_t *state)
server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_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,
(ply_boot_server_watch_for_keystroke_handler_t) on_watch_for_keystroke,
(ply_boot_server_ignore_keystroke_handler_t) on_ignore_keystroke,
(ply_boot_server_progress_pause_handler_t) on_progress_pause,
@@ -1288,6 +1297,7 @@ main (int argc,
ply_boot_splash_free (state.boot_splash);
state.boot_splash = NULL;
+ ply_command_parser_free (state.command_parser);
ply_list_free (state.windows);
ply_boot_server_free (state.boot_server);
diff --git a/src/plugins/splash/text/plugin.c b/src/plugins/splash/text/plugin.c
index 6a5b4b0..c8dc051 100644
--- a/src/plugins/splash/text/plugin.c
+++ b/src/plugins/splash/text/plugin.c
@@ -67,6 +67,8 @@ struct _ply_boot_splash_plugin
ply_text_progress_bar_t *progress_bar;
+ char *message;
+
uint32_t is_animating : 1;
};
void hide_splash_screen (ply_boot_splash_plugin_t *plugin,
@@ -81,6 +83,7 @@ create_plugin (void)
plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));
plugin->progress_bar = ply_text_progress_bar_new ();
+ plugin->message = NULL;
return plugin;
}
@@ -107,17 +110,45 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
hide_splash_screen (plugin, plugin->loop);
ply_text_progress_bar_free (plugin->progress_bar);
+ if (plugin->message != NULL)
+ free (plugin->message);
free (plugin);
}
static void
+show_message (ply_boot_splash_plugin_t *plugin)
+{
+ int window_width, window_height;
+ int i;
+
+ window_width = ply_window_get_number_of_text_columns (plugin->window);
+ window_height = ply_window_get_number_of_text_rows (plugin->window);
+
+ ply_window_set_text_cursor_position (plugin->window,
+ 0, window_height / 2);
+
+ for (i=0; i < window_width; i++)
+ {
+ write (STDOUT_FILENO, " ", strlen (" "));
+ }
+ ply_window_set_text_cursor_position (plugin->window,
+ (window_width - strlen (plugin->message)) / 2,
+ window_height / 2);
+
+ write (STDOUT_FILENO, plugin->message, strlen (plugin->message));
+}
+
+static void
start_animation (ply_boot_splash_plugin_t *plugin)
{
assert (plugin != NULL);
assert (plugin->loop != NULL);
+ if (plugin->message != NULL)
+ show_message (plugin);
+
if (plugin->is_animating)
return;
@@ -324,6 +355,16 @@ void display_normal (ply_boot_splash_plugin_t *plugin)
start_animation(plugin);
}
+void display_message (ply_boot_splash_plugin_t *plugin,
+ const char *message)
+{
+ if (plugin->message != NULL)
+ free (plugin->message);
+
+ plugin->message = strdup (message);
+ start_animation (plugin);
+}
+
void
display_password (ply_boot_splash_plugin_t *plugin,
const char *prompt,
@@ -409,6 +450,7 @@ ply_boot_splash_plugin_get_interface (void)
.on_boot_progress = on_boot_progress,
.hide_splash_screen = hide_splash_screen,
.display_normal = display_normal,
+ .display_message = display_message,
.display_password = display_password,
.display_question = display_question,
};
diff --git a/src/ply-boot-protocol.h b/src/ply-boot-protocol.h
index 5b2d102..419d481 100644
--- a/src/ply-boot-protocol.h
+++ b/src/ply-boot-protocol.h
@@ -30,6 +30,7 @@
#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD "*"
#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_CACHED_PASSWORD "c"
#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_QUESTION "W"
+#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_MESSAGE "M"
#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE "K"
#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE_REMOVE "L"
#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_PROGRESS_PAUSE "A"
diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c
index 8615f3b..23ae822 100644
--- a/src/ply-boot-server.c
+++ b/src/ply-boot-server.c
@@ -60,6 +60,7 @@ struct _ply_boot_server
ply_boot_server_hide_splash_handler_t hide_splash_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;
ply_boot_server_watch_for_keystroke_handler_t watch_for_keystroke_handler;
ply_boot_server_ignore_keystroke_handler_t ignore_keystroke_handler;
ply_boot_server_progress_pause_handler_t progress_pause_handler;
@@ -74,6 +75,7 @@ ply_boot_server_t *
ply_boot_server_new (ply_boot_server_update_handler_t 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,
ply_boot_server_watch_for_keystroke_handler_t watch_for_keystroke_handler,
ply_boot_server_ignore_keystroke_handler_t ignore_keystroke_handler,
ply_boot_server_progress_pause_handler_t progress_pause_handler,
@@ -96,6 +98,7 @@ ply_boot_server_new (ply_boot_server_update_handler_t update_handler,
server->update_handler = 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;
server->watch_for_keystroke_handler = watch_for_keystroke_handler;
server->ignore_keystroke_handler = ignore_keystroke_handler;
server->progress_pause_handler = progress_pause_handler;
@@ -444,6 +447,11 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection)
free(command);
return;
}
+ else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_MESSAGE) == 0)
+ {
+ if (server->display_message_handler != NULL)
+ server->display_message_handler(server->user_data, argument, server);
+ }
else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_KEYSTROKE) == 0)
{
ply_trigger_t *answer;
@@ -659,6 +667,13 @@ on_ask_question (ply_event_loop_t *loop)
}
static void
+on_display_message (ply_event_loop_t *loop)
+{
+ printf ("got display message request\n");
+ return;
+}
+
+static void
on_watch_for_keystroke (ply_event_loop_t *loop)
{
printf ("got keystroke request\n");
@@ -705,6 +720,7 @@ main (int argc,
server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_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,
(ply_boot_server_watch_for_keystroke_handler_t) on_watch_for_keystroke,
(ply_boot_server_ignore_keystroke_handler_t) on_ignore_keystroke,
(ply_boot_server_progress_pause_handler_t) on_progress_pause,
diff --git a/src/ply-boot-server.h b/src/ply-boot-server.h
index 0817ea6..99ee2a5 100644
--- a/src/ply-boot-server.h
+++ b/src/ply-boot-server.h
@@ -60,6 +60,9 @@ typedef void (* ply_boot_server_ask_question_handler_t) (void
const char *prompt,
ply_trigger_t *answer,
ply_boot_server_t *server);
+typedef void (* ply_boot_server_display_message_handler_t) (void *user_data,
+ const char *message,
+ ply_boot_server_t *server);
typedef void (* ply_boot_server_watch_for_keystroke_handler_t) (void *user_data,
const char *keys,
ply_trigger_t *answer,
@@ -85,6 +88,7 @@ typedef void (* ply_boot_server_quit_handler_t) (void *user_data,
ply_boot_server_t *ply_boot_server_new (ply_boot_server_update_handler_t 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,
ply_boot_server_watch_for_keystroke_handler_t watch_for_keystroke_handler,
ply_boot_server_ignore_keystroke_handler_t ignore_keystroke_handler,
ply_boot_server_progress_pause_handler_t on_progress_pause,
diff --git a/src/ply-boot-splash.c b/src/ply-boot-splash.c
index b67ad20..a8697d8 100644
--- a/src/ply-boot-splash.c
+++ b/src/ply-boot-splash.c
@@ -326,6 +326,15 @@ void ply_boot_splash_display_normal (ply_boot_splash_t *splash)
if (splash->plugin_interface->display_normal != NULL)
splash->plugin_interface->display_normal (splash->plugin);
}
+void ply_boot_splash_display_message (ply_boot_splash_t *splash,
+ const char *message)
+{
+ 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);
+}
void ply_boot_splash_display_password (ply_boot_splash_t *splash,
const char *prompt,
int bullets)
diff --git a/src/ply-boot-splash.h b/src/ply-boot-splash.h
index f925694..4326357 100644
--- a/src/ply-boot-splash.h
+++ b/src/ply-boot-splash.h
@@ -55,6 +55,8 @@ void ply_boot_splash_update_output (ply_boot_splash_t *splash,
void ply_boot_splash_root_mounted (ply_boot_splash_t *splash);
void ply_boot_splash_hide (ply_boot_splash_t *splash);
void ply_boot_splash_display_normal (ply_boot_splash_t *splash);
+void ply_boot_splash_display_message (ply_boot_splash_t *splash,
+ const char *message);
void ply_boot_splash_display_password (ply_boot_splash_t *splash,
const char *prompt,
int bullets);
--
1.6.1.3
More information about the plymouth
mailing list