]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: complete C interface for watch/notify
authorYehuda Sadeh <yehuda@hq.newdream.net>
Sat, 30 Oct 2010 00:09:46 +0000 (17:09 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 24 Nov 2010 00:54:59 +0000 (16:54 -0800)
src/include/librados.h
src/include/librados.hpp
src/librados.cc

index c827dc9adae628c63ae33cd3e9dc52b215e00dbb..9152437a85485f31a68f704d85c6b73dbeb3e3d2 100644 (file)
@@ -118,6 +118,13 @@ int rados_aio_read(rados_pool_t pool, const char *oid,
                   off_t off, char *buf, size_t len,
                   rados_completion_t completion);
 
+/* watch/notify */
+typedef void (*rados_watchcb_t)(uint8_t opcode, uint64_t ver, void *arg);
+int rados_watch(rados_pool_t pool, const char *o, uint64_t ver, uint64_t *cookie,
+                rados_watchcb_t watchcb, void *arg);
+int rados_unwatch(rados_pool_t pool, const char *o, uint64_t cookie);
+int rados_notify(rados_pool_t pool, const char *o, uint64_t ver);
+
 #ifdef __cplusplus
 }
 #endif
index f8113003232cfd8cd27c4a524ef0939550256da5..0af7f72e371a3532d666eda15840439f93783dd5 100644 (file)
@@ -151,7 +151,7 @@ public:
 
   // watch/notify
   int watch(pool_t pool, const string& o, uint64_t ver, uint64_t *cookie, librados::Rados::WatchCtx *ctx);
-  int unwatch(pool_t pool, const string& o, uint64_t ver, uint64_t cookie);
+  int unwatch(pool_t pool, const string& o, uint64_t cookie);
   int notify(pool_t pool, const string& o, uint64_t ver);
 };
 
index 1ac75beb34913548f7d22bb425f990180d90ecce..ab2210be207841b3766b762d7167a1cc754b50e9 100644 (file)
@@ -2168,8 +2168,7 @@ int Rados::watch(pool_t pool, const string& o,
   return client->watch(*(RadosClient::PoolCtx *)pool, oid, ver, cookie, ctx);
 }
 
-int Rados::unwatch(pool_t pool, const string& o,
-                 uint64_t ver, uint64_t cookie)
+int Rados::unwatch(pool_t pool, const string& o, uint64_t cookie)
 {
   if (!client)
     return -EINVAL;
@@ -2662,3 +2661,35 @@ extern "C" int rados_aio_write_full(rados_pool_t pool, const char *o,
   bl.append(buf, len);
   return radosp->aio_write_full(*ctx, oid, bl, (RadosClient::AioCompletion*)completion);
 }
+
+struct C_WatchCB : public librados::Rados::WatchCtx {
+  rados_watchcb_t wcb;
+  void *arg;
+  C_WatchCB(rados_watchcb_t _wcb, void *_arg) : wcb(_wcb), arg(_arg) {}
+  void notify(uint8_t opcode, uint64_t ver) {
+    wcb(opcode, ver, arg);
+  }
+};
+
+int rados_watch(rados_pool_t pool, const char *o, uint64_t ver, uint64_t *cookie,
+                rados_watchcb_t watchcb, void *arg)
+{
+  RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
+  object_t oid(o);
+  C_WatchCB *wc = new C_WatchCB(watchcb, arg);
+  return radosp->watch(*ctx, oid, ver, cookie, wc);
+}
+
+int rados_unwatch(rados_pool_t pool, const char *o, uint64_t cookie)
+{
+  RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
+  object_t oid(o);
+  return radosp->unwatch(*ctx, oid, cookie);
+}
+
+int rados_notify(rados_pool_t pool, const char *o, uint64_t ver)
+{
+  RadosClient::PoolCtx *ctx = (RadosClient::PoolCtx *)pool;
+  object_t oid(o);
+  return radosp->notify(*ctx, oid, ver);
+}