AC_CHECK_FILE("${VAPIDIR}/sqlite3.vapi",
true,
[AC_MSG_ERROR("Unable to find Vala bindings for sqlite3")])
+ AC_CHECK_FILE("${VAPIDIR}/posix.vapi",
+ true,
+ [AC_MSG_ERROR("Unable to find Vala bindings for POSIX")])
else
VAPIDIR=`echo ${datadir}/vala/vapi`
fi
rygel-dbus-service.vala \
rygel-root-device.vala \
rygel-root-device-factory.vala \
+ rygel-signal-handler.vala \
rygel-main.vala
VAPI_SOURCE_FILES = rygel-configuration.vala \
-H rygel.h -C --library=rygel-1.0 --vapidir=$(srcdir) --thread \
--pkg cstuff --pkg rygel-build-config --pkg gupnp-1.0 \
--pkg gupnp-av-1.0 --pkg dbus-glib-1 --pkg gstreamer-0.10 \
- --pkg gio-2.0 --pkg gee-1.0 -g
+ --pkg gio-2.0 --pkg gee-1.0 --pkg posix -g
rygel_LDADD = librygel-configuration.a \
$(LIBGUPNP_LIBS) \
*/
#include <cstuff.h>
-#include <signal.h>
#include <string.h>
-static ApplicationExitCb on_app_exit = NULL;
-static gpointer data;
-static struct sigaction sig_action;
-
/* Copy-paste from gupnp. */
xmlNode *
get_xml_element (xmlNode *node,
return default_value;
}
-
-static void
-signal_handler (int signum)
-{
- gboolean restart;
-
- restart = (signum == SIGHUP);
-
- on_app_exit (restart, data);
-}
-
-void
-on_application_exit (ApplicationExitCb app_exit_cb,
- gpointer user_data)
-{
- on_app_exit = app_exit_cb;
- data = user_data;
-
- /* Hook the handler for SIGTERM */
- memset (&sig_action, 0, sizeof (sig_action));
- sig_action.sa_handler = signal_handler;
- sigaction (SIGINT, &sig_action, NULL);
- sigaction (SIGHUP, &sig_action, NULL);
-}
-
-void
-restart_application (const char **args) {
- execvp (args[0], args);
-}
#include <glib.h>
#include <uuid/uuid.h>
-typedef void (* ApplicationExitCb) (gboolean restart,
- gpointer user_data);
-
G_GNUC_INTERNAL xmlNode *
get_xml_element (xmlNode *node,
...);
G_GNUC_INTERNAL char *
generate_random_udn (void);
-G_GNUC_INTERNAL void
-on_application_exit (ApplicationExitCb app_exit_cb,
- gpointer user_data);
-
-G_GNUC_INTERNAL void
-restart_application (const char **args);
-
#endif /* __CSTUFF_H__ */
...);
[CCode (cname = "generate_random_udn", cheader_filename = "cstuff.h")]
public static string generate_random_udn ();
-
- public delegate void ApplicationExitCb (bool restart);
-
- [CCode (cname = "on_application_exit", cheader_filename = "cstuff.h")]
- public static void on_application_exit
- (ApplicationExitCb app_exit_cb);
-
- [CCode (cname = "restart_application", cheader_filename = "cstuff.h")]
- public static void restart_application (
- [CCode (array_length = false,
- array_null_terminated = true)]
- string[] args);
}
}
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-using CStuff;
using Gee;
using GUPnP;
+namespace Posix {
+ [CCode (cheader_filename = "unistd.h")]
+ public extern int execvp (string file, string[] argv);
+}
+
public class Rygel.Main : Object {
private static int PLUGIN_TIMEOUT = 5;
private PluginLoader plugin_loader;
+ private SignalHandler signal_handler;
private ContextManager context_manager;
private ArrayList <RootDeviceFactory> factories;
private ArrayList <RootDevice> root_devices;
this.plugin_loader.plugin_available.connect (this.on_plugin_loaded);
- Utils.on_application_exit (this.application_exit_cb);
+ this.signal_handler = SignalHandler.get_default ();
+ this.signal_handler.exit.connect (this.application_exit_cb);
+ this.signal_handler.restart.connect (this.application_restart_cb);
}
public void exit (int exit_code) {
return this.exit_code;
}
- private void application_exit_cb (bool restart) {
- this.restart = restart;
+ private void application_restart_cb () {
+ this.restart = true;
+
+ this.exit (0);
+ }
+ private void application_exit_cb () {
this.exit (0);
}
int exit_code = main.run ();
if (main.restart) {
- Utils.restart_application (original_args);
+ Posix.execvp (original_args[0], original_args);
}
return exit_code;
--- /dev/null
+/*
+ * Copyright (C) 2008,2010 Nokia Corporation.
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Posix;
+
+/**
+ * Handles Posix signals.
+ */
+public class Rygel.SignalHandler : GLib.Object {
+ private static SignalHandler handler;
+
+ public signal void exit ();
+ public signal void restart ();
+
+ private sigaction_t action;
+
+ public static SignalHandler get_default () {
+ if (handler == null) {
+ handler = new SignalHandler ();
+ }
+
+ return handler;
+ }
+
+ private SignalHandler () {
+ this.action = sigaction_t ();
+
+ this.action.sa_handler = this.signal_handler;
+
+ /* Hook the handler for SIGTERM */
+ sigaction (SIGINT, this.action, null);
+ sigaction (SIGHUP, this.action, null);
+ }
+
+ private static void signal_handler (int signum) {
+ if (signum == SIGHUP) {
+ handler.restart ();
+ } else {
+ handler.exit ();
+ }
+ }
+}
+