From 3647ed9c2b17150963799a84844d01928f6fe519 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 10 May 2017 17:06:38 +0200 Subject: [PATCH] feat(src/components/core/CoreManager): schedule global state emit in the app thread --- .../src/components/core/CoreHandlers.cpp | 18 ++++++++++++++---- .../src/components/core/CoreManager.cpp | 4 +++- .../src/components/core/CoreManager.hpp | 10 +++++++++- .../ui/views/App/Main/MainWindow.qml | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/linphone-desktop/src/components/core/CoreHandlers.cpp b/linphone-desktop/src/components/core/CoreHandlers.cpp index 63604e385..f4317b034 100644 --- a/linphone-desktop/src/components/core/CoreHandlers.cpp +++ b/linphone-desktop/src/components/core/CoreHandlers.cpp @@ -21,6 +21,7 @@ */ #include +#include #include "../../app/App.hpp" #include "../../Utils.hpp" @@ -32,6 +33,10 @@ using namespace std; // ============================================================================= +inline void logGlobalState (linphone::GlobalState gstate) { + qInfo() << QStringLiteral("Global state: %1.").arg(gstate); +} + void CoreHandlers::onAuthenticationRequested ( const shared_ptr &, const shared_ptr &authInfo, @@ -57,10 +62,15 @@ void CoreHandlers::onGlobalStateChanged ( linphone::GlobalState gstate, const string & ) { - qInfo() << QStringLiteral("Global state: %1.").arg(gstate); - - if (gstate == linphone::GlobalStateOn) - emit coreStarted (); + if (gstate == linphone::GlobalStateOn) { + QTimer::singleShot( + 0, App::getInstance(), [this, gstate]() { + logGlobalState(gstate); + emit coreStarted(); + } + ); + } else + logGlobalState(gstate); } void CoreHandlers::onCallStatsUpdated ( diff --git a/linphone-desktop/src/components/core/CoreManager.cpp b/linphone-desktop/src/components/core/CoreManager.cpp index f8d8c091d..2e38ab164 100644 --- a/linphone-desktop/src/components/core/CoreManager.cpp +++ b/linphone-desktop/src/components/core/CoreManager.cpp @@ -51,7 +51,7 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject( qInfo() << QStringLiteral("Core created. Enable iterate."); mInstance->mCbsTimer->start(); - emit mInstance->linphoneCoreCreated(); + emit mInstance->coreCreated(); } ); @@ -88,6 +88,8 @@ VcardModel *CoreManager::createDetachedVcardModel () { } void CoreManager::forceRefreshRegisters () { + Q_ASSERT(mCore != nullptr); + qInfo() << QStringLiteral("Refresh registers."); mCore->refreshRegisters(); } diff --git a/linphone-desktop/src/components/core/CoreManager.hpp b/linphone-desktop/src/components/core/CoreManager.hpp index 515342c65..39930082e 100644 --- a/linphone-desktop/src/components/core/CoreManager.hpp +++ b/linphone-desktop/src/components/core/CoreManager.hpp @@ -48,10 +48,12 @@ public: ~CoreManager () = default; std::shared_ptr getCore () { + Q_ASSERT(mCore != nullptr); return mCore; } std::shared_ptr getHandlers () { + Q_ASSERT(mHandlers != nullptr); return mHandlers; } @@ -72,22 +74,27 @@ public: // --------------------------------------------------------------------------- CallsListModel *getCallsListModel () const { + Q_ASSERT(mCallsListModel != nullptr); return mCallsListModel; } ContactsListModel *getContactsListModel () const { + Q_ASSERT(mContactsListModel != nullptr); return mContactsListModel; } SipAddressesModel *getSipAddressesModel () const { + Q_ASSERT(mSipAddressesModel != nullptr); return mSipAddressesModel; } SettingsModel *getSettingsModel () const { + Q_ASSERT(mSettingsModel != nullptr); return mSettingsModel; } AccountSettingsModel *getAccountSettingsModel () const { + Q_ASSERT(mAccountSettingsModel != nullptr); return mAccountSettingsModel; } @@ -99,6 +106,7 @@ public: static void uninit (); static CoreManager *getInstance () { + Q_ASSERT(mInstance != nullptr); return mInstance; } @@ -111,7 +119,7 @@ public: Q_INVOKABLE void forceRefreshRegisters (); signals: - void linphoneCoreCreated (); + void coreCreated (); private: CoreManager (QObject *parent, const QString &configPath); diff --git a/linphone-desktop/ui/views/App/Main/MainWindow.qml b/linphone-desktop/ui/views/App/Main/MainWindow.qml index 4d84cebfe..addf7c451 100644 --- a/linphone-desktop/ui/views/App/Main/MainWindow.qml +++ b/linphone-desktop/ui/views/App/Main/MainWindow.qml @@ -60,7 +60,7 @@ ApplicationWindow { Connections { target: CoreManager - onLinphoneCoreCreated: mainLoader.active = true + onCoreCreated: mainLoader.active = true } Shortcut {