]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Objecter: add a way to chain callbacks
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 7 Feb 2014 03:55:30 +0000 (19:55 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Feb 2014 20:34:33 +0000 (12:34 -0800)
The librados C api needs to do extra things like converting c++ data
structures or setting lengths, but some objecter operations already
have out_handlers that librados shouldn't override.

Add a method that chains contexts together by using a new context that
calls both the original and the newly added one.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/osdc/Objecter.h

index 3640b4266c2f172c1b81b7019a2237b815f7246f..2e7576878b723ce46f5d824b23c167bcad168fcb 100644 (file)
@@ -75,6 +75,37 @@ struct ObjectOperation {
     ops.rbegin()->op.flags = flags;
   }
 
+  /**
+   * This is a more limited form of C_Contexts, but that requires
+   * a ceph_context which we don't have here.
+   */
+  class C_TwoContexts : public Context {
+    Context *first;
+    Context *second;
+  public:
+    C_TwoContexts(Context *first, Context *second) : first(first),
+                                                    second(second) {}
+    void finish(int r) {
+      first->complete(r);
+      second->complete(r);
+    }
+  };
+
+  /**
+   * Add a callback to run when this operation completes,
+   * after any other callbacks for it.
+   */
+  void add_handler(Context *extra) {
+    size_t last = out_handler.size() - 1;
+    Context *orig = out_handler[last];
+    if (orig) {
+      Context *wrapper = new C_TwoContexts(orig, extra);
+      out_handler[last] = wrapper;
+    } else {
+      out_handler[last] = extra;
+    }
+  }
+
   OSDOp& add_op(int op) {
     int s = ops.size();
     ops.resize(s+1);