diff --git a/include/linphone/api/c-event-log.h b/include/linphone/api/c-event-log.h index 9d71a30e5..06840e39d 100644 --- a/include/linphone/api/c-event-log.h +++ b/include/linphone/api/c-event-log.h @@ -29,7 +29,6 @@ #endif // ifdef __cplusplus LINPHONE_PUBLIC LinphoneEventLog *linphone_event_log_new (void); -LINPHONE_PUBLIC LinphoneEventLog *linphone_event_log_clone (const LinphoneEventLog *event_log); LINPHONE_PUBLIC LinphoneEventLog *linphone_event_log_ref (LinphoneEventLog *event_log); LINPHONE_PUBLIC LinphoneEventLogType linphone_event_log_get_type (const LinphoneEventLog *event_log); @@ -38,7 +37,6 @@ LINPHONE_PUBLIC LinphoneCallEvent *linphone_call_event_new ( time_t time, LinphoneCall *call ); -LINPHONE_PUBLIC LinphoneCallEvent *linphone_call_event_clone (const LinphoneCallEvent *call_event); LINPHONE_PUBLIC LinphoneCall *linphone_call_event_get_call (const LinphoneCallEvent *call_event); LINPHONE_PUBLIC LinphoneConferenceEvent *linphone_conference_event_new ( @@ -46,7 +44,6 @@ LINPHONE_PUBLIC LinphoneConferenceEvent *linphone_conference_event_new ( time_t time, const LinphoneAddress *address ); -LINPHONE_PUBLIC LinphoneConferenceEvent *linphone_conference_event_clone (const LinphoneConferenceEvent *conference_event); LINPHONE_PUBLIC const LinphoneAddress *linphone_conference_event_get_address (const LinphoneConferenceEvent *conference_event); LINPHONE_PUBLIC LinphoneConferenceParticipantEvent *linphone_conference_participant_event_new ( @@ -55,9 +52,6 @@ LINPHONE_PUBLIC LinphoneConferenceParticipantEvent *linphone_conference_particip const LinphoneAddress *conferenceAddress, const LinphoneAddress *participantAddress ); -LINPHONE_PUBLIC LinphoneConferenceParticipantEvent *linphone_conference_participant_event_clone ( - const LinphoneConferenceParticipantEvent *conference_participant_event -); LINPHONE_PUBLIC const LinphoneAddress *linphone_conference_participant_event_get_participant_address ( const LinphoneConferenceParticipantEvent *conference_participant_event ); @@ -66,9 +60,6 @@ LINPHONE_PUBLIC LinphoneChatMessageEvent *linphone_chat_message_event_new ( LinphoneChatMessage *chat_message, time_t time ); -LINPHONE_PUBLIC LinphoneChatMessageEvent *linphone_chat_message_event_clone ( - const LinphoneChatMessageEvent *chat_message_event -); LINPHONE_PUBLIC LinphoneChatMessage *linphone_chat_message_event_get_chat_message ( const LinphoneChatMessageEvent *chat_message_event ); diff --git a/include/linphone/utils/general.h b/include/linphone/utils/general.h index 7ade05a19..cbd62d338 100644 --- a/include/linphone/utils/general.h +++ b/include/linphone/utils/general.h @@ -82,27 +82,42 @@ void l_assert (const char *condition, const char *file, int line); #define L_UNLIKELY(EXPRESSION) EXPRESSION #endif +class BaseObject; +class BaseObjectPrivate; class ClonableObject; class ClonableObjectPrivate; class Object; class ObjectPrivate; -#define L_INTERNAL_DECLARE_PRIVATE(CLASS) \ - inline CLASS ## Private *getPrivate() { \ - return reinterpret_cast(mPrivate); \ - } \ - inline const CLASS ## Private *getPrivate() const { \ - return reinterpret_cast(mPrivate); \ - } \ - friend class CLASS ## Private; \ - friend class Wrapper; +#define L_INTERNAL_CHECK_OBJECT_INHERITANCE(CLASS) \ + static_assert( \ + !(std::is_base_of::value && std::is_base_of::value), \ + "Multiple inheritance between BaseObject and ClonableObject is not allowed." \ + ); -#define L_INTERNAL_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) \ - inline CLASS ## Private *getPrivate() { \ - return reinterpret_cast(PARENT_TYPE::mPrivate); \ +#define L_INTERNAL_GET_BETTER_PRIVATE_ANCESTOR(CLASS) \ + std::conditional< \ + std::is_base_of::value, \ + BaseObject, \ + std::conditional< \ + std::is_base_of::value, \ + ClonableObject, \ + CLASS \ + >::type \ + >::type + +#define L_INTERNAL_DECLARE_PRIVATE(CLASS) \ + inline CLASS ## Private *getPrivate () { \ + L_INTERNAL_CHECK_OBJECT_INHERITANCE(CLASS); \ + return reinterpret_cast( \ + L_INTERNAL_GET_BETTER_PRIVATE_ANCESTOR(CLASS)::mPrivate \ + ); \ } \ - inline const CLASS ## Private *getPrivate() const { \ - return reinterpret_cast(PARENT_TYPE::mPrivate); \ + inline const CLASS ## Private *getPrivate () const { \ + L_INTERNAL_CHECK_OBJECT_INHERITANCE(CLASS); \ + return reinterpret_cast( \ + L_INTERNAL_GET_BETTER_PRIVATE_ANCESTOR(CLASS)::mPrivate \ + ); \ } \ friend class CLASS ## Private; \ friend class Wrapper; @@ -111,17 +126,13 @@ class ObjectPrivate; // Gives a control to C Wrapper. #ifndef LINPHONE_TESTER #define L_DECLARE_PRIVATE(CLASS) L_INTERNAL_DECLARE_PRIVATE(CLASS) - #define L_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) L_INTERNAL_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) #else #define L_DECLARE_PRIVATE(CLASS) \ L_INTERNAL_DECLARE_PRIVATE(CLASS) \ friend class Tester; - #define L_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) \ - L_INTERNAL_DECLARE_PRIVATE_T(CLASS, PARENT_TYPE) \ - friend class Tester; #endif -// Generic public helper. (Neither ClonableObject nor Object.) +// Generic public helper. (Neither ClonableObject.) // `void *` is used to avoid downcasting. template constexpr T *getPublicHelper (void *object, const void *) { @@ -135,11 +146,6 @@ inline T *getPublicHelper (const U *map, const ClonableObjectPrivate *context) { return static_cast(it->second); } -template -constexpr T *getPublicHelper (Object *object, const ObjectPrivate *) { - return static_cast(object); -} - #define L_DECLARE_PUBLIC(CLASS) \ inline CLASS *getPublic () { \ L_ASSERT(mPublic); \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3dcdcfb6c..aa0916e7b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -111,8 +111,12 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES nat/ice-agent.h nat/stun-client.h object/app-data-container.h + object/base-object-p.h + object/base-object.h object/clonable-object-p.h object/clonable-object.h + object/object-head-p.h + object/object-head.h object/object-p.h object/object.h object/property-container.h @@ -191,6 +195,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES nat/ice-agent.cpp nat/stun-client.cpp object/app-data-container.cpp + object/base-object.cpp object/clonable-object.cpp object/object.cpp object/property-container.cpp diff --git a/src/c-wrapper/api/c-address.cpp b/src/c-wrapper/api/c-address.cpp index be302f841..98e51434a 100644 --- a/src/c-wrapper/api/c-address.cpp +++ b/src/c-wrapper/api/c-address.cpp @@ -22,7 +22,7 @@ // ============================================================================= -L_DECLARE_C_CLONABLE_STRUCT_IMPL(Address); +L_DECLARE_C_CLONABLE_OBJECT_IMPL(Address); using namespace std; diff --git a/src/c-wrapper/api/c-call-params.cpp b/src/c-wrapper/api/c-call-params.cpp index a02639025..51e1e7295 100644 --- a/src/c-wrapper/api/c-call-params.cpp +++ b/src/c-wrapper/api/c-call-params.cpp @@ -23,7 +23,7 @@ // ============================================================================= -L_DECLARE_C_CLONABLE_STRUCT_IMPL(CallParams) +L_DECLARE_C_CLONABLE_OBJECT_IMPL(CallParams) using namespace std; diff --git a/src/c-wrapper/api/c-event-log.cpp b/src/c-wrapper/api/c-event-log.cpp index a80f76384..b1469ec0c 100644 --- a/src/c-wrapper/api/c-event-log.cpp +++ b/src/c-wrapper/api/c-event-log.cpp @@ -27,13 +27,13 @@ // ============================================================================= -L_DECLARE_C_CLONABLE_STRUCT_IMPL(EventLog); -L_DECLARE_C_CLONABLE_STRUCT_IMPL(CallEvent); -L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceEvent); -L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceParticipantEvent); -L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceParticipantDeviceEvent); -L_DECLARE_C_CLONABLE_STRUCT_IMPL(ConferenceSubjectEvent); -L_DECLARE_C_CLONABLE_STRUCT_IMPL(ChatMessageEvent); +L_DECLARE_C_BASE_OBJECT_IMPL(EventLog); +L_DECLARE_C_BASE_OBJECT_IMPL(CallEvent); +L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceEvent); +L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceParticipantEvent); +L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceParticipantDeviceEvent); +L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceSubjectEvent); +L_DECLARE_C_BASE_OBJECT_IMPL(ChatMessageEvent); using namespace std; diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index e36e288f4..cefeaba33 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -41,6 +41,10 @@ LINPHONE_BEGIN_NAMESPACE +// ----------------------------------------------------------------------------- +// MetaInfo. +// ----------------------------------------------------------------------------- + template struct CppTypeMetaInfo { enum { @@ -60,22 +64,27 @@ struct CTypeMetaInfo { class Wrapper { private: + // --------------------------------------------------------------------------- + // IsCppObject traits. + // --------------------------------------------------------------------------- + template struct IsCppObject { enum { - value = std::is_base_of::value || std::is_base_of::value + value = std::is_base_of::value || std::is_base_of::value }; }; template struct IsPrivateCppObject { enum { - value = std::is_base_of::value || std::is_base_of::value + value = std::is_base_of::value || + std::is_base_of::value }; }; template - struct IsDefinedCppObject { + struct IsRegisteredCppObject { enum { value = CppTypeMetaInfo::defined && ( !CppTypeMetaInfo::isSubtype || @@ -84,30 +93,70 @@ private: }; }; + // --------------------------------------------------------------------------- + // IsDefined traits. + // --------------------------------------------------------------------------- + template - struct IsDefinedNotClonableCppObject { + struct IsDefinedBaseCppObject { enum { - value = IsDefinedCppObject::value && std::is_base_of::value + value = IsRegisteredCppObject::value && + std::is_base_of::value && + !std::is_base_of::value + }; + }; + + template + struct IsDefinedCppObject { + enum { + value = IsRegisteredCppObject::value && std::is_base_of::value }; }; template struct IsDefinedClonableCppObject { enum { - value = IsDefinedCppObject::value && std::is_base_of::value + value = IsRegisteredCppObject::value && std::is_base_of::value }; }; - template - struct WrappedObject { + // --------------------------------------------------------------------------- + // Wrapped Objects. + // --------------------------------------------------------------------------- + + template + struct WrappedBaseObject { belle_sip_object_t base; - std::shared_ptr cppPtr; + CppType *cppPtr; }; - template + template + struct WrappedObject { + belle_sip_object_t base; + std::shared_ptr cppPtr; + }; + + template struct WrappedClonableObject { belle_sip_object_t base; - CType *cppPtr; + CppType *cppPtr; + }; + + template + struct WrappedObjectResolver { + typedef typename std::conditional< + IsDefinedBaseCppObject::value, + WrappedBaseObject, + typename std::conditional< + IsDefinedCppObject::value, + WrappedObject, + typename std::conditional< + IsDefinedClonableCppObject::value, + WrappedClonableObject, + void + >::type + >::type + >::type type; }; // --------------------------------------------------------------------------- @@ -162,7 +211,7 @@ public: template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value, CppType>::type > static L_INTERNAL_WRAPPER_CONSTEXPR std::shared_ptr getCppPtrFromC (CType *cObject) { #ifdef DEBUG @@ -186,27 +235,29 @@ public: template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value, CppType>::type > static L_INTERNAL_WRAPPER_CONSTEXPR std::shared_ptr getCppPtrFromC (const CType *cObject) { #ifdef DEBUG return getCppPtrFromC(const_cast(cObject)); #else - return reinterpret_cast *>(cObject)->cppPtr; + return reinterpret_cast::type *>(cObject)->cppPtr; #endif } template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if< + IsDefinedBaseCppObject::value || IsDefinedClonableCppObject::value, CppType + >::type > static L_INTERNAL_WRAPPER_CONSTEXPR CppType *getCppPtrFromC (CType *cObject) { #ifdef DEBUG typedef typename CTypeMetaInfo::cppType BaseType; typedef CppType DerivedType; - BaseType *cppObject = reinterpret_cast *>(cObject)->cppPtr; + BaseType *cppObject = reinterpret_cast::type *>(cObject)->cppPtr; if (!cppObject) abort("Cpp Object is null."); @@ -216,20 +267,22 @@ public: return derivedCppObject; #else - return reinterpret_cast *>(cObject)->cppPtr; + return reinterpret_cast::type *>(cObject)->cppPtr; #endif } template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if< + IsDefinedBaseCppObject::value || IsDefinedClonableCppObject::value, CppType + >::type > static L_INTERNAL_WRAPPER_CONSTEXPR const CppType *getCppPtrFromC (const CType *cObject) { #ifdef DEBUG return getCppPtrFromC(const_cast(cObject)); #else - return reinterpret_cast *>(cObject)->cppPtr; + return reinterpret_cast::type *>(cObject)->cppPtr; #endif } @@ -240,11 +293,28 @@ public: template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value, CppType>::type > static inline void setCppPtrFromC (CType *cObject, const std::shared_ptr &cppObject) { reinterpret_cast *>(cObject)->cppPtr = cppObject; - cppObject->setProperty("LinphonePrivate::Wrapper::cBackPtr", cObject); + cppObject->setCBackPtr(cObject); + } + + template< + typename CType, + typename CppType = typename CTypeMetaInfo::cppType, + typename = typename std::enable_if< + IsDefinedBaseCppObject::value || IsDefinedClonableCppObject::value, CppType + >::type + > + static inline void setCppPtrFromC (CType *cObject, CppType* &&cppObject) { + CppType **cppObjectAddr = &reinterpret_cast::type *>(cObject)->cppPtr; + if (*cppObjectAddr == cppObject) + return; + delete *cppObjectAddr; + + *cppObjectAddr = cppObject; + (*cppObjectAddr)->setCBackPtr(cObject); } template< @@ -259,7 +329,7 @@ public: delete *cppObjectAddr; *cppObjectAddr = new CppType(*cppObject); - (*cppObjectAddr)->setProperty("LinphonePrivate::Wrapper::cBackPtr", cObject); + (*cppObjectAddr)->setCBackPtr(cObject); } // --------------------------------------------------------------------------- @@ -268,34 +338,28 @@ public: template< typename CppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value>::type > - static inline typename CppTypeMetaInfo::cType *getCBackPtr (const std::shared_ptr &cppObject) { - typedef typename CppTypeMetaInfo::cType RetType; - - if (L_UNLIKELY(!cppObject)) - return nullptr; - - Variant variant = cppObject->getProperty("LinphonePrivate::Wrapper::cBackPtr"); - void *value = variant.getValue(); - if (value) - return static_cast(value); - - RetType *cObject = CppTypeMetaInfo::init(); - setCppPtrFromC(cObject, cppObject); - return cObject; + static inline CppType * &&getResolvedCppPtr (const CppType *cppObject) { + // Exists only for `getCBackPtr` impl. + abort("Cannot get resolved cpp ptr from BaseObject."); + return std::move(const_cast(cppObject)); } template< typename CppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value, CppType>::type > - static inline typename CppTypeMetaInfo::cType *getCBackPtr (CppType *cppObject) { + static inline std::shared_ptr getResolvedCppPtr (const CppType *cppObject) { if (L_UNLIKELY(!cppObject)) return nullptr; try { - return getCBackPtr(std::static_pointer_cast(cppObject->getSharedFromThis())); + typedef typename std::decaygetSharedFromThis())>::type SharedFromThisType; + + return std::static_pointer_cast( + std::const_pointer_cast(cppObject->getSharedFromThis()) + ); } catch (const std::bad_weak_ptr &e) { abort(e.what()); } @@ -308,19 +372,29 @@ public: typename CppType, typename = typename std::enable_if::value, CppType>::type > + static constexpr const CppType *getResolvedCppPtr (const CppType *cppObject) { + return cppObject; + } + + template< + typename CppType, + typename = typename std::enable_if::value, CppType>::type + > static inline typename CppTypeMetaInfo::cType *getCBackPtr (const CppType *cppObject) { if (L_UNLIKELY(!cppObject)) return nullptr; typedef typename CppTypeMetaInfo::cType RetType; - Variant variant = cppObject->getProperty("LinphonePrivate::Wrapper::cBackPtr"); - void *value = variant.getValue(); - if (value) + void *value = cppObject->getCBackPtr(); + if (value || IsDefinedBaseCppObject::value) return static_cast(value); RetType *cObject = CppTypeMetaInfo::init(); - setCppPtrFromC(cObject, cppObject); + + // Can be set only on Object or ClonableObject. Not BaseObject. + setCppPtrFromC(cObject, getResolvedCppPtr(cppObject)); + return cObject; } @@ -364,12 +438,12 @@ public: template< typename CppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value, CppType>::type > static inline bctbx_list_t *getResolvedCListFromCppList (const std::list> &cppList) { bctbx_list_t *result = nullptr; for (const auto &value : cppList) { - result = bctbx_list_append(result, belle_sip_object_ref(getCBackPtr(value))); + result = bctbx_list_append(result, belle_sip_object_ref(getCBackPtr(value.get()))); } return result; } @@ -388,7 +462,7 @@ public: template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if::value, CppType>::type > static inline std::list> getResolvedCppListFromCList (const bctbx_list_t *cList) { std::list> result; @@ -500,6 +574,30 @@ LINPHONE_END_NAMESPACE // C object declaration. // ----------------------------------------------------------------------------- +// Declare base wrapped C object. +#define L_DECLARE_C_BASE_OBJECT_IMPL(C_TYPE, ...) \ + static_assert(LinphonePrivate::CTypeMetaInfo::defined, "Type is not defined."); \ + struct _Linphone ## C_TYPE { \ + belle_sip_object_t base; \ + L_CPP_TYPE_OF_C_TYPE(C_TYPE) *cppPtr; \ + __VA_ARGS__ \ + }; \ + BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## C_TYPE); \ + Linphone ## C_TYPE *_linphone_ ## C_TYPE ## _init() { \ + return belle_sip_object_new(Linphone ## C_TYPE); \ + } \ + static void _linphone_ ## C_TYPE ## _uninit(Linphone ## C_TYPE * object) { \ + delete object->cppPtr; \ + } \ + BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## C_TYPE); \ + BELLE_SIP_INSTANCIATE_VPTR( \ + Linphone ## C_TYPE, belle_sip_object_t, \ + _linphone_ ## C_TYPE ## _uninit, \ + NULL, \ + NULL, \ + FALSE \ + ); + // Declare wrapped C object with constructor/destructor. #define L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(C_TYPE, CONSTRUCTOR, DESTRUCTOR, ...) \ struct _Linphone ## C_TYPE { \ @@ -511,6 +609,7 @@ LINPHONE_END_NAMESPACE // Declare wrapped C object. #define L_DECLARE_C_OBJECT_IMPL(C_TYPE, ...) \ + static_assert(LinphonePrivate::CTypeMetaInfo::defined, "Type is not defined."); \ struct _Linphone ## C_TYPE { \ belle_sip_object_t base; \ std::shared_ptr cppPtr; \ @@ -519,7 +618,7 @@ LINPHONE_END_NAMESPACE L_INTERNAL_DECLARE_C_OBJECT_FUNCTIONS(C_TYPE, L_INTERNAL_C_OBJECT_NO_XTOR, L_INTERNAL_C_OBJECT_NO_XTOR) // Declare clonable wrapped C object. -#define L_DECLARE_C_CLONABLE_STRUCT_IMPL(C_TYPE, ...) \ +#define L_DECLARE_C_CLONABLE_OBJECT_IMPL(C_TYPE, ...) \ static_assert(LinphonePrivate::CTypeMetaInfo::defined, "Type is not defined."); \ struct _Linphone ## C_TYPE { \ belle_sip_object_t base; \ @@ -602,7 +701,7 @@ LINPHONE_END_NAMESPACE // Get the wrapped C object of a C++ object. #define L_GET_C_BACK_PTR(CPP_OBJECT) \ - LinphonePrivate::Wrapper::getCBackPtr(CPP_OBJECT) + LinphonePrivate::Wrapper::getCBackPtr(LinphonePrivate::Utils::getPtr(CPP_OBJECT)) // Get/set user data on a wrapped C object. #define L_GET_USER_DATA_FROM_C_OBJECT(C_OBJECT) \ diff --git a/src/chat/chat-room/client-group-chat-room.h b/src/chat/chat-room/client-group-chat-room.h index dc44e18fe..5575b6b70 100644 --- a/src/chat/chat-room/client-group-chat-room.h +++ b/src/chat/chat-room/client-group-chat-room.h @@ -69,7 +69,7 @@ private: void onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const std::string &message) override; private: - L_DECLARE_PRIVATE_T(ClientGroupChatRoom, ChatRoom); + L_DECLARE_PRIVATE(ClientGroupChatRoom); L_DISABLE_COPY(ClientGroupChatRoom); }; diff --git a/src/content/content.h b/src/content/content.h index abf86c9d7..7f73b83f5 100644 --- a/src/content/content.h +++ b/src/content/content.h @@ -64,7 +64,7 @@ public: bool isEmpty () const; private: - L_DECLARE_PRIVATE_T(Content, ClonableObject); + L_DECLARE_PRIVATE(Content); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/call/call-event.cpp b/src/event-log/call/call-event.cpp index b4d6be335..a63dcc3ad 100644 --- a/src/event-log/call/call-event.cpp +++ b/src/event-log/call/call-event.cpp @@ -41,18 +41,6 @@ CallEvent::CallEvent (Type type, time_t time, const shared_ptr &call) : d->call = call; } -CallEvent::CallEvent (const CallEvent &src) : CallEvent(src.getType(), src.getTime(), src.getCall()) {} - -CallEvent &CallEvent::operator= (const CallEvent &src) { - L_D(); - if (this != &src) { - EventLog::operator=(src); - d->call = src.getPrivate()->call; - } - - return *this; -} - shared_ptr CallEvent::getCall () const { L_D(); return d->call; diff --git a/src/event-log/call/call-event.h b/src/event-log/call/call-event.h index 85ae6c28d..648973957 100644 --- a/src/event-log/call/call-event.h +++ b/src/event-log/call/call-event.h @@ -34,14 +34,12 @@ class CallEventPrivate; class LINPHONE_PUBLIC CallEvent : public EventLog { public: CallEvent (Type type, std::time_t time, const std::shared_ptr &message); - CallEvent (const CallEvent &src); - - CallEvent &operator= (const CallEvent &src); std::shared_ptr getCall () const; private: L_DECLARE_PRIVATE(CallEvent); + L_DISABLE_COPY(CallEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/chat/chat-message-event.cpp b/src/event-log/chat/chat-message-event.cpp index 6e26e48e3..498c417ac 100644 --- a/src/event-log/chat/chat-message-event.cpp +++ b/src/event-log/chat/chat-message-event.cpp @@ -42,20 +42,6 @@ ChatMessageEvent::ChatMessageEvent ( d->chatMessage = chatMessage; } -ChatMessageEvent::ChatMessageEvent ( - const ChatMessageEvent &src -) : ChatMessageEvent(src.getTime(), src.getChatMessage()) {} - -ChatMessageEvent &ChatMessageEvent::operator= (const ChatMessageEvent &src) { - L_D(); - if (this != &src) { - EventLog::operator=(src); - d->chatMessage = src.getPrivate()->chatMessage; - } - - return *this; -} - shared_ptr ChatMessageEvent::getChatMessage () const { L_D(); return d->chatMessage; diff --git a/src/event-log/chat/chat-message-event.h b/src/event-log/chat/chat-message-event.h index becbdadd8..82ccc1804 100644 --- a/src/event-log/chat/chat-message-event.h +++ b/src/event-log/chat/chat-message-event.h @@ -34,14 +34,12 @@ class ChatMessageEventPrivate; class LINPHONE_PUBLIC ChatMessageEvent : public EventLog { public: ChatMessageEvent (std::time_t time, const std::shared_ptr &chatMessage); - ChatMessageEvent (const ChatMessageEvent &src); - - ChatMessageEvent &operator= (const ChatMessageEvent &src); std::shared_ptr getChatMessage () const; private: L_DECLARE_PRIVATE(ChatMessageEvent); + L_DISABLE_COPY(ChatMessageEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/conference/conference-event.cpp b/src/event-log/conference/conference-event.cpp index c11c94428..daeac96a7 100644 --- a/src/event-log/conference/conference-event.cpp +++ b/src/event-log/conference/conference-event.cpp @@ -33,9 +33,6 @@ ConferenceEvent::ConferenceEvent (Type type, time_t time, const Address &confere d->conferenceAddress = conferenceAddress; } -ConferenceEvent::ConferenceEvent (const ConferenceEvent &src) : - ConferenceEvent(src.getType(), src.getTime(), src.getConferenceAddress()) {} - ConferenceEvent::ConferenceEvent ( ConferenceEventPrivate &p, Type type, @@ -46,16 +43,6 @@ ConferenceEvent::ConferenceEvent ( d->conferenceAddress = conferenceAddress; } -ConferenceEvent &ConferenceEvent::operator= (const ConferenceEvent &src) { - L_D(); - if (this != &src) { - EventLog::operator=(src); - d->conferenceAddress = src.getPrivate()->conferenceAddress; - } - - return *this; -} - const Address &ConferenceEvent::getConferenceAddress () const { L_D(); return d->conferenceAddress; diff --git a/src/event-log/conference/conference-event.h b/src/event-log/conference/conference-event.h index 05fb34dc4..080c9e9a2 100644 --- a/src/event-log/conference/conference-event.h +++ b/src/event-log/conference/conference-event.h @@ -32,9 +32,6 @@ class ConferenceEventPrivate; class LINPHONE_PUBLIC ConferenceEvent : public EventLog { public: ConferenceEvent (Type type, std::time_t time, const Address &conferenceAddress); - ConferenceEvent (const ConferenceEvent &src); - - ConferenceEvent &operator= (const ConferenceEvent &src); const Address &getConferenceAddress () const; @@ -43,6 +40,7 @@ protected: private: L_DECLARE_PRIVATE(ConferenceEvent); + L_DISABLE_COPY(ConferenceEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/conference/conference-notified-event.cpp b/src/event-log/conference/conference-notified-event.cpp index cca45750e..5a0e4f857 100644 --- a/src/event-log/conference/conference-notified-event.cpp +++ b/src/event-log/conference/conference-notified-event.cpp @@ -37,15 +37,6 @@ ConferenceNotifiedEvent::ConferenceNotifiedEvent ( d->notifyId = notifyId; } -ConferenceNotifiedEvent::ConferenceNotifiedEvent ( - const ConferenceNotifiedEvent &src -) : ConferenceNotifiedEvent( - src.getType(), - src.getTime(), - src.getConferenceAddress(), - src.getNotifyId() -) {} - ConferenceNotifiedEvent::ConferenceNotifiedEvent ( ConferenceNotifiedEventPrivate &p, Type type, @@ -57,16 +48,6 @@ ConferenceNotifiedEvent::ConferenceNotifiedEvent ( d->notifyId = notifyId; } -ConferenceNotifiedEvent &ConferenceNotifiedEvent::operator= (const ConferenceNotifiedEvent &src) { - L_D(); - if (this != &src) { - ConferenceEvent::operator=(src); - d->notifyId = src.getPrivate()->notifyId; - } - - return *this; -} - unsigned int ConferenceNotifiedEvent::getNotifyId () const { L_D(); return d->notifyId; diff --git a/src/event-log/conference/conference-notified-event.h b/src/event-log/conference/conference-notified-event.h index 2f3c8f860..4f238e857 100644 --- a/src/event-log/conference/conference-notified-event.h +++ b/src/event-log/conference/conference-notified-event.h @@ -31,9 +31,6 @@ class ConferenceNotifiedEventPrivate; class LINPHONE_PUBLIC ConferenceNotifiedEvent : public ConferenceEvent { public: ConferenceNotifiedEvent (Type type, std::time_t time, const Address &conferenceAddress, unsigned int notifiyId); - ConferenceNotifiedEvent (const ConferenceNotifiedEvent &src); - - ConferenceNotifiedEvent &operator= (const ConferenceNotifiedEvent &src); unsigned int getNotifyId () const; @@ -48,6 +45,7 @@ protected: private: L_DECLARE_PRIVATE(ConferenceNotifiedEvent); + L_DISABLE_COPY(ConferenceNotifiedEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/conference/conference-participant-device-event.cpp b/src/event-log/conference/conference-participant-device-event.cpp index 83cc88398..fbfbcceda 100644 --- a/src/event-log/conference/conference-participant-device-event.cpp +++ b/src/event-log/conference/conference-participant-device-event.cpp @@ -56,28 +56,6 @@ ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent ( d->gruuAddress = gruuAddress; } -ConferenceParticipantDeviceEvent::ConferenceParticipantDeviceEvent (const ConferenceParticipantDeviceEvent &src) : - ConferenceParticipantDeviceEvent( - src.getType(), - src.getTime(), - src.getConferenceAddress(), - src.getNotifyId(), - src.getParticipantAddress(), - src.getGruuAddress() - ) {} - -ConferenceParticipantDeviceEvent &ConferenceParticipantDeviceEvent::operator= ( - const ConferenceParticipantDeviceEvent &src -) { - L_D(); - if (this != &src) { - ConferenceParticipantEvent::operator=(src); - d->gruuAddress = src.getPrivate()->gruuAddress; - } - - return *this; -} - const Address &ConferenceParticipantDeviceEvent::getGruuAddress () const { L_D(); return d->gruuAddress; diff --git a/src/event-log/conference/conference-participant-device-event.h b/src/event-log/conference/conference-participant-device-event.h index 3ee2b9a95..d57834dd7 100644 --- a/src/event-log/conference/conference-participant-device-event.h +++ b/src/event-log/conference/conference-participant-device-event.h @@ -38,14 +38,12 @@ public: const Address &participantAddress, const Address &gruuAddress ); - ConferenceParticipantDeviceEvent (const ConferenceParticipantDeviceEvent &src); - - ConferenceParticipantDeviceEvent &operator= (const ConferenceParticipantDeviceEvent &src); const Address &getGruuAddress () const; private: L_DECLARE_PRIVATE(ConferenceParticipantDeviceEvent); + L_DISABLE_COPY(ConferenceParticipantDeviceEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/conference/conference-participant-event.cpp b/src/event-log/conference/conference-participant-event.cpp index b64e886b2..b5e8406b6 100644 --- a/src/event-log/conference/conference-participant-event.cpp +++ b/src/event-log/conference/conference-participant-event.cpp @@ -44,16 +44,6 @@ ConferenceParticipantEvent::ConferenceParticipantEvent ( d->participantAddress = participantAddress; } -ConferenceParticipantEvent::ConferenceParticipantEvent ( - const ConferenceParticipantEvent &src -) : ConferenceParticipantEvent( - src.getType(), - src.getTime(), - src.getConferenceAddress(), - src.getNotifyId(), - src.getParticipantAddress() -) {} - ConferenceParticipantEvent::ConferenceParticipantEvent ( ConferenceParticipantEventPrivate &p, Type type, @@ -66,16 +56,6 @@ ConferenceParticipantEvent::ConferenceParticipantEvent ( d->participantAddress = participantAddress; } -ConferenceParticipantEvent &ConferenceParticipantEvent::operator= (const ConferenceParticipantEvent &src) { - L_D(); - if (this != &src) { - ConferenceEvent::operator=(src); - d->participantAddress = src.getPrivate()->participantAddress; - } - - return *this; -} - const Address &ConferenceParticipantEvent::getParticipantAddress () const { L_D(); return d->participantAddress; diff --git a/src/event-log/conference/conference-participant-event.h b/src/event-log/conference/conference-participant-event.h index d5127459a..792583dcf 100644 --- a/src/event-log/conference/conference-participant-event.h +++ b/src/event-log/conference/conference-participant-event.h @@ -37,9 +37,6 @@ public: unsigned int notifyId, const Address &participantAddress ); - ConferenceParticipantEvent (const ConferenceParticipantEvent &src); - - ConferenceParticipantEvent &operator= (const ConferenceParticipantEvent &src); const Address &getParticipantAddress () const; @@ -55,6 +52,7 @@ protected: private: L_DECLARE_PRIVATE(ConferenceParticipantEvent); + L_DISABLE_COPY(ConferenceParticipantEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/conference/conference-subject-event.cpp b/src/event-log/conference/conference-subject-event.cpp index 1dcd45a0b..e07061dc2 100644 --- a/src/event-log/conference/conference-subject-event.cpp +++ b/src/event-log/conference/conference-subject-event.cpp @@ -49,19 +49,6 @@ ConferenceSubjectEvent::ConferenceSubjectEvent ( d->subject = subject; } -ConferenceSubjectEvent::ConferenceSubjectEvent (const ConferenceSubjectEvent &src) : - ConferenceSubjectEvent(src.getTime(), src.getConferenceAddress(), src.getNotifyId(), src.getSubject()) {} - -ConferenceSubjectEvent &ConferenceSubjectEvent::operator= (const ConferenceSubjectEvent &src) { - L_D(); - if (this != &src) { - ConferenceEvent::operator=(src); - d->subject = src.getPrivate()->subject; - } - - return *this; -} - const string &ConferenceSubjectEvent::getSubject () const { L_D(); return d->subject; diff --git a/src/event-log/conference/conference-subject-event.h b/src/event-log/conference/conference-subject-event.h index 20f5fe982..8ea9a039f 100644 --- a/src/event-log/conference/conference-subject-event.h +++ b/src/event-log/conference/conference-subject-event.h @@ -20,6 +20,8 @@ #ifndef _CONFERENCE_SUBJECT_EVENT_H_ #define _CONFERENCE_SUBJECT_EVENT_H_ +#include + #include "conference-notified-event.h" // ============================================================================= @@ -36,14 +38,12 @@ public: unsigned int notifyId, const std::string &subject ); - ConferenceSubjectEvent (const ConferenceSubjectEvent &src); - - ConferenceSubjectEvent &operator= (const ConferenceSubjectEvent &src); const std::string &getSubject () const; private: L_DECLARE_PRIVATE(ConferenceSubjectEvent); + L_DISABLE_COPY(ConferenceSubjectEvent); }; LINPHONE_END_NAMESPACE diff --git a/src/event-log/event-log-p.h b/src/event-log/event-log-p.h index 5732a56cc..ccfe7a721 100644 --- a/src/event-log/event-log-p.h +++ b/src/event-log/event-log-p.h @@ -20,14 +20,15 @@ #ifndef _EVENT_LOG_P_H_ #define _EVENT_LOG_P_H_ +#include "object/base-object-p.h" + #include "event-log.h" -#include "object/clonable-object-p.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class EventLogPrivate : public ClonableObjectPrivate { +class EventLogPrivate : public BaseObjectPrivate { public: long storageId = -1; diff --git a/src/event-log/event-log.cpp b/src/event-log/event-log.cpp index cdb2281bb..087ee6797 100644 --- a/src/event-log/event-log.cpp +++ b/src/event-log/event-log.cpp @@ -23,23 +23,14 @@ LINPHONE_BEGIN_NAMESPACE -EventLog::EventLog () : ClonableObject(*new EventLogPrivate) {} +EventLog::EventLog () : BaseObject(*new EventLogPrivate) {} -EventLog::EventLog (const EventLog &) : ClonableObject(*new EventLogPrivate) {} - -EventLog::EventLog (EventLogPrivate &p, Type type, time_t time) : ClonableObject(*new EventLogPrivate) { +EventLog::EventLog (EventLogPrivate &p, Type type, std::time_t time) : BaseObject(p) { L_D(); d->type = type; d->time = time; } -EventLog &EventLog::operator= (const EventLog &src) { - L_D(); - if (this != &src) - d->type = src.getPrivate()->type; - return *this; -} - EventLog::Type EventLog::getType () const { L_D(); return d->type; diff --git a/src/event-log/event-log.h b/src/event-log/event-log.h index e5f0d682a..3134421e8 100644 --- a/src/event-log/event-log.h +++ b/src/event-log/event-log.h @@ -25,7 +25,7 @@ #include "linphone/enums/event-log-enums.h" #include "linphone/utils/enum-generator.h" -#include "object/clonable-object.h" +#include "object/base-object.h" // ============================================================================= @@ -33,16 +33,13 @@ LINPHONE_BEGIN_NAMESPACE class EventLogPrivate; -class LINPHONE_PUBLIC EventLog : public ClonableObject { +class LINPHONE_PUBLIC EventLog : public BaseObject { friend class MainDb; public: L_DECLARE_ENUM(Type, L_ENUM_VALUES_EVENT_LOG_TYPE); EventLog (); - EventLog (const EventLog &src); - - EventLog &operator= (const EventLog &src); Type getType () const; std::time_t getTime () const; @@ -52,6 +49,7 @@ protected: private: L_DECLARE_PRIVATE(EventLog); + L_DISABLE_COPY(EventLog); }; LINPHONE_END_NAMESPACE diff --git a/src/object/base-object-p.h b/src/object/base-object-p.h new file mode 100644 index 000000000..3db55188e --- /dev/null +++ b/src/object/base-object-p.h @@ -0,0 +1,47 @@ +/* + * base-object-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + #ifndef _BASE_OBJECT_P_H_ + #define _BASE_OBJECT_P_H_ + +#include "linphone/utils/general.h" + +#include "object-head-p.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class BaseObjectPrivate { + L_OBJECT_PRIVATE; + +public: + BaseObjectPrivate () = default; + virtual ~BaseObjectPrivate () = default; + +protected: + BaseObject *mPublic = nullptr; + +private: + L_DECLARE_PUBLIC(BaseObject); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _BASE_OBJECT_P_H_ diff --git a/src/object/base-object.cpp b/src/object/base-object.cpp new file mode 100644 index 000000000..b1551c5ed --- /dev/null +++ b/src/object/base-object.cpp @@ -0,0 +1,38 @@ +/* + * base-object.cpp + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "base-object-p.h" + +#include "base-object.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +L_OBJECT_IMPL(BaseObject); + +BaseObject::BaseObject (BaseObjectPrivate &p) : mPrivate(&p) { + mPrivate->mPublic = this; +} + +BaseObject::~BaseObject () { + delete mPrivate; +} + +LINPHONE_END_NAMESPACE diff --git a/src/object/base-object.h b/src/object/base-object.h new file mode 100644 index 000000000..49d219f4a --- /dev/null +++ b/src/object/base-object.h @@ -0,0 +1,56 @@ +/* + * base-object.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _BASE_OBJECT_H_ +#define _BASE_OBJECT_H_ + +#include "linphone/utils/general.h" + +#include "object-head.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +class BaseObjectPrivate; + +/* + * Base Object of Linphone. Cannot be cloned. Cannot be Shared. + * It's the base class of Object. It's useful for lightweight entities + * like Events. + */ +class LINPHONE_PUBLIC BaseObject { + L_OBJECT; + +public: + virtual ~BaseObject (); + +protected: + explicit BaseObject (BaseObjectPrivate &p); + + BaseObjectPrivate *mPrivate = nullptr; + +private: + L_DECLARE_PRIVATE(BaseObject); + L_DISABLE_COPY(BaseObject); +}; + +LINPHONE_END_NAMESPACE + +#endif // ifndef _BASE_OBJECT_H_ diff --git a/src/object/clonable-object-p.h b/src/object/clonable-object-p.h index c1de00036..af30d627c 100644 --- a/src/object/clonable-object-p.h +++ b/src/object/clonable-object-p.h @@ -24,11 +24,15 @@ #include "linphone/utils/general.h" +#include "object-head-p.h" + // ============================================================================= LINPHONE_BEGIN_NAMESPACE class ClonableObjectPrivate { + L_OBJECT_PRIVATE; + public: ClonableObjectPrivate () = default; virtual ~ClonableObjectPrivate () = default; diff --git a/src/object/clonable-object.cpp b/src/object/clonable-object.cpp index 4851cd2d8..831e7879a 100644 --- a/src/object/clonable-object.cpp +++ b/src/object/clonable-object.cpp @@ -42,6 +42,8 @@ void ClonableObjectPrivate::unref () { // ----------------------------------------------------------------------------- +L_OBJECT_IMPL(ClonableObject); + ClonableObject::ClonableObject (ClonableObjectPrivate &p) : mPrivate(&p) { // Q-pointer must be empty. It's a constructor that takes a new private data. L_ASSERT(!mPrivate->mPublic); diff --git a/src/object/clonable-object.h b/src/object/clonable-object.h index 34c91ef69..30df6b61f 100644 --- a/src/object/clonable-object.h +++ b/src/object/clonable-object.h @@ -20,13 +20,20 @@ #ifndef _CLONABLE_OBJECT_H_ #define _CLONABLE_OBJECT_H_ +#include "object-head.h" #include "property-container.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE +/* + * Clonable Object of Linphone. Generally it's just a data object with no + * intelligence. + */ class LINPHONE_PUBLIC ClonableObject : public PropertyContainer { + L_OBJECT; + public: virtual ~ClonableObject (); diff --git a/src/object/object-head-p.h b/src/object/object-head-p.h new file mode 100644 index 000000000..7f221ec5a --- /dev/null +++ b/src/object/object-head-p.h @@ -0,0 +1,38 @@ +/* + * object-head-p.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _OBJECT_HEAD_P_H_ +#define _OBJECT_HEAD_P_H_ + +// ============================================================================= + +#define L_OBJECT_IMPL(CLASS) \ + void *CLASS::getCBackPtr () const { \ + L_D(); \ + return d->cBackPtr; \ + } \ + void CLASS::setCBackPtr (void *cBackPtr) { \ + L_D(); \ + d->cBackPtr = cBackPtr; \ + } + +#define L_OBJECT_PRIVATE \ + void *cBackPtr = nullptr; + +#endif // ifndef _OBJECT_HEAD_P_H_ diff --git a/src/object/object-head.h b/src/object/object-head.h new file mode 100644 index 000000000..181a0c467 --- /dev/null +++ b/src/object/object-head.h @@ -0,0 +1,29 @@ +/* + * object-head.h + * Copyright (C) 2010-2017 Belledonne Communications SARL + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _OBJECT_HEAD_H_ +#define _OBJECT_HEAD_H_ + +// ============================================================================= + +#define L_OBJECT \ + void *getCBackPtr () const; \ + void setCBackPtr (void *cBackPtr); + +#endif // ifndef _OBJECT_HEAD_H_ diff --git a/src/object/object-p.h b/src/object/object-p.h index c03afac98..842fd3c6f 100644 --- a/src/object/object-p.h +++ b/src/object/object-p.h @@ -23,21 +23,16 @@ #include #include +#include "base-object-p.h" #include "variant/variant.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class ObjectPrivate { +class ObjectPrivate : public BaseObjectPrivate { friend class ObjectFactory; -public: - virtual ~ObjectPrivate () = default; - -protected: - Object *mPublic = nullptr; - private: std::unordered_map properties; std::weak_ptr weak; diff --git a/src/object/object.cpp b/src/object/object.cpp index 7c62c0c42..179e2392a 100644 --- a/src/object/object.cpp +++ b/src/object/object.cpp @@ -30,13 +30,7 @@ using namespace std; LINPHONE_BEGIN_NAMESPACE -Object::Object (ObjectPrivate &p) : mPrivate(&p) { - mPrivate->mPublic = this; -} - -Object::~Object () { - delete mPrivate; -} +Object::Object (ObjectPrivate &p) : BaseObject(p) {} shared_ptr Object::getSharedFromThis () { return const_pointer_cast(static_cast(this)->getSharedFromThis()); @@ -46,7 +40,7 @@ shared_ptr Object::getSharedFromThis () const { shared_ptr object; try { - object = mPrivate->weak.lock(); + object = getPrivate()->weak.lock(); if (!object) lFatal() << GET_SHARED_FROM_THIS_FATAL_ERROR; } catch (const exception &) { diff --git a/src/object/object.h b/src/object/object.h index 843b48b9d..910d0bcb3 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -22,17 +22,22 @@ #include +#include "base-object.h" #include "property-container.h" // ============================================================================= LINPHONE_BEGIN_NAMESPACE -class LINPHONE_PUBLIC Object : public PropertyContainer { +/* + * Main Object of Linphone. Can be shared but is not Clonable. + * Must be built with ObjectFactory. + */ +class LINPHONE_PUBLIC Object : public BaseObject, public PropertyContainer { friend class ObjectFactory; public: - virtual ~Object (); + virtual ~Object () = default; protected: explicit Object (ObjectPrivate &p); @@ -40,8 +45,6 @@ protected: std::shared_ptr getSharedFromThis (); std::shared_ptr getSharedFromThis () const; - ObjectPrivate *mPrivate = nullptr; - private: L_DECLARE_PRIVATE(Object); L_DISABLE_COPY(Object);