From a51a54bc5979a2491f152abc47ad54e6b63f27c8 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Tue, 23 Nov 2021 05:21:56 +0100 Subject: Restructure source and resource files (#46) importantly, res is now res/res and css is now res/css --- filecache.hpp | 79 ----------------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 filecache.hpp (limited to 'filecache.hpp') diff --git a/filecache.hpp b/filecache.hpp deleted file mode 100644 index d25fdb3..0000000 --- a/filecache.hpp +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "util.hpp" -#include "http.hpp" - -class FileCacheWorkerThread { -public: - using callback_type = sigc::slot; - - FileCacheWorkerThread(); - ~FileCacheWorkerThread(); - - void set_file_path(const std::filesystem::path &path); - - void add_image(const std::string &string, callback_type callback); - - void stop(); - -private: - void loop(); - - bool m_stop = false; - std::thread m_thread; - - struct QueueEntry { - std::string URL; - callback_type Callback; - }; - - std::condition_variable m_cv; - - mutable std::mutex m_queue_mutex; - std::queue m_queue; - - std::unordered_map m_curl_file_handles; - std::unordered_map m_handle_urls; - std::unordered_map m_paths; - std::unordered_map m_callbacks; - - int m_running_handles = 0; - - std::unordered_set m_handles; - CURLM *m_multi_handle; - - std::filesystem::path m_data_path; -}; - -class Cache { -public: - Cache(); - ~Cache(); - - using callback_type = std::function; - void GetFileFromURL(std::string url, callback_type cb); - std::string GetPathIfCached(std::string url); - void ClearCache(); - -private: - void CleanupFutures(); - void RespondFromPath(std::filesystem::path path, callback_type cb); - void OnResponse(const std::string &url); - void OnFetchComplete(const std::string &url); - - std::unordered_map> m_callbacks; - std::vector> m_futures; - std::filesystem::path m_tmp_path; - - mutable std::mutex m_mutex; - - FileCacheWorkerThread m_worker; -}; -- cgit v1.2.3