mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 02:06:08 +08:00
Ref T730, use an event loop with parent "this"
* central function to get QEventLoop (this can also be used to set a timeout) * do NOT use sApp as parent -> parent must be in same thread
This commit is contained in:
committed by
Mat Sutcliffe
parent
e4e4dd090e
commit
b802933422
@@ -61,7 +61,7 @@ namespace BlackCore
|
|||||||
{"networkversion", networkVersion.toString()},
|
{"networkversion", networkVersion.toString()},
|
||||||
};
|
};
|
||||||
|
|
||||||
QPointer<QEventLoop> loop(new QEventLoop(sApp));
|
QPointer<QEventLoop> loop(this->newEventLoop());
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (isShuttingDown()) { return {}; }
|
if (isShuttingDown()) { return {}; }
|
||||||
|
|
||||||
QPointer<QEventLoop> loop(new QEventLoop(sApp));
|
QPointer<QEventLoop> loop(this->newEventLoop());
|
||||||
QByteArray receivedData;
|
QByteArray receivedData;
|
||||||
|
|
||||||
// posted in QAM thread, reply is nullptr if called from another thread
|
// posted in QAM thread, reply is nullptr if called from another thread
|
||||||
@@ -197,7 +197,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (isShuttingDown()) { return {}; }
|
if (isShuttingDown()) { return {}; }
|
||||||
|
|
||||||
QPointer<QEventLoop> loop(new QEventLoop(sApp));
|
QPointer<QEventLoop> loop(this->newEventLoop());
|
||||||
QByteArray receivedData;
|
QByteArray receivedData;
|
||||||
|
|
||||||
// posted in QAM thread, reply is nullptr if called from another thread
|
// posted in QAM thread, reply is nullptr if called from another thread
|
||||||
@@ -295,7 +295,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (QDateTime::currentDateTimeUtc() > m_expiryLocalUtc.addSecs(-5 * 60))
|
if (QDateTime::currentDateTimeUtc() > m_expiryLocalUtc.addSecs(-5 * 60))
|
||||||
{
|
{
|
||||||
connectTo(m_username, m_password, m_networkVersion);
|
this->connectTo(m_username, m_password, m_networkVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,6 +327,16 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QEventLoop *CApiServerConnection::newEventLoop()
|
||||||
|
{
|
||||||
|
QEventLoop *loop = new QEventLoop(this);
|
||||||
|
if (sApp)
|
||||||
|
{
|
||||||
|
QObject::connect(sApp, &CApplication::aboutToShutdown, loop, &QEventLoop::quit, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
return loop;
|
||||||
|
}
|
||||||
|
|
||||||
bool CApiServerConnection::isShuttingDown()
|
bool CApiServerConnection::isShuttingDown()
|
||||||
{
|
{
|
||||||
return !sApp || sApp->isShuttingDown();
|
return !sApp || sApp->isShuttingDown();
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
if (! m_isAuthenticated)
|
if (! m_isAuthenticated)
|
||||||
{
|
{
|
||||||
BlackMisc::CLogMessage(this).debug(u"AFV not authenticated");
|
CLogMessage(this).debug(u"AFV not authenticated");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +149,9 @@ namespace BlackCore
|
|||||||
//! Message if reply has error
|
//! Message if reply has error
|
||||||
void logRequestDuration(const QNetworkReply *reply, const QString &addMsg = {});
|
void logRequestDuration(const QNetworkReply *reply, const QString &addMsg = {});
|
||||||
|
|
||||||
|
//! Get QLoop for network access, using class must delete the loop
|
||||||
|
QEventLoop *newEventLoop();
|
||||||
|
|
||||||
//! Application shutting down
|
//! Application shutting down
|
||||||
static bool isShuttingDown();
|
static bool isShuttingDown();
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace BlackMisc
|
|||||||
return QStringLiteral("0x%1").arg(reinterpret_cast<long long>(t), 0, 16);
|
return QStringLiteral("0x%1").arg(reinterpret_cast<long long>(t), 0, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString CThreadUtils::threadInfo(QThread *thread)
|
const QString CThreadUtils::threadInfo(const QThread *thread)
|
||||||
{
|
{
|
||||||
static const QString info("thread: %1 name: '%2' priority: '%3'");
|
static const QString info("thread: %1 name: '%2' priority: '%3'");
|
||||||
if (!thread) { return QString("no thread"); }
|
if (!thread) { return QString("no thread"); }
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace BlackMisc
|
|||||||
static const QString threadToString(const void *t);
|
static const QString threadToString(const void *t);
|
||||||
|
|
||||||
//! Info about current thread
|
//! Info about current thread
|
||||||
static const QString threadInfo(QThread *thread);
|
static const QString threadInfo(const QThread *thread);
|
||||||
|
|
||||||
//! Info about current thread
|
//! Info about current thread
|
||||||
static const QString currentThreadInfo();
|
static const QString currentThreadInfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user