tasn pushed a commit to branch clouseau-0.1.

commit 10a69c85b381993def62aa9db16fd7355ef76e35
Author: Tom 'TAsn' Hacohen <[email protected]>
Date:   Fri Aug 30 16:33:29 2013 +0100

    Add module interface for elm-clouseau integration.
---
 src/lib/clouseau_client.c | 70 ++++++++++++++++++++++++++++++++++++++++++++---
 src/scripts/gen_script.sh |  3 +-
 2 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/src/lib/clouseau_client.c b/src/lib/clouseau_client.c
index 6d4271c..bee48d5 100644
--- a/src/lib/clouseau_client.c
+++ b/src/lib/clouseau_client.c
@@ -13,6 +13,65 @@
 static Eina_Bool _elm_is_init = EINA_FALSE;
 static const char *_my_app_name = NULL;
 
+static int _connect_to_daemon(void);
+
+/**************************************************************************/
+/* This is an attempt to somehow replicate what's available in new versions
+ * of clouseau. I.e the module interface. */
+
+static int _clouseau_init_count = 0;
+static char *_module_my_app_name = NULL;
+
+EAPI Eina_Bool
+clouseau_app_connect(const char *appname)
+{
+   _my_app_name = _module_my_app_name = strdup(appname);
+   if(!_connect_to_daemon())
+     {
+        printf("Failed to connect to server.\n");
+        return EINA_FALSE;
+     }
+
+   return EINA_TRUE;
+}
+
+EAPI int
+clouseau_init(void)
+{
+   if (++_clouseau_init_count == 1)
+     {
+        eina_init();
+        ecore_init();
+        ecore_con_init();
+        clouseau_data_init();
+     }
+
+   return _clouseau_init_count;
+}
+
+EAPI int
+clouseau_shutdown(void)
+{
+   if (--_clouseau_init_count == 0)
+     {
+        clouseau_data_shutdown();
+        ecore_con_shutdown();
+        ecore_shutdown();
+        eina_shutdown();
+        free(_module_my_app_name);
+        _my_app_name = _module_my_app_name = NULL;
+     }
+   else if (_clouseau_init_count < 0)
+     {
+        _clouseau_init_count = 0;
+        printf("Tried to shutdown although not initiated.\n");
+     }
+
+   return _clouseau_init_count;
+}
+
+/***************************** END OF EINA MODULE *************************/
+
 static void
 libclouseau_item_add(Evas_Object *o, Clouseau_Tree_Item *parent)
 {
@@ -302,6 +361,8 @@ elm_init(int argc, char **argv)
 {
    int (*_elm_init)(int, char **) = dlsym(RTLD_NEXT, __func__);
 
+   setenv("ELM_CLOUSEAU", "0", 1);
+
    if (!_elm_is_init)
      {
         _my_app_name = argv[0];
@@ -324,17 +385,17 @@ ecore_main_loop_begin(void)
         _my_app_name = "clouseau";
      }
 
-   if(!_connect_to_daemon())
+   clouseau_init();
+
+   if (!clouseau_app_connect(_my_app_name))
      {
         printf("Failed to connect to server.\n");
         return;
      }
 
-   clouseau_data_init();
-
    _ecore_main_loop_begin();
 
-   clouseau_data_shutdown();
+   clouseau_shutdown();
 
    return;
 }
@@ -383,3 +444,4 @@ evas_object_free(Evas_Object *obj, int clean_layer)
 
    _evas_object_free(obj, clean_layer);
 }
+
diff --git a/src/scripts/gen_script.sh b/src/scripts/gen_script.sh
index b1d1f01..2c43413 100755
--- a/src/scripts/gen_script.sh
+++ b/src/scripts/gen_script.sh
@@ -7,7 +7,8 @@ then
 else
 # Start clouseau daemon (will start single instance), then run app
    clouseaud
-   LD_PRELOAD="$1/libclouseau.so" "\$@"
+   #Set the ELM_CLOUSEAU in case preload is disabled.
+   ELM_CLOUSEAU=1 LD_PRELOAD="$1/libclouseau.so" "\$@"
 fi
 ENDOFMESSAGE
 

-- 

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk

Reply via email to