summaryrefslogtreecommitdiff
path: root/src/lib/eo/eo.c
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-05 15:40:41 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-07 14:43:25 +0100
commit0f32bb90476703f81fd08800eda0a0d89321f80f (patch)
tree97f71bd6fedc72e0609e0e807527de0da4a54072 /src/lib/eo/eo.c
parent0709bdea6f94149b6b319461edd27b7a0035552d (diff)
eo: here comes reflection API
this adds support in eo to generate a reflection API. To get the actaul reflection to the klass, the API efl_class_reflection_table_set needs to be called, the table in the end can be generated by eolian. Reflection API is inherited by the extended class. This means, if you have two reflection tables, first, the most upperst is called, then the next lower one is called. For now this API accepts NULL setter or getter, and will ignore them silently when they are called. fix T7681 Differential Revision: https://phab.enlightenment.org/D7879
Diffstat (limited to 'src/lib/eo/eo.c')
-rw-r--r--src/lib/eo/eo.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 0d1ae5b..beed059 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -819,7 +819,7 @@ _eo_class_funcs_set(Eo_Vtable *vtable, const Efl_Object_Ops *ops, const _Efl_Cla
819} 819}
820 820
821EAPI Eina_Bool 821EAPI Eina_Bool
822efl_class_functions_set(const Efl_Class *klass_id, const Efl_Object_Ops *object_ops, const Efl_Object_Ops *class_ops, const void *reflection_table) 822efl_class_functions_set(const Efl_Class *klass_id, const Efl_Object_Ops *object_ops, const Efl_Object_Ops *class_ops, const Efl_Object_Property_Reflection_Ops *reflection_table)
823{ 823{
824 EO_CLASS_POINTER_GOTO(klass_id, klass, err_klass); 824 EO_CLASS_POINTER_GOTO(klass_id, klass, err_klass);
825 Efl_Object_Ops empty_ops = { 0 }; 825 Efl_Object_Ops empty_ops = { 0 };
@@ -832,6 +832,8 @@ efl_class_functions_set(const Efl_Class *klass_id, const Efl_Object_Ops *object_
832 832
833 if (!class_ops) class_ops = &empty_ops; 833 if (!class_ops) class_ops = &empty_ops;
834 834
835 klass->reflection = reflection_table;
836
835 klass->ops_count = object_ops->count + class_ops->count; 837 klass->ops_count = object_ops->count + class_ops->count;
836 838
837 klass->base_id = _eo_ops_last_id; 839 klass->base_id = _eo_ops_last_id;
@@ -3597,3 +3599,63 @@ static const Eina_Value_Type _EINA_VALUE_TYPE_OBJECT = {
3597}; 3599};
3598 3600
3599EOAPI const Eina_Value_Type *EINA_VALUE_TYPE_OBJECT = &_EINA_VALUE_TYPE_OBJECT; 3601EOAPI const Eina_Value_Type *EINA_VALUE_TYPE_OBJECT = &_EINA_VALUE_TYPE_OBJECT;
3602
3603static const Efl_Object_Property_Reflection*
3604_efl_class_reflection_find(const _Efl_Class *klass, const char *property_name)
3605{
3606 const _Efl_Class **klass_iter = klass->extensions;
3607 const Efl_Object_Property_Reflection_Ops *ref = klass->reflection;
3608 unsigned int i;
3609
3610 for (i = 0; ref && i < ref->count; ++i)
3611 {
3612 if (eina_streq(property_name, ref->table[i].property_name))
3613 return &ref->table[i];
3614 }
3615
3616 if (klass->parent)
3617 {
3618 const Efl_Object_Property_Reflection *ref;
3619
3620 ref = _efl_class_reflection_find(klass->parent, property_name);
3621 if (ref) return ref;
3622 }
3623
3624 for (; *klass_iter; klass_iter++)
3625 {
3626 return _efl_class_reflection_find(*klass_iter, property_name);
3627 }
3628
3629 return NULL;
3630}
3631
3632EAPI void
3633efl_property_reflection_set(Eo *obj_id, const char *property_name, Eina_Value value)
3634{
3635 EO_OBJ_POINTER_GOTO(obj_id, obj, end);
3636 const Efl_Object_Property_Reflection *reflection = _efl_class_reflection_find(obj->klass, property_name);
3637
3638 if (!reflection || !reflection->set) goto end;
3639
3640 reflection->set(obj_id, value);
3641 EO_OBJ_DONE(obj_id);
3642 return;
3643end:
3644 eina_value_flush(&value);
3645 EO_OBJ_DONE(obj_id);
3646}
3647
3648EAPI Eina_Value
3649efl_property_reflection_get(Eo *obj_id, const char *property_name)
3650{
3651 EO_OBJ_POINTER(obj_id, obj);
3652 const Efl_Object_Property_Reflection *reflection = _efl_class_reflection_find(obj->klass, property_name);
3653
3654 if (!reflection || !reflection->get) goto end;
3655
3656 return reflection->get(obj_id);
3657end:
3658 EO_OBJ_DONE(obj_id);
3659
3660 return EINA_VALUE_EMPTY;
3661}