summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/main.c2
-rw-r--r--src/ply-boot-splash-plugin.h7
-rw-r--r--src/ply-boot-splash.c48
-rw-r--r--src/ply-window.c218
-rw-r--r--src/ply-window.h54
-rw-r--r--src/splash-plugins/fedora-fade-in/Makefile.am2
-rw-r--r--src/splash-plugins/fedora-fade-in/fedora-fade-in.c70
-rw-r--r--src/splash-plugins/text/text.c13
-rw-r--r--src/tests/Makefile.am1
-rw-r--r--src/tests/ply-boot-splash-test.am2
-rw-r--r--src/tests/ply-window-test.am8
12 files changed, 352 insertions, 75 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 540bf19..3baee74 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir) \
-I$(srcdir)/libply \
-I$(srcdir)
plymouthbindir = $(libexecdir)/plymouth
-plymouthbin_PROGRAMS = plymouth
+plymouthbin_PROGRAMS = plymouth
plymouth_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_PLUGIN_PATH=\"$(libdir)/plymouth/\"
plymouth_LDADD = $(PLYMOUTH_LIBS) libply/libply.la
diff --git a/src/main.c b/src/main.c
index 0f6ba0b..0acfc6b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -421,7 +421,7 @@ main (int argc,
return EX_UNAVAILABLE;
}
- state.boot_server = start_boot_server (&state);
+ state.boot_server = start_boot_server (&state);
if (state.boot_server == NULL)
{
diff --git a/src/ply-boot-splash-plugin.h b/src/ply-boot-splash-plugin.h
index 3b54dfa..789c478 100644
--- a/src/ply-boot-splash-plugin.h
+++ b/src/ply-boot-splash-plugin.h
@@ -27,6 +27,7 @@
#include <unistd.h>
#include "ply-event-loop.h"
+#include "ply-window.h"
typedef struct _ply_boot_splash_plugin ply_boot_splash_plugin_t;
@@ -35,10 +36,12 @@ typedef struct
ply_boot_splash_plugin_t * (* create_plugin) (void);
void (* destroy_plugin) (ply_boot_splash_plugin_t *plugin);
- bool (* show_splash_screen) (ply_boot_splash_plugin_t *plugin);
+ bool (* show_splash_screen) (ply_boot_splash_plugin_t *plugin,
+ ply_window_t *window);
void (* update_status) (ply_boot_splash_plugin_t *plugin,
const char *status);
- void (* hide_splash_screen) (ply_boot_splash_plugin_t *plugin);
+ void (* hide_splash_screen) (ply_boot_splash_plugin_t *plugin,
+ ply_window_t *window);
void (* attach_to_event_loop) (ply_boot_splash_plugin_t *plugin,
ply_event_loop_t *loop);
diff --git a/src/ply-boot-splash.c b/src/ply-boot-splash.c
index 86e806b..4a1f93c 100644
--- a/src/ply-boot-splash.c
+++ b/src/ply-boot-splash.c
@@ -43,6 +43,7 @@ struct _ply_boot_splash
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;
char *module_name;
char *status;
@@ -101,8 +102,10 @@ ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
if (get_boot_splash_plugin_interface == NULL)
{
+ ply_save_errno ();
ply_close_module (splash->module_handle);
splash->module_handle = NULL;
+ ply_restore_errno ();
return false;
}
@@ -110,8 +113,10 @@ ply_boot_splash_load_plugin (ply_boot_splash_t *splash)
if (splash->plugin_interface == NULL)
{
+ ply_save_errno ();
ply_close_module (splash->module_handle);
splash->module_handle = NULL;
+ ply_restore_errno ();
return false;
}
@@ -138,6 +143,23 @@ ply_boot_splash_unload_plugin (ply_boot_splash_t *splash)
splash->module_handle = NULL;
}
+static bool
+ply_boot_splash_create_window (ply_boot_splash_t *splash)
+{
+ splash->window = ply_window_new ("/dev/tty1");
+
+ if (!ply_window_open (splash->window))
+ {
+ ply_save_errno ();
+ ply_window_free (splash->window);
+ splash->window = NULL;
+ ply_restore_errno ();
+ return false;
+ }
+
+ return true;
+}
+
bool
ply_boot_splash_show (ply_boot_splash_t *splash)
{
@@ -145,8 +167,14 @@ ply_boot_splash_show (ply_boot_splash_t *splash)
assert (splash->module_name != NULL);
assert (splash->loop != NULL);
+ ply_trace ("trying to load %s", splash->module_name);
if (!ply_boot_splash_load_plugin (splash))
- return false;
+ {
+ ply_save_errno ();
+ ply_trace ("can't load plugin: %m");
+ ply_restore_errno ();
+ return false;
+ }
assert (splash->plugin_interface != NULL);
assert (splash->plugin != NULL);
@@ -155,9 +183,22 @@ ply_boot_splash_show (ply_boot_splash_t *splash)
splash->plugin_interface->attach_to_event_loop (splash->plugin,
splash->loop);
- if (!splash->plugin_interface->show_splash_screen (splash->plugin))
+
+ if (!ply_boot_splash_create_window (splash))
return false;
+ assert (splash->window != NULL);
+
+ if (!splash->plugin_interface->show_splash_screen (splash->plugin,
+ splash->window))
+ {
+
+ ply_save_errno ();
+ ply_trace ("can't show splash: %m");
+ ply_restore_errno ();
+ return false;
+ }
+
splash->is_shown = true;
return true;
}
@@ -197,7 +238,8 @@ ply_boot_splash_hide (ply_boot_splash_t *splash)
assert (splash->plugin != NULL);
assert (splash->plugin_interface->hide_splash_screen != NULL);
- splash->plugin_interface->hide_splash_screen (splash->plugin);
+ splash->plugin_interface->hide_splash_screen (splash->plugin,
+ splash->window);
ply_boot_splash_unload_plugin (splash);
splash->is_shown = false;
diff --git a/src/ply-window.c b/src/ply-window.c
new file mode 100644
index 0000000..bc0bfec
--- /dev/null
+++ b/src/ply-window.c
@@ -0,0 +1,218 @@
+/* ply-window.h - APIs for putting up a window screen
+ *
+ * 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 <rstrode@redhat.com>
+ */
+#include "config.h"
+#include "ply-window.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <linux/kd.h>
+
+#include "ply-event-loop.h"
+#include "ply-logger.h"
+#include "ply-utils.h"
+
+struct _ply_window
+{
+ ply_event_loop_t *loop;
+
+ char *tty_name;
+ int tty_fd;
+
+ ply_window_mode_t mode;
+};
+
+
+ply_window_t *
+ply_window_new (const char *tty_name)
+{
+ ply_window_t *window;
+
+ assert (tty_name != NULL);
+
+ window = calloc (1, sizeof (ply_window_t));
+ window->loop = NULL;
+ window->tty_name = strdup (tty_name);
+ window->tty_fd = -1;
+
+ return window;
+}
+
+bool
+ply_window_open (ply_window_t *window)
+{
+ assert (window != NULL);
+ assert (window->tty_name != NULL);
+ assert (window->tty_fd < 0);
+
+ window->tty_fd = open (window->tty_name, O_RDWR | O_NOCTTY);
+
+ if (window->tty_fd < 0)
+ return false;
+
+ if (!ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT))
+ return false;
+
+ return true;
+}
+
+void
+ply_window_close (ply_window_t *window)
+{
+ ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
+
+ close (window->tty_fd);
+ window->tty_fd = -1;
+}
+
+bool
+ply_window_set_mode (ply_window_t *window,
+ ply_window_mode_t mode)
+{
+ assert (window != NULL);
+ assert (mode == PLY_WINDOW_MODE_TEXT || mode == PLY_WINDOW_MODE_GRAPHICS);
+
+ switch (mode)
+ {
+ case PLY_WINDOW_MODE_TEXT:
+ if (ioctl (window->tty_fd, KDSETMODE, KD_TEXT) < 0)
+ return false;
+ break;
+
+ case PLY_WINDOW_MODE_GRAPHICS:
+ if (ioctl (window->tty_fd, KDSETMODE, KD_GRAPHICS) < 0)
+ return false;
+ break;
+ }
+
+ window->mode = mode;
+ return true;
+}
+
+void
+ply_window_free (ply_window_t *window)
+{
+ if (window == NULL)
+ return;
+
+ ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
+ ply_window_close (window);
+
+ free (window);
+}
+
+static void
+ply_window_detach_from_event_loop (ply_window_t *window)
+{
+ assert (window != NULL);
+ window->loop = NULL;
+}
+
+void
+ply_window_attach_to_event_loop (ply_window_t *window,
+ ply_event_loop_t *loop)
+{
+ assert (window != NULL);
+ assert (loop != NULL);
+ assert (window->loop == NULL);
+
+ window->loop = loop;
+
+ ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t)
+ ply_window_detach_from_event_loop,
+ window);
+}
+
+#ifdef PLY_WINDOW_ENABLE_TEST
+
+#include <stdio.h>
+
+#include "ply-event-loop.h"
+#include "ply-window.h"
+
+static void
+on_timeout (ply_window_t *window,
+ ply_event_loop_t *loop)
+{
+ ply_event_loop_exit (loop, 0);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ ply_event_loop_t *loop;
+ ply_window_t *window;
+ 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";
+
+ window = ply_window_new (tty_name);
+ ply_window_attach_to_event_loop (window, loop);
+
+ if (!ply_window_open (window))
+ {
+ ply_save_errno ();
+ perror ("could not open window");
+ ply_restore_errno ();
+ return errno;
+ }
+
+ if (!ply_window_set_mode (window, PLY_WINDOW_MODE_GRAPHICS))
+ {
+ ply_save_errno ();
+ perror ("could not set window for graphics mode");
+ ply_restore_errno ();
+ }
+
+ ply_event_loop_watch_for_timeout (loop,
+ 1.0,
+ (ply_event_loop_timeout_handler_t)
+ on_timeout,
+ window);
+ exit_code = ply_event_loop_run (loop);
+
+ ply_window_close (window);
+ ply_window_free (window);
+
+ return exit_code;
+}
+
+#endif /* PLY_WINDOW_ENABLE_TEST */
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
diff --git a/src/ply-window.h b/src/ply-window.h
new file mode 100644
index 0000000..da03238
--- /dev/null
+++ b/src/ply-window.h
@@ -0,0 +1,54 @@
+/* ply-window.h - APIs for putting up a splash screen
+ *
+ * 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 <rstrode@redhat.com>
+ */
+#ifndef PLY_WINDOW_H
+#define PLY_WINDOW_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "ply-event-loop.h"
+
+typedef struct _ply_window ply_window_t;
+
+typedef enum
+{
+ PLY_WINDOW_MODE_TEXT,
+ PLY_WINDOW_MODE_GRAPHICS
+} ply_window_mode_t;
+
+#ifndef PLY_HIDE_FUNCTION_DECLARATIONS
+ply_window_t *ply_window_new (const char *tty_name);
+void ply_window_free (ply_window_t *window);
+
+bool ply_window_open (ply_window_t *window);
+void ply_window_close (ply_window_t *window);
+bool ply_window_set_mode (ply_window_t *window,
+ ply_window_mode_t mode);
+
+void ply_window_attach_to_event_loop (ply_window_t *window,
+ ply_event_loop_t *loop);
+
+#endif
+
+#endif /* PLY_WINDOW_H */
+/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
diff --git a/src/splash-plugins/fedora-fade-in/Makefile.am b/src/splash-plugins/fedora-fade-in/Makefile.am
index 8d6b7d0..29ec948 100644
--- a/src/splash-plugins/fedora-fade-in/Makefile.am
+++ b/src/splash-plugins/fedora-fade-in/Makefile.am
@@ -11,6 +11,8 @@ fedora_fade_in_la_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_IMAGE_DIR=\"$(datadir)/
fedora_fade_in_la_LDFLAGS = -module -avoid-version -export-dynamic
fedora_fade_in_la_LIBADD = $(PLYMOUTH_LIBS) ../../libply/libply.la
fedora_fade_in_la_SOURCES = $(srcdir)/../../ply-boot-splash-plugin.h \
+ $(srcdir)/../../ply-window.h \
+ $(srcdir)/../../ply-window.c \
$(srcdir)/fedora-fade-in.c
plymouthdir = $(datadir)/plymouth
diff --git a/src/splash-plugins/fedora-fade-in/fedora-fade-in.c b/src/splash-plugins/fedora-fade-in/fedora-fade-in.c
index 0d6b926..25c675e 100644
--- a/src/splash-plugins/fedora-fade-in/fedora-fade-in.c
+++ b/src/splash-plugins/fedora-fade-in/fedora-fade-in.c
@@ -45,7 +45,7 @@
#include "ply-frame-buffer.h"
#include "ply-image.h"
#include "ply-utils.h"
-
+#include "ply-window.h"
#include <linux/kd.h>
@@ -68,8 +68,8 @@ struct _ply_boot_splash_plugin
ply_image_t *logo_image;
ply_image_t *star_image;
ply_list_t *stars;
+ ply_window_t *window;
- int console_fd;
double start_time;
double now;
};
@@ -81,7 +81,6 @@ create_plugin (void)
srand ((int) ply_get_timestamp ());
plugin = calloc (1, sizeof (ply_boot_splash_plugin_t));
- plugin->console_fd = -1;
plugin->start_time = 0.0;
plugin->frame_buffer = ply_frame_buffer_new (NULL);
@@ -152,45 +151,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
free (plugin);
}
-static bool
-set_graphics_mode (ply_boot_splash_plugin_t *plugin)
-{
- assert (plugin != NULL);
-
- if (ioctl (plugin->console_fd, KDSETMODE, KD_GRAPHICS) < 0)
- return false;
-
- return true;
-}
-
-static void
-set_text_mode (ply_boot_splash_plugin_t *plugin)
-{
- assert (plugin != NULL);
-
- ioctl (plugin->console_fd, KDSETMODE, KD_TEXT);
-}
-
-static bool
-open_console (ply_boot_splash_plugin_t *plugin)
-{
- assert (plugin != NULL);
-
- plugin->console_fd = open ("/dev/tty0", O_RDWR);
-
- if (plugin->console_fd < 0)
- return false;
-
- return true;
-}
-
-static void
-close_console (ply_boot_splash_plugin_t *plugin)
-{
- close (plugin->console_fd);
- plugin->console_fd = -1;
-}
-
static void
animate_at_time (ply_boot_splash_plugin_t *plugin,
double time)
@@ -265,7 +225,7 @@ on_timeout (ply_boot_splash_plugin_t *plugin)
{
double sleep_time;
- set_graphics_mode (plugin);
+ ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_GRAPHICS);
plugin->now = ply_get_timestamp ();
@@ -342,7 +302,7 @@ stop_animation (ply_boot_splash_plugin_t *plugin)
ply_frame_buffer_fill_with_color (plugin->frame_buffer, NULL,
0.0, 0.0, 0.0, 1.0);
- set_text_mode (plugin);
+ ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
}
static void
@@ -353,7 +313,8 @@ on_interrupt (ply_boot_splash_plugin_t *plugin)
}
bool
-show_splash_screen (ply_boot_splash_plugin_t *plugin)
+show_splash_screen (ply_boot_splash_plugin_t *plugin,
+ ply_window_t *window)
{
assert (plugin != NULL);
assert (plugin->logo_image != NULL);
@@ -371,18 +332,10 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin)
if (!ply_frame_buffer_open (plugin->frame_buffer))
return false;
- ply_trace ("opening console");
- if (!open_console (plugin))
- return false;
+ plugin->window = window;
- ply_trace ("settings graphics mode");
- if (!set_graphics_mode (plugin))
- {
- ply_save_errno ();
- close_console (plugin);
- ply_restore_errno ();
- return false;
- }
+ if (!ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_GRAPHICS))
+ return false;
ply_event_loop_watch_signal (plugin->loop,
SIGINT,
@@ -478,11 +431,12 @@ detach_from_event_loop (ply_boot_splash_plugin_t *plugin)
{
plugin->loop = NULL;
- set_text_mode (plugin);
+ ply_window_set_mode (plugin->window, PLY_WINDOW_MODE_TEXT);
}
void
-hide_splash_screen (ply_boot_splash_plugin_t *plugin)
+hide_splash_screen (ply_boot_splash_plugin_t *plugin,
+ ply_window_t *window)
{
assert (plugin != NULL);
diff --git a/src/splash-plugins/text/text.c b/src/splash-plugins/text/text.c
index d2f9b99..014885a 100644
--- a/src/splash-plugins/text/text.c
+++ b/src/splash-plugins/text/text.c
@@ -46,7 +46,7 @@
#include "ply-frame-buffer.h"
#include "ply-image.h"
#include "ply-utils.h"
-
+#include "ply-window.h"
#include <linux/kd.h>
@@ -94,16 +94,9 @@ open_console (ply_boot_splash_plugin_t *plugin)
return true;
}
-static void
-close_console (ply_boot_splash_plugin_t *plugin)
-{
- ply_trace ("closing console");
- close (plugin->console_fd);
- plugin->console_fd = -1;
-}
-
bool
-show_splash_screen (ply_boot_splash_plugin_t *plugin)
+show_splash_screen (ply_boot_splash_plugin_t *plugin,
+ ply_window_t *window)
{
assert (plugin != NULL);
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 7fc5eef..96279eb 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -7,6 +7,7 @@ TESTS =
include $(srcdir)/ply-boot-server-test.am
include $(srcdir)/ply-boot-splash-test.am
+include $(srcdir)/ply-window-test.am
noinst_PROGRAMS = $(TESTS)
MAINTAINERCLEANFILES = Makefile.in
diff --git a/src/tests/ply-boot-splash-test.am b/src/tests/ply-boot-splash-test.am
index d95d012..af67aad 100644
--- a/src/tests/ply-boot-splash-test.am
+++ b/src/tests/ply-boot-splash-test.am
@@ -5,5 +5,7 @@ ply_boot_splash_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la
ply_boot_splash_test_SOURCES = \
$(srcdir)/../ply-boot-splash-plugin.h \
+ $(srcdir)/../ply-window.h \
+ $(srcdir)/../ply-window.c \
$(srcdir)/../ply-boot-splash.h \
$(srcdir)/../ply-boot-splash.c
diff --git a/src/tests/ply-window-test.am b/src/tests/ply-window-test.am
new file mode 100644
index 0000000..09a5644
--- /dev/null
+++ b/src/tests/ply-window-test.am
@@ -0,0 +1,8 @@
+TESTS += ply-window-test
+
+ply_window_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_WINDOW_ENABLE_TEST
+ply_window_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la
+
+ply_window_test_SOURCES = \
+ $(srcdir)/../ply-window.h \
+ $(srcdir)/../ply-window.c