X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fstore.c;h=d83fe037717ea1778c51bc64dc4022b3b7d49567;hb=d3949cc58f81fc5c84231f79720250ded9e8f143;hp=7a63b04acc8a31e612491e610755292a0874a44a;hpb=6abd55eff09d83999c7a84e0ee63bdc3100f7666;p=bluesky.git diff --git a/bluesky/store.c b/bluesky/store.c index 7a63b04..d83fe03 100644 --- a/bluesky/store.c +++ b/bluesky/store.c @@ -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: