Commit cc341824 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/components/core/CoreHandlers): do not emit core started until core is not created

parent e9f59998
...@@ -442,7 +442,7 @@ QString App::getLocale () const { ...@@ -442,7 +442,7 @@ QString App::getLocale () const {
void App::openAppAfterInit () { void App::openAppAfterInit () {
tryToUsePreferredLocale(); tryToUsePreferredLocale();
qInfo() << QStringLiteral("Linphone core created."); qInfo() << QStringLiteral("Open linphone app.");
#ifndef __APPLE__ #ifndef __APPLE__
// Enable TrayIconSystem. // Enable TrayIconSystem.
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
* Author: Ronan Abhamon * Author: Ronan Abhamon
*/ */
#include <QMutex>
#include <QtDebug> #include <QtDebug>
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
...@@ -34,19 +35,57 @@ using namespace std; ...@@ -34,19 +35,57 @@ using namespace std;
// ============================================================================= // =============================================================================
// Emit a signal in the app context. // Schedule a function in app context.
#define emitApp(EMIT) \ void scheduleFunctionInApp (function<void()> func) {
do { \ App *app = App::getInstance();
App *app = App::getInstance(); \ if (QThread::currentThread() != app->thread()) {
if (QThread::currentThread() != app->thread()) { \ QTimer::singleShot(0, app, func);
QTimer::singleShot( \ } else
0, app, [this]() { \ func();
(EMIT); \ }
} \
); \ // -----------------------------------------------------------------------------
} else \
(EMIT); \ CoreHandlers::CoreHandlers (CoreManager *coreManager) {
} while (0) mCoreStartedLock = new QMutex();
QObject::connect(coreManager, &CoreManager::coreCreated, this, &CoreHandlers::handleCoreCreated);
}
CoreHandlers::~CoreHandlers () {
delete mCoreStartedLock;
}
// -----------------------------------------------------------------------------
void CoreHandlers::handleCoreCreated () {
mCoreStartedLock->lock();
Q_ASSERT(mCoreCreated == false);
mCoreCreated = true;
notifyCoreStarted();
mCoreStartedLock->unlock();
}
void CoreHandlers::handleCoreStarted () {
mCoreStartedLock->lock();
Q_ASSERT(mCoreStarted == false);
mCoreStarted = true;
notifyCoreStarted();
mCoreStartedLock->unlock();
}
void CoreHandlers::notifyCoreStarted () {
if (mCoreCreated && mCoreStarted)
scheduleFunctionInApp(
[this]() {
qInfo() << QStringLiteral("Core started.");
emit coreStarted();
}
);
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -75,10 +114,8 @@ void CoreHandlers::onGlobalStateChanged ( ...@@ -75,10 +114,8 @@ void CoreHandlers::onGlobalStateChanged (
linphone::GlobalState gstate, linphone::GlobalState gstate,
const string & const string &
) { ) {
qInfo() << QStringLiteral("Global state: %1.").arg(gstate);
if (gstate == linphone::GlobalStateOn) if (gstate == linphone::GlobalStateOn)
emitApp(coreStarted()); handleCoreStarted();
} }
void CoreHandlers::onCallStatsUpdated ( void CoreHandlers::onCallStatsUpdated (
......
...@@ -28,11 +28,18 @@ ...@@ -28,11 +28,18 @@
// ============================================================================= // =============================================================================
class CoreManager;
class QMutex;
class CoreHandlers : class CoreHandlers :
public QObject, public QObject,
public linphone::CoreListener { public linphone::CoreListener {
Q_OBJECT; Q_OBJECT;
public:
CoreHandlers (CoreManager *coreManager);
~CoreHandlers ();
signals: signals:
void authenticationRequested (const std::shared_ptr<linphone::AuthInfo> &authInfo); void authenticationRequested (const std::shared_ptr<linphone::AuthInfo> &authInfo);
void callStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state); void callStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
...@@ -42,6 +49,14 @@ signals: ...@@ -42,6 +49,14 @@ signals:
void registrationStateChanged (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig, linphone::RegistrationState state); void registrationStateChanged (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig, linphone::RegistrationState state);
private: private:
void handleCoreCreated ();
void handleCoreStarted ();
void notifyCoreStarted ();
// ---------------------------------------------------------------------------
// Linphone callbacks.
// ---------------------------------------------------------------------------
void onAuthenticationRequested ( void onAuthenticationRequested (
const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::AuthInfo> &authInfo, const std::shared_ptr<linphone::AuthInfo> &authInfo,
...@@ -91,6 +106,13 @@ private: ...@@ -91,6 +106,13 @@ private:
linphone::RegistrationState state, linphone::RegistrationState state,
const std::string &message const std::string &message
) override; ) override;
// ---------------------------------------------------------------------------
bool mCoreCreated = false;
bool mCoreStarted = false;
QMutex *mCoreStartedLock = nullptr;
}; };
#endif // CORE_HANDLERS_H_ #endif // CORE_HANDLERS_H_
...@@ -37,7 +37,7 @@ using namespace std; ...@@ -37,7 +37,7 @@ using namespace std;
CoreManager *CoreManager::mInstance = nullptr; CoreManager *CoreManager::mInstance = nullptr;
CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject(parent), mHandlers(make_shared<CoreHandlers>()) { CoreManager::CoreManager (QObject *parent, const QString &configPath) : QObject(parent), mHandlers(make_shared<CoreHandlers>(this)) {
mPromiseBuild = QtConcurrent::run(this, &CoreManager::createLinphoneCore, configPath); mPromiseBuild = QtConcurrent::run(this, &CoreManager::createLinphoneCore, configPath);
QObject::connect( QObject::connect(
......
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