Rework the storage interface so that operations are asynchronous.
[bluesky.git] / bluesky / bluesky-private.h
index a450085..7f5e646 100644 (file)
@@ -29,6 +29,62 @@ BlueSkyFS *bluesky_deserialize_superblock(const gchar *buf);
 void bluesky_serialize_inode(GString *out, BlueSkyInode *inode);
 BlueSkyInode *bluesky_deserialize_inode(BlueSkyFS *fs, const gchar *buf);
 
+/* Storage layer.  Requests can be performed asynchronously, so these objects
+ * help keep track of operations in progress. */
+typedef enum {
+    STORE_OP_NONE,
+    STORE_OP_GET,
+    STORE_OP_PUT,
+    STORE_OP_DELETE,
+} BlueSkyStoreOp;
+
+typedef enum {
+    ASYNC_NEW,              // Operation not yet submitted to storage layer
+    ASYNC_PENDING,          // Submitted to storage layer
+    ASYNC_RUNNING,          // Operation is in progress
+    ASYNC_COMPLETE,         // Operation finished, results available
+} BlueSkyAsyncStatus;
+
+typedef struct {
+    BlueSkyStore *store;
+
+    GMutex *lock;
+    GCond *completion_cond;     /* Used to wait for operation to complete. */
+
+    BlueSkyAsyncStatus status;
+
+    BlueSkyStoreOp op;
+    gchar *key;                 /* Key to read/write */
+    BlueSkyRCStr *data;         /* Data read/to write */
+
+    int result;                 /* Result code; 0 for success. */
+
+    gpointer store_private;     /* For use by the storage implementation */
+} BlueSkyStoreAsync;
+
+/* The abstraction layer for storage, allowing multiple implementations. */
+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);
+
+    /* Submit an operation (get/put/delete) to the storage layer to be
+     * performed asynchronously. */
+    void (*submit)(gpointer store, BlueSkyStoreAsync *async);
+
+    /* Clean up any implementation-private data in a BlueSkyStoreAsync. */
+    void (*cleanup)(gpointer store, BlueSkyStoreAsync *async);
+} BlueSkyStoreImplementation;
+
+void bluesky_store_register(const BlueSkyStoreImplementation *impl,
+                            const gchar *name);
+
+BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store);
+void bluesky_store_async_wait(BlueSkyStoreAsync *async);
+void bluesky_store_async_mark_complete(BlueSkyStoreAsync *async);
+
 #ifdef __cplusplus
 }
 #endif