From 20ddd4c67906f69d4242aeb845eadda46ef636e8 Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Wed, 19 Dec 2018 20:02:08 +0100 Subject: [PATCH] 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 --- src/bindings/mono/eina_mono/eina_promises.cs | 2 +- src/lib/ecore/Ecore_Eo.h | 1 - src/lib/ecore/efl_app.c | 18 ++++++------------ src/lib/ecore/efl_app.eo | 9 ++++++--- src/lib/ecore/efl_loop.c | 2 +- src/lib/ecore/efl_loop.eo | 2 +- src/lib/elementary/efl_ui_dnd.c | 4 ++-- src/tests/ecore/efl_app_suite.c | 2 +- src/tests/ecore/efl_app_test_loop.c | 14 +++++++------- src/tests/ecore/efl_app_test_loop_timer.c | 2 +- src/tests/efl_mono/EoPromises.cs | 14 +++++++------- src/tests/efl_mono/Promises.cs | 14 +++++++------- src/tests/efl_mono/libefl_mono_native_test.c | 2 +- src/tests/elementary/efl_ui_suite.c | 4 ++-- 14 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/bindings/mono/eina_mono/eina_promises.cs b/src/bindings/mono/eina_mono/eina_promises.cs index 395288cbc5..8be5f9d6cb 100644 --- a/src/bindings/mono/eina_mono/eina_promises.cs +++ b/src/bindings/mono/eina_mono/eina_promises.cs @@ -82,7 +82,7 @@ public class Promise : IDisposable /// 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? IntPtr scheduler = efl_loop_future_scheduler_get(loop.NativeHandle); diff --git a/src/lib/ecore/Ecore_Eo.h b/src/lib/ecore/Ecore_Eo.h index f73080ae4c..33e864f267 100644 --- a/src/lib/ecore/Ecore_Eo.h +++ b/src/lib/ecore/Ecore_Eo.h @@ -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. */ EAPI Eo *efl_main_loop_get(void); -EAPI Eo *efl_app_get(void); /** * @} diff --git a/src/lib/ecore/efl_app.c b/src/lib/ecore/efl_app.c index ffb256741a..8c5bf7ca8b 100644 --- a/src/lib/ecore/efl_app.c +++ b/src/lib/ecore/efl_app.c @@ -34,10 +34,13 @@ Efl_Version _app_efl_version = { 0, 0, 0, 0, NULL, NULL }; ////////////////////////////////////////////////////////////////////////// -EAPI Eo * -efl_app_get(void) +EOLIAN static Efl_App* +_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 * _efl_app_build_efl_version_get(const Eo *obj EINA_UNUSED, Efl_App_Data *pd EINA_UNUSED) { diff --git a/src/lib/ecore/efl_app.eo b/src/lib/ecore/efl_app.eo index d5ef77d44d..303d1a6d01 100644 --- a/src/lib/ecore/efl_app.eo +++ b/src/lib/ecore/efl_app.eo @@ -4,11 +4,14 @@ class Efl.App (Efl.Loop) { [[ ]] methods { - @property loop_main @class { - [[ Points to the main loop instance of the application. ]] + @property app_main @class { + [[ Returns the app object that is representing this process + + Note: This function call only works in the main loop thread of the process. + ]] get {} values { - main_loop: Efl.Loop; [[Application main loop]] + app : Efl.App; [[Application for this process]] } } @property build_efl_version { diff --git a/src/lib/ecore/efl_loop.c b/src/lib/ecore/efl_loop.c index 33b6398fbb..1ef212f731 100644 --- a/src/lib/ecore/efl_loop.c +++ b/src/lib/ecore/efl_loop.c @@ -61,7 +61,7 @@ static void _clean_old_environ(void); EAPI Eo * 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 diff --git a/src/lib/ecore/efl_loop.eo b/src/lib/ecore/efl_loop.eo index 8dcfc3e1e7..fe9cbd9a5d 100644 --- a/src/lib/ecore/efl_loop.eo +++ b/src/lib/ecore/efl_loop.eo @@ -11,7 +11,7 @@ class Efl.Loop extends Efl.Task The Efl main loop provides a clean and tiny event loop library with many modules to do lots of convenient things for a programmer, saving time and effort. It's lean and designed to work on anything from embedded systems all the way up to large - and powerful multi-cpu workstations. The main loop has a number of primitives you can use. + and powerful multi-cpu workstations. The main loop has a number of primitives you can use. It serializes these and allows for greater responsiveness without the need for threads (or any other concurrency). However you can provide these if you need to. diff --git a/src/lib/elementary/efl_ui_dnd.c b/src/lib/elementary/efl_ui_dnd.c index 360f05e4e5..8cf29d27ed 100644 --- a/src/lib/elementary/efl_ui_dnd.c +++ b/src/lib/elementary/efl_ui_dnd.c @@ -25,7 +25,7 @@ Eo* _efl_ui_selection_manager_get(Eo *obj) { 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"); if (!sel_man) { @@ -38,7 +38,7 @@ _efl_ui_selection_manager_get(Eo *obj) 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"); efl_del(sel_man); diff --git a/src/tests/ecore/efl_app_suite.c b/src/tests/ecore/efl_app_suite.c index 0767e83c0c..b3be09915a 100644 --- a/src/tests/ecore/efl_app_suite.c +++ b/src/tests/ecore/efl_app_suite.c @@ -17,7 +17,7 @@ EFL_START_TEST(efl_app_test_efl_build_version) ecore_init(); - app = efl_app_get(); + app = efl_app_main_get(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); diff --git a/src/tests/ecore/efl_app_test_loop.c b/src/tests/ecore/efl_app_test_loop.c index f80fd7e3d5..f8e0b5548f 100644 --- a/src/tests/ecore/efl_app_test_loop.c +++ b/src/tests/ecore/efl_app_test_loop.c @@ -15,24 +15,24 @@ EFL_START_TEST(efl_app_test_efl_loop_register) 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_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); - 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_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(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); ecore_shutdown(); diff --git a/src/tests/ecore/efl_app_test_loop_timer.c b/src/tests/ecore/efl_app_test_loop_timer.c index f2d83256af..999c5f1743 100644 --- a/src/tests/ecore/efl_app_test_loop_timer.c +++ b/src/tests/ecore/efl_app_test_loop_timer.c @@ -66,7 +66,7 @@ EFL_END_TEST 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); } EFL_END_TEST diff --git a/src/tests/efl_mono/EoPromises.cs b/src/tests/efl_mono/EoPromises.cs index d5772396da..ea7f75fd33 100644 --- a/src/tests/efl_mono/EoPromises.cs +++ b/src/tests/efl_mono/EoPromises.cs @@ -9,7 +9,7 @@ class TestEoPromises { public static void test_simple_task_run() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; Eina.Future future = loop.Idle(); bool callbackCalled = false; @@ -36,7 +36,7 @@ class TestEoPromises public static void test_object_promise() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); Eina.Future future = obj.GetFuture(); @@ -61,7 +61,7 @@ class TestEoPromises public static void test_object_promise_cancel() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); Eina.Future future = obj.GetFuture(); @@ -100,7 +100,7 @@ class TestLoopEoAsyncMethods { public static void test_simple_async() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; Task t = LoopConsumer.Consume(loop); loop.Begin(); @@ -113,7 +113,7 @@ class TestEoAsyncMethods public static void test_async_fulfill() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); Task task = obj.GetFutureAsync(); @@ -133,7 +133,7 @@ class TestEoAsyncMethods public static void test_async_cancel() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); CancellationTokenSource cancelSrc = new CancellationTokenSource(); @@ -162,7 +162,7 @@ class TestEoAsyncMethods public static void test_async_reject() { - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; var obj = new Dummy.TestObject(); Task task = obj.GetFutureAsync(); diff --git a/src/tests/efl_mono/Promises.cs b/src/tests/efl_mono/Promises.cs index 22c5239e25..b355a0ee3d 100644 --- a/src/tests/efl_mono/Promises.cs +++ b/src/tests/efl_mono/Promises.cs @@ -22,7 +22,7 @@ class TestPromises bool callbackCalled = false; Eina.Value received_value = null; - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); Eina.Future future = new Eina.Future(promise); @@ -47,7 +47,7 @@ class TestPromises bool callbackCalled = false; 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.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.Future future = new Eina.Future(promise); for (int i = 0; i < 4; i++) @@ -154,7 +154,7 @@ class TestPromises for (int i = 0; i < 4; i++) cbs.Add(genResolvedCb(i)); - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); Eina.Future future = new Eina.Future(promise); future = future.Chain(cbs); @@ -184,7 +184,7 @@ class TestPromises bool callbackCalled = false; 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.Future future = new Eina.Future(promise); @@ -211,7 +211,7 @@ class TestPromises bool callbackCalled = false; Eina.Value received_value = null; - Efl.Loop loop = Efl.App.GetLoopMain(); + Efl.Loop loop = Efl.App.AppMain; Eina.Promise promise = new Eina.Promise(); #pragma warning disable 0219 Eina.Future future = new Eina.Future(promise,(Eina.Value value) => { @@ -236,7 +236,7 @@ class TestPromises bool callbackCalled = false; 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.Future future = new Eina.Future(promise); diff --git a/src/tests/efl_mono/libefl_mono_native_test.c b/src/tests/efl_mono/libefl_mono_native_test.c index 841c6a92c6..b8f3361854 100644 --- a/src/tests/efl_mono/libefl_mono_native_test.c +++ b/src/tests/efl_mono/libefl_mono_native_test.c @@ -3822,7 +3822,7 @@ Eina_Future* _dummy_test_object_get_future(EINA_UNUSED Eo *obj, Dummy_Test_Objec { 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); pd->promise = eina_promise_new(scheduler, _promise_cancelled, pd); } diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c index 54e8ed184b..0ba2542c73 100644 --- a/src/tests/elementary/efl_ui_suite.c +++ b/src/tests/elementary/efl_ui_suite.c @@ -32,10 +32,10 @@ EFL_START_TEST(efl_ui_test_init) _efl_startup_time = ecore_time_unix_get(); _EFL_APP_VERSION_SET(); 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)); __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__); __EFL_MAIN_DESTRUCTOR; ecore_shutdown_ex();