summaryrefslogtreecommitdiff
path: root/src/mbgl/storage/sqlite_store.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/storage/sqlite_store.hpp')
-rw-r--r--src/mbgl/storage/sqlite_store.hpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/mbgl/storage/sqlite_store.hpp b/src/mbgl/storage/sqlite_store.hpp
new file mode 100644
index 0000000000..988eca2597
--- /dev/null
+++ b/src/mbgl/storage/sqlite_store.hpp
@@ -0,0 +1,49 @@
+#ifndef MBGL_STORAGE_SQLITE_STORE
+#define MBGL_STORAGE_SQLITE_STORE
+
+#include <mbgl/storage/response.hpp>
+#include <mbgl/storage/resource_type.hpp>
+#include <mbgl/util/ptr.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