diff --git a/Src/Client/ResourceCache.cpp b/Src/Client/AssetsManager.cpp similarity index 98% rename from Src/Client/ResourceCache.cpp rename to Src/Client/AssetsManager.cpp index b6c1622..db76844 100644 --- a/Src/Client/ResourceCache.cpp +++ b/Src/Client/AssetsManager.cpp @@ -1,4 +1,4 @@ -#include "ResourceCache.hpp" +#include "AssetsManager.hpp" #include "sqlite3.h" #include @@ -285,12 +285,12 @@ std::string CacheDatabase::hashToString(Hash_t hash) { // return hash; // } -coro<> ResourceHandler::asyncDestructor() { +coro<> AssetsManager::asyncDestructor() { assert(NeedShutdown); // Нормальный shutdown должен быть вызван co_await IAsyncDestructible::asyncDestructor(); } -void ResourceHandler::readWriteThread(AsyncUseControl::Lock lock) { +void AssetsManager::readWriteThread(AsyncUseControl::Lock lock) { LOG.info() << "Поток чтения/записи запущен"; while(!NeedShutdown || !WriteQueue.get_read().empty()) { @@ -412,10 +412,10 @@ void ResourceHandler::readWriteThread(AsyncUseControl::Lock lock) { lock.unlock(); } -ResourceHandler::ResourceHandler(boost::asio::io_context &ioc, const fs::path &cachePath, +AssetsManager::AssetsManager(boost::asio::io_context &ioc, const fs::path &cachePath, size_t maxCacheDirectorySize, size_t maxLifeTime) : IAsyncDestructible(ioc), - OffThread(&ResourceHandler::readWriteThread, this, AUC.use()) + OffThread(&AssetsManager::readWriteThread, this, AUC.use()) { LOG.info() << "Инициализировано хранилище кеша: " << cachePath.c_str(); } diff --git a/Src/Client/ResourceCache.hpp b/Src/Client/AssetsManager.hpp similarity index 91% rename from Src/Client/ResourceCache.hpp rename to Src/Client/AssetsManager.hpp index 0f9a910..8337b3b 100644 --- a/Src/Client/ResourceCache.hpp +++ b/Src/Client/AssetsManager.hpp @@ -1,10 +1,7 @@ #pragma once #include "Common/Abstract.hpp" -#include -#include #include -#include #include #include #include @@ -15,7 +12,6 @@ #include #include #include -#include namespace LV::Client { @@ -91,9 +87,9 @@ public: Обработка файлов в отдельном потоке */ -class ResourceHandler : public IAsyncDestructible { +class AssetsManager : public IAsyncDestructible { public: - using Ptr = std::shared_ptr; + using Ptr = std::shared_ptr; struct ResourceKey { Hash_t Hash; @@ -101,15 +97,11 @@ public: std::string Domain, Key; }; -protected: - ResourceHandler(boost::asio::io_context &ioc, const fs::path &cachePath, - size_t maxCacheDatabaseSize, size_t maxLifeTime); - public: - virtual ~ResourceHandler(); - static std::shared_ptr Create(asio::io_context &ioc, const fs::path& cachePath, + virtual ~AssetsManager(); + static std::shared_ptr Create(asio::io_context &ioc, const fs::path& cachePath, size_t maxCacheDirectorySize = 8*1024*1024*1024ULL, size_t maxLifeTime = 7*24*60*60) { - return createShared(ioc, new ResourceHandler(ioc, cachePath, maxCacheDirectorySize, maxLifeTime)); + return createShared(ioc, new AssetsManager(ioc, cachePath, maxCacheDirectorySize, maxLifeTime)); } // Добавить новый полученный с сервера ресурс @@ -190,6 +182,11 @@ private: bool NeedShutdown = false; std::thread OffThread; + + virtual coro<> asyncDestructor(); + AssetsManager(boost::asio::io_context &ioc, const fs::path &cachePath, + size_t maxCacheDatabaseSize, size_t maxLifeTime); + void readWriteThread(AsyncUseControl::Lock lock); };