ecore: fix bugs from composite models
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>
Tue, 6 Nov 2018 12:42:36 +0000 (10:42 -0200)
committerHermet Park <hermetpark@gmail.com>
Wed, 5 Dec 2018 05:51:19 +0000 (14:51 +0900)
Fix type error while getting boolean property from Efl.Model_Composite_Boolean.

Fix properties_get methods for all composite models.

Now properly call property.changed events when it is needed.

Use EINA_VALUE_TYPE_BOOL instead of EINA_VALUE_TYPE_UCHAR.

Remove some memory leaks.

src/Makefile_Ecore.am
src/lib/ecore/efl_model_composite_boolean.c
src/lib/ecore/efl_model_composite_private.h [new file with mode: 0644]
src/lib/ecore/efl_model_composite_selection.c
src/lib/ecore/efl_model_composite_selection.eo
src/lib/ecore/efl_model_composite_selection_children.eo
src/lib/ecore/meson.build

index 1a24712..fecdb7f 100644 (file)
@@ -126,6 +126,7 @@ lib/ecore/efl_model_container_private.h \
 lib/ecore/efl_model_composite.c \
 lib/ecore/efl_model_composite_boolean.c \
 lib/ecore/efl_model_composite_selection.c \
+lib/ecore/efl_model_composite_private.h \
 lib/ecore/efl_model_accessor_view.c \
 lib/ecore/efl_model_accessor_view_private.h \
 lib/ecore/efl_linear_interpolator.c \
index cb52e85..e710091 100644 (file)
@@ -5,6 +5,7 @@
 #include <Efl_Core.h>
 
 #include "efl_model_composite_boolean_children.eo.h"
+#include "efl_model_composite_private.h"
 
 typedef struct _Efl_Model_Composite_Boolean_Data Efl_Model_Composite_Boolean_Data;
 typedef struct _Efl_Model_Composite_Boolean_Children_Data Efl_Model_Composite_Boolean_Children_Data;
@@ -71,16 +72,11 @@ static Eina_Iterator *
 _efl_model_composite_boolean_children_efl_model_properties_get(const Eo *obj,
                                                                Efl_Model_Composite_Boolean_Children_Data *pd)
 {
-   Eina_Iterator *its;
-   Eina_Iterator *itr;
-
-   its = efl_model_properties_get(efl_super(obj, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS));
-   itr = eina_hash_iterator_key_new(pd->parent->values);
-
-   if (!its) return itr;
-   if (!itr) return its;
-
-   return eina_multi_iterator_new(its, itr);
+   EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(props,
+                                        obj, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS,
+                                        eina_hash_iterator_key_new(pd->parent->values),
+                                        "child.index");
+   return props;
 }
 
 static Eina_Value *
@@ -109,9 +105,9 @@ _efl_model_composite_boolean_children_efl_model_property_get(const Eo *obj,
    if ((pd->index >> 3) >= v->buffer_count)
      flag = v->default_value;
    else
-     flag = v->buffer[pd->index >> 3] & (1 << pd->index & 0x7);
+     flag = v->buffer[pd->index >> 3] & (((unsigned char)1) << (pd->index & 0x7));
 
-   return eina_value_uchar_new(!!flag);
+   return eina_value_bool_new(!!flag);
 }
 
 static Eina_Future *
@@ -139,7 +135,7 @@ _efl_model_composite_boolean_children_efl_model_property_set(Eo *obj,
      return efl_model_property_set(efl_super(obj, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS),
                                    property, value);
 
-   eina_value_setup(&b, EINA_VALUE_TYPE_UCHAR);
+   eina_value_setup(&b, EINA_VALUE_TYPE_BOOL);
    if (!eina_value_convert(value, &b))
      return eina_future_rejected(efl_loop_future_scheduler_get(obj),
                                  EFL_MODEL_ERROR_UNKNOWN);
@@ -165,12 +161,16 @@ _efl_model_composite_boolean_children_efl_model_property_set(Eo *obj,
 
    // It is assumed that during slice get the buffer is properly sized
    if (flag)
-     v->buffer[pd->index >> 3] |= 1 << (pd->index & 0x7);
+     v->buffer[pd->index >> 3] |= ((unsigned char)1) << (pd->index & 0x7);
    else
-     v->buffer[pd->index >> 3] &= ~(1 << (pd->index & 0x7));
+     v->buffer[pd->index >> 3] &= ~(((unsigned char)1) << (pd->index & 0x7));
 
+   // Calling "properties,changed" event
+   efl_model_properties_changed(obj, property);
+
+   // Return fulfilled future
    return eina_future_resolved(efl_loop_future_scheduler_get(obj),
-                               eina_value_uchar_init(!!flag));
+                               eina_value_bool_init(!!flag));
 }
 
 /**************** efl_model_composite_boolean **************/
@@ -225,6 +225,8 @@ _boolean_value_free(void *data)
    free(value->buffer);
    value->buffer = NULL;
    value->buffer_count = 0;
+
+   free(value);
 }
 
 static Eo *
