raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=f0335bde28e8d2e7346d9f138da60204b69d6f12

commit f0335bde28e8d2e7346d9f138da60204b69d6f12
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Mon May 30 19:47:21 2016 +0900

    efl loop - add an args event and ability to produce it
    
    this is an args event. right now we don't use it, but this should be
    done by some of the setup/init of an app and then produce an args
    event. the idea would be that this can be used by single-instance apps
    like web browsers, terminology to treat launch as an event.
---
 src/Makefile_Ecore.am          |  2 ++
 src/lib/ecore/Ecore_Eo.h       |  2 ++
 src/lib/ecore/ecore_main.c     | 23 ++++++++++++++++
 src/lib/ecore/efl_loop.eo      |  9 ++++++-
 src/lib/ecore/efl_loop_args.c  | 59 ++++++++++++++++++++++++++++++++++++++++++
 src/lib/ecore/efl_loop_args.eo | 25 ++++++++++++++++++
 6 files changed, 119 insertions(+), 1 deletion(-)

diff --git a/src/Makefile_Ecore.am b/src/Makefile_Ecore.am
index f0ad37d..dd8f67a 100644
--- a/src/Makefile_Ecore.am
+++ b/src/Makefile_Ecore.am
@@ -9,6 +9,7 @@ ecore_eolian_files_legacy = \
 
 ecore_eolian_files = \
        lib/ecore/efl_loop.eo \
+        lib/ecore/efl_loop_args.eo \
        lib/ecore/efl_loop_user.eo \
        lib/ecore/efl_loop_fd.eo \
        lib/ecore/ecore_parent.eo \
@@ -60,6 +61,7 @@ lib/ecore/ecore_idle_exiter.c \
 lib/ecore/ecore_idler.c \
 lib/ecore/ecore_job.c \
 lib/ecore/ecore_main.c \
+lib/ecore/efl_loop_args.c \
 lib/ecore/efl_loop_user.c \
 lib/ecore/efl_loop_fd.c \
 lib/ecore/ecore_pipe.c \
diff --git a/src/lib/ecore/Ecore_Eo.h b/src/lib/ecore/Ecore_Eo.h
index 10e9c42..4c53c21 100644
--- a/src/lib/ecore/Ecore_Eo.h
+++ b/src/lib/ecore/Ecore_Eo.h
@@ -62,6 +62,8 @@ extern "C" {
 
 #include "efl_loop.eo.h"
 
+#include "efl_loop_args.eo.h"
+
 #include "efl_loop_user.eo.h"
 
 #include "efl_loop_fd.eo.h"
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index a32daa8..1a94ecd 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -2839,6 +2839,29 @@ _efl_loop_timeout_cb(void *data, const Eo_Event *event 
EINA_UNUSED)
 }
 
 static void
+_efl_loop_args_job_cb(void *data, void *value EINA_UNUSED,
+                      Eina_Promise *promise EINA_UNUSED)
+{
+   Efl_Loop_Args *args = data;
+   Eo *obj = eo_parent_get(args);
+
+   eo_event_callback_call(obj, EFL_LOOP_EVENT_ARGS, args);
+   eo_unref(args); // FIXME: probably eo_del()
+}
+
+EOLIAN static void
+_efl_loop_args_add(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, int argc, const 
char **argv)
+{
+   Eina_Promise *job;
+   Efl_Loop_Args *args = eo_add(EFL_LOOP_ARGS_CLASS, obj);
+
+   if (!args) return;
+   efl_loop_args_set(args, argc, argv);
+   job = efl_loop_job(obj, args);
+   eina_promise_then(job, _efl_loop_args_job_cb, NULL, args);
+}
+
+static void
 _efl_loop_internal_cancel(Efl_Internal_Promise *p)
 {
    eina_promise_owner_error_set(p->promise, _promise_canceled);
diff --git a/src/lib/ecore/efl_loop.eo b/src/lib/ecore/efl_loop.eo
index c82ea5d..d446bff 100644
--- a/src/lib/ecore/efl_loop.eo
+++ b/src/lib/ecore/efl_loop.eo
@@ -44,13 +44,20 @@ class Efl.Loop (Eo.Base)
            @in data: const(void)* @optional; [[The data to be given when the 
promise is done.]]
         }
         return: promise<void*>; [[The promise that will be triggered.]]
