efl_app: introduce app_main for getting the app object

This brings in the possibility to receive the app object from bindings.
With the app object you can listen to pause / args / terminate / resume
events.

fix T7509

Differential Revision: https://phab.enlightenment.org/D7480
This commit is contained in:
Marcel Hollerbach 2018-12-19 20:02:08 +01:00
parent 7031a8cd7e
commit 20ddd4c679
14 changed files with 43 additions and 47 deletions

View File

@ -82,7 +82,7 @@ public class Promise : IDisposable
/// </summary> /// </summary>
public Promise(CancelCb cancelCb=null) public Promise(CancelCb cancelCb=null)
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
// Should we be able to pass different schedulers? // Should we be able to pass different schedulers?
IntPtr scheduler = efl_loop_future_scheduler_get(loop.NativeHandle); IntPtr scheduler = efl_loop_future_scheduler_get(loop.NativeHandle);

View File

@ -89,7 +89,6 @@ EAPI Eina_Promise *efl_loop_promise_new(const Eo *obj, Eina_Promise_Cancel_Cb ca
/* We ue the factory pattern here, so you shouldn't call eo_add directly. */ /* We ue the factory pattern here, so you shouldn't call eo_add directly. */
EAPI Eo *efl_main_loop_get(void); EAPI Eo *efl_main_loop_get(void);
EAPI Eo *efl_app_get(void);
/** /**
* @} * @}

View File

@ -34,10 +34,13 @@ Efl_Version _app_efl_version = { 0, 0, 0, 0, NULL, NULL };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
EAPI Eo * EOLIAN static Efl_App*
efl_app_get(void) _efl_app_app_main_get(const Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
{ {
return efl_main_loop_get(); if (_mainloop_singleton) return _mainloop_singleton;
_mainloop_singleton = efl_add_ref(EFL_APP_CLASS, NULL);
_mainloop_singleton_data = efl_data_scope_get(_mainloop_singleton, EFL_LOOP_CLASS);
return _mainloop_singleton;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -107,15 +110,6 @@ EFL_CALLBACKS_ARRAY_DEFINE(_event_callback_watch,
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
EOLIAN static Efl_Loop *
_efl_app_loop_main_get(const Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
{
if (_mainloop_singleton) return _mainloop_singleton;
_mainloop_singleton = efl_add_ref(EFL_APP_CLASS, NULL);
_mainloop_singleton_data = efl_data_scope_get(_mainloop_singleton, EFL_LOOP_CLASS);
return _mainloop_singleton;
}
EOLIAN static const Efl_Version * EOLIAN static const Efl_Version *
_efl_app_build_efl_version_get(const Eo *obj EINA_UNUSED, Efl_App_Data *pd EINA_UNUSED) _efl_app_build_efl_version_get(const Eo *obj EINA_UNUSED, Efl_App_Data *pd EINA_UNUSED)
{ {

View File

@ -4,11 +4,14 @@ class Efl.App (Efl.Loop)
{ {
[[ ]] [[ ]]
methods { methods {
@property loop_main @class { @property app_main @class {
[[ Points to the main loop instance of the application. ]] [[ Returns the app object that is representing this process
Note: This function call only works in the main loop thread of the process.
]]
get {} get {}
values { values {
main_loop: Efl.Loop; [[Application main loop]] app : Efl.App; [[Application for this process]]
} }
} }
@property build_efl_version { @property build_efl_version {

View File

@ -61,7 +61,7 @@ static void _clean_old_environ(void);
EAPI Eo * EAPI Eo *
efl_main_loop_get(void) efl_main_loop_get(void)
{ {
return efl_app_loop_main_get(EFL_APP_CLASS); return efl_app_main_get(EFL_APP_CLASS);
} }
EOLIAN static void EOLIAN static void

View File

@ -25,7 +25,7 @@ Eo*
_efl_ui_selection_manager_get(Eo *obj) _efl_ui_selection_manager_get(Eo *obj)
{ {
if (!efl_isa(obj, EFL_UI_WIDGET_CLASS)) return NULL; if (!efl_isa(obj, EFL_UI_WIDGET_CLASS)) return NULL;
Eo *app = efl_app_get(); Eo *app = efl_app_main_get(EFL_APP_CLASS);
Eo *sel_man = efl_key_data_get(app, "__selection_manager"); Eo *sel_man = efl_key_data_get(app, "__selection_manager");
if (!sel_man) if (!sel_man)
{ {
@ -38,7 +38,7 @@ _efl_ui_selection_manager_get(Eo *obj)
void void
_efl_ui_dnd_shutdown(void) _efl_ui_dnd_shutdown(void)
{ {
Eo *app = efl_app_get(); Eo *app = efl_app_main_get(EFL_APP_CLASS);
Eo *sel_man = efl_key_data_get(app, "__selection_manager"); Eo *sel_man = efl_key_data_get(app, "__selection_manager");
efl_del(sel_man); efl_del(sel_man);

View File

@ -17,7 +17,7 @@ EFL_START_TEST(efl_app_test_efl_build_version)
ecore_init(); ecore_init();
app = efl_app_get(); app = efl_app_main_get(EFL_APP_CLASS);
fail_if(!efl_isa(app, EFL_APP_CLASS)); fail_if(!efl_isa(app, EFL_APP_CLASS));
efl_build_version_set(EFL_VERSION_MAJOR, EFL_VERSION_MINOR, 0, 0, NULL, EFL_BUILD_ID); efl_build_version_set(EFL_VERSION_MAJOR, EFL_VERSION_MINOR, 0, 0, NULL, EFL_BUILD_ID);

View File

@ -15,24 +15,24 @@ EFL_START_TEST(efl_app_test_efl_loop_register)
ecore_init(); ecore_init();
t = efl_provider_find(efl_app_get(), EFL_LOOP_CLASS); t = efl_provider_find(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_CLASS);
fail_if(!efl_isa(t, EFL_LOOP_CLASS)); fail_if(!efl_isa(t, EFL_LOOP_CLASS));
fail_if(!efl_isa(t, EFL_APP_CLASS)); fail_if(!efl_isa(t, EFL_APP_CLASS));
t = efl_provider_find(efl_app_get(), EFL_LOOP_TIMER_CLASS); t = efl_provider_find(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_TIMER_CLASS);
fail_if(t != NULL); fail_if(t != NULL);
n = efl_add(EFL_LOOP_TIMER_CLASS, efl_app_get(), n = efl_add(EFL_LOOP_TIMER_CLASS, efl_app_main_get(EFL_APP_CLASS),
efl_loop_timer_interval_set(efl_added, 1.0)); efl_loop_timer_interval_set(efl_added, 1.0));
efl_loop_register(efl_app_get(), EFL_LOOP_TIMER_CLASS, n); efl_loop_register(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_TIMER_CLASS, n);
t = efl_provider_find(efl_app_get(), EFL_LOOP_TIMER_CLASS); t = efl_provider_find(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_TIMER_CLASS);
fail_if(!efl_isa(t, EFL_LOOP_TIMER_CLASS)); fail_if(!efl_isa(t, EFL_LOOP_TIMER_CLASS));
fail_if(t != n); fail_if(t != n);
efl_loop_unregister(efl_app_get(), EFL_LOOP_TIMER_CLASS, n); efl_loop_unregister(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_TIMER_CLASS, n);
t = efl_provider_find(efl_app_get(), EFL_LOOP_TIMER_CLASS); t = efl_provider_find(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_TIMER_CLASS);
fail_if(t != NULL); fail_if(t != NULL);
ecore_shutdown(); ecore_shutdown();

View File

@ -66,7 +66,7 @@ EFL_END_TEST
EFL_START_TEST(efl_app_test_loop_timer_invalid) EFL_START_TEST(efl_app_test_loop_timer_invalid)
{ {
Efl_Object *t = efl_add(EFL_LOOP_TIMER_CLASS, efl_app_get()); Efl_Object *t = efl_add(EFL_LOOP_TIMER_CLASS, efl_app_main_get(EFL_APP_CLASS));
fail_if(t != NULL); fail_if(t != NULL);
} }
EFL_END_TEST EFL_END_TEST

View File

@ -9,7 +9,7 @@ class TestEoPromises
{ {
public static void test_simple_task_run() public static void test_simple_task_run()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Future future = loop.Idle(); Eina.Future future = loop.Idle();
bool callbackCalled = false; bool callbackCalled = false;
@ -36,7 +36,7 @@ class TestEoPromises
public static void test_object_promise() public static void test_object_promise()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
var obj = new Dummy.TestObject(); var obj = new Dummy.TestObject();
Eina.Future future = obj.GetFuture(); Eina.Future future = obj.GetFuture();
@ -61,7 +61,7 @@ class TestEoPromises
public static void test_object_promise_cancel() public static void test_object_promise_cancel()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
var obj = new Dummy.TestObject(); var obj = new Dummy.TestObject();
Eina.Future future = obj.GetFuture(); Eina.Future future = obj.GetFuture();
@ -100,7 +100,7 @@ class TestLoopEoAsyncMethods
{ {
public static void test_simple_async() public static void test_simple_async()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Task t = LoopConsumer.Consume(loop); Task t = LoopConsumer.Consume(loop);
loop.Begin(); loop.Begin();
@ -113,7 +113,7 @@ class TestEoAsyncMethods
public static void test_async_fulfill() public static void test_async_fulfill()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
var obj = new Dummy.TestObject(); var obj = new Dummy.TestObject();
Task<Eina.Value> task = obj.GetFutureAsync(); Task<Eina.Value> task = obj.GetFutureAsync();
@ -133,7 +133,7 @@ class TestEoAsyncMethods
public static void test_async_cancel() public static void test_async_cancel()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
var obj = new Dummy.TestObject(); var obj = new Dummy.TestObject();
CancellationTokenSource cancelSrc = new CancellationTokenSource(); CancellationTokenSource cancelSrc = new CancellationTokenSource();
@ -162,7 +162,7 @@ class TestEoAsyncMethods
public static void test_async_reject() public static void test_async_reject()
{ {
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
var obj = new Dummy.TestObject(); var obj = new Dummy.TestObject();
Task<Eina.Value> task = obj.GetFutureAsync(); Task<Eina.Value> task = obj.GetFutureAsync();

View File

@ -22,7 +22,7 @@ class TestPromises
bool callbackCalled = false; bool callbackCalled = false;
Eina.Value received_value = null; Eina.Value received_value = null;
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
Eina.Future future = new Eina.Future(promise); Eina.Future future = new Eina.Future(promise);
@ -47,7 +47,7 @@ class TestPromises
bool callbackCalled = false; bool callbackCalled = false;
Eina.Error received_error = Eina.Error.NO_ERROR; Eina.Error received_error = Eina.Error.NO_ERROR;
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
Eina.Future future = new Eina.Future(promise); Eina.Future future = new Eina.Future(promise);
@ -108,7 +108,7 @@ class TestPromises
}; };
}; };
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
Eina.Future future = new Eina.Future(promise); Eina.Future future = new Eina.Future(promise);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -154,7 +154,7 @@ class TestPromises
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
cbs.Add(genResolvedCb(i)); cbs.Add(genResolvedCb(i));
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
Eina.Future future = new Eina.Future(promise); Eina.Future future = new Eina.Future(promise);
future = future.Chain(cbs); future = future.Chain(cbs);
@ -184,7 +184,7 @@ class TestPromises
bool callbackCalled = false; bool callbackCalled = false;
Eina.Error received_error = Eina.Error.NO_ERROR; Eina.Error received_error = Eina.Error.NO_ERROR;
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
Eina.Future future = new Eina.Future(promise); Eina.Future future = new Eina.Future(promise);
@ -211,7 +211,7 @@ class TestPromises
bool callbackCalled = false; bool callbackCalled = false;
Eina.Value received_value = null; Eina.Value received_value = null;
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
#pragma warning disable 0219 #pragma warning disable 0219
Eina.Future future = new Eina.Future(promise,(Eina.Value value) => { Eina.Future future = new Eina.Future(promise,(Eina.Value value) => {
@ -236,7 +236,7 @@ class TestPromises
bool callbackCalled = false; bool callbackCalled = false;
Eina.Error received_error = Eina.Error.NO_ERROR; Eina.Error received_error = Eina.Error.NO_ERROR;
Efl.Loop loop = Efl.App.GetLoopMain(); Efl.Loop loop = Efl.App.AppMain;
Eina.Promise promise = new Eina.Promise(); Eina.Promise promise = new Eina.Promise();
Eina.Future future = new Eina.Future(promise); Eina.Future future = new Eina.Future(promise);

View File

@ -3822,7 +3822,7 @@ Eina_Future* _dummy_test_object_get_future(EINA_UNUSED Eo *obj, Dummy_Test_Objec
{ {
if (pd->promise == NULL) if (pd->promise == NULL)
{ {
Eo *loop = efl_app_loop_main_get(EFL_APP_CLASS); Eo *loop = efl_app_main_get(EFL_APP_CLASS);
Eina_Future_Scheduler *scheduler = efl_loop_future_scheduler_get(loop); Eina_Future_Scheduler *scheduler = efl_loop_future_scheduler_get(loop);
pd->promise = eina_promise_new(scheduler, _promise_cancelled, pd); pd->promise = eina_promise_new(scheduler, _promise_cancelled, pd);
} }

View File

@ -32,10 +32,10 @@ EFL_START_TEST(efl_ui_test_init)
_efl_startup_time = ecore_time_unix_get(); _efl_startup_time = ecore_time_unix_get();
_EFL_APP_VERSION_SET(); _EFL_APP_VERSION_SET();
fail_if(!ecore_init()); fail_if(!ecore_init());
efl_event_callback_add(efl_app_get(), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL); efl_event_callback_add(efl_app_main_get(EFL_APP_CLASS), EFL_LOOP_EVENT_ARGUMENTS, efl_main, NULL);
fail_if(!ecore_init_ex(argc, argv)); fail_if(!ecore_init_ex(argc, argv));
__EFL_MAIN_CONSTRUCTOR; __EFL_MAIN_CONSTRUCTOR;
ret__ = efl_loop_begin(efl_app_get()); ret__ = efl_loop_begin(efl_app_main_get(EFL_APP_CLASS));
real__ = efl_loop_exit_code_process(ret__); real__ = efl_loop_exit_code_process(ret__);
__EFL_MAIN_DESTRUCTOR; __EFL_MAIN_DESTRUCTOR;
ecore_shutdown_ex(); ecore_shutdown_ex();