rygel r312 - trunk/src/rygel



Author: zeeshanak
Date: Wed Nov 26 17:00:39 2008
New Revision: 312
URL: http://svn.gnome.org/viewvc/rygel?rev=312&view=rev

Log:
Try to quit the app gracefully on SIGTERM.

Modified:
   trunk/src/rygel/cstuff.c
   trunk/src/rygel/cstuff.h
   trunk/src/rygel/cstuff.vapi
   trunk/src/rygel/rygel-main.vala

Modified: trunk/src/rygel/cstuff.c
==============================================================================
--- trunk/src/rygel/cstuff.c	(original)
+++ trunk/src/rygel/cstuff.c	Wed Nov 26 17:00:39 2008
@@ -21,6 +21,11 @@
  */
 
 #include <cstuff.h>
+#include <signal.h>
+
+static ApplicationExitCb on_app_exit = NULL;
+static gpointer data;
+static struct sigaction sig_action;
 
 /* Copy-paste from gupnp. */
 xmlNode *
@@ -67,3 +72,22 @@
         return default_value;
 }
 
+static void
+signal_handler (int signum)
+{
+        on_app_exit (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);
+}
+

Modified: trunk/src/rygel/cstuff.h
==============================================================================
--- trunk/src/rygel/cstuff.h	(original)
+++ trunk/src/rygel/cstuff.h	Wed Nov 26 17:00:39 2008
@@ -27,12 +27,18 @@
 #include <glib.h>
 #include <uuid/uuid.h>
 
+typedef void (* ApplicationExitCb)      (gpointer user_data);
+
 G_GNUC_INTERNAL xmlNode *
-get_xml_element                    (xmlNode *node,
-                                    ...);
+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);
+
 #endif /* __CSTUFF_H__ */
 

Modified: trunk/src/rygel/cstuff.vapi
==============================================================================
--- trunk/src/rygel/cstuff.vapi	(original)
+++ trunk/src/rygel/cstuff.vapi	Wed Nov 26 17:00:39 2008
@@ -42,5 +42,11 @@
                                                        ...);
         [CCode (cname = "generate_random_udn")]
         public static string generate_random_udn ();
+
+        public delegate void ApplicationExitCb ();
+
+        [CCode (cname = "on_application_exit")]
+        public static void on_application_exit
+                                        (ApplicationExitCb app_exit_cb);
     }
 }

Modified: trunk/src/rygel/rygel-main.vala
==============================================================================
--- trunk/src/rygel/rygel-main.vala	(original)
+++ trunk/src/rygel/rygel-main.vala	Wed Nov 26 17:00:39 2008
@@ -45,6 +45,8 @@
         this.exit_code = 0;
 
         this.plugin_loader.plugin_available += this.on_plugin_loaded;
+
+        Utils.on_application_exit (this.application_exit_cb);
     }
 
     public int run () {
@@ -60,6 +62,10 @@
         this.main_loop.quit ();
     }
 
+    private void application_exit_cb () {
+        this.exit (0);
+    }
+
     private void on_plugin_loaded (PluginLoader plugin_loader,
                                    Plugin       plugin) {
         try {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]