mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-02-07 15:08:24 +00:00
fix(src/components/core/CoreHandlers): do not emit core started until core is not created
This commit is contained in:
parent
e9f599984b
commit
cc3418240a
4 changed files with 77 additions and 18 deletions
|
|
@ -442,7 +442,7 @@ QString App::getLocale () const {
|
|||
void App::openAppAfterInit () {
|
||||
tryToUsePreferredLocale();
|
||||
|
||||
qInfo() << QStringLiteral("Linphone core created.");
|
||||
qInfo() << QStringLiteral("Open linphone app.");
|
||||
|
||||
#ifndef __APPLE__
|
||||
// Enable TrayIconSystem.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include <QMutex>
|
||||
#include <QtDebug>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
|
@ -34,19 +35,57 @@ using namespace std;
|
|||
|
||||
// =============================================================================
|
||||
|
||||
// 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)
|
||||
// Schedule a function in app context.
|
||||
void scheduleFunctionInApp (function<void()> func) {
|
||||
App *app = App::getInstance();
|
||||
if (QThread::currentThread() != app->thread()) {
|
||||
QTimer::singleShot(0, app, func);
|
||||
} else
|
||||
func();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
CoreHandlers::CoreHandlers (CoreManager *coreManager) {
|
||||
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 (
|
|||
linphone::GlobalState gstate,
|
||||
const string &
|
||||
) {
|
||||
qInfo() << QStringLiteral("Global state: %1.").arg(gstate);
|
||||
|
||||
if (gstate == linphone::GlobalStateOn)
|
||||
emitApp(coreStarted());
|
||||
handleCoreStarted();
|
||||
}
|
||||
|
||||
void CoreHandlers::onCallStatsUpdated (
|
||||
|
|
|
|||
|
|
@ -28,11 +28,18 @@
|
|||
|
||||
// =============================================================================
|
||||
|
||||
class CoreManager;
|
||||
class QMutex;
|
||||
|
||||
class CoreHandlers :
|
||||
public QObject,
|
||||
public linphone::CoreListener {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
CoreHandlers (CoreManager *coreManager);
|
||||
~CoreHandlers ();
|
||||
|
||||
signals:
|
||||
void authenticationRequested (const std::shared_ptr<linphone::AuthInfo> &authInfo);
|
||||
void callStateChanged (const std::shared_ptr<linphone::Call> &call, linphone::CallState state);
|
||||
|
|
@ -42,6 +49,14 @@ signals:
|
|||
void registrationStateChanged (const std::shared_ptr<linphone::ProxyConfig> &proxyConfig, linphone::RegistrationState state);
|
||||
|
||||
private:
|
||||
void handleCoreCreated ();
|
||||
void handleCoreStarted ();
|
||||
void notifyCoreStarted ();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Linphone callbacks.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
void onAuthenticationRequested (
|
||||
const std::shared_ptr<linphone::Core> &core,
|
||||
const std::shared_ptr<linphone::AuthInfo> &authInfo,
|
||||
|
|
@ -91,6 +106,13 @@ private:
|
|||
linphone::RegistrationState state,
|
||||
const std::string &message
|
||||
) override;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
bool mCoreCreated = false;
|
||||
bool mCoreStarted = false;
|
||||
|
||||
QMutex *mCoreStartedLock = nullptr;
|
||||
};
|
||||
|
||||
#endif // CORE_HANDLERS_H_
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ using namespace std;
|
|||
|
||||
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);
|
||||
|
||||
QObject::connect(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue