cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=f1bf1e58df38146a384fc8d4556400e0c02c4bc5

commit f1bf1e58df38146a384fc8d4556400e0c02c4bc5
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Wed Jan 27 11:42:48 2016 -0800

    eo: return a value when adding or removing callback to help the caller 
manage state.
---
 src/lib/eo/eo_base.eo                      |  4 ++++
 src/lib/eo/eo_base_class.c                 | 37 ++++++++++++++++++------------
 src/lib/evas/canvas/evas_canvas3d_object.c | 16 +++++++++----
 3 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/lib/eo/eo_base.eo b/src/lib/eo/eo_base.eo
index 53b49b3..18f780a 100644
--- a/src/lib/eo/eo_base.eo
+++ b/src/lib/eo/eo_base.eo
@@ -176,6 +176,7 @@ abstract Eo.Base ()
            callbacks of the same priority are called in reverse order of
            creation.
          ]]
+        return: bool; [[Return true when the callback has been successfully 
added.]]
          params {
             @in desc: const(Eo.Event_Description)*; [[The description of the 
event to listen to]]
             @in priority: Eo.Callback_Priority; [[The priority of the 
callback]]
@@ -185,6 +186,7 @@ abstract Eo.Base ()
       }
       event_callback_del {
          [[Del a callback with a specific data associated to it for an event.]]
+        return: bool; [[Return true when the callback has been successfully 
removed.]]
          params {
             @in desc: const(Eo.Event_Description)*; [[The description of the 
event to listen to]]
             @in func: Eo.Event_Cb; [[the callback to delete]]
@@ -197,6 +199,7 @@ abstract Eo.Base ()
            callbacks of the same priority are called in reverse order of
            creation.
          ]]
