summaryrefslogtreecommitdiff
path: root/include/mbgl/storage/sqlite_store.hpp
blob: a691b474e0c52ed1de665c64d038b0aa3f22916b (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
#ifndef MBGL_STORAGE_SQLITE_STORE
#define MBGL_STORAGE_SQLITE_STORE

#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/response.hpp>

#include <uv.h>

#include <string>
#include <thread>

typedef struct uv_worker_s uv_worker_t;

namespace mapbox {
namespace sqlite {
class Database;
}
}

namespace mbgl {

class SQLiteStore {
public:
    SQLiteStore(uv_loop_t *loop, const std::string &path);
    ~SQLiteStore();

    typedef void (*GetCallback)(std::unique_ptr<Response> &&entry, void *ptr);

    void get(const std::string &path, GetCallback cb, void *ptr);
    void put(const std::string &path, ResourceType type, const Response &entry);
    void updateExpiration(const std::string &path, int64_t expires);

private:
    void createSchema();
    void closeDatabase();
    static void runGet(uv_work_t *req);
    static void runPut(uv_work_t *req);
    static void deliverResult(uv_work_t *req, int status);

private:
    const std::thread::id thread_id;
    util::ptr<mapbox::sqlite::Database> db;
    uv_worker_t *worker = nullptr;
};

}

#endif