summaryrefslogtreecommitdiff
path: root/include/mbgl/storage/file_source.hpp
blob: 4cc95ae24e3d3e9feae0bd6c8f61f4b29678b835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef MBGL_STORAGE_FILE_SOURCE
#define MBGL_STORAGE_FILE_SOURCE

#include <mbgl/storage/resource_type.hpp>
#include <mbgl/storage/request.hpp>

#include <string>
#include <memory>
#include <unordered_map>
#include <functional>

typedef struct uv_loop_s uv_loop_t;
typedef struct uv_messenger_s uv_messenger_t;

namespace mbgl {

class BaseRequest;
class SQLiteStore;

class FileSource {
private:
    FileSource(const FileSource &) = delete;
    FileSource(FileSource &&) = delete;
    FileSource& operator=(const FileSource &) = delete;
    FileSource& operator=(FileSource &&) = delete;

public:
    FileSource(uv_loop_t *loop);
    ~FileSource();

public:
    // 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);

private:
    const unsigned long thread_id;

    // 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;
    std::shared_ptr<SQLiteStore> store;
    uv_loop_t *loop = nullptr;
    uv_messenger_t *queue = nullptr;
};

}

#endif