ecore: define behavior when no getter/setter callback function is defined for ModelVi...
authorCedric BAIL <cedric@osg.samsung.com>
Wed, 19 Dec 2018 22:49:23 +0000 (14:49 -0800)
committerShinwoo Kim <cinoo.kim@samsung.com>
Thu, 3 Jan 2019 09:00:28 +0000 (18:00 +0900)
This allow for simplifying the code that doesn't need to handle get/set/free
callback when not needed.

Reviewed-by: SangHyeon Jade Lee <sh10233.lee@samsung.com>
Differential Revision: https://phab.enlightenment.org/D7489

src/lib/ecore/efl_model_view.c

index da9b672..4fdcae6 100644 (file)
@@ -110,8 +110,8 @@ _logic_free(void *data)
    Efl_Model_View_Logic *logic = data;
    Eina_Stringshare *source;
 
-   logic->get.free_cb(logic->get.data);
-   logic->set.free_cb(logic->set.data);
+   if (logic->get.free_cb) logic->get.free_cb(logic->get.data);
+   if (logic->set.free_cb) logic->set.free_cb(logic->set.data);
    EINA_LIST_FREE(logic->sources, source)
      {
         efl_model_view_property_unbind(logic->object, source, logic->property);
@@ -121,6 +121,23 @@ _logic_free(void *data)
    free(logic);
 }
 
+static Eina_Value *
+_efl_model_view_property_dummy_get(void *data EINA_UNUSED,
+                                   const Efl_Model_View *model_view EINA_UNUSED,
+                                   Eina_Stringshare *property EINA_UNUSED)
+{
+   return eina_value_error_new(EFL_MODEL_ERROR_NOT_SUPPORTED);
+}
+
+static Eina_Future *
+_efl_model_view_property_dummy_set(void *data EINA_UNUSED,
+                                   Efl_Model_View *model_view,
+                                   Eina_Stringshare *property EINA_UNUSED,
+                                   Eina_Value *value EINA_UNUSED)
+{
+   return efl_loop_future_rejected(model_view, EFL_MODEL_ERROR_READ_ONLY);
+}
+
 static Eina_Error
 _efl_model_view_property_logic_add(Eo *obj, Efl_Model_View_Data *pd,
                                    const char *property,
@@ -145,10 +162,10 @@ _efl_model_view_property_logic_add(Eo *obj, Efl_Model_View_Data *pd,
 
    logic->object = obj;
    logic->property = prop;
-   logic->get.fct = get;
+   logic->get.fct = get ? get : _efl_model_view_property_dummy_get;
    logic->get.free_cb = get_free_cb;
    logic->get.data = get_data;
-   logic->set.fct = set;
+   logic->set.fct = set ? set : _efl_model_view_property_dummy_set;
    logic->set.free_cb = set_free_cb;
    logic->set.data = set_data;