Commit 771487a8 authored by Ronan's avatar Ronan
Browse files

fix(c-wrapper): add a way to clone custom properties of c objects

parent 2731c470
...@@ -32,10 +32,12 @@ using namespace std; ...@@ -32,10 +32,12 @@ using namespace std;
static void _linphone_content_constructor (LinphoneContent *content); static void _linphone_content_constructor (LinphoneContent *content);
static void _linphone_content_destructor (LinphoneContent *content); static void _linphone_content_destructor (LinphoneContent *content);
static void _linphone_content_c_clone (LinphoneContent *dest, const LinphoneContent *src);
L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(Content, L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(Content,
_linphone_content_constructor, _linphone_content_constructor,
_linphone_content_destructor, _linphone_content_destructor,
_linphone_content_c_clone,
void *cryptoContext; // Used to encrypt file for RCS file transfer. void *cryptoContext; // Used to encrypt file for RCS file transfer.
...@@ -57,6 +59,12 @@ static void _linphone_content_destructor (LinphoneContent *content) { ...@@ -57,6 +59,12 @@ static void _linphone_content_destructor (LinphoneContent *content) {
content->cache.~Cache(); content->cache.~Cache();
} }
static void _linphone_content_c_clone (LinphoneContent *dest, const LinphoneContent *src) {
new(&dest->cache) LinphoneContent::Cache();
dest->size = src->size;
dest->cache = src->cache;
}
// ============================================================================= // =============================================================================
// Reference and user data handling functions. // Reference and user data handling functions.
// ============================================================================= // =============================================================================
......
...@@ -612,6 +612,7 @@ LINPHONE_END_NAMESPACE ...@@ -612,6 +612,7 @@ LINPHONE_END_NAMESPACE
#undef L_INTERNAL_WRAPPER_CONSTEXPR #undef L_INTERNAL_WRAPPER_CONSTEXPR
#define L_INTERNAL_C_NO_XTOR(C_OBJECT) #define L_INTERNAL_C_NO_XTOR(C_OBJECT)
#define L_INTERNAL_C_NO_CLONE_C(C_DEST_OBJECT, C_SRC_OBJECT)
#define L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, ...) \ #define L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, ...) \
static_assert(LinphonePrivate::CTypeMetaInfo<Linphone ## C_TYPE>::defined, "Type is not defined."); \ static_assert(LinphonePrivate::CTypeMetaInfo<Linphone ## C_TYPE>::defined, "Type is not defined."); \
...@@ -669,7 +670,7 @@ LINPHONE_END_NAMESPACE ...@@ -669,7 +670,7 @@ LINPHONE_END_NAMESPACE
__VA_ARGS__ \ __VA_ARGS__ \
}; \ }; \
#define L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR) \ #define L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, CLONE_C) \
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_TYPE); \ BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_TYPE); \
Linphone ## C_TYPE *_linphone_ ## C_TYPE ## _init () { \ Linphone ## C_TYPE *_linphone_ ## C_TYPE ## _init () { \
Linphone ## C_TYPE *object = belle_sip_object_new(Linphone ## C_TYPE); \ Linphone ## C_TYPE *object = belle_sip_object_new(Linphone ## C_TYPE); \
...@@ -683,6 +684,7 @@ LINPHONE_END_NAMESPACE ...@@ -683,6 +684,7 @@ LINPHONE_END_NAMESPACE
static void _linphone_ ## C_TYPE ## _clone (Linphone ## C_TYPE *dest, const Linphone ## C_TYPE *src) { \ static void _linphone_ ## C_TYPE ## _clone (Linphone ## C_TYPE *dest, const Linphone ## C_TYPE *src) { \
L_ASSERT(src->cppPtr); \ L_ASSERT(src->cppPtr); \
dest->cppPtr = new L_CPP_TYPE_OF_C_TYPE(C_TYPE)(*src->cppPtr); \ dest->cppPtr = new L_CPP_TYPE_OF_C_TYPE(C_TYPE)(*src->cppPtr); \
CLONE_C(dest, src); \
} \ } \
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_TYPE); \ BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_TYPE); \
BELLE_SIP_INSTANCIATE_VPTR( \ BELLE_SIP_INSTANCIATE_VPTR( \
...@@ -760,15 +762,15 @@ LINPHONE_END_NAMESPACE ...@@ -760,15 +762,15 @@ LINPHONE_END_NAMESPACE
L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, __VA_ARGS__) \ L_INTERNAL_DECLARE_C_OBJECT(C_TYPE, __VA_ARGS__) \
L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR) L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR)
// Declare clonable wrapped C object with constructor/destructor. // Declare clonable wrapped C object with constructor/destructor and clone_c.
#define L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, ...) \ #define L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, CLONE_C, ...) \
L_INTERNAL_DECLARE_C_CLONABLE_OBJECT(C_TYPE, __VA_ARGS__) \ L_INTERNAL_DECLARE_C_CLONABLE_OBJECT(C_TYPE, __VA_ARGS__) \
L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR) L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, CLONE_C)
// Declare clonable wrapped C object. // Declare clonable wrapped C object.
#define L_DECLARE_C_CLONABLE_OBJECT_IMPL(C_TYPE, ...) \ #define L_DECLARE_C_CLONABLE_OBJECT_IMPL(C_TYPE, ...) \
L_INTERNAL_DECLARE_C_CLONABLE_OBJECT(C_TYPE, __VA_ARGS__) \ L_INTERNAL_DECLARE_C_CLONABLE_OBJECT(C_TYPE, __VA_ARGS__) \
L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR) L_INTERNAL_DECLARE_C_CLONABLE_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_XTOR, L_INTERNAL_C_NO_CLONE_C)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Helpers. // Helpers.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment