From: Ray Strode Date: Thu, 25 Sep 2008 04:03:53 +0000 (-0400) Subject: Replace ply-answer with a ply-trigger X-Git-Tag: 0.6.0~120 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47cc4b3aa8d725845e24f077507b7a79a7fc7694;p=thirdparty%2Fplymouth.git Replace ply-answer with a ply-trigger They were basically the same thing, so no reason to have duplicated code. --- diff --git a/src/libplybootsplash/Makefile.am b/src/libplybootsplash/Makefile.am index 59412273..44d06e02 100644 --- a/src/libplybootsplash/Makefile.am +++ b/src/libplybootsplash/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = -I$(top_srcdir) \ lib_LTLIBRARIES = libplybootsplash.la libplybootsplashdir = $(includedir)/plymouth-1/plybootsplash -libplybootsplash_HEADERS = ply-answer.h ply-entry.h ply-progress-bar.h ply-text-pulser.h ply-throbber.h ply-window.h ply-label.h ply-boot-splash-plugin.h ply-label-plugin.h +libplybootsplash_HEADERS = ply-entry.h ply-progress-bar.h ply-text-pulser.h ply-throbber.h ply-window.h ply-label.h ply-boot-splash-plugin.h ply-label-plugin.h libplybootsplash_la_CFLAGS = $(PLYMOUTH_CFLAGS) \ -DPLYMOUTH_BACKGROUND_COLOR=$(background_color) \ @@ -19,7 +19,6 @@ libplybootsplash_la_LDFLAGS = -export-symbols-regex '^[^_].*' \ -no-undefined libplybootsplash_la_SOURCES = \ $(libplybootsplash_HEADERS) \ - ply-answer.c \ ply-entry.c \ ply-label.c \ ply-progress-bar.c \ diff --git a/src/libplybootsplash/ply-answer.c b/src/libplybootsplash/ply-answer.c deleted file mode 100644 index 1cd90223..00000000 --- a/src/libplybootsplash/ply-answer.c +++ /dev/null @@ -1,165 +0,0 @@ -/* ply-answer.h - Object that takes a string and triggers a closure - * to use the string - * - * Copyright (C) 2007 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written by: Ray Strode - */ -#include "config.h" -#include "ply-answer.h" - -#include -#include -#include - -#include "ply-logger.h" -#include "ply-utils.h" - -struct _ply_answer -{ - ply_answer_handler_t handler; - void *user_data; - char *string; -}; - -ply_answer_t * -ply_answer_new (ply_answer_handler_t handler, - void *user_data) -{ - ply_answer_t *answer; - - answer = calloc (1, sizeof (ply_answer_t)); - answer->handler = handler; - answer->user_data = user_data; - - return answer; -} - -void -ply_answer_free (ply_answer_t *answer) -{ - if (answer == NULL) - return; - - free (answer->string); - free (answer); -} - -void -ply_answer_with_string (ply_answer_t *answer, - const char *string) -{ - assert (answer != NULL); - - answer->string = strdup (string); - - if (answer->handler != NULL) - answer->handler (answer->user_data, string, answer); -} - -char * -ply_answer_get_string (ply_answer_t *answer) -{ - return strdup (answer->string); -} - -void -ply_answer_unknown (ply_answer_t *answer) -{ - assert (answer != NULL); - - if (answer->handler != NULL) - answer->handler (answer->user_data, NULL, answer); -} - -#ifdef PLY_ANSWER_ENABLE_TEST - -#include - -#include "ply-event-loop.h" -#include "ply-answer.h" - -static void -on_timeout (ply_answer_t *answer, - ply_event_loop_t *loop) -{ - ply_event_loop_exit (loop, 0); -} - -static void -on_keypress (ply_answer_t *answer, - const char *keyboard_input) -{ - printf ("key '%c' (0x%x) was pressed\n", - keyboard_input[0], (unsigned int) keyboard_input[0]); -} - -int -main (int argc, - char **argv) -{ - ply_event_loop_t *loop; - ply_answer_t *answer; - int exit_code; - const char *tty_name; - - exit_code = 0; - - loop = ply_event_loop_new (); - - if (argc > 1) - tty_name = argv[1]; - else - tty_name = "/dev/tty1"; - - answer = ply_answer_new (tty_name); - ply_answer_attach_to_event_loop (answer, loop); - ply_answer_set_keyboard_input_handler (answer, - (ply_answer_keyboard_input_handler_t) - on_keypress, answer); - - if (!ply_answer_open (answer)) - { - ply_save_errno (); - perror ("could not open answer"); - ply_restore_errno (); - return errno; - } - - if (!ply_answer_set_mode (answer, PLY_ANSWER_MODE_TEXT)) - { - ply_save_errno (); - perror ("could not set answer for graphics mode"); - ply_restore_errno (); - } - - ply_event_loop_watch_for_timeout (loop, - 15.0, - (ply_event_loop_timeout_handler_t) - on_timeout, - answer); - exit_code = ply_event_loop_run (loop); - - ply_answer_close (answer); - ply_answer_free (answer); - - return exit_code; -} - -#endif /* PLY_ANSWER_ENABLE_TEST */ -/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libplybootsplash/ply-answer.h b/src/libplybootsplash/ply-answer.h deleted file mode 100644 index cc256513..00000000 --- a/src/libplybootsplash/ply-answer.h +++ /dev/null @@ -1,53 +0,0 @@ -/* ply-answer.h - Object that takes a string and triggers a closure - * to use the string - * - * Copyright (C) 2008 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * Written By: Ray Strode - */ -#ifndef PLY_ANSWER_H -#define PLY_ANSWER_H - -#include -#include -#include - -#include "ply-buffer.h" -#include "ply-event-loop.h" -#include "ply-frame-buffer.h" - -typedef struct _ply_answer ply_answer_t; - -typedef void (* ply_answer_handler_t) (void *user_data, - const char *string, - ply_answer_t *answer); - -#ifndef PLY_HIDE_FUNCTION_DECLARATIONS -ply_answer_t *ply_answer_new (ply_answer_handler_t handler, - void *user_data); -void ply_answer_free (ply_answer_t *answer); - -void ply_answer_with_string (ply_answer_t *answer, - const char *string); - -void ply_answer_unknown (ply_answer_t *answer); -char *ply_answer_get_string (ply_answer_t *answer); -#endif - -#endif /* PLY_ANSWER_H */ -/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libplybootsplash/ply-boot-splash-plugin.h b/src/libplybootsplash/ply-boot-splash-plugin.h index c5f35547..458cfc9d 100644 --- a/src/libplybootsplash/ply-boot-splash-plugin.h +++ b/src/libplybootsplash/ply-boot-splash-plugin.h @@ -26,7 +26,6 @@ #include #include -#include "ply-answer.h" #include "ply-buffer.h" #include "ply-event-loop.h" #include "ply-trigger.h" @@ -60,7 +59,7 @@ typedef struct void (* ask_for_password) (ply_boot_splash_plugin_t *plugin, const char *prompt, - ply_answer_t *answer); + ply_trigger_t *answer); void (* become_idle) (ply_boot_splash_plugin_t *plugin, ply_trigger_t *idle_trigger); } ply_boot_splash_plugin_interface_t; diff --git a/src/main.c b/src/main.c index 0cbf3d32..7c782c81 100644 --- a/src/main.c +++ b/src/main.c @@ -34,12 +34,12 @@ #include -#include "ply-answer.h" #include "ply-boot-server.h" #include "ply-boot-splash.h" #include "ply-event-loop.h" #include "ply-logger.h" #include "ply-terminal-session.h" +#include "ply-trigger.h" #include "ply-utils.h" #ifndef PLY_MAX_COMMAND_LINE_SIZE @@ -137,13 +137,13 @@ show_default_splash (state_t *state) static void on_ask_for_password (state_t *state, const char *prompt, - ply_answer_t *answer) + ply_trigger_t *answer) { if (state->boot_splash == NULL) { show_detailed_splash (state); if (state->boot_splash == NULL) - ply_answer_with_string (answer, ""); + ply_trigger_pull (answer, ""); return; } diff --git a/src/plugins/splash/details/plugin.c b/src/plugins/splash/details/plugin.c index 4e3292ba..7ae82530 100644 --- a/src/plugins/splash/details/plugin.c +++ b/src/plugins/splash/details/plugin.c @@ -40,7 +40,6 @@ #include #include -#include "ply-answer.h" #include "ply-boot-splash-plugin.h" #include "ply-buffer.h" #include "ply-event-loop.h" @@ -48,6 +47,7 @@ #include "ply-logger.h" #include "ply-frame-buffer.h" #include "ply-image.h" +#include "ply-trigger.h" #include "ply-utils.h" #include "ply-window.h" @@ -58,14 +58,14 @@ void ask_for_password (ply_boot_splash_plugin_t *plugin, const char *prompt, - ply_answer_t *answer); + ply_trigger_t *answer); ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void); struct _ply_boot_splash_plugin { ply_event_loop_t *loop; - ply_answer_t *pending_password_answer; + ply_trigger_t *pending_password_answer; ply_window_t *window; uint32_t keyboard_input_is_hidden : 1; @@ -125,7 +125,7 @@ on_enter (ply_boot_splash_plugin_t *plugin, { if (plugin->pending_password_answer != NULL) { - ply_answer_with_string (plugin->pending_password_answer, line); + ply_trigger_pull (plugin->pending_password_answer, line); plugin->keyboard_input_is_hidden = false; plugin->pending_password_answer = NULL; write (STDOUT_FILENO, CLEAR_LINE_SEQUENCE, strlen (CLEAR_LINE_SEQUENCE)); @@ -220,7 +220,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, if (plugin->pending_password_answer != NULL) { - ply_answer_with_string (plugin->pending_password_answer, ""); + ply_trigger_pull (plugin->pending_password_answer, ""); plugin->pending_password_answer = NULL; plugin->keyboard_input_is_hidden = false; } @@ -239,7 +239,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, void ask_for_password (ply_boot_splash_plugin_t *plugin, const char *prompt, - ply_answer_t *answer) + ply_trigger_t *answer) { plugin->pending_password_answer = answer; diff --git a/src/plugins/splash/fade-in/plugin.c b/src/plugins/splash/fade-in/plugin.c index e91dc3bd..3dda09f8 100644 --- a/src/plugins/splash/fade-in/plugin.c +++ b/src/plugins/splash/fade-in/plugin.c @@ -39,7 +39,6 @@ #include #include -#include "ply-answer.h" #include "ply-boot-splash-plugin.h" #include "ply-buffer.h" #include "ply-entry.h" @@ -48,6 +47,7 @@ #include "ply-logger.h" #include "ply-frame-buffer.h" #include "ply-image.h" +#include "ply-trigger.h" #include "ply-utils.h" #include "ply-window.h" @@ -77,7 +77,7 @@ struct _ply_boot_splash_plugin ply_entry_t *entry; - ply_answer_t *pending_password_answer; + ply_trigger_t *pending_password_answer; double start_time; double now; @@ -387,7 +387,7 @@ on_enter (ply_boot_splash_plugin_t *plugin, if (plugin->pending_password_answer == NULL) return; - ply_answer_with_string (plugin->pending_password_answer, text); + ply_trigger_pull (plugin->pending_password_answer, text); plugin->pending_password_answer = NULL; ply_entry_hide (plugin->entry); @@ -598,7 +598,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, if (plugin->pending_password_answer != NULL) { - ply_answer_with_string (plugin->pending_password_answer, ""); + ply_trigger_pull (plugin->pending_password_answer, ""); plugin->pending_password_answer = NULL; } @@ -651,7 +651,7 @@ show_password_entry (ply_boot_splash_plugin_t *plugin) void ask_for_password (ply_boot_splash_plugin_t *plugin, const char *prompt, - ply_answer_t *answer) + ply_trigger_t *answer) { plugin->pending_password_answer = answer; diff --git a/src/plugins/splash/spinfinity/plugin.c b/src/plugins/splash/spinfinity/plugin.c index ad05d068..02acb68b 100644 --- a/src/plugins/splash/spinfinity/plugin.c +++ b/src/plugins/splash/spinfinity/plugin.c @@ -40,7 +40,6 @@ #include #include -#include "ply-answer.h" #include "ply-boot-splash-plugin.h" #include "ply-buffer.h" #include "ply-entry.h" @@ -51,6 +50,7 @@ #include "ply-logger.h" #include "ply-frame-buffer.h" #include "ply-image.h" +#include "ply-trigger.h" #include "ply-utils.h" #include "ply-window.h" @@ -91,7 +91,7 @@ struct _ply_boot_splash_plugin double start_time; double wait_time; - ply_answer_t *pending_password_answer; + ply_trigger_t *pending_password_answer; ply_trigger_t *idle_trigger; uint32_t root_is_mounted : 1; @@ -348,7 +348,7 @@ on_enter (ply_boot_splash_plugin_t *plugin, if (plugin->pending_password_answer == NULL) return; - ply_answer_with_string (plugin->pending_password_answer, text); + ply_trigger_pull (plugin->pending_password_answer, text); plugin->pending_password_answer = NULL; ply_entry_hide (plugin->entry); @@ -506,7 +506,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, if (plugin->pending_password_answer != NULL) { - ply_answer_with_string (plugin->pending_password_answer, ""); + ply_trigger_pull (plugin->pending_password_answer, ""); plugin->pending_password_answer = NULL; } @@ -595,7 +595,7 @@ show_password_prompt (ply_boot_splash_plugin_t *plugin, void ask_for_password (ply_boot_splash_plugin_t *plugin, const char *prompt, - ply_answer_t *answer) + ply_trigger_t *answer) { plugin->pending_password_answer = answer; plugin->wait_time = ply_get_timestamp (); diff --git a/src/plugins/splash/text/plugin.c b/src/plugins/splash/text/plugin.c index 23bcc1f6..d46ef349 100644 --- a/src/plugins/splash/text/plugin.c +++ b/src/plugins/splash/text/plugin.c @@ -40,7 +40,7 @@ #include #include -#include "ply-answer.h" +#include "ply-trigger.h" #include "ply-boot-splash-plugin.h" #include "ply-buffer.h" #include "ply-event-loop.h" @@ -61,7 +61,7 @@ struct _ply_boot_splash_plugin { ply_event_loop_t *loop; - ply_answer_t *pending_password_answer; + ply_trigger_t *pending_password_answer; ply_window_t *window; ply_text_pulser_t *pulser; @@ -176,7 +176,7 @@ on_enter (ply_boot_splash_plugin_t *plugin, { if (plugin->pending_password_answer != NULL) { - ply_answer_with_string (plugin->pending_password_answer, line); + ply_trigger_pull (plugin->pending_password_answer, line); plugin->keyboard_input_is_hidden = false; plugin->pending_password_answer = NULL; @@ -272,7 +272,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, if (plugin->pending_password_answer != NULL) { - ply_answer_with_string (plugin->pending_password_answer, ""); + ply_trigger_pull (plugin->pending_password_answer, ""); plugin->pending_password_answer = NULL; } @@ -305,7 +305,7 @@ hide_splash_screen (ply_boot_splash_plugin_t *plugin, void ask_for_password (ply_boot_splash_plugin_t *plugin, const char *prompt, - ply_answer_t *answer) + ply_trigger_t *answer) { int window_width, window_height; diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index eafdce81..ff6ef29e 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -31,9 +31,11 @@ #include #include +#include "ply-buffer.h" #include "ply-event-loop.h" #include "ply-list.h" #include "ply-logger.h" +#include "ply-trigger.h" #include "ply-utils.h" typedef struct @@ -47,7 +49,7 @@ struct _ply_boot_server { ply_event_loop_t *loop; ply_list_t *connections; - ply_list_t *cached_answers; + ply_list_t *cached_passwords; int socket_fd; ply_boot_server_update_handler_t update_handler; @@ -78,7 +80,7 @@ ply_boot_server_new (ply_boot_server_update_handler_t update_handler, server = calloc (1, sizeof (ply_boot_server_t)); server->connections = ply_list_new (); - server->cached_answers = ply_list_new (); + server->cached_passwords = ply_list_new (); server->loop = NULL; server->is_listening = false; server->update_handler = update_handler; @@ -108,7 +110,7 @@ ply_boot_server_free (ply_boot_server_t *server) ply_boot_connection_on_hangup (connection); } ply_list_free (server->connections); - ply_list_free (server->cached_answers); + ply_list_free (server->cached_passwords); free (server); } @@ -207,8 +209,7 @@ ply_boot_connection_is_from_root (ply_boot_connection_t *connection) static void ply_boot_connection_on_password_answer (ply_boot_connection_t *connection, - const char *password, - ply_answer_t *answer) + const char *password) { uint8_t size; @@ -240,9 +241,11 @@ ply_boot_connection_on_password_answer (ply_boot_connection_t *connection, !ply_write (connection->fd, password, size)) ply_error ("could not write bytes: %m"); + + ply_list_append_data (connection->server->cached_passwords, + strdup (password)); } - ply_list_append_data (connection->server->cached_answers, answer); } static void @@ -312,9 +315,11 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) } else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD) == 0) { - ply_answer_t *answer; + ply_trigger_t *answer; - answer = ply_answer_new ((ply_answer_handler_t) + answer = ply_trigger_new (NULL); + ply_trigger_add_handler (answer, + (ply_trigger_handler_t) ply_boot_connection_on_password_answer, connection); @@ -337,7 +342,7 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) buffer = ply_buffer_new (); - node = ply_list_get_first_node (server->cached_answers); + node = ply_list_get_first_node (server->cached_passwords); /* Add each answer separated by their NUL terminators into * a buffer that we write out to the client @@ -345,17 +350,14 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) while (node != NULL) { ply_list_node_t *next_node; - ply_answer_t *answer; - char *answer_string; + const char *password; - next_node = ply_list_get_next_node (server->cached_answers, node); - answer = ply_list_node_get_data (node); - answer_string = ply_answer_get_string (answer); - ply_buffer_append_bytes (buffer, - answer_string, - strlen (answer_string) + 1); - free (answer_string); + next_node = ply_list_get_next_node (server->cached_passwords, node); + password = (const char *) ply_list_node_get_data (node); + ply_buffer_append_bytes (buffer, + password, + strlen (password) + 1); node = next_node; } diff --git a/src/ply-boot-server.h b/src/ply-boot-server.h index d9cf7224..e685ad91 100644 --- a/src/ply-boot-server.h +++ b/src/ply-boot-server.h @@ -26,7 +26,7 @@ #include #include -#include "ply-answer.h" +#include "ply-trigger.h" #include "ply-boot-protocol.h" #include "ply-event-loop.h" @@ -51,7 +51,7 @@ typedef void (* ply_boot_server_password_answer_handler_t) (void *a ply_boot_server_t *server); typedef void (* ply_boot_server_ask_for_password_handler_t) (void *user_data, const char *prompt, - ply_answer_t *answer, + ply_trigger_t *answer, ply_boot_server_t *server); typedef void (* ply_boot_server_system_initialized_handler_t) (void *user_data, diff --git a/src/ply-boot-splash.c b/src/ply-boot-splash.c index 46bd21ab..832491e6 100644 --- a/src/ply-boot-splash.c +++ b/src/ply-boot-splash.c @@ -231,7 +231,7 @@ ply_boot_splash_root_mounted (ply_boot_splash_t *splash) void ply_boot_splash_ask_for_password (ply_boot_splash_t *splash, const char *prompt, - ply_answer_t *answer) + ply_trigger_t *trigger) { assert (splash != NULL); @@ -241,13 +241,13 @@ ply_boot_splash_ask_for_password (ply_boot_splash_t *splash, if (splash->plugin_interface->ask_for_password == NULL) { - ply_answer_unknown (answer); + ply_trigger_pull (trigger, NULL); return; } splash->plugin_interface->ask_for_password (splash->plugin, prompt, - answer); + trigger); } static void diff --git a/src/ply-boot-splash.h b/src/ply-boot-splash.h index 5efa6785..057e626d 100644 --- a/src/ply-boot-splash.h +++ b/src/ply-boot-splash.h @@ -26,7 +26,6 @@ #include #include -#include "ply-answer.h" #include "ply-event-loop.h" #include "ply-window.h" #include "ply-buffer.h" @@ -51,7 +50,7 @@ void ply_boot_splash_root_mounted (ply_boot_splash_t *splash); void ply_boot_splash_ask_for_password (ply_boot_splash_t *splash, const char *prompt, - ply_answer_t *answer); + ply_trigger_t *answer); void ply_boot_splash_hide (ply_boot_splash_t *splash); void ply_boot_splash_attach_to_event_loop (ply_boot_splash_t *splash, ply_event_loop_t *loop);