Add pluggable support for multiple storage backends.
[bluesky.git] / bluesky / bluesky.h
index b250206..8980c98 100644 (file)
@@ -16,7 +16,7 @@
 extern "C" {
 #endif
 
-struct S3Store;
+void bluesky_init(void);
 
 /* Reference-counted blocks of memory, used for passing data in and out of
  * storage backends and in other places. */
@@ -40,6 +40,35 @@ void bluesky_crypt_random_bytes(guchar *buf, gint len);
 BlueSkyRCStr *bluesky_crypt_encrypt(BlueSkyRCStr *in, const uint8_t *key);
 BlueSkyRCStr *bluesky_crypt_decrypt(BlueSkyRCStr *in, const uint8_t *key);
 
+/* Storage interface.  This presents a key-value store abstraction, and can
+ * have multiple implementations: in-memory, on-disk, in-cloud. */
+typedef struct {
+    /* Create a new store instance and return a handle to it. */
+    gpointer (*create)();
+
+    /* Clean up any resources used by this store. */
+    void (*destroy)(gpointer store);
+
+    /* Fetch an item with the given name, or return NULL if not found. */
+    BlueSkyRCStr * (*get)(gpointer store, const gchar *key);
+
+    /* Store an item to the given key name. */
+    void (*put)(gpointer store, const gchar *key, BlueSkyRCStr *val);
+} BlueSkyStoreImplementation;
+
+void bluesky_store_register(const BlueSkyStoreImplementation *impl,
+                            const gchar *name);
+
+struct _BlueSkyStore;
+typedef struct _BlueSkyStore BlueSkyStore;
+
+void bluesky_store_init();
+BlueSkyStore *bluesky_store_new(const gchar *type);
+void bluesky_store_free(BlueSkyStore *store);
+BlueSkyRCStr *bluesky_store_get(BlueSkyStore *store, const gchar *key);
+void bluesky_store_put(BlueSkyStore *store,
+                       const gchar *key, BlueSkyRCStr *val);
+
 /* File types.  The numeric values are chosen to match with those used in
  * NFSv3. */
 typedef enum {
@@ -61,7 +90,7 @@ typedef struct {
     GHashTable *inodes;         /* Cached inodes */
     uint64_t next_inum;         /* Next available inode for allocation */
 
-    struct S3Store *store;
+    BlueSkyStore *store;
 
     uint8_t *encryption_key;
 } BlueSkyFS;
@@ -170,10 +199,6 @@ void bluesky_file_write(BlueSkyInode *inode, uint64_t offset,
 void bluesky_file_read(BlueSkyInode *inode, uint64_t offset,
                        char *buf, gint len);
 
-struct S3Store *s3store_new();
-BlueSkyRCStr *s3store_get(struct S3Store *store, const gchar *key);
-void s3store_put(struct S3Store *store, const gchar *key, BlueSkyRCStr *val);
-
 #ifdef __cplusplus
 }
 #endif