simplify a bit init/shutdown functions
authorcaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 10 Oct 2009 06:28:58 +0000 (06:28 +0000)
committercaro <caro@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 10 Oct 2009 06:28:58 +0000 (06:28 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/e_dbus@42997 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/dbus/e_dbus.c
src/lib/hal/e_hal_main.c

index bff50f1..e22b005 100644 (file)
@@ -21,7 +21,7 @@
 int _e_dbus_log_dom = -1;
 static int connection_slot = -1;
 
-static int init = 0;
+static int _edbus_init_count = 0;
 static int close_connection = 0;
 EAPI int E_DBUS_EVENT_SIGNAL = 0;
 
@@ -595,29 +595,31 @@ e_dbus_connection_dbus_connection_get(E_DBus_Connection *conn)
 EAPI int
 e_dbus_init(void)
 {
-  if (++init != 1) return init;
+  if (++_edbus_init_count != 1)
+    return _edbus_init_count;
   
   /**
    * eina initialization 
    */
   
-  if(!eina_init())
+  if (!eina_init())
     {
       fprintf(stderr,"E-dbus: Enable to initialize the eina module");
-      return -1;
+      return --_edbus_init_count;
     }
 
-  _e_dbus_log_dom = eina_log_domain_register("e_dbus",E_DBUS_COLOR_DEFAULT);
-  if(_e_dbus_log_dom < 0)
+  _e_dbus_log_dom = eina_log_domain_register("e_dbus", E_DBUS_COLOR_DEFAULT);
+  if (_e_dbus_log_dom < 0)
     {
       EINA_LOG_ERR("Enable to create a 'e_dbus' log domain");
       eina_shutdown();
-      return -1;
+      return --_edbus_init_count;
     }
 
   E_DBUS_EVENT_SIGNAL = ecore_event_type_new();
   e_dbus_object_init();
-  return init;
+
+  return _edbus_init_count;
 }
 
 /**
@@ -626,10 +628,13 @@ e_dbus_init(void)
 EAPI int
 e_dbus_shutdown(void)
 {
-  if (--init) return init;
+  if (--_edbus_init_count)
+    return _edbus_init_count;
+
   e_dbus_object_shutdown();
   eina_log_domain_unregister(_e_dbus_log_dom);
   _e_dbus_log_dom = -1;
   eina_shutdown();
-  return init;
+
+  return _edbus_init_count;
 }
index 6d2bf44..c9d217b 100644 (file)
@@ -7,42 +7,40 @@ int _e_dbus_hal_init_count = 0;
 EAPI int
 e_hal_init(void)
 {
-   if (_e_dbus_hal_init_count)
-     return ++_e_dbus_hal_init_count;
+   if (++_e_dbus_hal_init_count != 1)
+     return _e_dbus_hal_init_count;
 
    if (!eina_init())
-     return 0;
+     return --_e_dbus_hal_init_count;
 
    _e_dbus_hal_log_dom = eina_log_domain_register
      ("e_hal", E_DBUS_COLOR_DEFAULT);
    if (_e_dbus_hal_log_dom < 0)
      {
        EINA_LOG_ERR("Could not register 'e_hal' log domain.");
-       goto error_log_domain;
-       return 0;
+       goto shutdown_eina;
      }
 
    if (!e_dbus_init()) {
       ERR("Could not initialize E_DBus.");
-      goto error_e_dbus;
+      goto unregister_log_domain;
    }
 
-   _e_dbus_hal_init_count = 1;
-   return 1;
+   return _e_dbus_hal_init_count;
 
error_e_dbus:
unregister_log_domain:
    eina_log_domain_unregister(_e_dbus_hal_log_dom);
    _e_dbus_hal_log_dom = -1;
error_log_domain:
shutdown_eina:
    eina_shutdown();
-   return 0;
+
+   return _e_dbus_hal_init_count;
 }
 
 EAPI int
 e_hal_shutdown(void)
 {
-   _e_dbus_hal_init_count--;
-   if (_e_dbus_hal_init_count)
+   if (--_e_dbus_hal_init_count != 0)
      return _e_dbus_hal_init_count;
 
    e_dbus_shutdown();
@@ -51,5 +49,5 @@ e_hal_shutdown(void)
    _e_dbus_hal_log_dom = -1;
    eina_shutdown();
 
-   return 0;
+   return _e_dbus_hal_init_count;
 }