From f90b8b5b4ecbd861bb39b87d0f11f1b459784a3f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 10 May 2017 17:29:03 +0200 Subject: [PATCH] feat(src/components/core/CoreHandlers): create a emitApp macro to emit a signal in the app context --- .../src/components/core/CoreHandlers.cpp | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/linphone-desktop/src/components/core/CoreHandlers.cpp b/linphone-desktop/src/components/core/CoreHandlers.cpp index f4317b034..26b7eb175 100644 --- a/linphone-desktop/src/components/core/CoreHandlers.cpp +++ b/linphone-desktop/src/components/core/CoreHandlers.cpp @@ -21,6 +21,7 @@ */ #include +#include #include #include "../../app/App.hpp" @@ -33,9 +34,21 @@ using namespace std; // ============================================================================= -inline void logGlobalState (linphone::GlobalState gstate) { - qInfo() << QStringLiteral("Global state: %1.").arg(gstate); -} +// Emit a signal in the app context. +#define emitApp(EMIT) \ + do { \ + App *app = App::getInstance(); \ + if (QThread::currentThread() != app->thread()) { \ + QTimer::singleShot( \ + 0, app, [this]() { \ + (EMIT); \ + } \ + ); \ + } else \ + (EMIT); \ + } while (0) + +// ----------------------------------------------------------------------------- void CoreHandlers::onAuthenticationRequested ( const shared_ptr &, @@ -62,15 +75,10 @@ void CoreHandlers::onGlobalStateChanged ( linphone::GlobalState gstate, const string & ) { - if (gstate == linphone::GlobalStateOn) { - QTimer::singleShot( - 0, App::getInstance(), [this, gstate]() { - logGlobalState(gstate); - emit coreStarted(); - } - ); - } else - logGlobalState(gstate); + qInfo() << QStringLiteral("Global state: %1.").arg(gstate); + + if (gstate == linphone::GlobalStateOn) + emitApp(coreStarted()); } void CoreHandlers::onCallStatsUpdated (