forked from enlightenment/efl
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.
This commit is contained in:
parent
afb4a194a8
commit
f0335bde28
|
@ -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 \
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -2838,6 +2838,29 @@ _efl_loop_timeout_cb(void *data, const Eo_Event *event EINA_UNUSED)
|
|||
return EO_CALLBACK_CONTINUE;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue