diff --git a/src/c-wrapper/api/c-address.cpp b/src/c-wrapper/api/c-address.cpp index cdff96c75..a07fec135 100644 --- a/src/c-wrapper/api/c-address.cpp +++ b/src/c-wrapper/api/c-address.cpp @@ -37,7 +37,7 @@ LinphoneAddress *linphone_address_new (const char *address) { LinphoneAddress *object = L_INIT(Address); L_SET_CPP_PTR_FROM_C_OBJECT(object, cppPtr); - delete cppPtr; + return object; } diff --git a/src/c-wrapper/api/c-call-params.cpp b/src/c-wrapper/api/c-call-params.cpp index a937e8fdd..cf614024a 100644 --- a/src/c-wrapper/api/c-call-params.cpp +++ b/src/c-wrapper/api/c-call-params.cpp @@ -511,11 +511,9 @@ void linphone_call_params_unref (LinphoneCallParams *cp) { // ============================================================================= LinphoneCallParams *linphone_call_params_new (LinphoneCore *core) { - LinphoneCallParams *params = _linphone_CallParams_init(); - auto mediaSessionParams = new LinphonePrivate::MediaSessionParams(); - L_SET_CPP_PTR_FROM_C_OBJECT(params, mediaSessionParams); + LinphoneCallParams *params = L_INIT(CallParams); + L_SET_CPP_PTR_FROM_C_OBJECT(params, new LinphonePrivate::MediaSessionParams()); L_GET_CPP_PTR_FROM_C_OBJECT(params)->initDefault(L_GET_CPP_PTR_FROM_C_OBJECT(core)); - delete mediaSessionParams; return params; } diff --git a/src/c-wrapper/api/c-call.cpp b/src/c-wrapper/api/c-call.cpp index 0fa450fa5..c3f05d29a 100644 --- a/src/c-wrapper/api/c-call.cpp +++ b/src/c-wrapper/api/c-call.cpp @@ -43,12 +43,6 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(Call, bctbx_list_t *callbacks; /* A list of LinphoneCallCbs object */ LinphoneCallCbs *currentCbs; /* The current LinphoneCallCbs object used to call a callback */ char *authenticationTokenCache; - LinphoneCallParams *currentParamsCache; - LinphoneCallParams *paramsCache; - LinphoneCallParams *remoteParamsCache; - LinphoneAddress *diversionAddressCache; - LinphoneAddress *remoteAddressCache; - LinphoneAddress *toAddressCache; mutable char *referToCache; char *remoteContactCache; char *remoteUserAgentCache; @@ -59,28 +53,9 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(Call, LinphoneChatRoom *chat_room; ) -static void _linphone_call_constructor (LinphoneCall *call) { - call->currentParamsCache = linphone_call_params_new_for_wrapper(); - call->paramsCache = linphone_call_params_new_for_wrapper(); - call->remoteParamsCache = linphone_call_params_new_for_wrapper(); - call->diversionAddressCache = linphone_address_new(nullptr); - call->remoteAddressCache = linphone_address_new(nullptr); - call->toAddressCache = linphone_address_new(nullptr); -} +static void _linphone_call_constructor (LinphoneCall *call) {} static void _linphone_call_destructor (LinphoneCall *call) { - if (call->currentParamsCache) - linphone_call_params_unref(call->currentParamsCache); - if (call->paramsCache) - linphone_call_params_unref(call->paramsCache); - if (call->remoteParamsCache) - linphone_call_params_unref(call->remoteParamsCache); - if (call->diversionAddressCache) - linphone_address_unref(call->diversionAddressCache); - if (call->remoteAddressCache) - linphone_address_unref(call->remoteAddressCache); - if (call->toAddressCache) - linphone_address_unref(call->toAddressCache); if (call->referToCache) bctbx_free(call->referToCache); if (call->remoteContactCache) @@ -92,7 +67,6 @@ static void _linphone_call_destructor (LinphoneCall *call) { bctbx_list_free_with_data(call->callbacks, (bctbx_list_free_func)linphone_call_cbs_unref); } - // ============================================================================= // TODO: To remove! // ============================================================================= @@ -231,13 +205,11 @@ bool_t linphone_call_asked_to_autoanswer (LinphoneCall *call) { } const LinphoneAddress *linphone_call_get_remote_address (const LinphoneCall *call) { - L_SET_CPP_PTR_FROM_C_OBJECT(call->remoteAddressCache, &L_GET_CPP_PTR_FROM_C_OBJECT(call)->getRemoteAddress()); - return call->remoteAddressCache; + return L_GET_C_BACK_PTR(&L_GET_CPP_PTR_FROM_C_OBJECT(call)->getRemoteAddress()); } const LinphoneAddress *linphone_call_get_to_address (const LinphoneCall *call) { - L_SET_CPP_PTR_FROM_C_OBJECT(call->toAddressCache, &L_GET_CPP_PTR_FROM_C_OBJECT(call)->getToAddress()); - return call->toAddressCache; + return L_GET_C_BACK_PTR(&L_GET_CPP_PTR_FROM_C_OBJECT(call)->getToAddress()); } const char *linphone_call_get_to_header (const LinphoneCall *call, const char *name) { @@ -255,11 +227,8 @@ char *linphone_call_get_remote_address_as_string (const LinphoneCall *call) { } const LinphoneAddress *linphone_call_get_diversion_address (const LinphoneCall *call) { - LinphonePrivate::Address diversionAddress(L_GET_CPP_PTR_FROM_C_OBJECT(call)->getDiversionAddress()); - if (!diversionAddress.isValid()) - return nullptr; - L_SET_CPP_PTR_FROM_C_OBJECT(call->diversionAddressCache, &diversionAddress); - return call->diversionAddressCache; + const LinphonePrivate::Address &diversionAddress = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getDiversionAddress(); + return diversionAddress.isValid() ? L_GET_C_BACK_PTR(&diversionAddress) : nullptr; } LinphoneCallDir linphone_call_get_dir (const LinphoneCall *call) { @@ -309,17 +278,13 @@ int linphone_call_get_duration (const LinphoneCall *call) { return L_GET_CPP_PTR_FROM_C_OBJECT(call)->getDuration(); } -const LinphoneCallParams *linphone_call_get_current_params(LinphoneCall *call) { - L_SET_CPP_PTR_FROM_C_OBJECT(call->currentParamsCache, L_GET_CPP_PTR_FROM_C_OBJECT(call)->getCurrentParams()); - return call->currentParamsCache; +const LinphoneCallParams *linphone_call_get_current_params (LinphoneCall *call) { + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(call)->getCurrentParams()); } const LinphoneCallParams *linphone_call_get_remote_params(LinphoneCall *call) { const LinphonePrivate::MediaSessionParams *remoteParams = L_GET_CPP_PTR_FROM_C_OBJECT(call)->getRemoteParams(); - if (!remoteParams) - return nullptr; - L_SET_CPP_PTR_FROM_C_OBJECT(call->remoteParamsCache, remoteParams); - return call->remoteParamsCache; + return remoteParams ? L_GET_C_BACK_PTR(remoteParams) : nullptr; } void linphone_call_enable_camera (LinphoneCall *call, bool_t enable) { @@ -645,8 +610,7 @@ void linphone_call_set_params (LinphoneCall *call, const LinphoneCallParams *par } const LinphoneCallParams *linphone_call_get_params (LinphoneCall *call) { - L_SET_CPP_PTR_FROM_C_OBJECT(call->paramsCache, L_GET_CPP_PTR_FROM_C_OBJECT(call)->getParams()); - return call->paramsCache; + return L_GET_C_BACK_PTR(L_GET_CPP_PTR_FROM_C_OBJECT(call)->getParams()); } // ============================================================================= diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index 17ec09ff5..776e58f58 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -413,7 +413,7 @@ public: typename CppType = typename CTypeMetaInfo::cppType, typename = typename std::enable_if::value, CppType>::type > - static inline void setCppPtrFromC (CType *cObject, CppType* &&cppObject) { + static inline void setCppPtrFromC (CType *cObject, CppType *cppObject) { CppType **cppObjectAddr = &reinterpret_cast *>(cObject)->cppPtr; if (*cppObjectAddr == cppObject) return; @@ -427,15 +427,6 @@ public: #endif } - template< - typename CType, - typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type - > - static inline void setCppPtrFromC (CType *cObject, const CppType *cppObject) { - setCppPtrFromC(cObject, new CppType(*cppObject)); - } - // --------------------------------------------------------------------------- // Get c back ptr resolver helpers. // --------------------------------------------------------------------------- @@ -464,7 +455,7 @@ private: return static_cast(value); RetType *cObject = CppTypeMetaInfo::init(); - setCppPtrFromC(cObject, cppObject); + setCppPtrFromC(cObject, const_cast(cppObject)); return cObject; } @@ -731,7 +722,7 @@ LINPHONE_END_NAMESPACE static void _linphone_ ## C_TYPE ## _uninit(Linphone ## C_TYPE * object) { \ LinphonePrivate::Wrapper::uninitClonableCppObject(object); \ } \ - 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); \ dest->cppPtr = new L_CPP_TYPE_OF_C_TYPE(C_TYPE)(*src->cppPtr); \ } \