Crash fix on all asynchronous operations. Make alive connections, fix destructor calls.

This commit is contained in:
Julien Wadel 2025-01-22 20:21:13 +01:00
parent 2e08bfe507
commit 1c1bd91080
29 changed files with 80 additions and 98 deletions

View file

@ -296,8 +296,7 @@ App::~App() {
} }
void App::setSelf(QSharedPointer<App>(me)) { void App::setSelf(QSharedPointer<App>(me)) {
mCoreModelConnection = QSharedPointer<SafeConnection<App, CoreModel>>( mCoreModelConnection = SafeConnection<App, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<App, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mCoreModelConnection->makeConnectToModel(&CoreModel::callCreated, mCoreModelConnection->makeConnectToModel(&CoreModel::callCreated,
[this](const std::shared_ptr<linphone::Call> &call) { [this](const std::shared_ptr<linphone::Call> &call) {
if (call->getDir() == linphone::Call::Dir::Incoming) return; if (call->getDir() == linphone::Call::Dir::Incoming) return;
@ -355,8 +354,7 @@ void App::setSelf(QSharedPointer<App>(me)) {
mCoreModelConnection->invokeToCore([this, state] { setCoreStarted(state == linphone::GlobalState::On); }); mCoreModelConnection->invokeToCore([this, state] { setCoreStarted(state == linphone::GlobalState::On); });
}); });
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
mCliModelConnection = QSharedPointer<SafeConnection<App, CliModel>>( mCliModelConnection = SafeConnection<App, CliModel>::create(me, CliModel::getInstance());
new SafeConnection<App, CliModel>(me, CliModel::getInstance()), &QObject::deleteLater);
mCliModelConnection->makeConnectToCore(&App::receivedMessage, [this](int, const QByteArray &byteArray) { mCliModelConnection->makeConnectToCore(&App::receivedMessage, [this](int, const QByteArray &byteArray) {
QString command(byteArray); QString command(byteArray);
if (command.isEmpty()) { if (command.isEmpty()) {

View file

@ -141,8 +141,7 @@ AccountCore::AccountCore(const AccountCore &accountCore) {
} }
void AccountCore::setSelf(QSharedPointer<AccountCore> me) { void AccountCore::setSelf(QSharedPointer<AccountCore> me) {
mAccountModelConnection = QSharedPointer<SafeConnection<AccountCore, AccountModel>>( mAccountModelConnection = SafeConnection<AccountCore, AccountModel>::create(me, mAccountModel);
new SafeConnection<AccountCore, AccountModel>(me, mAccountModel));
mAccountModelConnection->makeConnectToModel( mAccountModelConnection->makeConnectToModel(
&AccountModel::registrationStateChanged, [this](const std::shared_ptr<linphone::Account> &account, &AccountModel::registrationStateChanged, [this](const std::shared_ptr<linphone::Account> &account,
linphone::RegistrationState state, const std::string &message) { linphone::RegistrationState state, const std::string &message) {
@ -237,8 +236,7 @@ void AccountCore::setSelf(QSharedPointer<AccountCore> me) {
mAccountModelConnection->makeConnectToCore(&AccountCore::lRefreshNotifications, [this]() { mAccountModelConnection->makeConnectToCore(&AccountCore::lRefreshNotifications, [this]() {
mAccountModelConnection->invokeToModel([this]() { mAccountModel->refreshUnreadNotifications(); }); mAccountModelConnection->invokeToModel([this]() { mAccountModel->refreshUnreadNotifications(); });
}); });
mCoreModelConnection = QSharedPointer<SafeConnection<AccountCore, CoreModel>>( mCoreModelConnection = SafeConnection<AccountCore, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<AccountCore, CoreModel>(me, CoreModel::getInstance()));
mAccountModelConnection->makeConnectToCore(&AccountCore::unreadCallNotificationsChanged, [this]() { mAccountModelConnection->makeConnectToCore(&AccountCore::unreadCallNotificationsChanged, [this]() {
mAccountModelConnection->invokeToModel([this]() { CoreModel::getInstance()->unreadNotificationsChanged(); }); mAccountModelConnection->invokeToModel([this]() { CoreModel::getInstance()->unreadNotificationsChanged(); });
}); });

View file

@ -126,8 +126,7 @@ void AccountDeviceList::deleteDevice(AccountDeviceGui *deviceGui) {
void AccountDeviceList::setSelf(QSharedPointer<AccountDeviceList> me) { void AccountDeviceList::setSelf(QSharedPointer<AccountDeviceList> me) {
if (mCoreModelConnection) mCoreModelConnection->disconnect(); if (mCoreModelConnection) mCoreModelConnection->disconnect();
mCoreModelConnection = QSharedPointer<SafeConnection<AccountDeviceList, CoreModel>>( mCoreModelConnection = SafeConnection<AccountDeviceList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<AccountDeviceList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mCoreModelConnection->invokeToModel([=] { mCoreModelConnection->invokeToModel([=] {
auto core = CoreModel::getInstance()->getCore(); auto core = CoreModel::getInstance()->getCore();
auto ams = core->createAccountManagerServices(); auto ams = core->createAccountManagerServices();
@ -136,10 +135,8 @@ void AccountDeviceList::setSelf(QSharedPointer<AccountDeviceList> me) {
mAccountManagerServicesModel = amsModel; mAccountManagerServicesModel = amsModel;
if (mAccountManagerServicesModelConnection) mAccountManagerServicesModelConnection->disconnect(); if (mAccountManagerServicesModelConnection) mAccountManagerServicesModelConnection->disconnect();
mAccountManagerServicesModelConnection = mAccountManagerServicesModelConnection =
QSharedPointer<SafeConnection<AccountDeviceList, AccountManagerServicesModel>>( SafeConnection<AccountDeviceList, AccountManagerServicesModel>::create(me,
new SafeConnection<AccountDeviceList, AccountManagerServicesModel>(me, mAccountManagerServicesModel);
mAccountManagerServicesModel),
&QObject::deleteLater);
mAccountManagerServicesModelConnection->makeConnectToModel( mAccountManagerServicesModelConnection->makeConnectToModel(
&AccountManagerServicesModel::requestSuccessfull, &AccountManagerServicesModel::requestSuccessfull,
[this](const std::shared_ptr<const linphone::AccountManagerServicesRequest> &request, [this](const std::shared_ptr<const linphone::AccountManagerServicesRequest> &request,

View file

@ -47,8 +47,7 @@ AccountList::~AccountList() {
} }
void AccountList::setSelf(QSharedPointer<AccountList> me) { void AccountList::setSelf(QSharedPointer<AccountList> me) {
mModelConnection = QSharedPointer<SafeConnection<AccountList, CoreModel>>( mModelConnection = SafeConnection<AccountList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<AccountList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mModelConnection->makeConnectToCore(&AccountList::lUpdate, [this](bool isInitialization) { mModelConnection->makeConnectToCore(&AccountList::lUpdate, [this](bool isInitialization) {
mModelConnection->invokeToModel([this, isInitialization]() { mModelConnection->invokeToModel([this, isInitialization]() {

View file

@ -72,8 +72,7 @@ void CarddavCore::remove() {
} }
void CarddavCore::setSelf(QSharedPointer<CarddavCore> me) { void CarddavCore::setSelf(QSharedPointer<CarddavCore> me) {
mCarddavModelConnection = QSharedPointer<SafeConnection<CarddavCore, CarddavModel>>( mCarddavModelConnection = SafeConnection<CarddavCore, CarddavModel>::create(me, mCarddavModel);
new SafeConnection<CarddavCore, CarddavModel>(me, mCarddavModel), &QObject::deleteLater);
mCarddavModelConnection->makeConnectToModel(&CarddavModel::saved, [this](bool success) { mCarddavModelConnection->makeConnectToModel(&CarddavModel::saved, [this](bool success) {
mCarddavModelConnection->invokeToCore([this, success]() { emit saved(success); }); mCarddavModelConnection->invokeToCore([this, success]() { emit saved(success); });
}); });

View file

@ -53,8 +53,7 @@ CarddavList::~CarddavList() {
} }
void CarddavList::setSelf(QSharedPointer<CarddavList> me) { void CarddavList::setSelf(QSharedPointer<CarddavList> me) {
mModelConnection = QSharedPointer<SafeConnection<CarddavList, CoreModel>>( mModelConnection = SafeConnection<CarddavList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<CarddavList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mModelConnection->makeConnectToCore(&CarddavList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&CarddavList::lUpdate, [this]() {
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {
mustBeInLinphoneThread(getClassName()); mustBeInLinphoneThread(getClassName());

View file

@ -70,8 +70,7 @@ bool LdapCore::isValid() {
} }
void LdapCore::setSelf(QSharedPointer<LdapCore> me) { void LdapCore::setSelf(QSharedPointer<LdapCore> me) {
mLdapModelConnection = QSharedPointer<SafeConnection<LdapCore, LdapModel>>( mLdapModelConnection = SafeConnection<LdapCore, LdapModel>::create(me, mLdapModel);
new SafeConnection<LdapCore, LdapModel>(me, mLdapModel), &QObject::deleteLater);
DEFINE_CORE_GETSET_CONNECT(mLdapModelConnection, LdapCore, LdapModel, mLdapModel, QString, serverUrl, ServerUrl) DEFINE_CORE_GETSET_CONNECT(mLdapModelConnection, LdapCore, LdapModel, mLdapModel, QString, serverUrl, ServerUrl)
DEFINE_CORE_GETSET_CONNECT(mLdapModelConnection, LdapCore, LdapModel, mLdapModel, QString, bindDn, BindDn) DEFINE_CORE_GETSET_CONNECT(mLdapModelConnection, LdapCore, LdapModel, mLdapModel, QString, bindDn, BindDn)

View file

@ -52,8 +52,7 @@ LdapList::~LdapList() {
} }
void LdapList::setSelf(QSharedPointer<LdapList> me) { void LdapList::setSelf(QSharedPointer<LdapList> me) {
mModelConnection = QSharedPointer<SafeConnection<LdapList, CoreModel>>( mModelConnection = SafeConnection<LdapList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<LdapList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mModelConnection->makeConnectToCore(&LdapList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&LdapList::lUpdate, [this]() {
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {
QList<QSharedPointer<LdapCore>> *ldaps = new QList<QSharedPointer<LdapCore>>(); QList<QSharedPointer<LdapCore>> *ldaps = new QList<QSharedPointer<LdapCore>>();

View file

@ -76,13 +76,10 @@ CallHistoryCore::~CallHistoryCore() {
} }
void CallHistoryCore::setSelf(QSharedPointer<CallHistoryCore> me) { void CallHistoryCore::setSelf(QSharedPointer<CallHistoryCore> me) {
mHistoryModelConnection = QSharedPointer<SafeConnection<CallHistoryCore, CallHistoryModel>>( mHistoryModelConnection = SafeConnection<CallHistoryCore, CallHistoryModel>::create(me, mCallHistoryModel);
new SafeConnection<CallHistoryCore, CallHistoryModel>(me, mCallHistoryModel), &QObject::deleteLater); mCoreModelConnection = SafeConnection<CallHistoryCore, CoreModel>::create(me, CoreModel::getInstance());
mCoreModelConnection = QSharedPointer<SafeConnection<CallHistoryCore, CoreModel>>(
new SafeConnection<CallHistoryCore, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
if (mFriendModel) { if (mFriendModel) {
mFriendModelConnection = QSharedPointer<SafeConnection<CallHistoryCore, FriendModel>>( mFriendModelConnection = SafeConnection<CallHistoryCore, FriendModel>::create(me, mFriendModel);
new SafeConnection<CallHistoryCore, FriendModel>(me, mFriendModel), &QObject::deleteLater);
mFriendModelConnection->makeConnectToModel(&FriendModel::fullNameChanged, [this]() { mFriendModelConnection->makeConnectToModel(&FriendModel::fullNameChanged, [this]() {
auto fullName = mFriendModel->getFullName(); auto fullName = mFriendModel->getFullName();
mCoreModelConnection->invokeToCore([this, fullName]() { mCoreModelConnection->invokeToCore([this, fullName]() {
@ -108,8 +105,7 @@ void CallHistoryCore::setSelf(QSharedPointer<CallHistoryCore> me) {
mCoreModelConnection->invokeToCore([this, friendModel, displayName]() { mCoreModelConnection->invokeToCore([this, friendModel, displayName]() {
mFriendModel = friendModel; mFriendModel = friendModel;
auto me = mCoreModelConnection->mCore.mQData; // Locked from previous call. auto me = mCoreModelConnection->mCore.mQData; // Locked from previous call.
mFriendModelConnection = QSharedPointer<SafeConnection<CallHistoryCore, FriendModel>>( mFriendModelConnection = SafeConnection<CallHistoryCore, FriendModel>::create(me, mFriendModel);
new SafeConnection<CallHistoryCore, FriendModel>(me, mFriendModel), &QObject::deleteLater);
mFriendModelConnection->makeConnectToModel(&FriendModel::fullNameChanged, [this]() { mFriendModelConnection->makeConnectToModel(&FriendModel::fullNameChanged, [this]() {
auto fullName = mFriendModel->getFullName(); auto fullName = mFriendModel->getFullName();
mCoreModelConnection->invokeToCore([this, fullName]() { mCoreModelConnection->invokeToCore([this, fullName]() {

View file

@ -53,8 +53,7 @@ CallHistoryList::~CallHistoryList() {
} }
void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) { void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) {
mModelConnection = QSharedPointer<SafeConnection<CallHistoryList, CoreModel>>( mModelConnection = SafeConnection<CallHistoryList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<CallHistoryList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this]() {
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {

View file

@ -183,8 +183,7 @@ CallCore::~CallCore() {
} }
void CallCore::setSelf(QSharedPointer<CallCore> me) { void CallCore::setSelf(QSharedPointer<CallCore> me) {
mCallModelConnection = QSharedPointer<SafeConnection<CallCore, CallModel>>( mCallModelConnection = SafeConnection<CallCore, CallModel>::create(me, mCallModel);
new SafeConnection<CallCore, CallModel>(me, mCallModel), &QObject::deleteLater);
mCallModelConnection->makeConnectToCore(&CallCore::lSetMicrophoneMuted, [this](bool isMuted) { mCallModelConnection->makeConnectToCore(&CallCore::lSetMicrophoneMuted, [this](bool isMuted) {
mCallModelConnection->invokeToModel([this, isMuted]() { mCallModel->setMicrophoneMuted(isMuted); }); mCallModelConnection->invokeToModel([this, isMuted]() { mCallModel->setMicrophoneMuted(isMuted); });
}); });
@ -783,8 +782,7 @@ void CallCore::findRemoteLdapFriend(QSharedPointer<CallCore> me) {
linphoneSearch->setLimitedSearch(true); linphoneSearch->setLimitedSearch(true);
mLdapMagicSearchModel = Utils::makeQObject_ptr<MagicSearchModel>(linphoneSearch); mLdapMagicSearchModel = Utils::makeQObject_ptr<MagicSearchModel>(linphoneSearch);
mLdapMagicSearchModel->setSelf(mLdapMagicSearchModel); mLdapMagicSearchModel->setSelf(mLdapMagicSearchModel);
mLdapMagicSearchModelConnection = QSharedPointer<SafeConnection<CallCore, MagicSearchModel>>( mLdapMagicSearchModelConnection = SafeConnection<CallCore, MagicSearchModel>::create(me, mLdapMagicSearchModel);
new SafeConnection<CallCore, MagicSearchModel>(me, mLdapMagicSearchModel), &QObject::deleteLater);
mLdapMagicSearchModelConnection->makeConnectToModel( mLdapMagicSearchModelConnection->makeConnectToModel(
&MagicSearchModel::searchResultsReceived, &MagicSearchModel::searchResultsReceived,
[this, remoteAdress = mRemoteAddress](const std::list<std::shared_ptr<linphone::SearchResult>> &results) { [this, remoteAdress = mRemoteAddress](const std::list<std::shared_ptr<linphone::SearchResult>> &results) {

View file

@ -53,8 +53,7 @@ CallList::~CallList() {
} }
void CallList::setSelf(QSharedPointer<CallList> me) { void CallList::setSelf(QSharedPointer<CallList> me) {
mModelConnection = QSharedPointer<SafeConnection<CallList, CoreModel>>( mModelConnection = SafeConnection<CallList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<CallList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mModelConnection->makeConnectToCore(&CallList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&CallList::lUpdate, [this]() {
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {

View file

@ -56,8 +56,7 @@ ConferenceCore::~ConferenceCore() {
} }
void ConferenceCore::setSelf(QSharedPointer<ConferenceCore> me) { void ConferenceCore::setSelf(QSharedPointer<ConferenceCore> me) {
mConferenceModelConnection = QSharedPointer<SafeConnection<ConferenceCore, ConferenceModel>>( mConferenceModelConnection = SafeConnection<ConferenceCore, ConferenceModel>::create(me, mConferenceModel);
new SafeConnection<ConferenceCore, ConferenceModel>(me, mConferenceModel), &QObject::deleteLater);
mConferenceModelConnection->makeConnectToModel( mConferenceModelConnection->makeConnectToModel(
&ConferenceModel::activeSpeakerParticipantDevice, &ConferenceModel::activeSpeakerParticipantDevice,
[this](const std::shared_ptr<linphone::ParticipantDevice> &participantDevice) { [this](const std::shared_ptr<linphone::ParticipantDevice> &participantDevice) {

View file

@ -156,9 +156,8 @@ void ConferenceInfoCore::setSelf(QSharedPointer<ConferenceInfoCore> me) {
if (me) { if (me) {
if (mConferenceInfoModel) { if (mConferenceInfoModel) {
mConfInfoModelConnection = nullptr; mConfInfoModelConnection = nullptr;
mConfInfoModelConnection = QSharedPointer<SafeConnection<ConferenceInfoCore, ConferenceInfoModel>>( mConfInfoModelConnection =
new SafeConnection<ConferenceInfoCore, ConferenceInfoModel>(me, mConferenceInfoModel), SafeConnection<ConferenceInfoCore, ConferenceInfoModel>::create(me, mConferenceInfoModel);
&QObject::deleteLater);
mConfInfoModelConnection->makeConnectToModel(&ConferenceInfoModel::dateTimeChanged, mConfInfoModelConnection->makeConnectToModel(&ConferenceInfoModel::dateTimeChanged,
[this](const QDateTime &date) { [this](const QDateTime &date) {
@ -222,8 +221,7 @@ void ConferenceInfoCore::setSelf(QSharedPointer<ConferenceInfoCore> me) {
[this](const std::list<std::shared_ptr<linphone::Address>> &failedInvitations) {}); [this](const std::list<std::shared_ptr<linphone::Address>> &failedInvitations) {});
} else { // Create } else { // Create
mCoreModelConnection = QSharedPointer<SafeConnection<ConferenceInfoCore, CoreModel>>( mCoreModelConnection = SafeConnection<ConferenceInfoCore, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<ConferenceInfoCore, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
} }
} }
} }

View file

@ -56,8 +56,7 @@ ConferenceInfoList::~ConferenceInfoList() {
} }
void ConferenceInfoList::setSelf(QSharedPointer<ConferenceInfoList> me) { void ConferenceInfoList::setSelf(QSharedPointer<ConferenceInfoList> me) {
mCoreModelConnection = QSharedPointer<SafeConnection<ConferenceInfoList, CoreModel>>( mCoreModelConnection = SafeConnection<ConferenceInfoList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<ConferenceInfoList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mCoreModelConnection->makeConnectToCore(&ConferenceInfoList::lUpdate, [this](bool isInitialization) { mCoreModelConnection->makeConnectToCore(&ConferenceInfoList::lUpdate, [this](bool isInitialization) {
mCoreModelConnection->invokeToModel([this, isInitialization]() { mCoreModelConnection->invokeToModel([this, isInitialization]() {

View file

@ -123,8 +123,7 @@ void FriendCore::setSelf(SafeSharedPointer<FriendCore> me) {
void FriendCore::setSelf(QSharedPointer<FriendCore> me) { void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
if (me) { if (me) {
if (mFriendModel) { if (mFriendModel) {
mFriendModelConnection = QSharedPointer<SafeConnection<FriendCore, FriendModel>>( mFriendModelConnection = SafeConnection<FriendCore, FriendModel>::create(me, mFriendModel);
new SafeConnection<FriendCore, FriendModel>(me, mFriendModel), &QObject::deleteLater);
mFriendModelConnection->makeConnectToModel(&FriendModel::updated, [this]() { mFriendModelConnection->makeConnectToModel(&FriendModel::updated, [this]() {
mFriendModelConnection->invokeToCore([this]() { emit friendUpdated(); }); mFriendModelConnection->invokeToCore([this]() { emit friendUpdated(); });
}); });
@ -199,8 +198,7 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
mFriendModelConnection->invokeToModel([this, starred]() { mFriendModel->setStarred(starred); }); mFriendModelConnection->invokeToModel([this, starred]() { mFriendModel->setStarred(starred); });
}); });
if (!mCoreModelConnection) { if (!mCoreModelConnection) {
mCoreModelConnection = QSharedPointer<SafeConnection<FriendCore, CoreModel>>( mCoreModelConnection = SafeConnection<FriendCore, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<FriendCore, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
} }
mCoreModelConnection->makeConnectToModel( mCoreModelConnection->makeConnectToModel(
&CoreModel::callStateChanged, &CoreModel::callStateChanged,
@ -227,8 +225,7 @@ void FriendCore::setSelf(QSharedPointer<FriendCore> me) {
}); });
} else { // Create } else { // Create
mCoreModelConnection = QSharedPointer<SafeConnection<FriendCore, CoreModel>>( mCoreModelConnection = SafeConnection<FriendCore, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<FriendCore, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
} }
} }
} }

View file

@ -68,8 +68,7 @@ ParticipantCore::~ParticipantCore() {
} }
void ParticipantCore::setSelf(QSharedPointer<ParticipantCore> me) { void ParticipantCore::setSelf(QSharedPointer<ParticipantCore> me) {
mParticipantConnection = QSharedPointer<SafeConnection<ParticipantCore, ParticipantModel>>( mParticipantConnection = SafeConnection<ParticipantCore, ParticipantModel>::create(me, mParticipantModel);
new SafeConnection<ParticipantCore, ParticipantModel>(me, mParticipantModel), &QObject::deleteLater);
mParticipantConnection->makeConnectToCore(&ParticipantCore::lStartInvitation, [this](const int &secs) { mParticipantConnection->makeConnectToCore(&ParticipantCore::lStartInvitation, [this](const int &secs) {
QTimer::singleShot(secs * 1000, this, &ParticipantCore::onEndOfInvitation); QTimer::singleShot(secs * 1000, this, &ParticipantCore::onEndOfInvitation);
}); });

View file

@ -68,9 +68,8 @@ ParticipantDeviceCore::~ParticipantDeviceCore() {
} }
void ParticipantDeviceCore::setSelf(QSharedPointer<ParticipantDeviceCore> me) { void ParticipantDeviceCore::setSelf(QSharedPointer<ParticipantDeviceCore> me) {
mParticipantDeviceModelConnection = QSharedPointer<SafeConnection<ParticipantDeviceCore, ParticipantDeviceModel>>( mParticipantDeviceModelConnection =
new SafeConnection<ParticipantDeviceCore, ParticipantDeviceModel>(me, mParticipantDeviceModel), SafeConnection<ParticipantDeviceCore, ParticipantDeviceModel>::create(me, mParticipantDeviceModel);
&QObject::deleteLater);
mParticipantDeviceModelConnection->makeConnectToModel( mParticipantDeviceModelConnection->makeConnectToModel(
&ParticipantDeviceModel::isSpeakingChanged, [this](bool speaking) { &ParticipantDeviceModel::isSpeakingChanged, [this](bool speaking) {
mParticipantDeviceModelConnection->invokeToCore([this, speaking] { setIsSpeaking(speaking); }); mParticipantDeviceModelConnection->invokeToCore([this, speaking] { setIsSpeaking(speaking); });

View file

@ -119,8 +119,7 @@ void ParticipantDeviceList::setConferenceModel(const std::shared_ptr<ConferenceM
void ParticipantDeviceList::setSelf(QSharedPointer<ParticipantDeviceList> me) { void ParticipantDeviceList::setSelf(QSharedPointer<ParticipantDeviceList> me) {
if (mConferenceModelConnection) mConferenceModelConnection->disconnect(); if (mConferenceModelConnection) mConferenceModelConnection->disconnect();
mConferenceModelConnection = QSharedPointer<SafeConnection<ParticipantDeviceList, ConferenceModel>>( mConferenceModelConnection = SafeConnection<ParticipantDeviceList, ConferenceModel>::create(me, mConferenceModel);
new SafeConnection<ParticipantDeviceList, ConferenceModel>(me, mConferenceModel), &QObject::deleteLater);
if (mConferenceModel) { if (mConferenceModel) {
mConferenceModelConnection->makeConnectToModel( mConferenceModelConnection->makeConnectToModel(
&ConferenceModel::participantDeviceAdded, &ConferenceModel::participantDeviceAdded,

View file

@ -52,8 +52,7 @@ ParticipantList::~ParticipantList() {
void ParticipantList::setSelf(QSharedPointer<ParticipantList> me) { void ParticipantList::setSelf(QSharedPointer<ParticipantList> me) {
if (mConferenceModelConnection) mConferenceModelConnection->disconnect(); if (mConferenceModelConnection) mConferenceModelConnection->disconnect();
mConferenceModelConnection = QSharedPointer<SafeConnection<ParticipantList, ConferenceModel>>( mConferenceModelConnection = SafeConnection<ParticipantList, ConferenceModel>::create(me, mConferenceModel);
new SafeConnection<ParticipantList, ConferenceModel>(me, mConferenceModel), &QObject::deleteLater);
if (mConferenceModel) { if (mConferenceModel) {
mConferenceModelConnection->makeConnectToCore(&ParticipantList::lUpdateParticipants, [this] { mConferenceModelConnection->makeConnectToCore(&ParticipantList::lUpdateParticipants, [this] {
mConferenceModelConnection->invokeToModel([this]() { mConferenceModelConnection->invokeToModel([this]() {

View file

@ -67,10 +67,8 @@ DownloadablePayloadTypeCore::~DownloadablePayloadTypeCore() {
void DownloadablePayloadTypeCore::setSelf(QSharedPointer<DownloadablePayloadTypeCore> me) { void DownloadablePayloadTypeCore::setSelf(QSharedPointer<DownloadablePayloadTypeCore> me) {
mDownloadablePayloadTypeModelConnection = mDownloadablePayloadTypeModelConnection =
QSharedPointer<SafeConnection<DownloadablePayloadTypeCore, DownloadablePayloadTypeModel>>( SafeConnection<DownloadablePayloadTypeCore, DownloadablePayloadTypeModel>::create(
new SafeConnection<DownloadablePayloadTypeCore, DownloadablePayloadTypeModel>( me, mDownloadablePayloadTypeModel);
me, mDownloadablePayloadTypeModel),
&QObject::deleteLater);
mDownloadablePayloadTypeModelConnection->makeConnectToCore( mDownloadablePayloadTypeModelConnection->makeConnectToCore(
&DownloadablePayloadTypeCore::extractSuccess, [this](QString filePath) { &DownloadablePayloadTypeCore::extractSuccess, [this](QString filePath) {

View file

@ -50,8 +50,7 @@ PayloadTypeCore::~PayloadTypeCore() {
} }
void PayloadTypeCore::setSelf(QSharedPointer<PayloadTypeCore> me) { void PayloadTypeCore::setSelf(QSharedPointer<PayloadTypeCore> me) {
mPayloadTypeModelConnection = QSharedPointer<SafeConnection<PayloadTypeCore, PayloadTypeModel>>( mPayloadTypeModelConnection = SafeConnection<PayloadTypeCore, PayloadTypeModel>::create(me, mPayloadTypeModel);
new SafeConnection<PayloadTypeCore, PayloadTypeModel>(me, mPayloadTypeModel), &QObject::deleteLater);
DEFINE_CORE_GETSET_CONNECT(mPayloadTypeModelConnection, PayloadTypeCore, PayloadTypeModel, mPayloadTypeModel, bool, DEFINE_CORE_GETSET_CONNECT(mPayloadTypeModelConnection, PayloadTypeCore, PayloadTypeModel, mPayloadTypeModel, bool,
enabled, Enabled) enabled, Enabled)
} }

View file

@ -50,8 +50,7 @@ PayloadTypeList::~PayloadTypeList() {
} }
void PayloadTypeList::setSelf(QSharedPointer<PayloadTypeList> me) { void PayloadTypeList::setSelf(QSharedPointer<PayloadTypeList> me) {
mModelConnection = QSharedPointer<SafeConnection<PayloadTypeList, CoreModel>>( mModelConnection = SafeConnection<PayloadTypeList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<PayloadTypeList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mModelConnection->makeConnectToCore(&PayloadTypeList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&PayloadTypeList::lUpdate, [this]() {
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {
QList<QSharedPointer<PayloadTypeCore>> *payloadTypes = new QList<QSharedPointer<PayloadTypeCore>>(); QList<QSharedPointer<PayloadTypeCore>> *payloadTypes = new QList<QSharedPointer<PayloadTypeCore>>();

View file

@ -50,8 +50,7 @@ MagicSearchList::~MagicSearchList() {
} }
void MagicSearchList::setSelf(QSharedPointer<MagicSearchList> me) { void MagicSearchList::setSelf(QSharedPointer<MagicSearchList> me) {
mCoreModelConnection = QSharedPointer<SafeConnection<MagicSearchList, CoreModel>>( mCoreModelConnection = SafeConnection<MagicSearchList, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<MagicSearchList, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
mCoreModelConnection->makeConnectToModel( mCoreModelConnection->makeConnectToModel(
&CoreModel::friendCreated, [this](const std::shared_ptr<linphone::Friend> &f) { &CoreModel::friendCreated, [this](const std::shared_ptr<linphone::Friend> &f) {
auto friendCore = FriendCore::create(f); auto friendCore = FriendCore::create(f);
@ -74,9 +73,8 @@ void MagicSearchList::setSelf(QSharedPointer<MagicSearchList> me) {
mCoreModelConnection->invokeToCore([this, magicSearch] { mCoreModelConnection->invokeToCore([this, magicSearch] {
mMagicSearch = magicSearch; mMagicSearch = magicSearch;
mMagicSearch->setSelf(mMagicSearch); mMagicSearch->setSelf(mMagicSearch);
mModelConnection = QSharedPointer<SafeConnection<MagicSearchList, MagicSearchModel>>( mModelConnection = SafeConnection<MagicSearchList, MagicSearchModel>::create(
new SafeConnection<MagicSearchList, MagicSearchModel>(mCoreModelConnection->mCore.mQData, mMagicSearch), mCoreModelConnection->mCore.mQData, mMagicSearch);
&QObject::deleteLater);
mModelConnection->makeConnectToCore( mModelConnection->makeConnectToCore(
&MagicSearchList::lSearch, &MagicSearchList::lSearch,
[this](QString filter, int sourceFlags, LinphoneEnums::MagicSearchAggregation aggregationFlag, [this](QString filter, int sourceFlags, LinphoneEnums::MagicSearchAggregation aggregationFlag,

View file

@ -190,8 +190,7 @@ SettingsCore::~SettingsCore() {
void SettingsCore::setSelf(QSharedPointer<SettingsCore> me) { void SettingsCore::setSelf(QSharedPointer<SettingsCore> me) {
mustBeInLinphoneThread(getClassName()); mustBeInLinphoneThread(getClassName());
mSettingsModelConnection = QSharedPointer<SafeConnection<SettingsCore, SettingsModel>>( mSettingsModelConnection = SafeConnection<SettingsCore, SettingsModel>::create(me, SettingsModel::getInstance());
new SafeConnection<SettingsCore, SettingsModel>(me, SettingsModel::getInstance()), &QObject::deleteLater);
// VFS // VFS
mSettingsModelConnection->makeConnectToModel(&SettingsModel::vfsEnabledChanged, [this](const bool enabled) { mSettingsModelConnection->makeConnectToModel(&SettingsModel::vfsEnabledChanged, [this](const bool enabled) {
@ -388,8 +387,7 @@ void SettingsCore::setSelf(QSharedPointer<SettingsCore> me) {
DEFINE_CORE_GET_CONNECT(mSettingsModelConnection, SettingsCore, SettingsModel, settingsModel, QVariantList, DEFINE_CORE_GET_CONNECT(mSettingsModelConnection, SettingsCore, SettingsModel, settingsModel, QVariantList,
shortcuts, Shortcuts) shortcuts, Shortcuts)
auto coreModelConnection = QSharedPointer<SafeConnection<SettingsCore, CoreModel>>( auto coreModelConnection = SafeConnection<SettingsCore, CoreModel>::create(me, CoreModel::getInstance());
new SafeConnection<SettingsCore, CoreModel>(me, CoreModel::getInstance()), &QObject::deleteLater);
coreModelConnection->makeConnectToModel( coreModelConnection->makeConnectToModel(
&CoreModel::logCollectionUploadStateChanged, [this](auto core, auto state, auto info) { &CoreModel::logCollectionUploadStateChanged, [this](auto core, auto state, auto info) {

View file

@ -48,9 +48,8 @@ VideoSourceDescriptorCore::~VideoSourceDescriptorCore() {
} }
void VideoSourceDescriptorCore::setSelf(QSharedPointer<VideoSourceDescriptorCore> me) { void VideoSourceDescriptorCore::setSelf(QSharedPointer<VideoSourceDescriptorCore> me) {
mVideoDescModelConnection = QSharedPointer<SafeConnection<VideoSourceDescriptorCore, VideoSourceDescriptorModel>>( mVideoDescModelConnection =
new SafeConnection<VideoSourceDescriptorCore, VideoSourceDescriptorModel>(me, mVideoDescModel), SafeConnection<VideoSourceDescriptorCore, VideoSourceDescriptorModel>::create(me, mVideoDescModel);
&QObject::deleteLater);
mVideoDescModelConnection->makeConnectToCore(&VideoSourceDescriptorCore::lSetWindowId, [this](quint64 id) { mVideoDescModelConnection->makeConnectToCore(&VideoSourceDescriptorCore::lSetWindowId, [this](quint64 id) {
mVideoDescModelConnection->invokeToModel([this, id]() { mVideoDescModel->setScreenSharingWindow((void *)id); }); mVideoDescModelConnection->invokeToModel([this, id]() { mVideoDescModel->setScreenSharingWindow((void *)id); });
}); });

View file

@ -37,8 +37,7 @@ VariantObject::VariantObject(QString name, QVariant defaultValue, QObject *paren
App::getInstance()->mEngine->setObjectOwnership(mCoreObject.get(), QQmlEngine::CppOwnership); App::getInstance()->mEngine->setObjectOwnership(mCoreObject.get(), QQmlEngine::CppOwnership);
App::getInstance()->mEngine->setObjectOwnership(mModelObject.get(), QQmlEngine::CppOwnership); App::getInstance()->mEngine->setObjectOwnership(mModelObject.get(), QQmlEngine::CppOwnership);
mConnection = QSharedPointer<SafeConnection<SafeObject, SafeObject>>( mConnection = SafeConnection<SafeObject, SafeObject>::create(mCoreObject, mModelObject);
new SafeConnection<SafeObject, SafeObject>(mCoreObject, mModelObject), &QObject::deleteLater);
// Note: do not use member because 'this' is managed by GUI and can be deleted. Objects scope should have the same // 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. // as connections so it should be fine to use the object directly.

View file

@ -372,11 +372,10 @@ VariantObject *Utils::findAvatarByAddress(const QString &address) {
VariantObject *Utils::findFriendByAddress(const QString &address) { VariantObject *Utils::findFriendByAddress(const QString &address) {
VariantObject *data = new VariantObject("findFriendByAddress"); VariantObject *data = new VariantObject("findFriendByAddress");
if (!data) return nullptr; if (!data) return nullptr;
data->makeRequest([data, address]() { data->makeRequest([address]() {
auto linFriend = ToolModel::findFriendByAddress(address); auto linFriend = ToolModel::findFriendByAddress(address);
if (!linFriend) return QVariant(); if (!linFriend) return QVariant();
auto friendCore = FriendCore::create(linFriend); auto friendCore = FriendCore::create(linFriend);
connect(friendCore.get(), &FriendCore::removed, data, &VariantObject::invokeRequestValue);
return QVariant::fromValue(new FriendGui(friendCore)); return QVariant::fromValue(new FriendGui(friendCore));
}); });
// Rebuild friend if needed // Rebuild friend if needed
@ -384,6 +383,7 @@ VariantObject *Utils::findFriendByAddress(const QString &address) {
if (f->getAddress()->weakEqual(ToolModel::interpretUrl(address))) data->invokeRequestValue(); 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::friendCreated, updateValue); // New Friend
data->makeUpdateCond(CoreModel::getInstance().get(), &CoreModel::friendRemoved, updateValue); // New Friend
data->requestValue(); data->requestValue();
return data; return data;
} }

View file

@ -64,8 +64,8 @@
template <class A, class B> template <class A, class B>
class SafeConnection : public QObject { class SafeConnection : public QObject {
public: // Use create functions.
// SafeConnection(SafeSharedPointer<QObject> a, SafeSharedPointer<QObject> b); protected:
SafeConnection(QSharedPointer<A> a, std::shared_ptr<B> b) SafeConnection(QSharedPointer<A> a, std::shared_ptr<B> b)
: mCore(a), mModel(b), mCoreObject(a.get()), mModelObject(b.get()) { : mCore(a), mModel(b), mCoreObject(a.get()), mModelObject(b.get()) {
} }
@ -84,9 +84,28 @@ public:
}); });
mLocker.unlock(); mLocker.unlock();
} }
void setSelf(QSharedPointer<SafeConnection> me) {
mSelf = me;
}
public:
static QSharedPointer<SafeConnection> create(QSharedPointer<A> a, std::shared_ptr<B> b) {
QSharedPointer<SafeConnection> me =
QSharedPointer<SafeConnection<A, B>>(new SafeConnection<A, B>(a, b), &QObject::deleteLater);
me->setSelf(me);
return me;
}
static QSharedPointer<SafeConnection> create(QSharedPointer<A> a, QSharedPointer<B> b) {
QSharedPointer<SafeConnection> me =
QSharedPointer<SafeConnection<A, B>>(new SafeConnection<A, B>(a, b), &QObject::deleteLater);
me->setSelf(me);
return me;
}
SafeSharedPointer<A> mCore; SafeSharedPointer<A> mCore;
SafeSharedPointer<B> mModel; SafeSharedPointer<B> mModel;
QMutex mLocker; QMutex mLocker;
QWeakPointer<SafeConnection> mSelf;
template <typename Func1, typename Func2> template <typename Func1, typename Func2>
inline QMetaObject::Connection makeConnectToModel(Func1 signal, Func2 slot) { inline QMetaObject::Connection makeConnectToModel(Func1 signal, Func2 slot) {
@ -112,9 +131,9 @@ public:
template <typename Func, typename... Args> template <typename Func, typename... Args>
void invokeToModel(Func &&callable, Args &&...args) { void invokeToModel(Func &&callable, Args &&...args) {
if (!tryLock()) return; if (!tryLock()) return;
auto model = mModel.get(); auto connection = mSelf.lock();
QMetaObject::invokeMethod(model, [&, model, callable, args...]() { // Is async QMetaObject::invokeMethod(mModel.get(), [&, connection, callable, args...]() { // Is async
QMetaObject::invokeMethod(model, callable, args...); // Is Sync QMetaObject::invokeMethod(mModel.get(), callable, args...); // Is Sync
unlock(); unlock();
}); });
} }
@ -123,7 +142,8 @@ public:
template <typename Func, typename... Args> template <typename Func, typename... Args>
void invokeToCore(Func &&callable, Args &&...args) { void invokeToCore(Func &&callable, Args &&...args) {
if (!tryLock()) return; if (!tryLock()) return;
QMetaObject::invokeMethod(mCore.get(), [&, callable, args...]() { // Is async auto connection = mSelf.lock();
QMetaObject::invokeMethod(mCore.get(), [&, connection, callable, args...]() { // Is async
QMetaObject::invokeMethod(mCore.get(), callable, args...); // Is Sync QMetaObject::invokeMethod(mCore.get(), callable, args...); // Is Sync
unlock(); unlock();
}); });
@ -131,15 +151,18 @@ public:
bool tryLock() { bool tryLock() {
mLocker.lock(); mLocker.lock();
if (!mCore.lock() || !mModel.lock()) { // Direct locking auto coreLocked = mCore.lock();
mCore.reset(); auto modelLocked = mModel.lock();
mModel.reset(); if (!coreLocked || !modelLocked) {
if (coreLocked) mCore.unlock();
if (modelLocked) mModel.unlock();
mLocker.unlock(); mLocker.unlock();
return false; return false;
} }
mLocker.unlock(); mLocker.unlock();
return true; return true;
} }
void unlock() { void unlock() {
mLocker.lock(); mLocker.lock();
mCore.unlock(); mCore.unlock();