Commit 3647ed9c authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/core/CoreManager): schedule global state emit in the app thread

parent 9ee13e18
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
*/ */
#include <QtDebug> #include <QtDebug>
#include <QTimer>
#include "../../app/App.hpp" #include "../../app/App.hpp"
#include "../../Utils.hpp" #include "../../Utils.hpp"
...@@ -32,6 +33,10 @@ using namespace std; ...@@ -32,6 +33,10 @@ using namespace std;
// ============================================================================= // =============================================================================
inline void logGlobalState (linphone::GlobalState gstate) {
qInfo() << QStringLiteral("Global state: %1.").arg(gstate);
}
void CoreHandlers::onAuthenticationRequested ( void CoreHandlers::onAuthenticationRequested (
const shared_ptr<linphone::Core> &, const shared_ptr<linphone::Core> &,
const shared_ptr<linphone::AuthInfo> &authInfo, const shared_ptr<linphone::AuthInfo> &authInfo,
...@@ -57,10 +62,15 @@ void CoreHandlers::onGlobalStateChanged ( ...@@ -57,10 +62,15 @@ void CoreHandlers::onGlobalStateChanged (
linphone::GlobalState gstate, linphone::GlobalState gstate,
const string & const string &
) { ) {
qInfo() << QStringLiteral("Global state: %1.").arg(gstate); if (gstate == linphone::GlobalStateOn) {
QTimer::singleShot(
if (gstate == linphone::GlobalStateOn) 0, App::getInstance(), [this, gstate]() {
emit coreStarted (); logGlobalState(gstate);
emit coreStarted();
}
);
} else
logGlobalState(gstate);
} }
void CoreHandlers::onCallStatsUpdated ( void CoreHandlers::onCallStatsUpdated (
......
...@@ -51,7 +51,7 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject( ...@@ -51,7 +51,7 @@ CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject(
qInfo() << QStringLiteral("Core created. Enable iterate."); qInfo() << QStringLiteral("Core created. Enable iterate.");
mInstance->mCbsTimer->start(); mInstance->mCbsTimer->start();
emit mInstance->linphoneCoreCreated(); emit mInstance->coreCreated();
} }
); );
...@@ -88,6 +88,8 @@ VcardModel *CoreManager::createDetachedVcardModel () { ...@@ -88,6 +88,8 @@ VcardModel *CoreManager::createDetachedVcardModel () {
} }
void CoreManager::forceRefreshRegisters () { void CoreManager::forceRefreshRegisters () {
Q_ASSERT(mCore != nullptr);
qInfo() << QStringLiteral("Refresh registers."); qInfo() << QStringLiteral("Refresh registers.");
mCore->refreshRegisters(); mCore->refreshRegisters();
} }
......
...@@ -48,10 +48,12 @@ public: ...@@ -48,10 +48,12 @@ public:
~CoreManager () = default; ~CoreManager () = default;
std::shared_ptr<linphone::Core> getCore () { std::shared_ptr<linphone::Core> getCore () {
Q_ASSERT(mCore != nullptr);
return mCore; return mCore;
} }
std::shared_ptr<CoreHandlers> getHandlers () { std::shared_ptr<CoreHandlers> getHandlers () {
Q_ASSERT(mHandlers != nullptr);
return mHandlers; return mHandlers;
} }
...@@ -72,22 +74,27 @@ public: ...@@ -72,22 +74,27 @@ public:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
CallsListModel *getCallsListModel () const { CallsListModel *getCallsListModel () const {
Q_ASSERT(mCallsListModel != nullptr);
return mCallsListModel; return mCallsListModel;
} }
ContactsListModel *getContactsListModel () const { ContactsListModel *getContactsListModel () const {
Q_ASSERT(mContactsListModel != nullptr);
return mContactsListModel; return mContactsListModel;
} }
SipAddressesModel *getSipAddressesModel () const { SipAddressesModel *getSipAddressesModel () const {
Q_ASSERT(mSipAddressesModel != nullptr);
return mSipAddressesModel; return mSipAddressesModel;
} }
SettingsModel *getSettingsModel () const { SettingsModel *getSettingsModel () const {
Q_ASSERT(mSettingsModel != nullptr);
return mSettingsModel; return mSettingsModel;
} }
AccountSettingsModel *getAccountSettingsModel () const { AccountSettingsModel *getAccountSettingsModel () const {
Q_ASSERT(mAccountSettingsModel != nullptr);
return mAccountSettingsModel; return mAccountSettingsModel;
} }
...@@ -99,6 +106,7 @@ public: ...@@ -99,6 +106,7 @@ public:
static void uninit (); static void uninit ();
static CoreManager *getInstance () { static CoreManager *getInstance () {
Q_ASSERT(mInstance != nullptr);
return mInstance; return mInstance;
} }
...@@ -111,7 +119,7 @@ public: ...@@ -111,7 +119,7 @@ public:
Q_INVOKABLE void forceRefreshRegisters (); Q_INVOKABLE void forceRefreshRegisters ();
signals: signals:
void linphoneCoreCreated (); void coreCreated ();
private: private:
CoreManager (QObject *parent, const QString &configPath); CoreManager (QObject *parent, const QString &configPath);
......
...@@ -60,7 +60,7 @@ ApplicationWindow { ...@@ -60,7 +60,7 @@ ApplicationWindow {
Connections { Connections {
target: CoreManager target: CoreManager
onLinphoneCoreCreated: mainLoader.active = true onCoreCreated: mainLoader.active = true
} }
Shortcut { Shortcut {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment