Files
MapLibreParticleLab/include/mbgl/platform/default/caching_http_file_source.hpp
Mike Morris dac76a0f92 break out FileSource as an abstract class
add CachingHTTPFileSource implementation
2014-12-03 12:25:11 -05:00

53 lines
1.2 KiB
C++

#ifndef MBGL_STORAGE_CACHING_HTTP_FILE_SOURCE
#define MBGL_STORAGE_CACHING_HTTP_FILE_SOURCE
#include <mbgl/storage/file_source.hpp>
#include <unordered_map>
typedef struct uv_messenger_s uv_messenger_t;
namespace mbgl {
class BaseRequest;
class SQLiteStore;
class CachingHTTPFileSource : public FileSource {
public:
CachingHTTPFileSource(uv_loop_t*, const std::string &path_);
CachingHTTPFileSource(const std::string &path_);
~CachingHTTPFileSource();
// Stores and checks the libuv loop for requests
void setLoop(uv_loop_t*);
bool hasLoop();
// Stores and retrieves the base path/URL for relative requests
void setBase(const std::string &value);
const std::string &getBase() const;
std::unique_ptr<Request> request(ResourceType type, const std::string &url);
void prepare(std::function<void()> fn);
void retryAllPending();
private:
unsigned long thread_id;
// Path to the cache database.
std::string path;
// Stores a URL that is used as a base for loading resources with relative path.
std::string base;
std::unordered_map<std::string, std::weak_ptr<BaseRequest>> pending;
util::ptr<SQLiteStore> store;
uv_loop_t *loop = nullptr;
uv_messenger_t *queue = nullptr;
};
}
#endif