#include "ply-boot-server.h"
#include "ply-boot-splash.h"
#include "ply-event-loop.h"
+#include "ply-list.h"
#include "ply-logger.h"
#include "ply-terminal-session.h"
#include "ply-trigger.h"
{
ply_event_loop_t *loop;
ply_boot_server_t *boot_server;
- ply_window_t *window;
+ ply_list_t *windows;
ply_boot_splash_t *boot_splash;
ply_terminal_session_t *session;
ply_buffer_t *boot_buffer;
state->number_of_errors++;
}
+static bool
+has_open_window (state_t *state)
+{
+ ply_list_node_t *node;
+
+ node = ply_list_get_first_node (state->windows);
+ while (node != NULL)
+ {
+ ply_list_node_t *next_node;
+ ply_window_t *window;
+
+ next_node = ply_list_get_next_node (state->windows, node);
+
+ window = ply_list_node_get_data (node);
+
+ if (ply_window_is_open (window))
+ return true;
+
+ node = next_node;
+ }
+
+ return false;
+}
+
static bool
plymouth_should_show_default_splash (state_t *state)
{
if (state->console != NULL)
return false;
- if (state->window == NULL)
+ if (!has_open_window (state))
return false;
for (i = 0; strings[i] != NULL; i++)
}
static void
-on_show_splash (state_t *state)
+open_windows (state_t *state)
{
+ ply_list_node_t *node;
+
+ node = ply_list_get_first_node (state->windows);
+ while (node != NULL)
+ {
+ ply_list_node_t *next_node;
+ ply_window_t *window;
+
+ next_node = ply_list_get_next_node (state->windows, node);
+
+ window = ply_list_node_get_data (node);
- if (state->window == NULL)
- state->window = create_window (state, state->console);
+ if (!ply_window_is_open (window))
+ ply_window_open (window);
+
+ node = next_node;
+ }
+}
+
+static void
+close_windows (state_t *state)
+{
+ ply_list_node_t *node;
+
+ node = ply_list_get_first_node (state->windows);
+ while (node != NULL)
+ {
+ ply_list_node_t *next_node;
+ ply_window_t *window;
+
+ next_node = ply_list_get_next_node (state->windows, node);
+
+ window = ply_list_node_get_data (node);
+
+ if (ply_window_is_open (window))
+ ply_window_close (window);
+
+ ply_window_free (window);
+
+ node = next_node;
+ }
+
+ ply_list_free (state->windows);
+}
+
+static void
+on_show_splash (state_t *state)
+{
+ open_windows (state);
if (plymouth_should_show_default_splash (state))
show_default_splash (state);
state->boot_splash = NULL;
}
- ply_trace ("closing splash window");
- if (state->window != NULL)
- {
- ply_window_close (state->window);
- ply_window_free (state->window);
- state->window = NULL;
- }
+ close_windows (state);
if (state->session != NULL)
{
ply_trace ("creating window on %s", tty_name != NULL? tty_name : "active vt");
window = ply_window_new (tty_name);
- ply_trace ("attaching window to event loop");
- ply_window_attach_to_event_loop (window, state->loop);
+ return window;
+}
- ply_trace ("opening window");
- if (state->console == NULL && !ply_window_open (window))
+static void
+add_windows_to_boot_splash (state_t *state,
+ ply_boot_splash_t *splash)
+{
+ ply_list_node_t *node;
+
+ node = ply_list_get_first_node (state->windows);
+ while (node != NULL)
{
- ply_save_errno ();
- ply_trace ("could not open window: %m");
- ply_window_free (window);
- ply_restore_errno ();
- return NULL;
- }
+ ply_list_node_t *next_node;
+ ply_window_t *window;
- ply_trace ("listening for escape key");
- ply_window_set_escape_handler (window, (ply_window_escape_handler_t)
- on_escape_pressed, state);
+ next_node = ply_list_get_next_node (state->windows, node);
- return window;
+ window = ply_list_node_get_data (node);
+
+ if (ply_window_is_open (window))
+ {
+ ply_trace ("adding window to boot splash");
+ ply_boot_splash_add_window (splash, window);
+ }
+
+ ply_trace ("listening for escape key");
+ ply_window_set_escape_handler (window, (ply_window_escape_handler_t)
+ on_escape_pressed, state);
+ node = next_node;
+ }
}
static ply_boot_splash_t *
ply_trace ("Loading boot splash plugin '%s'",
module_path);
- splash = ply_boot_splash_new (module_path, state->window, state->boot_buffer);
+
+ splash = ply_boot_splash_new (module_path, state->boot_buffer);
+
+ if (!ply_boot_splash_load (splash))
+ {
+ ply_save_errno ();
+ ply_boot_splash_free (splash);
+ ply_restore_errno ();
+ return NULL;
+ }
ply_trace ("attaching plugin to event loop");
ply_boot_splash_attach_to_event_loop (splash, state->loop);
+ ply_trace ("adding windows to boot splash");
+ add_windows_to_boot_splash (state, splash);
+
ply_trace ("showing plugin");
if (!ply_boot_splash_show (splash))
{
}
static void
-check_for_serial_console (state_t *state)
+check_for_consoles (state_t *state)
{
char *console_key;
char *remaining_command_line;
*end = '\0';
remaining_command_line += end - state->console;
}
+
+ ply_list_append_data (state->windows, create_window (state, state->console));
}
+
+ if (ply_list_get_length (state->windows) == 0)
+ ply_list_append_data (state->windows, ply_window_new ("tty1"));
}
static bool
return false;
check_verbosity (state);
- check_for_serial_console (state);
+
+ state->windows = ply_list_new ();
+ check_for_consoles (state);
if (state->console != NULL)
redirect_standard_io_to_device (state->console);
ply_boot_splash_free (state.boot_splash);
state.boot_splash = NULL;
- ply_window_free (state.window);
- state.window = NULL;
+ ply_list_free (state.windows);
ply_boot_server_free (state.boot_server);
state.boot_server = NULL;
ply_module_handle_t *module_handle;
const ply_boot_splash_plugin_interface_t *plugin_interface;
ply_boot_splash_plugin_t *plugin;
- ply_window_t *window;
ply_buffer_t *boot_buffer;
ply_trigger_t *idle_trigger;
double start_time;
double wait_time;
+ uint32_t is_loaded : 1;
uint32_t is_shown : 1;
};
ply_boot_splash_t *
ply_boot_splash_new (const char *module_name,
- ply_window_t *window,
ply_buffer_t *boot_buffer)
{
ply_boot_splash_t *splash;
splash->module_handle = NULL;
splash->is_shown = false;
- splash->window = window;
splash->boot_buffer = boot_buffer;
return splash;
}
-static bool
-ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
+void
+ply_boot_splash_add_window (ply_boot_splash_t *splash,
+ ply_window_t *window)
+{
+ splash->plugin_interface->add_window (splash->plugin, window);
+}
+
+void
+ply_boot_splash_remove_window (ply_boot_splash_t *splash,
+ ply_window_t *window)
+{
+ splash->plugin_interface->remove_window (splash->plugin, window);
+}
+
+bool
+ply_boot_splash_load (ply_boot_splash_t *splash)
{
assert (splash != NULL);
assert (splash->module_name != NULL);
assert (splash->plugin != NULL);
+ splash->is_loaded = true;
+
return true;
}
}
}
-static void
-ply_boot_splash_unload_plugin (ply_boot_splash_t *splash)
+void
+ply_boot_splash_unload (ply_boot_splash_t *splash)
{
assert (splash != NULL);
assert (splash->plugin != NULL);
splash->module_handle = NULL;
save_boot_duration (splash);
+
+ splash->is_loaded = false;
}
void
return;
if (splash->module_handle != NULL)
- ply_boot_splash_unload_plugin (splash);
+ ply_boot_splash_unload (splash);
free (splash->module_name);
free (splash);
splash->start_time = ply_get_timestamp ();
splash->boot_duration = DEFAULT_BOOT_DURATION;
- ply_trace ("trying to load %s", splash->module_name);
- if (!ply_boot_splash_load_plugin (splash))
- {
- ply_save_errno ();
- ply_trace ("can't load plugin: %m");
- ply_restore_errno ();
- return false;
- }
-
assert (splash->plugin_interface != NULL);
assert (splash->plugin != NULL);
assert (splash->plugin_interface->show_splash_screen != NULL);
- splash->plugin_interface->add_window (splash->plugin, splash->window);
-
ply_trace ("showing splash screen\n");
if (!splash->plugin_interface->show_splash_screen (splash->plugin,
splash->loop,
splash->plugin_interface->hide_splash_screen (splash->plugin,
splash->loop);
- splash->plugin_interface->remove_window (splash->plugin, splash->window);
-
splash->is_shown = false;
if (splash->loop != NULL)
(ply_window_escape_handler_t) on_quit, &state);
state.buffer = ply_buffer_new ();
- state.splash = ply_boot_splash_new (module_name, state.window, state.buffer);
+ state.splash = ply_boot_splash_new (module_name, state.buffer);
+ if (!ply_boot_splash_load_plugin (state.spalsh))
+ {
+ perror ("could not load splash screen");
+ return errno;
+ }
+
+ ply_boot_splash_add_window (state.window);
ply_boot_splash_attach_to_event_loop (state.splash, state.loop);
if (!ply_boot_splash_show (state.splash))