##// END OF EJS Templates
Creates constructor for ScalarSeries that directly takes vectors...
Creates constructor for ScalarSeries that directly takes vectors It is used in Amda result parser to avoid an extra loop

File last commit:

r389:13937fa7979a
r392:cae900f78dff
Show More
NetworkController.cpp
88 lines | 2.9 KiB | text/x-c | CppLexer
/ core / src / Network / NetworkController.cpp
Intialization of network controller
r339 #include "Network/NetworkController.h"
#include <QMutex>
Add execute skelleton Network
r386 #include <QNetworkAccessManager>
#include <QNetworkReply>
Implement the network controller to permit the execution of a request...
r389 #include <QNetworkRequest>
Intialization of network controller
r339 #include <QThread>
Implement the network controller to permit the execution of a request...
r389 #include <unordered_map>
Intialization of network controller
r339 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
struct NetworkController::NetworkControllerPrivate {
Implement the network controller to permit the execution of a request...
r389 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
Intialization of network controller
r339 QMutex m_WorkingMutex;
Add execute skelleton Network
r386
Implement the network controller to permit the execution of a request...
r389 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToVariableId;
Add execute skelleton Network
r386 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
Intialization of network controller
r339 };
NetworkController::NetworkController(QObject *parent)
: QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
{
Add execute skelleton Network
r386 }
Implement the network controller to permit the execution of a request...
r389 void NetworkController::onProcessRequested(const QNetworkRequest &request, QUuid identifier,
std::function<void(QNetworkReply *, QUuid)> callback)
Add execute skelleton Network
r386 {
Implement the network controller to permit the execution of a request...
r389 qCDebug(LOG_NetworkController()) << tr("NetworkController registered")
<< QThread::currentThread();
auto reply = impl->m_AccessManager->get(request);
// Store the couple reply id
impl->m_NetworkReplyToVariableId[reply] = identifier;
auto onReplyFinished = [reply, this, identifier, callback]() {
qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
<< QThread::currentThread();
auto it = impl->m_NetworkReplyToVariableId.find(reply);
if (it != impl->m_NetworkReplyToVariableId.cend()) {
callback(reply, identifier);
}
};
auto onReplyDownloadProgress = [reply, this]() {
Add execute skelleton Network
r386
Implement the network controller to permit the execution of a request...
r389 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyDownloadProgress")
<< QThread::currentThread();
auto it = impl->m_NetworkReplyToVariableId.find(reply);
if (it != impl->m_NetworkReplyToVariableId.cend()) {
emit this->replyDownloadProgress(it->second);
}
};
Add execute skelleton Network
r386
Implement the network controller to permit the execution of a request...
r389
connect(reply, &QNetworkReply::finished, this, onReplyFinished);
connect(reply, &QNetworkReply::downloadProgress, this, onReplyDownloadProgress);
Intialization of network controller
r339 }
void NetworkController::initialize()
{
qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
impl->m_WorkingMutex.lock();
Implement the network controller to permit the execution of a request...
r389 impl->m_AccessManager = std::make_unique<QNetworkAccessManager>();
Intialization of network controller
r339 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
}
void NetworkController::finalize()
{
impl->m_WorkingMutex.unlock();
}
Implement the network controller to permit the execution of a request...
r389 void NetworkController::onReplyCanceled(QUuid identifier)
{
auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
auto end = impl->m_NetworkReplyToVariableId.cend();
auto it = std::find_if(impl->m_NetworkReplyToVariableId.cbegin(), end, findReply);
if (it != end) {
it->first->abort();
}
}
Intialization of network controller
r339 void NetworkController::waitForFinish()
{
QMutexLocker locker{&impl->m_WorkingMutex};
}