forked from enlightenment/efl
eo: make reflection setter able to return an error code in case of failure.
Reviewed-by: Marcel Hollerbach <marcel-hollerbach@t-online.de> Differential Revision: https://phab.enlightenment.org/D7935
This commit is contained in:
parent
56a91961ce
commit
b23f65291f
|
@ -408,23 +408,30 @@ _gen_reflect_set(Eina_Strbuf *buf, const char *cnamel, const Eolian_Type *valt,
|
|||
else
|
||||
eina_hash_set(refh, &fid, (void *)EOLIAN_PROP_SET);
|
||||
|
||||
eina_strbuf_append(buf, "\nstatic void\n");
|
||||
eina_strbuf_append(buf, "\nstatic Eina_Error\n");
|
||||
eina_strbuf_append_printf(buf, "__eolian_%s_%s_set_reflect(Eo *obj, Eina_Value val)\n",
|
||||
cnamel, eolian_function_name_get(fid));
|
||||
eina_strbuf_append(buf, "{\n");
|
||||
eina_strbuf_append(buf, " Eina_Error r = 0;");
|
||||
|
||||
Eina_Stringshare *ct = eolian_type_c_type_get(valt, EOLIAN_C_TYPE_PARAM);
|
||||
const char *starsp = (ct[strlen(ct) - 1] != '*') ? " " : "";
|
||||
eina_strbuf_append_printf(buf, " %s%scval;\n", ct, starsp);
|
||||
eina_stringshare_del(ct);
|
||||
|
||||
eina_strbuf_append_printf(buf, " eina_value_%s_convert(&val, &cval);\n", initf);
|
||||
eina_strbuf_append_printf(buf, " if (!eina_value_%s_convert(&val, &cval))\n", initf);
|
||||
eina_strbuf_append(buf, " {\n");
|
||||
eina_strbuf_append(buf, " r = EINA_ERROR_VALUE_FAILED;\n");
|
||||
eina_strbuf_append(buf, " goto end;\n");
|
||||
eina_strbuf_append(buf, " }\n");
|
||||
|
||||
Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, EOLIAN_PROP_SET, EINA_FALSE);
|
||||
eina_strbuf_append_printf(buf, " %s(obj, cval);\n", fcn);
|
||||
eina_stringshare_del(fcn);
|
||||
|
||||
eina_strbuf_append(buf, " end:\n");
|
||||
eina_strbuf_append(buf, " eina_value_flush(&val);\n");
|
||||
eina_strbuf_append(buf, " return r;\n");
|
||||
|
||||
eina_strbuf_append(buf, "}\n\n");
|
||||
}
|
||||
|
|
|
@ -827,7 +827,7 @@ struct _Efl_Class_Description
|
|||
/**
|
||||
* Setter type which is used to set an #Eina_Value, this function should access one particular property field
|
||||
*/
|
||||
typedef void (*Efl_Object_Property_Reflection_Setter)(Eo *obj, Eina_Value value);
|
||||
typedef Eina_Error (*Efl_Object_Property_Reflection_Setter)(Eo *obj, Eina_Value value);
|
||||
|
||||
/**
|
||||
* Getter type which is used to get an #Eina_Value, this function should access one particular property field
|
||||
|
@ -1985,7 +1985,7 @@ EAPI Eina_Bool efl_destructed_is(const Eo *obj);
|
|||
* @param value The value to set, the value passed here will be flushed by the function
|
||||
*
|
||||
*/
|
||||
EAPI void efl_property_reflection_set(Eo *obj, const char *property_name, Eina_Value value);
|
||||
EAPI Eina_Error efl_property_reflection_set(Eo *obj, const char *property_name, Eina_Value value);
|
||||
|
||||
/**
|
||||
* @brief Retrieve an #Eina_Value containing the current value of the property specified with \c property_name.
|
||||
|
|
|
@ -3636,20 +3636,25 @@ _efl_class_reflection_find(const _Efl_Class *klass, const char *property_name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
EAPI Eina_Error
|
||||
efl_property_reflection_set(Eo *obj_id, const char *property_name, Eina_Value value)
|
||||
{
|
||||
Eina_Error r = EINA_ERROR_NOT_IMPLEMENTED;
|
||||
Eina_Bool freed = EINA_FALSE;
|
||||
|
||||
EO_OBJ_POINTER_GOTO(obj_id, obj, end);
|
||||
const Efl_Object_Property_Reflection *reflection = _efl_class_reflection_find(obj->klass, property_name);
|
||||
|
||||
if (!reflection || !reflection->set) goto end;
|
||||
if (reflection && reflection->set)
|
||||
{
|
||||
r = reflection->set(obj_id, value);
|
||||
freed = EINA_TRUE;
|
||||
}
|
||||
|
||||
reflection->set(obj_id, value);
|
||||
EO_OBJ_DONE(obj_id);
|
||||
return;
|
||||
end:
|
||||
eina_value_flush(&value);
|
||||
end:
|
||||
if (!freed) eina_value_flush(&value);
|
||||
EO_OBJ_DONE(obj_id);
|
||||
return r;
|
||||
}
|
||||
|
||||
EAPI Eina_Value
|
||||
|
|
|
@ -23,7 +23,7 @@ _a_set(Eo *obj EINA_UNUSED, void *class_data, int a)
|
|||
efl_event_callback_legacy_call(obj, EV_A_CHANGED, &pd->a);
|
||||
}
|
||||
|
||||
static void
|
||||
static Eina_Error
|
||||
_a_set_reflect(Eo *obj, Eina_Value value)
|
||||
{
|
||||
int a;
|
||||
|
@ -31,6 +31,8 @@ _a_set_reflect(Eo *obj, Eina_Value value)
|
|||
eina_value_int_convert(&value, &a);
|
||||
simple_a_set(obj, a);
|
||||
eina_value_flush(&value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -45,12 +45,16 @@ EFL_START_TEST(eo_test_reflection_simple)
|
|||
const int numb = 42;
|
||||
int number_ref;
|
||||
Eina_Value numb_val = eina_value_int_init(numb);
|
||||
Eina_Value useless_val = eina_value_int_init(7);
|
||||
Eo *simple = efl_new(SIMPLE_CLASS);
|
||||
|
||||
simple_a_set(simple, 22);
|
||||
efl_property_reflection_set(simple, "simple_a", numb_val);
|
||||
ck_assert_int_eq(simple_a_get(simple), numb);
|
||||
|
||||
ck_assert_int_eq(efl_property_reflection_set(simple, "should_fail", useless_val),
|
||||
EINA_ERROR_NOT_IMPLEMENTED);
|
||||
|
||||
simple_a_set(simple, 22);
|
||||
Eina_Value res = efl_property_reflection_get(simple, "simple_a");
|
||||
eina_value_int_convert(&res, &number_ref);
|
||||
|
|
|
@ -3,13 +3,19 @@ EWAPI float BAR = 10.300000f;
|
|||
Eina_Bool _class_simple_a_set(Eo *obj, Evas_Simple_Data *pd, int value);
|
||||
|
||||
|
||||
static void
|
||||
static Eina_Error
|
||||
__eolian_class_simple_a_set_reflect(Eo *obj, Eina_Value val)
|
||||
{
|
||||
int cval;
|
||||
eina_value_int_convert(&val, &cval);
|
||||
Eina_Error r = 0; int cval;
|
||||
if (!eina_value_int_convert(&val, &cval))
|
||||
{
|
||||
r = EINA_ERROR_VALUE_FAILED;
|
||||
goto end;
|
||||
}
|
||||
efl_canvas_object_simple_a_set(obj, cval);
|
||||
end:
|
||||
eina_value_flush(&val);
|
||||
return r;
|
||||
}
|
||||
|
||||
EOAPI EFL_FUNC_BODYV(efl_canvas_object_simple_a_set, Eina_Bool, EINA_TRUE /* true */, EFL_FUNC_CALL(value), int value);
|
||||
|
|
Loading…
Reference in New Issue