Fix required package list (need git-core, not git).
[bluesky.git] / bluesky / store.c
index 7a63b04..d83fe03 100644 (file)
@@ -45,13 +45,25 @@ BlueSkyStore *bluesky_store_new(const gchar *type)
 {
     const BlueSkyStoreImplementation *impl;
 
-    impl = g_hash_table_lookup(store_implementations, type);
-    if (impl == NULL)
+    gchar *scheme, *path;
+    scheme = g_strdup(type);
+    path = strchr(scheme, ':');
+    if (path != NULL) {
+        *path = '\0';
+        path++;
+    }
+
+    impl = g_hash_table_lookup(store_implementations, scheme);
+    if (impl == NULL) {
+        g_free(scheme);
         return NULL;
+    }
 
-    gpointer handle = impl->create();
-    if (handle == NULL)
+    gpointer handle = impl->create(path);
+    if (handle == NULL) {
+        g_free(scheme);
         return NULL;
+    }
 
     BlueSkyStore *store = g_new(BlueSkyStore, 1);
     store->impl = impl;
@@ -59,6 +71,7 @@ BlueSkyStore *bluesky_store_new(const gchar *type)
     store->lock = g_mutex_new();
     store->cond_idle = g_cond_new();
     store->pending = 0;
+    g_free(scheme);
     return store;
 }
 
@@ -88,6 +101,11 @@ BlueSkyStoreAsync *bluesky_store_async_new(BlueSkyStore *store)
     return async;
 }
 
+gpointer bluesky_store_async_get_handle(BlueSkyStoreAsync *async)
+{
+    return async->store->handle;
+}
+
 void bluesky_store_async_ref(BlueSkyStoreAsync *async)
 {
     if (async == NULL)
@@ -215,6 +233,7 @@ static void op_complete(gpointer a, gpointer b)
 {
     BlueSkyStoreAsync *barrier = (BlueSkyStoreAsync *)b;
 
+    bluesky_store_async_ref(barrier);
     g_mutex_lock(barrier->lock);
     barrier->store_private
         = GINT_TO_POINTER(GPOINTER_TO_INT(barrier->store_private) - 1);
@@ -223,6 +242,7 @@ static void op_complete(gpointer a, gpointer b)
         bluesky_store_async_mark_complete(barrier);
     }
     g_mutex_unlock(barrier->lock);
+    bluesky_store_async_unref(barrier);
 }
 
 /* Add the given operation to the barrier.  The barrier will not complete until
@@ -294,7 +314,7 @@ typedef struct {
     GHashTable *store;
 } MemStore;
 
-static gpointer memstore_create()
+static gpointer memstore_create(const gchar *path)
 {
     MemStore *store = g_new(MemStore, 1);
     store->lock = g_mutex_new();
@@ -360,7 +380,7 @@ static BlueSkyStoreImplementation memstore_impl = {
 };
 
 /* Store implementation which writes data as files to disk. */
-static gpointer filestore_create()
+static gpointer filestore_create(const gchar *path)
 {
     return GINT_TO_POINTER(1);
 }
@@ -395,10 +415,12 @@ static void filestore_submit(gpointer s, BlueSkyStoreAsync *async)
     switch (async->op) {
     case STORE_OP_GET:
         async->data = filestore_get(async->key);
+        async->result = 0;
         break;
 
     case STORE_OP_PUT:
         filestore_put(async->key, async->data);
+        async->result = 0;
         break;
 
     default: