From be1d6f99ede425ad561821c08925b8fac8bc7701 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 24 Oct 2017 11:15:42 +0200 Subject: [PATCH] feat(Event): events are now shared --- src/c-wrapper/api/c-dial-plan.cpp | 41 +++--- src/c-wrapper/api/c-event-log.cpp | 20 +-- src/c-wrapper/internal/c-tools.h | 138 ++++++------------ src/chat/chat-room/client-group-chat-room.cpp | 24 +-- src/db/main-db-p.h | 16 +- src/db/main-db.cpp | 40 ++--- src/db/main-db.h | 4 +- src/event-log/event-log.h | 1 + src/object/base-object.h | 2 +- src/object/object.h | 1 + 10 files changed, 120 insertions(+), 167 deletions(-) diff --git a/src/c-wrapper/api/c-dial-plan.cpp b/src/c-wrapper/api/c-dial-plan.cpp index beafd3ecd..534d0d417 100644 --- a/src/c-wrapper/api/c-dial-plan.cpp +++ b/src/c-wrapper/api/c-dial-plan.cpp @@ -18,7 +18,6 @@ */ #include "linphone/api/c-dial-plan.h" -#include "linphone/wrapper_utils.h" #include "c-wrapper/c-wrapper.h" #include "dial-plan/dial-plan.h" @@ -29,61 +28,61 @@ using namespace std; L_DECLARE_C_OBJECT_IMPL(DialPlan); -LinphoneDialPlan *linphone_dial_plan_ref(LinphoneDialPlan *dp) { - return (LinphoneDialPlan *)belle_sip_object_ref(dp); +LinphoneDialPlan *linphone_dial_plan_ref (LinphoneDialPlan *dp) { + return reinterpret_cast(belle_sip_object_ref(dp)); } -void linphone_dial_plan_unref(LinphoneDialPlan *dp) { +void linphone_dial_plan_unref (LinphoneDialPlan *dp) { belle_sip_object_unref(dp); } -const char * linphone_dial_plan_get_country(const LinphoneDialPlan *dp) { +const char *linphone_dial_plan_get_country (const LinphoneDialPlan *dp) { return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getCountry()); } -const char * linphone_dial_plan_get_iso_country_code(const LinphoneDialPlan *dp) { +const char *linphone_dial_plan_get_iso_country_code (const LinphoneDialPlan *dp) { return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getIsoCountryCode()); } -const char * linphone_dial_plan_get_country_calling_code(const LinphoneDialPlan *dp) { +const char *linphone_dial_plan_get_country_calling_code (const LinphoneDialPlan *dp) { return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getCountryCallingCode()); } -int linphone_dial_plan_get_national_number_length(const LinphoneDialPlan *dp) { +int linphone_dial_plan_get_national_number_length (const LinphoneDialPlan *dp) { return L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getNationalNumberLength(); } -const char * linphone_dial_plan_get_international_call_prefix(const LinphoneDialPlan *dp) { +const char *linphone_dial_plan_get_international_call_prefix (const LinphoneDialPlan *dp) { return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(dp)->getInternationalCallPrefix()); } -int linphone_dial_plan_lookup_ccc_from_e164(const char* e164) { - return LinphonePrivate::DialPlan::lookupCccFromE164(L_C_TO_STRING(e164)); +int linphone_dial_plan_lookup_ccc_from_e164 (const char *e164) { + return LinphonePrivate::DialPlan::lookupCccFromE164(L_C_TO_STRING(e164)); } -int linphone_dial_plan_lookup_ccc_from_iso(const char* iso) { +int linphone_dial_plan_lookup_ccc_from_iso (const char *iso) { return LinphonePrivate::DialPlan::lookupCccFromIso(L_C_TO_STRING(iso)); } -const LinphoneDialPlan* linphone_dial_plan_by_ccc_as_int(int ccc) { - const LinphonePrivate::DialPlan& dp = LinphonePrivate::DialPlan::findByCccAsInt(ccc); +const LinphoneDialPlan *linphone_dial_plan_by_ccc_as_int (int ccc) { + const LinphonePrivate::DialPlan &dp = LinphonePrivate::DialPlan::findByCccAsInt(ccc); return L_GET_C_BACK_PTR(&dp); } -const LinphoneDialPlan* linphone_dial_plan_by_ccc(const char *ccc) { - const LinphonePrivate::DialPlan& dp = LinphonePrivate::DialPlan::findByCcc(L_C_TO_STRING(ccc)); +const LinphoneDialPlan *linphone_dial_plan_by_ccc (const char *ccc) { + const LinphonePrivate::DialPlan &dp = LinphonePrivate::DialPlan::findByCcc(L_C_TO_STRING(ccc)); return L_GET_C_BACK_PTR(&dp); } -const LinphoneDialPlan* linphone_dial_plan_get_all() { - return NULL; +const LinphoneDialPlan *linphone_dial_plan_get_all () { + return nullptr; } -const bctbx_list_t * linphone_dial_plan_get_all_list() { - const list& dps = LinphonePrivate::DialPlan::getAllDialPlans(); +const bctbx_list_t *linphone_dial_plan_get_all_list () { + const list &dps = LinphonePrivate::DialPlan::getAllDialPlans(); return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(dps); } -bool_t linphone_dial_plan_is_generic(const LinphoneDialPlan *ccc) { +bool_t linphone_dial_plan_is_generic (const LinphoneDialPlan *ccc) { return L_GET_CPP_PTR_FROM_C_OBJECT(ccc)->isGeneric(); } diff --git a/src/c-wrapper/api/c-event-log.cpp b/src/c-wrapper/api/c-event-log.cpp index c6a2a21d6..b4af02343 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_BASE_OBJECT_IMPL(CallEvent); -L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceChatMessageEvent); -L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceEvent); -L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceParticipantDeviceEvent); -L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceParticipantEvent); -L_DECLARE_C_BASE_OBJECT_IMPL(ConferenceSubjectEvent); -L_DECLARE_C_BASE_OBJECT_IMPL(EventLog); +L_DECLARE_C_OBJECT_IMPL(CallEvent); +L_DECLARE_C_OBJECT_IMPL(ConferenceChatMessageEvent); +L_DECLARE_C_OBJECT_IMPL(ConferenceEvent); +L_DECLARE_C_OBJECT_IMPL(ConferenceParticipantDeviceEvent); +L_DECLARE_C_OBJECT_IMPL(ConferenceParticipantEvent); +L_DECLARE_C_OBJECT_IMPL(ConferenceSubjectEvent); +L_DECLARE_C_OBJECT_IMPL(EventLog); using namespace std; @@ -43,7 +43,7 @@ using namespace std; LinphoneEventLog *linphone_event_log_new () { LinphoneEventLog *event_log = _linphone_EventLog_init(); - L_SET_CPP_PTR_FROM_C_OBJECT(event_log, new LinphonePrivate::EventLog()); + L_SET_CPP_PTR_FROM_C_OBJECT(event_log, make_shared()); return event_log; } @@ -66,7 +66,7 @@ LinphoneCallEvent *linphone_call_event_new (LinphoneEventLogType type, time_t ti LinphoneCallEvent *call_event = _linphone_CallEvent_init(); L_SET_CPP_PTR_FROM_C_OBJECT( call_event, - new LinphonePrivate::CallEvent( + make_shared( static_cast(type), time, L_GET_CPP_PTR_FROM_C_OBJECT(call) @@ -128,7 +128,7 @@ LinphoneConferenceChatMessageEvent *linphone_chat_message_event_new (LinphoneCha LinphoneConferenceChatMessageEvent *chat_message_event = _linphone_ConferenceChatMessageEvent_init(); L_SET_CPP_PTR_FROM_C_OBJECT( chat_message_event, - new LinphonePrivate::ConferenceChatMessageEvent( + make_shared( time, L_GET_CPP_PTR_FROM_C_OBJECT(chat_message) ) diff --git a/src/c-wrapper/internal/c-tools.h b/src/c-wrapper/internal/c-tools.h index bc04192ef..3783688c6 100644 --- a/src/c-wrapper/internal/c-tools.h +++ b/src/c-wrapper/internal/c-tools.h @@ -99,16 +99,14 @@ private: template struct IsDefinedBaseCppObject { enum { - value = IsRegisteredCppObject::value && - std::is_base_of::value && - !std::is_base_of::value + value = IsRegisteredCppObject::value && std::is_base_of::value }; }; template struct IsDefinedCppObject { enum { - value = IsRegisteredCppObject::value && std::is_base_of::value + value = IsDefinedBaseCppObject::value && std::is_base_of::value }; }; @@ -125,12 +123,6 @@ private: template struct WrappedBaseObject { - belle_sip_object_t base; - CppType *cppPtr; - }; - - template - struct WrappedObject { belle_sip_object_t base; std::shared_ptr cppPtr; }; @@ -141,23 +133,6 @@ private: 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; - }; - // --------------------------------------------------------------------------- // Runtime checker. // --------------------------------------------------------------------------- @@ -210,14 +185,14 @@ 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 typedef typename CTypeMetaInfo::cppType BaseType; typedef CppType DerivedType; - std::shared_ptr cppObject = reinterpret_cast *>(cObject)->cppPtr; + std::shared_ptr cppObject = reinterpret_cast *>(cObject)->cppPtr; if (!cppObject) abort("Cpp Object is null."); @@ -227,36 +202,34 @@ public: return derivedCppObject; #else - return reinterpret_cast *>(cObject)->cppPtr; + return reinterpret_cast *>(cObject)->cppPtr; #endif } 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::type *>(cObject)->cppPtr; + return reinterpret_cast *>(cObject)->cppPtr; #endif } template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if< - IsDefinedBaseCppObject::value || IsDefinedClonableCppObject::value, CppType - >::type + typename = typename std::enable_if::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::type *>(cObject)->cppPtr; + BaseType *cppObject = reinterpret_cast *>(cObject)->cppPtr; if (!cppObject) abort("Cpp Object is null."); @@ -266,22 +239,20 @@ public: return derivedCppObject; #else - return reinterpret_cast::type *>(cObject)->cppPtr; + return reinterpret_cast *>(cObject)->cppPtr; #endif } template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if< - IsDefinedBaseCppObject::value || IsDefinedClonableCppObject::value, CppType - >::type + typename = typename std::enable_if::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::type *>(cObject)->cppPtr; + return reinterpret_cast *>(cObject)->cppPtr; #endif } @@ -292,22 +263,20 @@ 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; + reinterpret_cast *>(cObject)->cppPtr = cppObject; cppObject->setCBackPtr(cObject); } template< typename CType, typename CppType = typename CTypeMetaInfo::cppType, - typename = typename std::enable_if< - IsDefinedBaseCppObject::value || IsDefinedClonableCppObject::value, CppType - >::type + typename = typename std::enable_if::value, CppType>::type > static inline void setCppPtrFromC (CType *cObject, CppType* &&cppObject) { - CppType **cppObjectAddr = &reinterpret_cast::type *>(cObject)->cppPtr; + CppType **cppObjectAddr = &reinterpret_cast *>(cObject)->cppPtr; if (*cppObjectAddr == cppObject) return; delete *cppObjectAddr; @@ -322,13 +291,7 @@ public: typename = typename std::enable_if::value, CppType>::type > static inline void setCppPtrFromC (CType *cObject, const CppType *cppObject) { - CppType **cppObjectAddr = &reinterpret_cast *>(cObject)->cppPtr; - if (*cppObjectAddr == cppObject) - return; - delete *cppObjectAddr; - - *cppObjectAddr = new CppType(*cppObject); - (*cppObjectAddr)->setCBackPtr(cObject); + setCppPtrFromC(cObject, new CppType(*cppObject)); } // --------------------------------------------------------------------------- @@ -337,17 +300,7 @@ public: template< typename CppType, - typename = typename std::enable_if::value>::type - > - 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 std::shared_ptr getResolvedCppPtr (const CppType *cppObject) { if (L_UNLIKELY(!cppObject)) @@ -377,7 +330,9 @@ public: template< typename CppType, - typename = typename std::enable_if::value, CppType>::type + typename = typename std::enable_if< + IsDefinedCppObject::value || IsDefinedClonableCppObject::value, CppType + >::type > static inline typename CppTypeMetaInfo::cType *getCBackPtr (const CppType *cppObject) { if (L_UNLIKELY(!cppObject)) @@ -386,7 +341,7 @@ public: typedef typename CppTypeMetaInfo::cType RetType; void *value = cppObject->getCBackPtr(); - if (value || IsDefinedBaseCppObject::value) + if (value) return static_cast(value); RetType *cObject = CppTypeMetaInfo::init(); @@ -397,6 +352,27 @@ public: return cObject; } + template< + typename CppType, + typename = typename std::enable_if::value, CppType>::type + > + static inline typename CppTypeMetaInfo::cType *getCBackPtr (const std::shared_ptr &cppObject) { + if (L_UNLIKELY(!cppObject)) + return nullptr; + + typedef typename CppTypeMetaInfo::cType RetType; + + void *value = cppObject->getCBackPtr(); + if (value) + return static_cast(value); + + RetType *cObject = CppTypeMetaInfo::init(); + + setCppPtrFromC(cObject, cppObject); + + return cObject; + } + // --------------------------------------------------------------------------- // Get/set user data. // --------------------------------------------------------------------------- @@ -442,7 +418,7 @@ public: 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.get()))); + result = bctbx_list_append(result, belle_sip_object_ref(getCBackPtr(value))); } return result; } @@ -573,30 +549,6 @@ 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 { \ @@ -700,7 +652,7 @@ LINPHONE_END_NAMESPACE // Get the wrapped C object of a C++ object. #define L_GET_C_BACK_PTR(CPP_OBJECT) \ - LinphonePrivate::Wrapper::getCBackPtr(LinphonePrivate::Utils::getPtr(CPP_OBJECT)) + LinphonePrivate::Wrapper::getCBackPtr(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.cpp b/src/chat/chat-room/client-group-chat-room.cpp index 1d51e386e..6d8b6ede5 100644 --- a/src/chat/chat-room/client-group-chat-room.cpp +++ b/src/chat/chat-room/client-group-chat-room.cpp @@ -276,7 +276,7 @@ void ClientGroupChatRoom::onParticipantAdded (time_t tm, const Address &addr) { LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsParticipantAddedCb cb = linphone_chat_room_cbs_get_participant_added(cbs); - const ConferenceParticipantEvent event( + shared_ptr event = make_shared( EventLog::Type::ConferenceParticipantAdded, tm, dConference->conferenceAddress, @@ -286,7 +286,7 @@ void ClientGroupChatRoom::onParticipantAdded (time_t tm, const Address &addr) { Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event); if (cb) - cb(cr, L_GET_C_BACK_PTR(&event)); + cb(cr, L_GET_C_BACK_PTR(event)); } void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr) { @@ -301,7 +301,7 @@ void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr) LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsParticipantRemovedCb cb = linphone_chat_room_cbs_get_participant_removed(cbs); - const ConferenceParticipantEvent event( + shared_ptr event = make_shared( EventLog::Type::ConferenceParticipantRemoved, tm, dConference->conferenceAddress, @@ -311,7 +311,7 @@ void ClientGroupChatRoom::onParticipantRemoved (time_t tm, const Address &addr) Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event); if (cb) - cb(cr, L_GET_C_BACK_PTR(&event)); + cb(cr, L_GET_C_BACK_PTR(event)); dConference->participants.remove(participant); } @@ -332,7 +332,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (time_t tm, const Address &addr, LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsParticipantAdminStatusChangedCb cb = linphone_chat_room_cbs_get_participant_admin_status_changed(cbs); - const ConferenceParticipantEvent event( + shared_ptr event = make_shared( isAdmin ? EventLog::Type::ConferenceParticipantSetAdmin : EventLog::Type::ConferenceParticipantUnsetAdmin, tm, dConference->conferenceAddress, @@ -342,7 +342,7 @@ void ClientGroupChatRoom::onParticipantSetAdmin (time_t tm, const Address &addr, Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event); if (cb) - cb(cr, L_GET_C_BACK_PTR(&event)); + cb(cr, L_GET_C_BACK_PTR(event)); } void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subject) { @@ -351,7 +351,7 @@ void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subjec LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsSubjectChangedCb cb = linphone_chat_room_cbs_get_subject_changed(cbs); - const ConferenceSubjectEvent event( + shared_ptr event = make_shared( tm, dConference->conferenceAddress, dConference->eventHandler->getLastNotify(), @@ -360,7 +360,7 @@ void ClientGroupChatRoom::onSubjectChanged (time_t tm, const std::string &subjec Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event); if (cb) - cb(cr, L_GET_C_BACK_PTR(&event)); + cb(cr, L_GET_C_BACK_PTR(event)); } void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &addr, const Address &gruu) { @@ -378,7 +378,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &ad LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsParticipantDeviceAddedCb cb = linphone_chat_room_cbs_get_participant_device_added(cbs); - const ConferenceParticipantDeviceEvent event( + shared_ptr event = make_shared( EventLog::Type::ConferenceParticipantDeviceAdded, tm, dConference->conferenceAddress, @@ -389,7 +389,7 @@ void ClientGroupChatRoom::onParticipantDeviceAdded (time_t tm, const Address &ad Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event); if (cb) - cb(cr, L_GET_C_BACK_PTR(&event)); + cb(cr, L_GET_C_BACK_PTR(event)); } void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address &addr, const Address &gruu) { @@ -407,7 +407,7 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address & LinphoneChatRoom *cr = L_GET_C_BACK_PTR(this); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsParticipantDeviceRemovedCb cb = linphone_chat_room_cbs_get_participant_device_removed(cbs); - const ConferenceParticipantDeviceEvent event( + shared_ptr event = make_shared( EventLog::Type::ConferenceParticipantDeviceRemoved, tm, dConference->conferenceAddress, @@ -418,7 +418,7 @@ void ClientGroupChatRoom::onParticipantDeviceRemoved (time_t tm, const Address & Conference::getCore()->cppCore.getPrivate()->mainDb.addEvent(event); if (cb) - cb(cr, L_GET_C_BACK_PTR(&event)); + cb(cr, L_GET_C_BACK_PTR(event)); } // ----------------------------------------------------------------------------- diff --git a/src/db/main-db-p.h b/src/db/main-db-p.h index b026c59f8..9f916d47c 100644 --- a/src/db/main-db-p.h +++ b/src/db/main-db-p.h @@ -99,14 +99,14 @@ private: const std::string &peerAddress ) const; - long long insertEvent (const EventLog &eventLog); - long long insertConferenceEvent (const EventLog &eventLog, long long *chatRoomId = nullptr); - long long insertConferenceCallEvent (const EventLog &eventLog); - long long insertConferenceChatMessageEvent (const EventLog &eventLog); - long long insertConferenceNotifiedEvent (const EventLog &eventLog); - long long insertConferenceParticipantEvent (const EventLog &eventLog); - long long insertConferenceParticipantDeviceEvent (const EventLog &eventLog); - long long insertConferenceSubjectEvent (const EventLog &eventLog); + long long insertEvent (const std::shared_ptr &eventLog); + long long insertConferenceEvent (const std::shared_ptr &eventLog, long long *chatRoomId = nullptr); + long long insertConferenceCallEvent (const std::shared_ptr &eventLog); + long long insertConferenceChatMessageEvent (const std::shared_ptr &eventLog); + long long insertConferenceNotifiedEvent (const std::shared_ptr &eventLog); + long long insertConferenceParticipantEvent (const std::shared_ptr &eventLog); + long long insertConferenceParticipantDeviceEvent (const std::shared_ptr &eventLog); + long long insertConferenceSubjectEvent (const std::shared_ptr &eventLog); L_DECLARE_PUBLIC(MainDb); }; diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index 07df094ae..7adbc9075 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -366,19 +366,19 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} // ----------------------------------------------------------------------------- - long long MainDbPrivate::insertEvent (const EventLog &eventLog) { + long long MainDbPrivate::insertEvent (const shared_ptr &eventLog) { L_Q(); soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO event (type, date) VALUES (:type, :date)", - soci::use(static_cast(eventLog.getType())), soci::use(Utils::getLongAsTm(eventLog.getTime())); + soci::use(static_cast(eventLog->getType())), soci::use(Utils::getLongAsTm(eventLog->getTime())); return q->getLastInsertId(); } - long long MainDbPrivate::insertConferenceEvent (const EventLog &eventLog, long long *chatRoomId) { + long long MainDbPrivate::insertConferenceEvent (const shared_ptr &eventLog, long long *chatRoomId) { long long eventId = insertEvent(eventLog); long long curChatRoomId = insertSipAddress( - static_cast(eventLog).getConferenceAddress().asString() + static_pointer_cast(eventLog)->getConferenceAddress().asString() ); soci::session *session = dbSession.getBackendSession(); @@ -391,20 +391,20 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return eventId; } - long long MainDbPrivate::insertConferenceCallEvent (const EventLog &eventLog) { + long long MainDbPrivate::insertConferenceCallEvent (const shared_ptr &eventLog) { // TODO. return 0; } - long long MainDbPrivate::insertConferenceChatMessageEvent (const EventLog &eventLog) { - shared_ptr chatMessage = static_cast(eventLog).getChatMessage(); + long long MainDbPrivate::insertConferenceChatMessageEvent (const shared_ptr &eventLog) { + shared_ptr chatMessage = static_pointer_cast(eventLog)->getChatMessage(); shared_ptr chatRoom = chatMessage->getChatRoom(); if (!chatRoom) { lError() << "Unable to get a valid chat room. It was removed from database."; return -1; } - tm eventTime = Utils::getLongAsTm(static_cast(eventLog.getTime())); + tm eventTime = Utils::getLongAsTm(static_cast(eventLog->getTime())); long long localSipAddressId = insertSipAddress(chatMessage->getLocalAddress().asString()); long long remoteSipAddressId = insertSipAddress(chatMessage->getRemoteAddress().asString()); @@ -429,10 +429,10 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return eventId; } - long long MainDbPrivate::insertConferenceNotifiedEvent (const EventLog &eventLog) { + long long MainDbPrivate::insertConferenceNotifiedEvent (const shared_ptr &eventLog) { long long chatRoomId; long long eventId = insertConferenceEvent(eventLog, &chatRoomId); - unsigned int lastNotifyId = static_cast(eventLog).getNotifyId(); + unsigned int lastNotifyId = static_pointer_cast(eventLog)->getNotifyId(); soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_notified_event (event_id, notify_id)" @@ -443,10 +443,10 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return eventId; } - long long MainDbPrivate::insertConferenceParticipantEvent (const EventLog &eventLog) { + long long MainDbPrivate::insertConferenceParticipantEvent (const shared_ptr &eventLog) { long long eventId = insertConferenceNotifiedEvent(eventLog); long long participantAddressId = insertSipAddress( - static_cast(eventLog).getParticipantAddress().asString() + static_pointer_cast(eventLog)->getParticipantAddress().asString() ); soci::session *session = dbSession.getBackendSession(); @@ -456,10 +456,10 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return eventId; } - long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const EventLog &eventLog) { + long long MainDbPrivate::insertConferenceParticipantDeviceEvent (const shared_ptr &eventLog) { long long eventId = insertConferenceParticipantEvent(eventLog); long long gruuAddressId = insertSipAddress( - static_cast(eventLog).getGruuAddress().asString() + static_pointer_cast(eventLog)->getGruuAddress().asString() ); soci::session *session = dbSession.getBackendSession(); @@ -469,13 +469,13 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return eventId; } - long long MainDbPrivate::insertConferenceSubjectEvent (const EventLog &eventLog) { + long long MainDbPrivate::insertConferenceSubjectEvent (const shared_ptr &eventLog) { long long eventId = insertConferenceNotifiedEvent(eventLog); soci::session *session = dbSession.getBackendSession(); *session << "INSERT INTO conference_subject_event (event_id, subject)" " VALUES (:eventId, :subject)", soci::use(eventId), soci::use( - static_cast(eventLog).getSubject() + static_pointer_cast(eventLog)->getSubject() ); return eventId; @@ -716,7 +716,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} *session << participantMessageDeleter; } - bool MainDb::addEvent (const EventLog &eventLog) { + bool MainDb::addEvent (const shared_ptr &eventLog) { L_D(); if (!isConnected()) { @@ -730,7 +730,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} soci::transaction tr(*d->dbSession.getBackendSession()); - switch (eventLog.getType()) { + switch (eventLog->getType()) { case EventLog::Type::None: return false; @@ -774,7 +774,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return soFarSoGood; } - bool MainDb::deleteEvent (const EventLog &eventLog) { + bool MainDb::deleteEvent (const shared_ptr &eventLog) { L_D(); if (!isConnected()) { @@ -782,7 +782,7 @@ MainDb::MainDb () : AbstractDb(*new MainDbPrivate) {} return false; } - long long &storageId = const_cast(eventLog).getPrivate()->storageId; + long long &storageId = eventLog->getPrivate()->storageId; if (storageId < 0) return false; diff --git a/src/db/main-db.h b/src/db/main-db.h index 08531f11d..1d22ba3a5 100644 --- a/src/db/main-db.h +++ b/src/db/main-db.h @@ -48,8 +48,8 @@ public: MainDb (); // Generic. - bool addEvent (const EventLog &eventLog); - bool deleteEvent (const EventLog &eventLog); + bool addEvent (const std::shared_ptr &eventLog); + bool deleteEvent (const std::shared_ptr &eventLog); void cleanEvents (FilterMask mask = NoFilter); int getEventsCount (FilterMask mask = NoFilter) const; diff --git a/src/event-log/event-log.h b/src/event-log/event-log.h index 3134421e8..98acbe238 100644 --- a/src/event-log/event-log.h +++ b/src/event-log/event-log.h @@ -21,6 +21,7 @@ #define _EVENT_LOG_H_ #include +#include #include "linphone/enums/event-log-enums.h" #include "linphone/utils/enum-generator.h" diff --git a/src/object/base-object.h b/src/object/base-object.h index 49d219f4a..b19ff3a6d 100644 --- a/src/object/base-object.h +++ b/src/object/base-object.h @@ -31,7 +31,7 @@ LINPHONE_BEGIN_NAMESPACE class BaseObjectPrivate; /* - * Base Object of Linphone. Cannot be cloned. Cannot be Shared. + * Base Object of Linphone. Cannot be cloned. Can be Shared. * It's the base class of Object. It's useful for lightweight entities * like Events. */ diff --git a/src/object/object.h b/src/object/object.h index 910d0bcb3..0721cc0ef 100644 --- a/src/object/object.h +++ b/src/object/object.h @@ -31,6 +31,7 @@ LINPHONE_BEGIN_NAMESPACE /* * Main Object of Linphone. Can be shared but is not Clonable. + * Supports properties and shared from this. * Must be built with ObjectFactory. */ class LINPHONE_PUBLIC Object : public BaseObject, public PropertyContainer {