diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 2ee30a73e..831fd503e 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -296,8 +296,7 @@ App::~App() { } void App::setSelf(QSharedPointer(me)) { - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mCoreModelConnection->makeConnectToModel(&CoreModel::callCreated, [this](const std::shared_ptr &call) { if (call->getDir() == linphone::Call::Dir::Incoming) return; @@ -355,8 +354,7 @@ void App::setSelf(QSharedPointer(me)) { mCoreModelConnection->invokeToCore([this, state] { setCoreStarted(state == linphone::GlobalState::On); }); }); //--------------------------------------------------------------------------------------------- - mCliModelConnection = QSharedPointer>( - new SafeConnection(me, CliModel::getInstance()), &QObject::deleteLater); + mCliModelConnection = SafeConnection::create(me, CliModel::getInstance()); mCliModelConnection->makeConnectToCore(&App::receivedMessage, [this](int, const QByteArray &byteArray) { QString command(byteArray); if (command.isEmpty()) { diff --git a/Linphone/core/account/AccountCore.cpp b/Linphone/core/account/AccountCore.cpp index f7fbcdfcd..bfe080c3f 100644 --- a/Linphone/core/account/AccountCore.cpp +++ b/Linphone/core/account/AccountCore.cpp @@ -141,8 +141,7 @@ AccountCore::AccountCore(const AccountCore &accountCore) { } void AccountCore::setSelf(QSharedPointer me) { - mAccountModelConnection = QSharedPointer>( - new SafeConnection(me, mAccountModel)); + mAccountModelConnection = SafeConnection::create(me, mAccountModel); mAccountModelConnection->makeConnectToModel( &AccountModel::registrationStateChanged, [this](const std::shared_ptr &account, linphone::RegistrationState state, const std::string &message) { @@ -237,8 +236,7 @@ void AccountCore::setSelf(QSharedPointer me) { mAccountModelConnection->makeConnectToCore(&AccountCore::lRefreshNotifications, [this]() { mAccountModelConnection->invokeToModel([this]() { mAccountModel->refreshUnreadNotifications(); }); }); - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance())); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mAccountModelConnection->makeConnectToCore(&AccountCore::unreadCallNotificationsChanged, [this]() { mAccountModelConnection->invokeToModel([this]() { CoreModel::getInstance()->unreadNotificationsChanged(); }); }); diff --git a/Linphone/core/account/AccountDeviceList.cpp b/Linphone/core/account/AccountDeviceList.cpp index 324eae2dc..9d554249b 100644 --- a/Linphone/core/account/AccountDeviceList.cpp +++ b/Linphone/core/account/AccountDeviceList.cpp @@ -126,8 +126,7 @@ void AccountDeviceList::deleteDevice(AccountDeviceGui *deviceGui) { void AccountDeviceList::setSelf(QSharedPointer me) { if (mCoreModelConnection) mCoreModelConnection->disconnect(); - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mCoreModelConnection->invokeToModel([=] { auto core = CoreModel::getInstance()->getCore(); auto ams = core->createAccountManagerServices(); @@ -136,10 +135,8 @@ void AccountDeviceList::setSelf(QSharedPointer me) { mAccountManagerServicesModel = amsModel; if (mAccountManagerServicesModelConnection) mAccountManagerServicesModelConnection->disconnect(); mAccountManagerServicesModelConnection = - QSharedPointer>( - new SafeConnection(me, - mAccountManagerServicesModel), - &QObject::deleteLater); + SafeConnection::create(me, + mAccountManagerServicesModel); mAccountManagerServicesModelConnection->makeConnectToModel( &AccountManagerServicesModel::requestSuccessfull, [this](const std::shared_ptr &request, diff --git a/Linphone/core/account/AccountList.cpp b/Linphone/core/account/AccountList.cpp index 66d4c0845..6c2d6f4e8 100644 --- a/Linphone/core/account/AccountList.cpp +++ b/Linphone/core/account/AccountList.cpp @@ -47,8 +47,7 @@ AccountList::~AccountList() { } void AccountList::setSelf(QSharedPointer me) { - mModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mModelConnection->makeConnectToCore(&AccountList::lUpdate, [this](bool isInitialization) { mModelConnection->invokeToModel([this, isInitialization]() { diff --git a/Linphone/core/address-books/carddav/CarddavCore.cpp b/Linphone/core/address-books/carddav/CarddavCore.cpp index e338f4ff8..7c2adef71 100644 --- a/Linphone/core/address-books/carddav/CarddavCore.cpp +++ b/Linphone/core/address-books/carddav/CarddavCore.cpp @@ -72,8 +72,7 @@ void CarddavCore::remove() { } void CarddavCore::setSelf(QSharedPointer me) { - mCarddavModelConnection = QSharedPointer>( - new SafeConnection(me, mCarddavModel), &QObject::deleteLater); + mCarddavModelConnection = SafeConnection::create(me, mCarddavModel); mCarddavModelConnection->makeConnectToModel(&CarddavModel::saved, [this](bool success) { mCarddavModelConnection->invokeToCore([this, success]() { emit saved(success); }); }); diff --git a/Linphone/core/address-books/carddav/CarddavList.cpp b/Linphone/core/address-books/carddav/CarddavList.cpp index 051c3bb07..958e8af91 100644 --- a/Linphone/core/address-books/carddav/CarddavList.cpp +++ b/Linphone/core/address-books/carddav/CarddavList.cpp @@ -53,8 +53,7 @@ CarddavList::~CarddavList() { } void CarddavList::setSelf(QSharedPointer me) { - mModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mModelConnection->makeConnectToCore(&CarddavList::lUpdate, [this]() { mModelConnection->invokeToModel([this]() { mustBeInLinphoneThread(getClassName()); diff --git a/Linphone/core/address-books/ldap/LdapCore.cpp b/Linphone/core/address-books/ldap/LdapCore.cpp index 81fbb25f0..ad9840a38 100644 --- a/Linphone/core/address-books/ldap/LdapCore.cpp +++ b/Linphone/core/address-books/ldap/LdapCore.cpp @@ -70,8 +70,7 @@ bool LdapCore::isValid() { } void LdapCore::setSelf(QSharedPointer me) { - mLdapModelConnection = QSharedPointer>( - new SafeConnection(me, mLdapModel), &QObject::deleteLater); + mLdapModelConnection = SafeConnection::create(me, mLdapModel); DEFINE_CORE_GETSET_CONNECT(mLdapModelConnection, LdapCore, LdapModel, mLdapModel, QString, serverUrl, ServerUrl) DEFINE_CORE_GETSET_CONNECT(mLdapModelConnection, LdapCore, LdapModel, mLdapModel, QString, bindDn, BindDn) diff --git a/Linphone/core/address-books/ldap/LdapList.cpp b/Linphone/core/address-books/ldap/LdapList.cpp index 374a16d79..3a5abcf66 100644 --- a/Linphone/core/address-books/ldap/LdapList.cpp +++ b/Linphone/core/address-books/ldap/LdapList.cpp @@ -52,8 +52,7 @@ LdapList::~LdapList() { } void LdapList::setSelf(QSharedPointer me) { - mModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mModelConnection->makeConnectToCore(&LdapList::lUpdate, [this]() { mModelConnection->invokeToModel([this]() { QList> *ldaps = new QList>(); diff --git a/Linphone/core/call-history/CallHistoryCore.cpp b/Linphone/core/call-history/CallHistoryCore.cpp index 448bb96ec..1fa440ca5 100644 --- a/Linphone/core/call-history/CallHistoryCore.cpp +++ b/Linphone/core/call-history/CallHistoryCore.cpp @@ -76,13 +76,10 @@ CallHistoryCore::~CallHistoryCore() { } void CallHistoryCore::setSelf(QSharedPointer me) { - mHistoryModelConnection = QSharedPointer>( - new SafeConnection(me, mCallHistoryModel), &QObject::deleteLater); - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mHistoryModelConnection = SafeConnection::create(me, mCallHistoryModel); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); if (mFriendModel) { - mFriendModelConnection = QSharedPointer>( - new SafeConnection(me, mFriendModel), &QObject::deleteLater); + mFriendModelConnection = SafeConnection::create(me, mFriendModel); mFriendModelConnection->makeConnectToModel(&FriendModel::fullNameChanged, [this]() { auto fullName = mFriendModel->getFullName(); mCoreModelConnection->invokeToCore([this, fullName]() { @@ -108,8 +105,7 @@ void CallHistoryCore::setSelf(QSharedPointer me) { mCoreModelConnection->invokeToCore([this, friendModel, displayName]() { mFriendModel = friendModel; auto me = mCoreModelConnection->mCore.mQData; // Locked from previous call. - mFriendModelConnection = QSharedPointer>( - new SafeConnection(me, mFriendModel), &QObject::deleteLater); + mFriendModelConnection = SafeConnection::create(me, mFriendModel); mFriendModelConnection->makeConnectToModel(&FriendModel::fullNameChanged, [this]() { auto fullName = mFriendModel->getFullName(); mCoreModelConnection->invokeToCore([this, fullName]() { diff --git a/Linphone/core/call-history/CallHistoryList.cpp b/Linphone/core/call-history/CallHistoryList.cpp index f553ede82..ff9a3356a 100644 --- a/Linphone/core/call-history/CallHistoryList.cpp +++ b/Linphone/core/call-history/CallHistoryList.cpp @@ -53,8 +53,7 @@ CallHistoryList::~CallHistoryList() { } void CallHistoryList::setSelf(QSharedPointer me) { - mModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this]() { mModelConnection->invokeToModel([this]() { diff --git a/Linphone/core/call/CallCore.cpp b/Linphone/core/call/CallCore.cpp index 7c17ee6f3..8a299721d 100644 --- a/Linphone/core/call/CallCore.cpp +++ b/Linphone/core/call/CallCore.cpp @@ -183,8 +183,7 @@ CallCore::~CallCore() { } void CallCore::setSelf(QSharedPointer me) { - mCallModelConnection = QSharedPointer>( - new SafeConnection(me, mCallModel), &QObject::deleteLater); + mCallModelConnection = SafeConnection::create(me, mCallModel); mCallModelConnection->makeConnectToCore(&CallCore::lSetMicrophoneMuted, [this](bool isMuted) { mCallModelConnection->invokeToModel([this, isMuted]() { mCallModel->setMicrophoneMuted(isMuted); }); }); @@ -783,8 +782,7 @@ void CallCore::findRemoteLdapFriend(QSharedPointer me) { linphoneSearch->setLimitedSearch(true); mLdapMagicSearchModel = Utils::makeQObject_ptr(linphoneSearch); mLdapMagicSearchModel->setSelf(mLdapMagicSearchModel); - mLdapMagicSearchModelConnection = QSharedPointer>( - new SafeConnection(me, mLdapMagicSearchModel), &QObject::deleteLater); + mLdapMagicSearchModelConnection = SafeConnection::create(me, mLdapMagicSearchModel); mLdapMagicSearchModelConnection->makeConnectToModel( &MagicSearchModel::searchResultsReceived, [this, remoteAdress = mRemoteAddress](const std::list> &results) { diff --git a/Linphone/core/call/CallList.cpp b/Linphone/core/call/CallList.cpp index a0f030035..e62e11edc 100644 --- a/Linphone/core/call/CallList.cpp +++ b/Linphone/core/call/CallList.cpp @@ -53,8 +53,7 @@ CallList::~CallList() { } void CallList::setSelf(QSharedPointer me) { - mModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mModelConnection->makeConnectToCore(&CallList::lUpdate, [this]() { mModelConnection->invokeToModel([this]() { diff --git a/Linphone/core/conference/ConferenceCore.cpp b/Linphone/core/conference/ConferenceCore.cpp index 2b87b2d3d..3dcb93fab 100644 --- a/Linphone/core/conference/ConferenceCore.cpp +++ b/Linphone/core/conference/ConferenceCore.cpp @@ -56,8 +56,7 @@ ConferenceCore::~ConferenceCore() { } void ConferenceCore::setSelf(QSharedPointer me) { - mConferenceModelConnection = QSharedPointer>( - new SafeConnection(me, mConferenceModel), &QObject::deleteLater); + mConferenceModelConnection = SafeConnection::create(me, mConferenceModel); mConferenceModelConnection->makeConnectToModel( &ConferenceModel::activeSpeakerParticipantDevice, [this](const std::shared_ptr &participantDevice) { diff --git a/Linphone/core/conference/ConferenceInfoCore.cpp b/Linphone/core/conference/ConferenceInfoCore.cpp index a06b55644..1b0c101ab 100644 --- a/Linphone/core/conference/ConferenceInfoCore.cpp +++ b/Linphone/core/conference/ConferenceInfoCore.cpp @@ -156,9 +156,8 @@ void ConferenceInfoCore::setSelf(QSharedPointer me) { if (me) { if (mConferenceInfoModel) { mConfInfoModelConnection = nullptr; - mConfInfoModelConnection = QSharedPointer>( - new SafeConnection(me, mConferenceInfoModel), - &QObject::deleteLater); + mConfInfoModelConnection = + SafeConnection::create(me, mConferenceInfoModel); mConfInfoModelConnection->makeConnectToModel(&ConferenceInfoModel::dateTimeChanged, [this](const QDateTime &date) { @@ -222,8 +221,7 @@ void ConferenceInfoCore::setSelf(QSharedPointer me) { [this](const std::list> &failedInvitations) {}); } else { // Create - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); } } } diff --git a/Linphone/core/conference/ConferenceInfoList.cpp b/Linphone/core/conference/ConferenceInfoList.cpp index 9557ad89c..e4c3cdf70 100644 --- a/Linphone/core/conference/ConferenceInfoList.cpp +++ b/Linphone/core/conference/ConferenceInfoList.cpp @@ -56,8 +56,7 @@ ConferenceInfoList::~ConferenceInfoList() { } void ConferenceInfoList::setSelf(QSharedPointer me) { - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mCoreModelConnection->makeConnectToCore(&ConferenceInfoList::lUpdate, [this](bool isInitialization) { mCoreModelConnection->invokeToModel([this, isInitialization]() { diff --git a/Linphone/core/friend/FriendCore.cpp b/Linphone/core/friend/FriendCore.cpp index a08b568d8..c78d8beda 100644 --- a/Linphone/core/friend/FriendCore.cpp +++ b/Linphone/core/friend/FriendCore.cpp @@ -123,8 +123,7 @@ void FriendCore::setSelf(SafeSharedPointer me) { void FriendCore::setSelf(QSharedPointer me) { if (me) { if (mFriendModel) { - mFriendModelConnection = QSharedPointer>( - new SafeConnection(me, mFriendModel), &QObject::deleteLater); + mFriendModelConnection = SafeConnection::create(me, mFriendModel); mFriendModelConnection->makeConnectToModel(&FriendModel::updated, [this]() { mFriendModelConnection->invokeToCore([this]() { emit friendUpdated(); }); }); @@ -199,8 +198,7 @@ void FriendCore::setSelf(QSharedPointer me) { mFriendModelConnection->invokeToModel([this, starred]() { mFriendModel->setStarred(starred); }); }); if (!mCoreModelConnection) { - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); } mCoreModelConnection->makeConnectToModel( &CoreModel::callStateChanged, @@ -227,8 +225,7 @@ void FriendCore::setSelf(QSharedPointer me) { }); } else { // Create - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); } } } diff --git a/Linphone/core/participant/ParticipantCore.cpp b/Linphone/core/participant/ParticipantCore.cpp index 400b1cac1..5134763a0 100644 --- a/Linphone/core/participant/ParticipantCore.cpp +++ b/Linphone/core/participant/ParticipantCore.cpp @@ -68,8 +68,7 @@ ParticipantCore::~ParticipantCore() { } void ParticipantCore::setSelf(QSharedPointer me) { - mParticipantConnection = QSharedPointer>( - new SafeConnection(me, mParticipantModel), &QObject::deleteLater); + mParticipantConnection = SafeConnection::create(me, mParticipantModel); mParticipantConnection->makeConnectToCore(&ParticipantCore::lStartInvitation, [this](const int &secs) { QTimer::singleShot(secs * 1000, this, &ParticipantCore::onEndOfInvitation); }); diff --git a/Linphone/core/participant/ParticipantDeviceCore.cpp b/Linphone/core/participant/ParticipantDeviceCore.cpp index 42b70319b..b823b186e 100644 --- a/Linphone/core/participant/ParticipantDeviceCore.cpp +++ b/Linphone/core/participant/ParticipantDeviceCore.cpp @@ -68,9 +68,8 @@ ParticipantDeviceCore::~ParticipantDeviceCore() { } void ParticipantDeviceCore::setSelf(QSharedPointer me) { - mParticipantDeviceModelConnection = QSharedPointer>( - new SafeConnection(me, mParticipantDeviceModel), - &QObject::deleteLater); + mParticipantDeviceModelConnection = + SafeConnection::create(me, mParticipantDeviceModel); mParticipantDeviceModelConnection->makeConnectToModel( &ParticipantDeviceModel::isSpeakingChanged, [this](bool speaking) { mParticipantDeviceModelConnection->invokeToCore([this, speaking] { setIsSpeaking(speaking); }); diff --git a/Linphone/core/participant/ParticipantDeviceList.cpp b/Linphone/core/participant/ParticipantDeviceList.cpp index a9e5562c9..d92554d0d 100644 --- a/Linphone/core/participant/ParticipantDeviceList.cpp +++ b/Linphone/core/participant/ParticipantDeviceList.cpp @@ -119,8 +119,7 @@ void ParticipantDeviceList::setConferenceModel(const std::shared_ptr me) { if (mConferenceModelConnection) mConferenceModelConnection->disconnect(); - mConferenceModelConnection = QSharedPointer>( - new SafeConnection(me, mConferenceModel), &QObject::deleteLater); + mConferenceModelConnection = SafeConnection::create(me, mConferenceModel); if (mConferenceModel) { mConferenceModelConnection->makeConnectToModel( &ConferenceModel::participantDeviceAdded, diff --git a/Linphone/core/participant/ParticipantList.cpp b/Linphone/core/participant/ParticipantList.cpp index c9c561028..9f8c349ba 100644 --- a/Linphone/core/participant/ParticipantList.cpp +++ b/Linphone/core/participant/ParticipantList.cpp @@ -52,8 +52,7 @@ ParticipantList::~ParticipantList() { void ParticipantList::setSelf(QSharedPointer me) { if (mConferenceModelConnection) mConferenceModelConnection->disconnect(); - mConferenceModelConnection = QSharedPointer>( - new SafeConnection(me, mConferenceModel), &QObject::deleteLater); + mConferenceModelConnection = SafeConnection::create(me, mConferenceModel); if (mConferenceModel) { mConferenceModelConnection->makeConnectToCore(&ParticipantList::lUpdateParticipants, [this] { mConferenceModelConnection->invokeToModel([this]() { diff --git a/Linphone/core/payload-type/DownloadablePayloadTypeCore.cpp b/Linphone/core/payload-type/DownloadablePayloadTypeCore.cpp index 6ce8a5444..e2c56c1a6 100644 --- a/Linphone/core/payload-type/DownloadablePayloadTypeCore.cpp +++ b/Linphone/core/payload-type/DownloadablePayloadTypeCore.cpp @@ -67,10 +67,8 @@ DownloadablePayloadTypeCore::~DownloadablePayloadTypeCore() { void DownloadablePayloadTypeCore::setSelf(QSharedPointer me) { mDownloadablePayloadTypeModelConnection = - QSharedPointer>( - new SafeConnection( - me, mDownloadablePayloadTypeModel), - &QObject::deleteLater); + SafeConnection::create( + me, mDownloadablePayloadTypeModel); mDownloadablePayloadTypeModelConnection->makeConnectToCore( &DownloadablePayloadTypeCore::extractSuccess, [this](QString filePath) { diff --git a/Linphone/core/payload-type/PayloadTypeCore.cpp b/Linphone/core/payload-type/PayloadTypeCore.cpp index df22b3bda..c612442f7 100644 --- a/Linphone/core/payload-type/PayloadTypeCore.cpp +++ b/Linphone/core/payload-type/PayloadTypeCore.cpp @@ -50,8 +50,7 @@ PayloadTypeCore::~PayloadTypeCore() { } void PayloadTypeCore::setSelf(QSharedPointer me) { - mPayloadTypeModelConnection = QSharedPointer>( - new SafeConnection(me, mPayloadTypeModel), &QObject::deleteLater); + mPayloadTypeModelConnection = SafeConnection::create(me, mPayloadTypeModel); DEFINE_CORE_GETSET_CONNECT(mPayloadTypeModelConnection, PayloadTypeCore, PayloadTypeModel, mPayloadTypeModel, bool, enabled, Enabled) } diff --git a/Linphone/core/payload-type/PayloadTypeList.cpp b/Linphone/core/payload-type/PayloadTypeList.cpp index 34d035b84..2186d91f6 100644 --- a/Linphone/core/payload-type/PayloadTypeList.cpp +++ b/Linphone/core/payload-type/PayloadTypeList.cpp @@ -50,8 +50,7 @@ PayloadTypeList::~PayloadTypeList() { } void PayloadTypeList::setSelf(QSharedPointer me) { - mModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mModelConnection->makeConnectToCore(&PayloadTypeList::lUpdate, [this]() { mModelConnection->invokeToModel([this]() { QList> *payloadTypes = new QList>(); diff --git a/Linphone/core/search/MagicSearchList.cpp b/Linphone/core/search/MagicSearchList.cpp index c22e3d1da..9ee42bdc5 100644 --- a/Linphone/core/search/MagicSearchList.cpp +++ b/Linphone/core/search/MagicSearchList.cpp @@ -50,8 +50,7 @@ MagicSearchList::~MagicSearchList() { } void MagicSearchList::setSelf(QSharedPointer me) { - mCoreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); mCoreModelConnection->makeConnectToModel( &CoreModel::friendCreated, [this](const std::shared_ptr &f) { auto friendCore = FriendCore::create(f); @@ -74,9 +73,8 @@ void MagicSearchList::setSelf(QSharedPointer me) { mCoreModelConnection->invokeToCore([this, magicSearch] { mMagicSearch = magicSearch; mMagicSearch->setSelf(mMagicSearch); - mModelConnection = QSharedPointer>( - new SafeConnection(mCoreModelConnection->mCore.mQData, mMagicSearch), - &QObject::deleteLater); + mModelConnection = SafeConnection::create( + mCoreModelConnection->mCore.mQData, mMagicSearch); mModelConnection->makeConnectToCore( &MagicSearchList::lSearch, [this](QString filter, int sourceFlags, LinphoneEnums::MagicSearchAggregation aggregationFlag, diff --git a/Linphone/core/setting/SettingsCore.cpp b/Linphone/core/setting/SettingsCore.cpp index f2ce4f796..63ccc0876 100644 --- a/Linphone/core/setting/SettingsCore.cpp +++ b/Linphone/core/setting/SettingsCore.cpp @@ -190,8 +190,7 @@ SettingsCore::~SettingsCore() { void SettingsCore::setSelf(QSharedPointer me) { mustBeInLinphoneThread(getClassName()); - mSettingsModelConnection = QSharedPointer>( - new SafeConnection(me, SettingsModel::getInstance()), &QObject::deleteLater); + mSettingsModelConnection = SafeConnection::create(me, SettingsModel::getInstance()); // VFS mSettingsModelConnection->makeConnectToModel(&SettingsModel::vfsEnabledChanged, [this](const bool enabled) { @@ -388,8 +387,7 @@ void SettingsCore::setSelf(QSharedPointer me) { DEFINE_CORE_GET_CONNECT(mSettingsModelConnection, SettingsCore, SettingsModel, settingsModel, QVariantList, shortcuts, Shortcuts) - auto coreModelConnection = QSharedPointer>( - new SafeConnection(me, CoreModel::getInstance()), &QObject::deleteLater); + auto coreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); coreModelConnection->makeConnectToModel( &CoreModel::logCollectionUploadStateChanged, [this](auto core, auto state, auto info) { diff --git a/Linphone/core/videoSource/VideoSourceDescriptorCore.cpp b/Linphone/core/videoSource/VideoSourceDescriptorCore.cpp index e1d9cbc0f..18fd81946 100644 --- a/Linphone/core/videoSource/VideoSourceDescriptorCore.cpp +++ b/Linphone/core/videoSource/VideoSourceDescriptorCore.cpp @@ -48,9 +48,8 @@ VideoSourceDescriptorCore::~VideoSourceDescriptorCore() { } void VideoSourceDescriptorCore::setSelf(QSharedPointer me) { - mVideoDescModelConnection = QSharedPointer>( - new SafeConnection(me, mVideoDescModel), - &QObject::deleteLater); + mVideoDescModelConnection = + SafeConnection::create(me, mVideoDescModel); mVideoDescModelConnection->makeConnectToCore(&VideoSourceDescriptorCore::lSetWindowId, [this](quint64 id) { mVideoDescModelConnection->invokeToModel([this, id]() { mVideoDescModel->setScreenSharingWindow((void *)id); }); }); diff --git a/Linphone/model/object/VariantObject.cpp b/Linphone/model/object/VariantObject.cpp index df98316ad..33874b416 100644 --- a/Linphone/model/object/VariantObject.cpp +++ b/Linphone/model/object/VariantObject.cpp @@ -37,8 +37,7 @@ VariantObject::VariantObject(QString name, QVariant defaultValue, QObject *paren App::getInstance()->mEngine->setObjectOwnership(mCoreObject.get(), QQmlEngine::CppOwnership); App::getInstance()->mEngine->setObjectOwnership(mModelObject.get(), QQmlEngine::CppOwnership); - mConnection = QSharedPointer>( - new SafeConnection(mCoreObject, mModelObject), &QObject::deleteLater); + mConnection = SafeConnection::create(mCoreObject, mModelObject); // Note: do not use member because 'this' is managed by GUI and can be deleted. Objects scope should have the same // as connections so it should be fine to use the object directly. diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 6ec5bd972..5f01076db 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -372,11 +372,10 @@ VariantObject *Utils::findAvatarByAddress(const QString &address) { VariantObject *Utils::findFriendByAddress(const QString &address) { VariantObject *data = new VariantObject("findFriendByAddress"); if (!data) return nullptr; - data->makeRequest([data, address]() { + data->makeRequest([address]() { auto linFriend = ToolModel::findFriendByAddress(address); if (!linFriend) return QVariant(); auto friendCore = FriendCore::create(linFriend); - connect(friendCore.get(), &FriendCore::removed, data, &VariantObject::invokeRequestValue); return QVariant::fromValue(new FriendGui(friendCore)); }); // Rebuild friend if needed @@ -384,6 +383,7 @@ VariantObject *Utils::findFriendByAddress(const QString &address) { if (f->getAddress()->weakEqual(ToolModel::interpretUrl(address))) data->invokeRequestValue(); }; data->makeUpdateCond(CoreModel::getInstance().get(), &CoreModel::friendCreated, updateValue); // New Friend + data->makeUpdateCond(CoreModel::getInstance().get(), &CoreModel::friendRemoved, updateValue); // New Friend data->requestValue(); return data; } diff --git a/Linphone/tool/thread/SafeConnection.hpp b/Linphone/tool/thread/SafeConnection.hpp index 375757dce..15fd91ffd 100644 --- a/Linphone/tool/thread/SafeConnection.hpp +++ b/Linphone/tool/thread/SafeConnection.hpp @@ -64,8 +64,8 @@ template class SafeConnection : public QObject { -public: - // SafeConnection(SafeSharedPointer a, SafeSharedPointer b); + // Use create functions. +protected: SafeConnection(QSharedPointer a, std::shared_ptr b) : mCore(a), mModel(b), mCoreObject(a.get()), mModelObject(b.get()) { } @@ -84,9 +84,28 @@ public: }); mLocker.unlock(); } + void setSelf(QSharedPointer me) { + mSelf = me; + } + +public: + static QSharedPointer create(QSharedPointer a, std::shared_ptr b) { + QSharedPointer me = + QSharedPointer>(new SafeConnection(a, b), &QObject::deleteLater); + me->setSelf(me); + return me; + } + static QSharedPointer create(QSharedPointer a, QSharedPointer b) { + QSharedPointer me = + QSharedPointer>(new SafeConnection(a, b), &QObject::deleteLater); + me->setSelf(me); + return me; + } + SafeSharedPointer mCore; SafeSharedPointer mModel; QMutex mLocker; + QWeakPointer mSelf; template inline QMetaObject::Connection makeConnectToModel(Func1 signal, Func2 slot) { @@ -112,9 +131,9 @@ public: template void invokeToModel(Func &&callable, Args &&...args) { if (!tryLock()) return; - auto model = mModel.get(); - QMetaObject::invokeMethod(model, [&, model, callable, args...]() { // Is async - QMetaObject::invokeMethod(model, callable, args...); // Is Sync + auto connection = mSelf.lock(); + QMetaObject::invokeMethod(mModel.get(), [&, connection, callable, args...]() { // Is async + QMetaObject::invokeMethod(mModel.get(), callable, args...); // Is Sync unlock(); }); } @@ -123,23 +142,27 @@ public: template void invokeToCore(Func &&callable, Args &&...args) { if (!tryLock()) return; - QMetaObject::invokeMethod(mCore.get(), [&, callable, args...]() { // Is async - QMetaObject::invokeMethod(mCore.get(), callable, args...); // Is Sync + auto connection = mSelf.lock(); + QMetaObject::invokeMethod(mCore.get(), [&, connection, callable, args...]() { // Is async + QMetaObject::invokeMethod(mCore.get(), callable, args...); // Is Sync unlock(); }); } bool tryLock() { mLocker.lock(); - if (!mCore.lock() || !mModel.lock()) { // Direct locking - mCore.reset(); - mModel.reset(); + auto coreLocked = mCore.lock(); + auto modelLocked = mModel.lock(); + if (!coreLocked || !modelLocked) { + if (coreLocked) mCore.unlock(); + if (modelLocked) mModel.unlock(); mLocker.unlock(); return false; } mLocker.unlock(); return true; } + void unlock() { mLocker.lock(); mCore.unlock();