+        return: bool; [[Return true when the callback has been successfully 
added.]]
          params {
             @in array: const(Eo.Callback_Array_Item)*; [[an 
#Eo_Callback_Array_Item of events to listen to]]
             @in priority: Eo.Callback_Priority; [[The priority of the 
callback]]
@@ -207,6 +210,7 @@ abstract Eo.Base ()
          [[Del a callback array with a specific data associated to it for an
            event.
          ]]
+        return: bool; [[Return true when the callback has been successfully 
removed.]]
          params {
             @in array: const(Eo.Callback_Array_Item)*; [[an 
#Eo_Callback_Array_Item of events to listen to]]
             @in user_data: const(void)*; [[The data to compare]]
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index d27e256..64c6df3 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -551,13 +551,14 @@ _eo_callbacks_sorted_insert(Eo_Base_Data *pd, 
Eo_Callback_Description *cb)
      }
 }
 
-EOLIAN static void
+EOLIAN static Eina_Bool
 _eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data *pd,
                     const Eo_Event_Description *desc,
                     Eo_Callback_Priority priority,
                     Eo_Event_Cb func,
                     const void *user_data)
 {
+   const Eo_Callback_Array_Item arr[] = { {desc, func}, {NULL, NULL}};
    Eo_Callback_Description *cb;
 
    cb = calloc(1, sizeof(*cb));
@@ -565,7 +566,7 @@ _eo_base_event_callback_priority_add(Eo *obj, Eo_Base_Data 
*pd,
      {
         ERR("Tried adding callback with invalid values: cb: %p desc: %p func: 
%p\n", cb, desc, func);
         free(cb);
-        return;
+        return EINA_FALSE;
      }
    cb->items.item.desc = desc;
    cb->items.item.func = func;
@@ -573,13 +574,12 @@ _eo_base_event_callback_priority_add(Eo *obj, 
Eo_Base_Data *pd,
    cb->priority = priority;
    _eo_callbacks_sorted_insert(pd, cb);
 
-     {
-        const Eo_Callback_Array_Item arr[] = { {desc, func}, {NULL, NULL}};
-        eo_do(obj, eo_event_callback_call(EO_BASE_EVENT_CALLBACK_ADD, (void 
*)arr));
-     }
+   eo_do(obj, eo_event_callback_call(EO_BASE_EVENT_CALLBACK_ADD, (void *)arr));
+
+   return EINA_TRUE;
 }
 
-EOLIAN static void
+EOLIAN static Eina_Bool
 _eo_base_event_callback_del(Eo *obj, Eo_Base_Data *pd,
                     const Eo_Event_Description *desc,
                     Eo_Event_Cb func,
@@ -598,14 +598,15 @@ _eo_base_event_callback_del(Eo *obj, Eo_Base_Data *pd,
              pd->deletions_waiting = EINA_TRUE;
              _eo_callbacks_clear(pd);
              eo_do(obj, eo_event_callback_call(EO_BASE_EVENT_CALLBACK_DEL, 
(void *)arr); );
-             return;
+             return EINA_TRUE;
           }
      }
 
    DBG("Callback of object %p with function %p and data %p not found.", obj, 
func, user_data);
+   return EINA_FALSE;
 }
 
-EOLIAN static void
+EOLIAN static Eina_Bool
 _eo_base_event_callback_array_priority_add(Eo *obj, Eo_Base_Data *pd,
                           const Eo_Callback_Array_Item *array,
                           Eo_Callback_Priority priority,
@@ -614,19 +615,24 @@ _eo_base_event_callback_array_priority_add(Eo *obj, 
Eo_Base_Data *pd,
    Eo_Callback_Description *cb;
 
    cb = calloc(1, sizeof(*cb));
-   if (!cb) return;
+   if (!cb || !array)
+     {
+        ERR("Tried adding array of callbacks with invalid values: cb: %p 
array: %p\n", cb, array);
+        free(cb);
+        return EINA_FALSE;
+     }
    cb->func_data = (void *) user_data;
    cb->priority = priority;
    cb->items.item_array = array;
    cb->func_array = EINA_TRUE;
    _eo_callbacks_sorted_insert(pd, cb);
 
-     {
-        eo_do(obj, eo_event_callback_call(EO_BASE_EVENT_CALLBACK_ADD, (void 
*)array); );
-     }
+   eo_do(obj, eo_event_callback_call(EO_BASE_EVENT_CALLBACK_ADD, (void 
*)array); );
+
+   return EINA_TRUE;
 }
 
-EOLIAN static void
+EOLIAN static Eina_Bool
 _eo_base_event_callback_array_del(Eo *obj, Eo_Base_Data *pd,
                  const Eo_Callback_Array_Item *array,
                  const void *user_data)
@@ -643,11 +649,12 @@ _eo_base_event_callback_array_del(Eo *obj, Eo_Base_Data 
*pd,
              _eo_callbacks_clear(pd);
 
              eo_do(obj, eo_event_callback_call(EO_BASE_EVENT_CALLBACK_DEL, 
(void *)array); );
-             return;
+             return EINA_TRUE;
           }
      }
 
    DBG("Callback of object %p with function array %p and data %p not found.", 
obj, array, user_data);
+   return EINA_FALSE;
 }
 
 static Eina_Bool
diff --git a/src/lib/evas/canvas/evas_canvas3d_object.c 
b/src/lib/evas/canvas/evas_canvas3d_object.c
index 3cba61c..e9604fa 100644
--- a/src/lib/evas/canvas/evas_canvas3d_object.c
+++ b/src/lib/evas/canvas/evas_canvas3d_object.c
@@ -64,7 +64,7 @@ _evas_canvas3d_object_update(Eo *obj, 
Evas_Canvas3D_Object_Data *pd)
    memset(&pd->dirty[0], 0x00, sizeof(Eina_Bool) * EVAS_CANVAS3D_STATE_MAX);
 }
 
-EOLIAN static void
+EOLIAN static Eina_Bool
 _evas_canvas3d_object_eo_base_event_callback_priority_add(Eo *obj,
                                                     Evas_Canvas3D_Object_Data 
*pd EINA_UNUSED,
                                                     const Eo_Event_Description 
*desc,
@@ -72,18 +72,24 @@ 
_evas_canvas3d_object_eo_base_event_callback_priority_add(Eo *obj,
                                                     Eo_Event_Cb func,
                                                     const void *user_data)
 {
-   eo_do_super(obj, MY_CLASS, eo_event_callback_priority_add(desc, priority, 
func, user_data));
+   Eina_Bool r = EINA_FALSE;
+
+   eo_do_super(obj, MY_CLASS, r = eo_event_callback_priority_add(desc, 
priority, func, user_data));
    eo_do(obj, evas_canvas3d_object_callback_register(desc->name, user_data));
+
+   return r;
 }
 
-EOLIAN static void
+EOLIAN static Eina_Bool
 _evas_canvas3d_object_eo_base_event_callback_del(Eo *obj, 
Evas_Canvas3D_Object_Data *pd EINA_UNUSED,
                                            const Eo_Event_Description *desc,
                                            Eo_Event_Cb func,
                                            const void *user_data)
 {
-   eo_do_super(obj, MY_CLASS, eo_event_callback_del(desc, func, user_data));
-   eo_do(obj, evas_canvas3d_object_callback_unregister(desc->name));
+   Eina_Bool r = EINA_FALSE;
+   eo_do_super(obj, MY_CLASS, r = eo_event_callback_del(desc, func, 
user_data));
+   if (r) eo_do(obj, evas_canvas3d_object_callback_unregister(desc->name));
+   return r;
 }
 
 #include "canvas/evas_canvas3d_object.eo.c"

-- 


Reply via email to