Enlightenment CVS committal

Author  : tsauerbeck
Project : misc
Module  : embrace

Dir     : misc/embrace/src


Modified Files:
        embrace.c embrace.h main.c 


Log Message:
restart embrace on SIGHUP
===================================================================
RCS file: /cvsroot/enlightenment/misc/embrace/src/embrace.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- embrace.c   13 Mar 2004 10:59:38 -0000      1.2
+++ embrace.c   1 Apr 2004 18:29:36 -0000       1.3
@@ -1,5 +1,5 @@
 /*
- * $Id: embrace.c,v 1.2 2004/03/13 10:59:38 tsauerbeck Exp $
+ * $Id: embrace.c,v 1.3 2004/04/01 18:29:36 tsauerbeck Exp $
  *
  * Copyright (C) 2004 Embrace project.
  *
@@ -22,7 +22,6 @@
 #endif
 
 #include <Edb.h>
-#include <Ecore_Job.h>
 #include <Esmart/container.h>
 #include <Esmart/dragable.h>
 #include <stdio.h>
@@ -38,6 +37,8 @@
 #include "mailbox.h"
 #include "embrace_plugin.h"
 
+static int last_signal;
+
 /**
  * Copies one string to another, but '~' is expanded.
  */
@@ -242,7 +243,7 @@
        return e_db_open_read (file);
 }
 
-bool embrace_load_config (Embrace *e)
+static bool embrace_load_config (Embrace *e)
 {
        E_DB_File *edb;
        bool ret;
@@ -256,7 +257,7 @@
        return ret;
 }
 
-bool embrace_load_mailboxes (Embrace *e)
+static bool embrace_load_mailboxes (Embrace *e)
 {
        E_DB_File *edb;
        bool ret;
@@ -418,12 +419,29 @@
        return ui_load_container (e);
 }
 
+static int on_sighup (void *udata, int type, void *event)
+{
+       Embrace *e = udata;
+
+       assert (e);
+
+       embrace_stop (e);
+       embrace_deinit (e);
+
+       if (embrace_init (e))
+               embrace_run (e);
+       else
+               ecore_main_loop_quit ();
+
+       return 0;
+}
+
 Embrace *embrace_new ()
 {
        return calloc (1, sizeof (Embrace));
 }
 
-void embrace_free_mailboxes (Embrace *e)
+static void free_mailboxes (Embrace *e)
 {
        MailBox *mb;
 
@@ -437,7 +455,7 @@
        }
 }
 
-void embrace_free_plugins (Embrace *e)
+static void free_plugins (Embrace *e)
 {
        EmbracePlugin *ep;
 
@@ -449,10 +467,9 @@
                e->plugins = evas_list_remove (e->plugins, ep);
                embrace_plugin_free (ep);
        }
-
 }
 
-void embrace_free_ui (Embrace *e)
+static void free_ui (Embrace *e)
 {
        assert (e);
 
@@ -468,14 +485,17 @@
        }
 }
 
-void embrace_free (Embrace *e)
+void embrace_deinit (Embrace *e)
 {
        assert (e);
 
-       embrace_free_mailboxes (e);
-       embrace_free_plugins (e);
-       embrace_free_ui (e);
+       free_mailboxes (e);
+       free_plugins (e);
+       free_ui (e);
+}
 
+void embrace_free (Embrace *e)
+{
        free (e);
 }
 
@@ -483,6 +503,8 @@
 {
        assert (e);
 
+       last_signal = SIGRTMIN;
+
        if (!embrace_load_config (e)) {
                fprintf (stderr, "Cannot load config!\n");
                return false;
@@ -514,6 +536,7 @@
        for (l = e->mailboxes; l; l = l->next)
                mailbox_check (l->data);
 
+       /* only exec once */
        return 0;
 }
 
@@ -522,17 +545,27 @@
        assert (e);
 
        ecore_evas_show (e->gui.ee);
-       ecore_timer_add (0.1, check_mailboxes, e);
+       ecore_idler_add (check_mailboxes, e);
+
+       e->evt_hup = ecore_event_handler_add (ECORE_EVENT_SIGNAL_HUP,
+                                             on_sighup, e);
+       assert (e->evt_hup);
 }
 
