summaryrefslogtreecommitdiff
path: root/src/lib/eo/eo.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-02-04 10:42:25 -0500
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-04 19:31:17 +0100
commitc946b1477dcaf35830ed66c409615f926ef0931b (patch)
treeebd998660ace6cbd4b77592947616daee555a4b1 /src/lib/eo/eo.c
parent305f77607cdd5e089424fc68ffa888df70f269ce (diff)
eo: implement class overriding (+unit tests)
this enables an app or a platform to add an override for a given class, then return a different object when that class is created. the benefit is that a class can be internally customized by the app without needing to modify upstream versions of that class @feature fix T7516 Reviewed-by: Marcel Hollerbach <marcel-hollerbach@t-online.de> Differential Revision: https://phab.enlightenment.org/D7702
Diffstat (limited to 'src/lib/eo/eo.c')
-rw-r--r--src/lib/eo/eo.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 8f711d8..c39777b 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -44,6 +44,7 @@ int _eo_log_dom = -1;
44Eina_Thread _efl_object_main_thread; 44Eina_Thread _efl_object_main_thread;
45static unsigned int efl_del_api_generation = 0; 45static unsigned int efl_del_api_generation = 0;
46static Efl_Object_Op _efl_del_api_op_id = 0; 46static Efl_Object_Op _efl_del_api_op_id = 0;
47static Eina_Hash *class_overrides;
47 48
48typedef enum _Eo_Ref_Op { 49typedef enum _Eo_Ref_Op {
49 EO_REF_OP_NONE, 50 EO_REF_OP_NONE,
@@ -868,6 +869,12 @@ _efl_add_internal_start(const char *file, int line, const Efl_Class *klass_id, E
868 869
869 if (is_fallback) fptr = _efl_add_fallback_stack_push(NULL); 870 if (is_fallback) fptr = _efl_add_fallback_stack_push(NULL);
870 871
872 if (class_overrides)
873 {
874 const Efl_Class *override = eina_hash_find(class_overrides, &klass_id);
875 if (override) klass_id = override;
876 }
877
871 EO_CLASS_POINTER_GOTO_PROXY(klass_id, klass, err_klass); 878 EO_CLASS_POINTER_GOTO_PROXY(klass_id, klass, err_klass);
872 879
873 // Check that in the case of efl_add we do pass a parent. 880 // Check that in the case of efl_add we do pass a parent.
@@ -2597,6 +2604,33 @@ efl_compatible(const Eo *obj, const Eo *obj_target)
2597} 2604}
2598 2605
2599EAPI Eina_Bool 2606EAPI Eina_Bool
2607efl_class_override_register(const Efl_Class *klass, const Efl_Class *override)
2608{
2609 EINA_SAFETY_ON_NULL_RETURN_VAL(klass, EINA_FALSE);
2610 EINA_SAFETY_ON_NULL_RETURN_VAL(override, EINA_FALSE);
2611 EINA_SAFETY_ON_TRUE_RETURN_VAL(!efl_isa(override, klass), EINA_FALSE);
2612 if (!class_overrides)
2613 class_overrides = eina_hash_pointer_new(NULL);
2614 EINA_SAFETY_ON_NULL_RETURN_VAL(class_overrides, EINA_FALSE);
2615
2616 eina_hash_set(class_overrides, &klass, override);
2617 return EINA_TRUE;
2618}
2619
2620EAPI Eina_Bool
2621efl_class_override_unregister(const Efl_Class *klass, const Efl_Class *override)
2622{
2623 const Efl_Class *set;
2624 EINA_SAFETY_ON_NULL_RETURN_VAL(klass, EINA_FALSE);
2625 EINA_SAFETY_ON_NULL_RETURN_VAL(override, EINA_FALSE);
2626 if (!class_overrides) return EINA_TRUE;
2627
2628 set = eina_hash_find(class_overrides, &klass);
2629 if (set != override) return EINA_FALSE;
2630 return eina_hash_del_by_key(class_overrides, &klass);
2631}
2632
2633EAPI Eina_Bool
2600efl_destructed_is(const Eo *obj_id) 2634efl_destructed_is(const Eo *obj_id)
2601{ 2635{
2602 Eina_Bool is; 2636 Eina_Bool is;