feat(c-wrapper): do not clone on setCppPtrFromC when object is clonable

This commit is contained in:
Ronan Abhamon 2018-04-23 10:53:05 +02:00
parent 6df0a4223b
commit ac2eccd78b
4 changed files with 15 additions and 62 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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());
}
// =============================================================================

View file

@ -413,7 +413,7 @@ public:
typename CppType = typename CTypeMetaInfo<CType>::cppType,
typename = typename std::enable_if<IsDefinedClonableCppObject<CppType>::value, CppType>::type
>
static inline void setCppPtrFromC (CType *cObject, CppType* &&cppObject) {
static inline void setCppPtrFromC (CType *cObject, CppType *cppObject) {
CppType **cppObjectAddr = &reinterpret_cast<WrappedClonableObject<CppType> *>(cObject)->cppPtr;
if (*cppObjectAddr == cppObject)
return;
@ -427,15 +427,6 @@ public:
#endif
}
template<
typename CType,
typename CppType = typename CTypeMetaInfo<CType>::cppType,
typename = typename std::enable_if<IsDefinedClonableCppObject<CppType>::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<RetType *>(value);
RetType *cObject = CppTypeMetaInfo<CppType>::init();
setCppPtrFromC(cObject, cppObject);
setCppPtrFromC(cObject, const_cast<CppType *>(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); \
} \