From 4944d0a8d0205c093bd65b9bcd325f96f318e6fc Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 26 Feb 2016 16:06:57 -0800 Subject: [PATCH] Handle threading inside AssetServer --- interface/src/Application.cpp | 7 +------ interface/src/Application.h | 2 -- interface/src/ui/DiskCacheEditor.cpp | 9 +++------ interface/src/ui/DiskCacheEditor.h | 4 ++-- libraries/networking/src/AssetClient.cpp | 12 ++++++++++-- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bc98245f32..bc04e111b0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1071,11 +1071,6 @@ void Application::cleanupBeforeQuit() { DependencyManager::destroy(); } -void Application::emptyLocalCache() { - auto assetClient = DependencyManager::get(); - QMetaObject::invokeMethod(assetClient.data(), "clearCache", Qt::QueuedConnection); -} - Application::~Application() { EntityTreePointer tree = getEntities()->getTree(); tree->setSimulation(NULL); @@ -3061,7 +3056,7 @@ void Application::reloadResourceCaches() { _viewFrustum.setOrientation(glm::quat()); queryOctree(NodeType::EntityServer, PacketType::EntityQuery, _entityServerJurisdictions); - emptyLocalCache(); + DependencyManager::get()->clearCache(); DependencyManager::get()->refreshAll(); DependencyManager::get()->refreshAll(); diff --git a/interface/src/Application.h b/interface/src/Application.h index b5a0894c3a..7c92331d43 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -330,8 +330,6 @@ private: void cleanupBeforeQuit(); - void emptyLocalCache(); - void update(float deltaTime); void setPalmData(Hand* hand, const controller::Pose& pose, float deltaTime, HandData::Hand whichHand, float triggerValue); diff --git a/interface/src/ui/DiskCacheEditor.cpp b/interface/src/ui/DiskCacheEditor.cpp index 0ec7e79191..f2720df22a 100644 --- a/interface/src/ui/DiskCacheEditor.cpp +++ b/interface/src/ui/DiskCacheEditor.cpp @@ -103,12 +103,10 @@ void DiskCacheEditor::makeDialog() { } void DiskCacheEditor::refresh() { - auto assetClient = DependencyManager::get(); - QMetaObject::invokeMethod(assetClient.data() , "cacheInfoRequest", Qt::QueuedConnection, - Q_ARG(QObject*, this), Q_ARG(QString, "update")); + DependencyManager::get()->cacheInfoRequest(this, "cacheInfoCallback"); } -void DiskCacheEditor::update(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize) { +void DiskCacheEditor::cacheInfoCallback(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize) { static const auto stringify = [](qint64 number) { static const QStringList UNITS = QStringList() << "B" << "KB" << "MB" << "GB"; static const qint64 CHUNK = 1024; @@ -141,7 +139,6 @@ void DiskCacheEditor::clear() { "are you sure you want to do that?", QMessageBox::Ok | QMessageBox::Cancel); if (buttonClicked == QMessageBox::Ok) { - auto assetClient = DependencyManager::get(); - QMetaObject::invokeMethod(assetClient.data() , "clearCache", Qt::QueuedConnection); + DependencyManager::get()->clearCache(); } } diff --git a/interface/src/ui/DiskCacheEditor.h b/interface/src/ui/DiskCacheEditor.h index 8d1b84fa8d..3f8fa1a883 100644 --- a/interface/src/ui/DiskCacheEditor.h +++ b/interface/src/ui/DiskCacheEditor.h @@ -33,9 +33,9 @@ public slots: private slots: void refresh(); - void update(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize); + void cacheInfoCallback(QString cacheDirectory, qint64 cacheSize, qint64 maximumCacheSize); void clear(); - + private: void makeDialog(); diff --git a/libraries/networking/src/AssetClient.cpp b/libraries/networking/src/AssetClient.cpp index 66b89f78a3..e70863f0b6 100644 --- a/libraries/networking/src/AssetClient.cpp +++ b/libraries/networking/src/AssetClient.cpp @@ -66,7 +66,12 @@ void AssetClient::init() { void AssetClient::cacheInfoRequest(QObject* reciever, QString slot) { - Q_ASSERT(QThread::currentThread() == thread()); + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "cacheInfoRequest", Qt::QueuedConnection, + Q_ARG(QObject*, reciever), Q_ARG(QString, slot)); + return; + } + if (auto* cache = qobject_cast(NetworkAccessManager::getInstance().cache())) { QMetaObject::invokeMethod(reciever, slot.toStdString().data(), Qt::QueuedConnection, @@ -79,7 +84,10 @@ void AssetClient::cacheInfoRequest(QObject* reciever, QString slot) { } void AssetClient::clearCache() { - Q_ASSERT(QThread::currentThread() == thread()); + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "clearCache", Qt::QueuedConnection); + return; + } if (auto cache = NetworkAccessManager::getInstance().cache()) { qDebug() << "AssetClient::clearCache(): Clearing disk cache.";