summaryrefslogtreecommitdiff
path: root/src/lib/eo
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-06-04 22:39:51 +0000
committerCedric BAIL <cedric.bail@free.fr>2019-06-25 17:08:53 -0700
commitfb7f9d4ed3ea3c21dc6d57b623c887732cf88ff8 (patch)
tree3ae8af0bafb9c5e002267749bf9017c4395ec9de /src/lib/eo
parent673bce2b91db20b5b337596e63b28389fcecf7e9 (diff)
eo: add an API entry for custom instantiation of Eo objects for binding usage
Add a new function in the Eo API in order to provide more options on object instantiation for binding creators. For the Eo lib to be able to construct objects that inherit from bindings in many languages we should provide a way for bindings to call different kinds of constructors, in a way that simply overriding the `efl_constructor` method is not enough. We need a way to differentiate at construction time if the Eo is being constructed from C or from the binding, because if it is the former we need too call the inherited object constructor from C and instantiate a new object, and if it is the later we need to avoid instantiating a new object because we are already in the middle of the process of creating a new one. `efl_constructor` alone does not provide any way of distinguishing between those situations, so, being able to pass additional information for efl_add_start (like a custom constructor pointer) is necessary to make the right distinction. Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9070
Diffstat (limited to 'src/lib/eo')
-rw-r--r--src/lib/eo/Eo.h29
-rw-r--r--src/lib/eo/eo.c18
2 files changed, 44 insertions, 3 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 63e4c6b89a..5390e61c8e 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -1540,6 +1540,35 @@ EAPI Eo *_efl_added_get(void);
1540EAPI Eo * _efl_add_internal_start(const char *file, int line, const Efl_Class *klass_id, Eo *parent, Eina_Bool ref, Eina_Bool is_fallback); 1540EAPI Eo * _efl_add_internal_start(const char *file, int line, const Efl_Class *klass_id, Eo *parent, Eina_Bool ref, Eina_Bool is_fallback);
1541 1541
1542/** 1542/**
1543 * @typedef Efl_Substitute_Ctor_Cb
1544 * Callback to be called instead of the object constructor.
1545 *
1546 * Only intended for binding creators.
1547 *
1548 * @param data Additional data previously supplied by the user
1549 * @param obj_id The object being constructed.
1550 * @return The constructed object in case of success, NULL otherwise.
1551 */
1552typedef Eo *(*Efl_Substitute_Ctor_Cb)(void *data, Eo *obj_id);
1553
1554/**
1555 * @brief Just like _efl_add_internal_start() but with additional options
1556 *
1557 * Only intended for binding creators.
1558 *
1559 * @param file File name of the call site, used for debug logs.
1560 * @param line Line number of the call site, used for debug logs.
1561 * @param klass_id Pointer for the class being instantiated.
1562 * @param ref Whether or not the object will have an additional reference if it has a parent.
1563 * @param parent Object parent, can be NULL.
1564 * @param is_fallback Whether or not the fallback @c efl_added behaviour is to be used.
1565 * @param substitute_ctor Optional callback to replace the call for efl_constructor(), if NULL efl_constructor() will be called normally.
1566 * @param sub_ctor_data Additional data to be passed to the @p substitute_ctor callback.
1567 * @return An handle to the new object on success, NULL otherwise.
1568 */
1569EAPI Eo * _efl_add_internal_start_bindings(const char *file, int line, const Efl_Class *klass_id, Eo *parent, Eina_Bool ref, Eina_Bool is_fallback, Efl_Substitute_Ctor_Cb substitute_ctor, void *sub_ctor_data);
1570
1571/**
1543 * @brief Unrefs the object and reparents it to NULL. 1572 * @brief Unrefs the object and reparents it to NULL.
1544 * 1573 *
1545 * Because efl_del() unrefs and reparents to NULL, it doesn't really delete the 1574 * Because efl_del() unrefs and reparents to NULL, it doesn't really delete the
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index db96b24ef7..c1156ec386 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -857,8 +857,8 @@ err_klass:
857 return EINA_FALSE; 857 return EINA_FALSE;
858} 858}
859 859
860EAPI Eo * 860static Eo *
861_efl_add_internal_start(const char *file, int line, const Efl_Class *klass_id, Eo *parent_id, Eina_Bool ref, Eina_Bool is_fallback) 861_efl_add_internal_start_do(const char *file, int line, const Efl_Class *klass_id, Eo *parent_id, Eina_Bool ref, Eina_Bool is_fallback, Efl_Substitute_Ctor_Cb substitute_ctor, void *sub_ctor_data)
862{ 862{
863 const char *func_name = __FUNCTION__; 863 const char *func_name = __FUNCTION__;
864 _Eo_Object *obj; 864 _Eo_Object *obj;
@@ -918,7 +918,8 @@ _efl_add_internal_start(const char *file, int line, const Efl_Class *klass_id, E
918 if (parent_id) efl_parent_set(eo_id, parent_id); 918 if (parent_id) efl_parent_set(eo_id, parent_id);
919 919
920 /* eo_id can change here. Freeing is done on the resolved object. */ 920 /* eo_id can change here. Freeing is done on the resolved object. */
921 eo_id = efl_constructor(eo_id); 921 if (!substitute_ctor) eo_id = efl_constructor(eo_id);
922 else eo_id = substitute_ctor(sub_ctor_data, eo_id);
922 // not likely so use goto to alleviate l1 instruction cache of rare code 923 // not likely so use goto to alleviate l1 instruction cache of rare code
923 if (!eo_id) goto err_noid; 924 if (!eo_id) goto err_noid;
924 // not likely so use goto to alleviate l1 instruction cache of rare code 925 // not likely so use goto to alleviate l1 instruction cache of rare code
@@ -962,6 +963,17 @@ err_parent:
962 return NULL; 963 return NULL;
963} 964}
964 965
966EAPI Eo *
967_efl_add_internal_start(const char *file, int line, const Efl_Class *klass_id, Eo *parent_id, Eina_Bool ref, Eina_Bool is_fallback)
968{
969 return _efl_add_internal_start_do(file, line, klass_id, parent_id, ref, is_fallback, NULL, NULL);
970}
971
972EAPI Eo * _efl_add_internal_start_bindings(const char *file, int line, const Efl_Class *klass_id, Eo *parent_id, Eina_Bool ref, Eina_Bool is_fallback, Efl_Substitute_Ctor_Cb substitute_ctor, void *sub_ctor_data)
973{
974 return _efl_add_internal_start_do(file, line, klass_id, parent_id, ref, is_fallback, substitute_ctor, sub_ctor_data);
975}
976
965static Eo * 977static Eo *
966_efl_add_internal_end(Eo *eo_id, Eo *finalized_id) 978_efl_add_internal_end(Eo *eo_id, Eo *finalized_id)
967{ 979{