]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd: make watch_item_t dencoder-compatible
authorGreg Farnum <gfarnum@redhat.com>
Fri, 26 Apr 2019 05:22:22 +0000 (22:22 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Fri, 26 Apr 2019 05:58:34 +0000 (22:58 -0700)
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/osd/osd_types.h

index 8fb2fdfff3946e0f03d3f11d3d2d977ad2a6d3e8..6b0a3ced15c696382b0986f5c14001107dc65dcc 100644 (file)
@@ -5624,6 +5624,35 @@ struct watch_item_t {
     }
     DECODE_FINISH(bl);
   }
+  void dump_bare(ceph::Formatter *f) const {
+    f->dump_stream("watcher") << name;
+    f->dump_int("cookie", cookie);
+    f->dump_int("timeout", timeout_seconds);
+    f->open_object_section("addr");
+    addr.dump(f);
+    f->close_section();
+  }
+  void dump(ceph::Formatter *f) const {
+    f->open_object_section("watch_item_t");
+    dump_bare(f);
+    f->close_section();
+  }
+  static void generate_test_instances(std::list<watch_item_t*>& o) {
+    entity_addr_t ea;
+    ea.set_type(entity_addr_t::TYPE_LEGACY);
+    ea.set_nonce(1000);
+    ea.set_family(AF_INET);
+    ea.set_in4_quad(0, 127);
+    ea.set_in4_quad(1, 0);
+    ea.set_in4_quad(2, 0);
+    ea.set_in4_quad(3, 1);
+    ea.set_port(1024);
+    o.push_back(new watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT, 1), 10, 30, ea));
+    ea.set_nonce(1001);
+    ea.set_in4_quad(3, 2);
+    ea.set_port(1025);
+    o.push_back(new watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT, 2), 20, 60, ea));
+  }
 };
 WRITE_CLASS_ENCODER_FEATURES(watch_item_t)
 
@@ -5653,12 +5682,7 @@ struct obj_list_watch_response_t {
     f->open_array_section("entries");
     for (std::list<watch_item_t>::const_iterator p = entries.begin(); p != entries.end(); ++p) {
       f->open_object_section("watch");
-      f->dump_stream("watcher") << p->name;
-      f->dump_int("cookie", p->cookie);
-      f->dump_int("timeout", p->timeout_seconds);
-      f->open_object_section("addr");
-      p->addr.dump(f);
-      f->close_section();
+      p->dump_bare(f);
       f->close_section();
     }
     f->close_section();
@@ -5667,19 +5691,12 @@ struct obj_list_watch_response_t {
     entity_addr_t ea;
     o.push_back(new obj_list_watch_response_t);
     o.push_back(new obj_list_watch_response_t);
-    ea.set_type(entity_addr_t::TYPE_LEGACY);
-    ea.set_nonce(1000);
-    ea.set_family(AF_INET);
-    ea.set_in4_quad(0, 127);
-    ea.set_in4_quad(1, 0);
-    ea.set_in4_quad(2, 0);
-    ea.set_in4_quad(3, 1);
-    ea.set_port(1024);
-    o.back()->entries.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT, 1), 10, 30, ea));
-    ea.set_nonce(1001);
-    ea.set_in4_quad(3, 2);
-    ea.set_port(1025);
-    o.back()->entries.push_back(watch_item_t(entity_name_t(entity_name_t::TYPE_CLIENT, 2), 20, 60, ea));
+    std::list<watch_item_t*> test_watchers;
+    watch_item_t::generate_test_instances(test_watchers);
+    for (auto &e : test_watchers) {
+      o.back()->entries.push_back(*e);
+      delete e;
+    }
   }
 };
 WRITE_CLASS_ENCODER_FEATURES(obj_list_watch_response_t)