eo base - add loop_get for base class
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Thu, 21 Apr 2016 06:15:13 +0000 (15:15 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Thu, 21 Apr 2016 06:19:36 +0000 (15:19 +0900)
base class objects will ask their parent object to get the loop. this
means it recurses all objects regardless of type until it finds an
object that returns a proper loop object - eg a loop object returns
itself, a window, gfx/ui object returns the mainloop object etc. etc.

@feature

src/lib/eo/eo_base.eo
src/lib/eo/eo_base_class.c
src/tests/eo/suite/eo_test_general.c

index a804e1b82814e03528d3f783f2dfcf4956e0984f..d1fc1ab6e365a4b09e316dc1ff2b93e2ec934d58 100644 (file)
@@ -137,6 +137,24 @@ abstract Eo.Base ()
             finalized: bool;
          }
       }
+      @property loop {
+         [[The owning loop object.
+
+           Objects that have anything to do with I/O, time based events
+           or anything async should have an owining loop. They will ask
+           their parent for the owning loop and iterate until the
+           toplevel/root object. The root object should be a loop object
+           which will return itself. Some objects may shortcut this
+           and be fixed to live in only a single loop. Either way all
+           you need to do is get the loop for an object and use that
+           for I/O, timing etc. needs.
+         ]]
+         get {
+         }
+         values {
+            obj: Eo.Base *; [[ XXX: this should be Efl.Loop *; ]]
+         }
+      }
       constructor {
          [[Call the object's constructor.
 
index 16c0d4f77ce8ac137c53f018599ea9d8aca39146..f81e54e10fdcd84a9b054a36e8ea2478010d2a4f 100644 (file)
@@ -682,6 +682,14 @@ _eo_base_finalized_get(Eo *obj_id, Eo_Base_Data *pd EINA_UNUSED)
    return obj->finalized;
 }
 
+// XXX: this should be Efl_Loop *;
+EOLIAN static Eo_Base *
+_eo_base_loop_get(Eo *obj EINA_UNUSED, Eo_Base_Data *pd)
+{
+   if (!pd->parent) return eo_loop_get(pd->parent);
+   return NULL;
+}
+
 /* Children accessor */
 typedef struct _Eo_Children_Iterator Eo_Children_Iterator;
 struct _Eo_Children_Iterator
index 44d39d2c6432137a8b2a2516c231b1133df113e3..2980c19a779dfc086d82a8b80c42683eaf5c7f61 100644 (file)
@@ -1139,6 +1139,23 @@ START_TEST(eo_comment)
 }
 END_TEST
 
+START_TEST(eo_loop)
+{
+   eo_init();
+   Eo *obj = eo_add(SIMPLE_CLASS, NULL);
+   Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
+   Eo *objtmp;
+
+   eo_parent_set(obj2, obj);
+   objtmp = eo_loop_get(obj2);
+   fail_if(NULL != objtmp);
+
+   eo_del(obj);
+
+   eo_shutdown();
+}
+END_TEST
+
 void eo_test_general(TCase *tc)
 {
    tcase_add_test(tc, eo_simple);
@@ -1159,4 +1176,5 @@ void eo_test_general(TCase *tc)
    tcase_add_test(tc, eo_del_intercept);
    tcase_add_test(tc, eo_name);
    tcase_add_test(tc, eo_comment);
+   tcase_add_test(tc, eo_loop);
 }