-int embrace_signal_get ()
+void embrace_stop (Embrace *e)
 {
-       static int sig;
+       assert (e);
+
+       assert (e->evt_hup);
 
-       if (!sig)
-               sig = SIGRTMIN;
+       ecore_event_handler_del (e->evt_hup);
+       e->evt_hup = NULL;
+}
 
-       assert (sig != _NSIG);
+int embrace_signal_get ()
+{
+       last_signal++;
+       assert (last_signal > SIGRTMIN && last_signal != _NSIG);
 
-       return ++sig;
+       return last_signal;
 }
===================================================================
RCS file: /cvsroot/enlightenment/misc/embrace/src/embrace.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- embrace.h   1 Mar 2004 20:02:58 -0000       1.1
+++ embrace.h   1 Apr 2004 18:29:36 -0000       1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: embrace.h,v 1.1 2004/03/01 20:02:58 tsauerbeck Exp $
+ * $Id: embrace.h,v 1.2 2004/04/01 18:29:36 tsauerbeck Exp $
  *
  * Copyright (C) 2004 Embrace project.
  *
@@ -21,6 +21,7 @@
 #define __EMBRACE_H
 
 #include <Evas.h>
+#include <Ecore.h>
 #include <Ecore_Evas.h>
 #include <Edje.h>
 #include <limits.h>
@@ -40,6 +41,8 @@
        Evas_List *mailboxes;
        Evas_List *plugins;
 
+       Ecore_Event_Handler *evt_hup;
+
        Gui gui;
        Config cfg;
 } Embrace;
@@ -48,7 +51,10 @@
 void embrace_free (Embrace *e);
 
 bool embrace_init (Embrace *e);
+void embrace_deinit (Embrace *e);
+
 void embrace_run (Embrace *e);
+void embrace_stop (Embrace *e);
 
 int embrace_signal_get ();
 void embrace_expand_path (char *str, char *dest, int destlen);
===================================================================
RCS file: /cvsroot/enlightenment/misc/embrace/src/main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- main.c      23 Mar 2004 19:43:38 -0000      1.2
+++ main.c      1 Apr 2004 18:29:36 -0000       1.3
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.2 2004/03/23 19:43:38 tsauerbeck Exp $
+ * $Id: main.c,v 1.3 2004/04/01 18:29:36 tsauerbeck Exp $
  *
  * Copyright (C) 2004 Embrace project.
  *
@@ -27,18 +27,13 @@
 
 #include "embrace.h"
 
-#define BAIL_OUT() {     \
-       if (e)               \
-               embrace_free(e); \
-       shutdown();          \
-       return 1;            \
-}
-
-static int on_signal_exit (void *udata, int type, void *event)
-{
-       ecore_main_loop_quit ();
-
-       return 1;
+#define BAIL_OUT() { \
+       if (e) {                \
+               embrace_deinit (e); \
+               embrace_free (e);   \
+       }                       \
+       shutdown();             \
+       return 1;               \
 }
 
 static bool init ()
@@ -50,9 +45,6 @@
        edje_init ();
        edje_frametime_set (1.0 / 60.0);
 
-       ecore_event_handler_add (ECORE_EVENT_SIGNAL_EXIT, on_signal_exit,
-                                NULL);
-
        if (lt_dlinit ()) {
                fprintf (stderr, "Cannot initialize LTDL!\n");
                return false;
@@ -92,14 +84,18 @@
                BAIL_OUT ();
        }
 
-       if (!embrace_init (e)) {
+       if (!embrace_init (e))
                BAIL_OUT ();
-       }
 
        embrace_run (e);
        ecore_main_loop_begin ();
 
+       /* we don't need to call embrace_stop() here, since the timers
+        * and the event handlers are free'd by ecore
+        */
+       embrace_deinit (e);
        embrace_free (e);
+
        shutdown ();
 
        return 0;




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to