##// END OF EJS Templates
Handles items with same names in the same node...
Handles items with same names in the same node This case is handled by adding suffix (plugin name) when displaying items in the widget

File last commit:

r760:ba0e6f7d7791
r1077:c90049fe7bc2
Show More
NetworkController.cpp
148 lines | 5.5 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>
Add thread protection on AbortDownload process
r423 #include <QReadWriteLock>
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{} {}
Implementation of V5 acquisition
r539
void lockRead() { m_Lock.lockForRead(); }
void lockWrite() { m_Lock.lockForWrite(); }
void unlock() { m_Lock.unlock(); }
Intialization of network controller
r339 QMutex m_WorkingMutex;
Add execute skelleton Network
r386
Add thread protection on AbortDownload process
r423 QReadWriteLock m_Lock;
Update networkcontroller for abort mechanism
r755 std::unordered_map<QNetworkReply *, QUuid> m_NetworkReplyToId;
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 }
request is now passed by shared pointer instead of const &
r751 void NetworkController::onProcessRequested(std::shared_ptr<QNetworkRequest> request,
QUuid identifier,
Implement the network controller to permit the execution of a request...
r389 std::function<void(QNetworkReply *, QUuid)> callback)
Add execute skelleton Network
r386 {
request is now passed by shared pointer instead of const &
r751 qCDebug(LOG_NetworkController()) << tr("NetworkController onProcessRequested")
<< QThread::currentThread()->objectName() << &request;
auto reply = impl->m_AccessManager->get(*request);
Implement the network controller to permit the execution of a request...
r389
// Store the couple reply id
Add thread protection on AbortDownload process
r423 impl->lockWrite();
Update networkcontroller for abort mechanism
r755 impl->m_NetworkReplyToId[reply] = identifier;
qCDebug(LOG_NetworkController()) << tr("Store for reply: ") << identifier;
Add thread protection on AbortDownload process
r423 impl->unlock();
Implement the network controller to permit the execution of a request...
r389
Implementation of progression
r750 auto onReplyFinished = [request, reply, this, identifier, callback]() {
Implement the network controller to permit the execution of a request...
r389
Add thread protection on AbortDownload process
r423 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished")
request is now passed by shared pointer instead of const &
r751 << QThread::currentThread() << request.get() << reply;
Add thread protection on AbortDownload process
r423 impl->lockRead();
Update networkcontroller for abort mechanism
r755 auto it = impl->m_NetworkReplyToId.find(reply);
if (it != impl->m_NetworkReplyToId.cend()) {
Correction for MR
r760 qCDebug(LOG_NetworkController()) << tr("Remove for reply: ") << it->second;
impl->unlock();
Add thread protection on AbortDownload process
r423 impl->lockWrite();
Update networkcontroller for abort mechanism
r755 impl->m_NetworkReplyToId.erase(reply);
Add thread protection on AbortDownload process
r423 impl->unlock();
// Deletes reply
Implement the network controller to permit the execution of a request...
r389 callback(reply, identifier);
Add thread protection on AbortDownload process
r423 reply->deleteLater();
Implement the network controller to permit the execution of a request...
r389 }
Correction for MR
r760 else {
impl->unlock();
}
Add thread protection on AbortDownload process
r423
qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyFinished END")
<< QThread::currentThread() << reply;
Implement the network controller to permit the execution of a request...
r389 };
Implementation of progression
r750 auto onReplyProgress = [reply, request, this](qint64 bytesRead, qint64 totalBytes) {
Add execute skelleton Network
r386
Update networkcontroller for abort mechanism
r755 // NOTE: a totalbytes of 0 can happened when a request has been aborted
if (totalBytes > 0) {
double progress = (bytesRead * 100.0) / totalBytes;
qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress") << progress
See last commit
r757 << QThread::currentThread() << request.get() << reply
<< bytesRead << totalBytes;
Update networkcontroller for abort mechanism
r755 impl->lockRead();
auto it = impl->m_NetworkReplyToId.find(reply);
if (it != impl->m_NetworkReplyToId.cend()) {
Correction for MR
r760 auto id = it->second;
impl->unlock();
emit this->replyDownloadProgress(id, request, progress);
}
else {
impl->unlock();
Update networkcontroller for abort mechanism
r755 }
Correction for MR
r760
Update networkcontroller for abort mechanism
r755 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyProgress END")
<< QThread::currentThread() << reply;
Implement the network controller to permit the execution of a request...
r389 }
};
Add execute skelleton Network
r386
Implement the network controller to permit the execution of a request...
r389
connect(reply, &QNetworkReply::finished, this, onReplyFinished);
Add implementation of progress bar on variable inspector connected to...
r401 connect(reply, &QNetworkReply::downloadProgress, this, onReplyProgress);
Display errors of NetworkAcessManager
r426 qCDebug(LOG_NetworkController()) << tr("NetworkController registered END")
<< QThread::currentThread()->objectName() << reply;
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>();
Display errors of NetworkAcessManager
r426
auto onReplyErrors = [this](QNetworkReply *reply, const QList<QSslError> &errors) {
qCCritical(LOG_NetworkController()) << tr("NetworkAcessManager errors: ") << errors;
};
connect(impl->m_AccessManager.get(), &QNetworkAccessManager::sslErrors, this, onReplyErrors);
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; };
Add thread protection on AbortDownload process
r423 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled")
See last commit
r757 << QThread::currentThread() << identifier;
Add thread protection on AbortDownload process
r423
Implement the network controller to permit the execution of a request...
r389
Add thread protection on AbortDownload process
r423 impl->lockRead();
Update networkcontroller for abort mechanism
r755 auto end = impl->m_NetworkReplyToId.cend();
auto it = std::find_if(impl->m_NetworkReplyToId.cbegin(), end, findReply);
Add thread protection on AbortDownload process
r423 impl->unlock();
Implement the network controller to permit the execution of a request...
r389 if (it != end) {
Update networkcontroller for abort mechanism
r755 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled ABORT DONE")
See last commit
r757 << QThread::currentThread() << identifier;
Implement the network controller to permit the execution of a request...
r389 it->first->abort();
}
Add thread protection on AbortDownload process
r423 qCDebug(LOG_NetworkController()) << tr("NetworkController onReplyCanceled END")
See last commit
r757 << QThread::currentThread();
Implement the network controller to permit the execution of a request...
r389 }
Intialization of network controller
r339 void NetworkController::waitForFinish()
{
QMutexLocker locker{&impl->m_WorkingMutex};
}