diff --git a/src/lib/ecore/efl_model_composite_private.h b/src/lib/ecore/efl_model_composite_private.h
new file mode 100644 (file)
index 0000000..eb9b07b
--- /dev/null
@@ -0,0 +1,39 @@
+
+#define EFL_MODEL_COMPOSITE_PROPERTIES(name, dyn, sta, ...) \
+  EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(name, NULL, NULL, (dyn), sta, ##__VA_ARGS__)
+
+#define EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(name, obj, klass, dyn, sta, ...)  \
+  Eina_Iterator *name;                                                         \
+  do                                                                           \
+    {                                                                          \
+       static const char *static_props__[] = {                                 \
+         sta,                                                                  \
+         ##__VA_ARGS__                                                         \
+       };                                                                      \
+       name = _efl_model_composite_properties_mix(                             \
+         ((obj) ? efl_model_properties_get(efl_super((obj), (klass))) : NULL), \
+         (dyn),                                                                \
+         EINA_C_ARRAY_ITERATOR_NEW(static_props__));                           \
+    }                                                                          \
+  while (0)
+
+
+static inline Eina_Iterator *
+_efl_model_composite_properties_mix(Eina_Iterator *super, Eina_Iterator *dyn, Eina_Iterator *sta)
+{
+   Eina_Iterator *its[3];
+   int i = 0;
+
+   if (sta)   its[i++] = sta;
+   if (dyn)   its[i++] = dyn;
+   if (super) its[i++] = super;
+
+   switch (i)
+     {
+      case 1: return its[0];
+      case 2: return eina_multi_iterator_new(its[0], its[1]);
+      case 3: return eina_multi_iterator_new(its[0], its[1], its[2]);
+      default: return NULL;
+     };
+}
+
index 622d183..cb35c0f 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "efl_model_composite_selection.eo.h"
 #include "efl_model_accessor_view_private.h"
+#include "efl_model_composite_private.h"
 
 typedef struct _Efl_Model_Composite_Selection_Data Efl_Model_Composite_Selection_Data;
 typedef struct _Efl_Model_Composite_Selection_Children_Data Efl_Model_Composite_Selection_Children_Data;
@@ -186,6 +187,17 @@ _unselect_slice_then(void *data EINA_UNUSED,
    return v;
 }
 
+static Eina_Iterator *
+_efl_model_composite_selection_efl_model_properties_get(const Eo *obj,
+                                                        Efl_Model_Composite_Selection_Data *pd EINA_UNUSED)
+{
+   EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(props,
+                                        obj, EFL_MODEL_COMPOSITE_SELECTION_CLASS,
+                                        NULL,
+                                        "selected", "exclusive");
+   return props;
+}
+
 static Eina_Future *
 _efl_model_composite_selection_efl_model_property_set(Eo *obj,
                                                       Efl_Model_Composite_Selection_Data *pd,
@@ -196,13 +208,18 @@ _efl_model_composite_selection_efl_model_property_set(Eo *obj,
    if (!strcmp("exclusive", property))
      {
         Eina_Bool exclusive = pd->exclusive;
+        Eina_Bool changed;
 
         vf = eina_value_bool_init(exclusive);
         eina_value_convert(value, &vf);
         eina_value_bool_get(&vf, &exclusive);
 
+        changed = (!pd->exclusive != !exclusive);
         pd->exclusive = !!exclusive;
 
+        if (changed)
+          efl_model_properties_changed(obj, "exclusive");
+
         return eina_future_resolved(efl_loop_future_scheduler_get(obj), vf);
      }
 
@@ -291,6 +308,17 @@ _untangle_array(void *data,
    return va;
 }
 
+static Eina_Iterator *
+_efl_model_composite_selection_children_efl_model_properties_get(const Eo *obj,
+                                                                 Efl_Model_Composite_Selection_Children_Data *pd EINA_UNUSED)
+{
+   EFL_MODEL_COMPOSITE_PROPERTIES_SUPER(props,
+                                        obj, EFL_MODEL_COMPOSITE_SELECTION_CHILDREN_CLASS,
+                                        NULL,
+                                        "selected");
+   return props;
+}
+
 static Eina_Future *
 _efl_model_composite_selection_children_efl_model_property_set(Eo *obj,
                                                                Efl_Model_Composite_Selection_Children_Data *pd EINA_UNUSED,
index 782a928..fca9b9c 100644 (file)
@@ -5,6 +5,7 @@ class Efl.Model_Composite_Selection (Efl.Model_Composite_Boolean)
       Efl.Object.constructor;
       Efl.Model.children_slice_get;
       Efl.Model.property { get; set; }
+      Efl.Model.properties { get; }
    }
    events {
       /* FIXME: The object is emitted in the event_info. This is redundant. */
index f3a9bd8..ef2af4d 100644 (file)
@@ -3,5 +3,7 @@ class Efl.Model_Composite_Selection_Children (Efl.Model_Composite_Boolean_Childr
    [[Efl model composite selection children class]]
    implements {
       Efl.Model.property { set; }
+      Efl.Model.properties { get; }
    }
+   /* FIXME: emitting Efl.Model_Composite_Selection.Selected. Use a default selection event! */
 }
index 96ad59b..cfa6609 100644 (file)
@@ -153,6 +153,7 @@ ecore_src = [
   'efl_model_composite.c',
   'efl_model_composite_boolean.c',
   'efl_model_composite_selection.c',
+  'efl_model_composite_private.h',
   'efl_model_accessor_view.c',
   'efl_model_accessor_view_private.h',
   'efl_linear_interpolator.c',