forked from enlightenment/efl
ecore: fix arguments to use Eo native array type.
This commit is contained in:
parent
b047bf7f64
commit
068f57a79d
|
@ -8,7 +8,6 @@ ecore_eolian_files_legacy = \
|
||||||
|
|
||||||
ecore_eolian_files = \
|
ecore_eolian_files = \
|
||||||
lib/ecore/efl_loop.eo \
|
lib/ecore/efl_loop.eo \
|
||||||
lib/ecore/efl_loop_args.eo \
|
|
||||||
lib/ecore/efl_loop_user.eo \
|
lib/ecore/efl_loop_user.eo \
|
||||||
lib/ecore/efl_loop_fd.eo \
|
lib/ecore/efl_loop_fd.eo \
|
||||||
lib/ecore/ecore_parent.eo \
|
lib/ecore/ecore_parent.eo \
|
||||||
|
@ -60,7 +59,6 @@ lib/ecore/ecore_idle_exiter.c \
|
||||||
lib/ecore/ecore_idler.c \
|
lib/ecore/ecore_idler.c \
|
||||||
lib/ecore/ecore_job.c \
|
lib/ecore/ecore_job.c \
|
||||||
lib/ecore/ecore_main.c \
|
lib/ecore/ecore_main.c \
|
||||||
lib/ecore/efl_loop_args.c \
|
|
||||||
lib/ecore/efl_loop_user.c \
|
lib/ecore/efl_loop_user.c \
|
||||||
lib/ecore/efl_loop_fd.c \
|
lib/ecore/efl_loop_fd.c \
|
||||||
lib/ecore/ecore_pipe.c \
|
lib/ecore/ecore_pipe.c \
|
||||||
|
|
|
@ -50,8 +50,6 @@ extern "C" {
|
||||||
|
|
||||||
#include "efl_loop.eo.h"
|
#include "efl_loop.eo.h"
|
||||||
|
|
||||||
#include "efl_loop_args.eo.h"
|
|
||||||
|
|
||||||
#include "efl_loop_user.eo.h"
|
#include "efl_loop_user.eo.h"
|
||||||
|
|
||||||
#include "efl_loop_fd.eo.h"
|
#include "efl_loop_fd.eo.h"
|
||||||
|
|
|
@ -2840,25 +2840,50 @@ _efl_loop_job_cb(void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_efl_loop_args_job_cb(void *data, void *value EINA_UNUSED)
|
_efl_loop_arguments_cleanup(Eina_Array *arga)
|
||||||
{
|
{
|
||||||
Efl_Loop_Args *args = data;
|
Eina_Stringshare *s;
|
||||||
Eo *obj = eo_parent_get(args);
|
|
||||||
|
|
||||||
eo_event_callback_call(obj, EFL_LOOP_EVENT_ARGS, args);
|
while ((s = eina_array_pop(arga)))
|
||||||
eo_del(args);
|
eina_stringshare_del(s);
|
||||||
|
eina_array_free(arga);
|
||||||
}
|
}
|
||||||
|
|
||||||
EOLIAN static void
|
static void
|
||||||
_efl_loop_args_add(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, int argc, const char **argv)
|
_efl_loop_arguments_send(void *data, void *value EINA_UNUSED)
|
||||||
|
{
|
||||||
|
Efl_Loop_Arguments arge;
|
||||||
|
Eina_Array *arga = data;
|
||||||
|
|
||||||
|
arge.argv = arga;
|
||||||
|
|
||||||
|
eo_event_callback_call(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS, &arge);
|
||||||
|
|
||||||
|
_efl_loop_arguments_cleanup(arga);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_efl_loop_arguments_cancel(void *data, Eina_Error err EINA_UNUSED)
|
||||||
|
{
|
||||||
|
_efl_loop_arguments_cleanup(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// It doesn't make sense to send those argument to any other mainloop
|
||||||
|
// As it also doesn't make sense to allow anyone to override this, so
|
||||||
|
// should be internal for sure, not even protected.
|
||||||
|
EAPI void
|
||||||
|
ecore_loop_arguments_send(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
Eina_Promise *job;
|
Eina_Promise *job;
|
||||||
Efl_Loop_Args *args = eo_add(EFL_LOOP_ARGS_CLASS, obj);
|
Eina_Array *arga;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
if (!args) return;
|
arga = eina_array_new(argc);
|
||||||
efl_loop_args_set(args, argc, argv);
|
for (i = 0; i < argc; i++)
|
||||||
job = efl_loop_job(obj, NULL);
|
eina_array_push(arga, eina_stringshare_add(argv[i]));
|
||||||
eina_promise_then(job, _efl_loop_args_job_cb, NULL, args);
|
|
||||||
|
job = efl_loop_job(ecore_main_loop_get(), NULL);
|
||||||
|
eina_promise_then(job, _efl_loop_arguments_send, _efl_loop_arguments_cancel, arga);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _efl_loop_timeout_force_cancel_cb(void *data, const Eo_Event *event EINA_UNUSED);
|
static void _efl_loop_timeout_force_cancel_cb(void *data, const Eo_Event *event EINA_UNUSED);
|
||||||
|
|
|
@ -149,6 +149,7 @@ EAPI void _ecore_magic_fail(const void *d,
|
||||||
Ecore_Magic m,
|
Ecore_Magic m,
|
||||||
Ecore_Magic req_m,
|
Ecore_Magic req_m,
|
||||||
const char *fname);
|
const char *fname);
|
||||||
|
EAPI void ecore_loop_arguments_send(int argc, const char **argv);
|
||||||
|
|
||||||
void _ecore_time_init(void);
|
void _ecore_time_init(void);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
struct Efl.Loop.Arguments {
|
||||||
|
argv: const(array<const(stringshare)>);
|
||||||
|
}
|
||||||
|
|
||||||
class Efl.Loop (Eo.Base)
|
class Efl.Loop (Eo.Base)
|
||||||
{
|
{
|
||||||
[[The Efl Main Loop
|
[[The Efl Main Loop
|
||||||
|
@ -61,20 +65,12 @@ class Efl.Loop (Eo.Base)
|
||||||
}
|
}
|
||||||
return: bool; [[true if successfully unregistered, false otherwise.]]
|
return: bool; [[true if successfully unregistered, false otherwise.]]
|
||||||
}
|
}
|
||||||
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: string*; [[The array of argument strings.]]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
events {
|
events {
|
||||||
idle,enter @restart; [[Event occurs once the main loop enters the idle state.]]
|
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,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.]]
|
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().]]
|
arguments: Efl.Loop.Arguments; [[Event happens when args are provided to the loop by args_add().]]
|
||||||
/* TODO: All of the legacy ecore events. (Ecore.h header) */
|
|
||||||
}
|
}
|
||||||
implements {
|
implements {
|
||||||
Eo.Base.constructor;
|
Eo.Base.constructor;
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
#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"
|
|
|
@ -1,25 +0,0 @@
|
||||||
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: string*; [[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: string; [[The argument string.]]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
implements {
|
|
||||||
Eo.Base.destructor;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -322,6 +322,9 @@ _sys_lang_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA
|
||||||
return ECORE_CALLBACK_PASS_ON;
|
return ECORE_CALLBACK_PASS_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To be used here only, do not copy that anywhere else for now.
|
||||||
|
EAPI void ecore_loop_arguments_send(int argc, const char **argv);
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
elm_init(int argc, char **argv)
|
elm_init(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -330,8 +333,7 @@ elm_init(int argc, char **argv)
|
||||||
elm_quicklaunch_init(argc, argv);
|
elm_quicklaunch_init(argc, argv);
|
||||||
elm_quicklaunch_sub_init(argc, argv);
|
elm_quicklaunch_sub_init(argc, argv);
|
||||||
|
|
||||||
efl_loop_args_add(ecore_main_loop_get(),
|
ecore_loop_arguments_send(argc - 1,
|
||||||
argc - 1,
|
|
||||||
(argc > 1) ? ((const char **)argv + 1) : NULL);
|
(argc > 1) ? ((const char **)argv + 1) : NULL);
|
||||||
|
|
||||||
_prefix_shutdown();
|
_prefix_shutdown();
|
||||||
|
|
|
@ -5,36 +5,32 @@
|
||||||
#include <Ecore.h>
|
#include <Ecore.h>
|
||||||
#include "ecore_suite.h"
|
#include "ecore_suite.h"
|
||||||
|
|
||||||
|
EAPI void ecore_loop_arguments_send(int argc, const char **argv);
|
||||||
|
|
||||||
|
static const char *args[] = {
|
||||||
|
"a", "b", "c", "d", "e", "f", "g", "h"
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cb_args1(void *data EINA_UNUSED, const Eo_Event *event)
|
_cb_args1(void *data EINA_UNUSED, const Eo_Event *event)
|
||||||
{
|
{
|
||||||
Efl_Loop_Args *args = event->info;
|
Efl_Loop_Arguments *arge = event->info;
|
||||||
int n;
|
unsigned int i;
|
||||||
|
|
||||||
n = efl_loop_args_arg_num_get(args);
|
fail_if(eina_array_count(arge->argv) != (sizeof (args) / sizeof (args[0])));
|
||||||
fail_if(n != 8);
|
for (i = 0; i < eina_array_count(arge->argv); i++)
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 0), "a"));
|
{
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 1), "b"));
|
fail_if(!!strcmp(eina_array_data_get(arge->argv, i), args[i]));
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 2), "c"));
|
}
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 3), "d"));
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 4), "e"));
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 5), "f"));
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 6), "g"));
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 7), "h"));
|
|
||||||
ecore_main_loop_quit();
|
ecore_main_loop_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(ecore_test_args1)
|
START_TEST(ecore_test_args1)
|
||||||
{
|
{
|
||||||
const char *args[] =
|
|
||||||
{
|
|
||||||
"a", "b", "c", "d", "e", "f", "g", "h"
|
|
||||||
};
|
|
||||||
|
|
||||||
ecore_init();
|
ecore_init();
|
||||||
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGS,
|
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS,
|
||||||
_cb_args1, NULL);
|
_cb_args1, NULL);
|
||||||
efl_loop_args_add(ecore_main_loop_get(), 8, args);
|
ecore_loop_arguments_send(8, args);
|
||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
ecore_shutdown();
|
ecore_shutdown();
|
||||||
}
|
}
|
||||||
|
@ -43,26 +39,23 @@ END_TEST
|
||||||
static void
|
static void
|
||||||
_cb_args2(void *data EINA_UNUSED, const Eo_Event *event)
|
_cb_args2(void *data EINA_UNUSED, const Eo_Event *event)
|
||||||
{
|
{
|
||||||
Efl_Loop_Args *args = event->info;
|
Efl_Loop_Arguments *arge = event->info;
|
||||||
int n;
|
|
||||||
|
|
||||||
n = efl_loop_args_arg_num_get(args);
|
fail_if(eina_array_count(arge->argv) != 1);
|
||||||
fail_if(n != 1);
|
fail_if(!!strcmp(eina_array_data_get(arge->argv, 0), "hello world"));
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 0), "hello world"));
|
|
||||||
ecore_main_loop_quit();
|
ecore_main_loop_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(ecore_test_args2)
|
START_TEST(ecore_test_args2)
|
||||||
{
|
{
|
||||||
const char *args[] =
|
const char *simple_args[] = {
|
||||||
{
|
|
||||||
"hello world"
|
"hello world"
|
||||||
};
|
};
|
||||||
|
|
||||||
ecore_init();
|
ecore_init();
|
||||||
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGS,
|
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS,
|
||||||
_cb_args2, NULL);
|
_cb_args2, NULL);
|
||||||
efl_loop_args_add(ecore_main_loop_get(), 1, args);
|
ecore_loop_arguments_send(1, simple_args);
|
||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
ecore_shutdown();
|
ecore_shutdown();
|
||||||
}
|
}
|
||||||
|
@ -71,52 +64,18 @@ END_TEST
|
||||||
static void
|
static void
|
||||||
_cb_args3(void *data EINA_UNUSED, const Eo_Event *event)
|
_cb_args3(void *data EINA_UNUSED, const Eo_Event *event)
|
||||||
{
|
{
|
||||||
Efl_Loop_Args *args = event->info;
|
Efl_Loop_Arguments *arge = event->info;
|
||||||
int n;
|
|
||||||
|
|
||||||
n = efl_loop_args_arg_num_get(args);
|
fail_if(eina_array_count(arge->argv) != 0);
|
||||||
fail_if(n != 0);
|
|
||||||
ecore_main_loop_quit();
|
ecore_main_loop_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(ecore_test_args3)
|
START_TEST(ecore_test_args3)
|
||||||
{
|
{
|
||||||
ecore_init();
|
ecore_init();
|
||||||
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGS,
|
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGUMENTS,
|
||||||
_cb_args3, NULL);
|
_cb_args3, NULL);
|
||||||
efl_loop_args_add(ecore_main_loop_get(), 0, NULL);
|
ecore_loop_arguments_send(0, NULL);
|
||||||
ecore_main_loop_begin();
|
|
||||||
ecore_shutdown();
|
|
||||||
}
|
|
||||||
END_TEST
|
|
||||||
|
|
||||||
static void
|
|
||||||
_cb_args4(void *data EINA_UNUSED, const Eo_Event *event)
|
|
||||||
{
|
|
||||||
Efl_Loop_Args *args = event->info;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = efl_loop_args_arg_num_get(args);
|
|
||||||
fail_if(n != 3);
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 0), "some really long string with lots more to it than is needed for an argument blah"));
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 1), "xxxxx"));
|
|
||||||
fail_if(!!strcmp(efl_loop_args_arg_get(args, 2), "y"));
|
|
||||||
ecore_main_loop_quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
START_TEST(ecore_test_args4)
|
|
||||||
{
|
|
||||||
const char *args[] =
|
|
||||||
{
|
|
||||||
"some really long string with lots more to it than is needed for an argument blah",
|
|
||||||
"xxxxx",
|
|
||||||
"y"
|
|
||||||
};
|
|
||||||
|
|
||||||
ecore_init();
|
|
||||||
eo_event_callback_add(ecore_main_loop_get(), EFL_LOOP_EVENT_ARGS,
|
|
||||||
_cb_args4, NULL);
|
|
||||||
efl_loop_args_add(ecore_main_loop_get(), 3, args);
|
|
||||||
ecore_main_loop_begin();
|
ecore_main_loop_begin();
|
||||||
ecore_shutdown();
|
ecore_shutdown();
|
||||||
}
|
}
|
||||||
|
@ -127,5 +86,4 @@ void ecore_test_ecore_args(TCase *tc)
|
||||||
tcase_add_test(tc, ecore_test_args1);
|
tcase_add_test(tc, ecore_test_args1);
|
||||||
tcase_add_test(tc, ecore_test_args2);
|
tcase_add_test(tc, ecore_test_args2);
|
||||||
tcase_add_test(tc, ecore_test_args3);
|
tcase_add_test(tc, ecore_test_args3);
|
||||||
tcase_add_test(tc, ecore_test_args4);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue