*
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#include "ResourceCache.hpp"
|
#include "AssetsManager.hpp"
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
@@ -285,12 +285,12 @@ std::string CacheDatabase::hashToString(Hash_t hash) {
|
|||||||
// return hash;
|
// return hash;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
coro<> ResourceHandler::asyncDestructor() {
|
coro<> AssetsManager::asyncDestructor() {
|
||||||
assert(NeedShutdown); // Нормальный shutdown должен быть вызван
|
assert(NeedShutdown); // Нормальный shutdown должен быть вызван
|
||||||
co_await IAsyncDestructible::asyncDestructor();
|
co_await IAsyncDestructible::asyncDestructor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceHandler::readWriteThread(AsyncUseControl::Lock lock) {
|
void AssetsManager::readWriteThread(AsyncUseControl::Lock lock) {
|
||||||
LOG.info() << "Поток чтения/записи запущен";
|
LOG.info() << "Поток чтения/записи запущен";
|
||||||
|
|
||||||
while(!NeedShutdown || !WriteQueue.get_read().empty()) {
|
while(!NeedShutdown || !WriteQueue.get_read().empty()) {
|
||||||
@@ -412,10 +412,10 @@ void ResourceHandler::readWriteThread(AsyncUseControl::Lock lock) {
|
|||||||
lock.unlock();
|
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)
|
size_t maxCacheDirectorySize, size_t maxLifeTime)
|
||||||
: IAsyncDestructible(ioc),
|
: IAsyncDestructible(ioc),
|
||||||
OffThread(&ResourceHandler::readWriteThread, this, AUC.use())
|
OffThread(&AssetsManager::readWriteThread, this, AUC.use())
|
||||||
{
|
{
|
||||||
LOG.info() << "Инициализировано хранилище кеша: " << cachePath.c_str();
|
LOG.info() << "Инициализировано хранилище кеша: " << cachePath.c_str();
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Common/Abstract.hpp"
|
#include "Common/Abstract.hpp"
|
||||||
#include <array>
|
|
||||||
#include <boost/lockfree/spsc_queue.hpp>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <chrono>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@@ -15,7 +12,6 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
|
|
||||||
namespace LV::Client {
|
namespace LV::Client {
|
||||||
@@ -91,9 +87,9 @@ public:
|
|||||||
|
|
||||||
Обработка файлов в отдельном потоке
|
Обработка файлов в отдельном потоке
|
||||||
*/
|
*/
|
||||||
class ResourceHandler : public IAsyncDestructible {
|
class AssetsManager : public IAsyncDestructible {
|
||||||
public:
|
public:
|
||||||
using Ptr = std::shared_ptr<ResourceHandler>;
|
using Ptr = std::shared_ptr<AssetsManager>;
|
||||||
|
|
||||||
struct ResourceKey {
|
struct ResourceKey {
|
||||||
Hash_t Hash;
|
Hash_t Hash;
|
||||||
@@ -101,15 +97,11 @@ public:
|
|||||||
std::string Domain, Key;
|
std::string Domain, Key;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
|
||||||
ResourceHandler(boost::asio::io_context &ioc, const fs::path &cachePath,
|
|
||||||
size_t maxCacheDatabaseSize, size_t maxLifeTime);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~ResourceHandler();
|
virtual ~AssetsManager();
|
||||||
static std::shared_ptr<ResourceHandler> Create(asio::io_context &ioc, const fs::path& cachePath,
|
static std::shared_ptr<AssetsManager> Create(asio::io_context &ioc, const fs::path& cachePath,
|
||||||
size_t maxCacheDirectorySize = 8*1024*1024*1024ULL, size_t maxLifeTime = 7*24*60*60) {
|
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;
|
bool NeedShutdown = false;
|
||||||
std::thread OffThread;
|
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);
|
void readWriteThread(AsyncUseControl::Lock lock);
|
||||||
};
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user