-
+      }
+      args_add {
+         [[Add a new set of arguments to the loop that makes an args event.]]
+         params {
+            argc: int; [[The number of strings in the argv array.]]
+            argv: const(char)**; [[The array of argument strings.]]
+         }
       }
    }
    events {
       idle,enter @restart; [[Event occurs once the main loop enters the idle 
state.]]
       idle,exit @restart; [[Event occurs once the main loop exits the idle 
state.]]
       idle @restart; [[Event occurs once the main loop is idler. Be carefull, 
this will spin your CPU high if you keep listening on this event.]]
+      args: Efl.Loop.Args; [[Event happens when args are provided to the loop 
by args_add().]]
       /* TODO: All of the legacy ecore events. (Ecore.h header) */
    }
    implements {
diff --git a/src/lib/ecore/efl_loop_args.c b/src/lib/ecore/efl_loop_args.c
new file mode 100644
index 0000000..003fcfbd
--- /dev/null
+++ b/src/lib/ecore/efl_loop_args.c
@@ -0,0 +1,59 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <Ecore.h>
+
+#include "ecore_private.h"
+
+#define MY_CLASS EFL_LOOP_ARGS_CLASS
+
+typedef struct _Efl_Loop_Args_Data Efl_Loop_Args_Data;
+struct _Efl_Loop_Args_Data
+{
+   int argc;
+   const char **argv;
+};
+
+EOLIAN static void
+_efl_loop_args_args_set(Eo *obj EINA_UNUSED, Efl_Loop_Args_Data *pd, int argc, 
const char **argv)
+{
+   int i;
+
+   if (argc < 0) return;
+   for (i = 0; i < pd->argc; i++) eina_stringshare_del(pd->argv[i]);
+   free(pd->argv);
+   pd->argc = argc;
+   if (argc > 0)
+     {
+        pd->argv = malloc(argc * sizeof(const char *));
+        for (i = 0; i < argc; i++) pd->argv[i] = eina_stringshare_add(argv[i]);
+     }
+}
+
+EOLIAN static int
+_efl_loop_args_arg_num_get(Eo *obj EINA_UNUSED, Efl_Loop_Args_Data *pd)
+{
+   return pd->argc;
+}
+
+EOLIAN const char *
+_efl_loop_args_arg_get(Eo *obj EINA_UNUSED, Efl_Loop_Args_Data *pd, int num)
+{
+   if ((num < 0) || (num >= pd->argc)) return NULL;
+   return pd->argv[num];
+}
+
+EOLIAN static void
+_efl_loop_args_eo_base_destructor(Eo *obj EINA_UNUSED, Efl_Loop_Args_Data *pd)
+{
+   int i;
+
+   for (i = 0; i < pd->argc; i++) eina_stringshare_del(pd->argv[i]);
+   free(pd->argv);
+   pd->argv = NULL;
+   pd->argc = 0;
+   eo_destructor(eo_super(obj, MY_CLASS));
+}
+
+#include "efl_loop_args.eo.c"
diff --git a/src/lib/ecore/efl_loop_args.eo b/src/lib/ecore/efl_loop_args.eo
new file mode 100644
index 0000000..1c4e76b
--- /dev/null
+++ b/src/lib/ecore/efl_loop_args.eo
@@ -0,0 +1,25 @@
+class Efl.Loop.Args (Eo.Base)
+{
+   [[The object holding arguments provided to the loop.]]
+   methods {
+      args_set {
+         [[Add a new set of arguments to the loop that makes an args event.]]
+         params {
+            argc: int; [[The number of strings in the argv array.]]
+            argv: const(char)**; [[The array of argument strings.]]
+         }
+      }
+      arg_num_get {
+         return: int; [[The number of argument strings.]]
+      }
+      arg_get {
+         params {
+            num: int; [[The argument number to get.]]
+         }
+         return: const(char)*; [[The argument string.]]
+      }
+   }
+   implements {
+      Eo.Base.destructor;
+   }
+}

-- 


Reply via email to