feat(src/components/core/CoreHandlers): create a emitApp macro to emit a signal in the app context

This commit is contained in:
Ronan Abhamon 2017-05-10 17:29:03 +02:00
parent 3647ed9c2b
commit f90b8b5b4e

View file

@ -21,6 +21,7 @@
*/
#include <QtDebug>
#include <QThread>
#include <QTimer>
#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<linphone::Core> &,
@ -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 (