]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2850] Pass ZoneTableSegment by reference to the ZoneWriter constructor
authorMukund Sivaraman <muks@isc.org>
Thu, 2 May 2013 08:39:55 +0000 (14:09 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 2 May 2013 08:39:55 +0000 (14:09 +0530)
src/lib/datasrc/client_list.cc
src/lib/datasrc/memory/zone_writer.cc
src/lib/datasrc/memory/zone_writer.h
src/lib/datasrc/tests/client_list_unittest.cc
src/lib/datasrc/tests/memory/zone_loader_util.cc
src/lib/datasrc/tests/memory/zone_writer_unittest.cc
src/lib/datasrc/tests/zone_finder_context_unittest.cc
src/lib/datasrc/tests/zone_loader_unittest.cc

index 94aee85bfc8d7da677be95b6ccc50a8e8f66c290..19f12c02fc024081be5d8c038aa02772df0b8f24 100644 (file)
@@ -155,7 +155,7 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
                 assert(load_action); // in this loop this should be always true
                 try {
                     memory::ZoneWriter writer(
-                        new_data_sources.back().ztable_segment_.get(),
+                        *new_data_sources.back().ztable_segment_,
                         load_action, zname, rrclass_);
                     writer.load();
                     writer.install();
@@ -349,7 +349,7 @@ ConfigurableClientList::getCachedZoneWriter(const Name& name) {
     return (ZoneWriterPair(ZONE_SUCCESS,
                            ZoneWriterPtr(
                                new memory::ZoneWriter(
-                                   result.info->ztable_segment_.get(),
+                                   *result.info->ztable_segment_,
                                    load_action, name, rrclass_))));
 }
 
index abe2c6ffeb3f7d361246322365ab3a6a9e9c2da3..43932fe41aefec9a0c5a7815059de352f0b5ff46 100644 (file)
@@ -23,7 +23,7 @@ namespace isc {
 namespace datasrc {
 namespace memory {
 
-ZoneWriter::ZoneWriter(ZoneTableSegment* segment,
+ZoneWriter::ZoneWriter(ZoneTableSegment& segment,
                        const LoadAction& load_action,
                        const dns::Name& origin,
                        const dns::RRClass& rrclass) :
@@ -34,7 +34,7 @@ ZoneWriter::ZoneWriter(ZoneTableSegment* segment,
     zone_data_(NULL),
     state_(ZW_UNUSED)
 {
-    if (!segment->isWritable()) {
+    if (!segment.isWritable()) {
         isc_throw(isc::InvalidOperation,
                   "Attempt to construct ZoneWriter for a read-only segment");
     }
@@ -52,7 +52,7 @@ ZoneWriter::load() {
         isc_throw(isc::InvalidOperation, "Trying to load twice");
     }
 
-    zone_data_ = load_action_(segment_->getMemorySegment());
+    zone_data_ = load_action_(segment_.getMemorySegment());
 
     if (!zone_data_) {
         // Bug inside load_action_.
@@ -68,12 +68,12 @@ ZoneWriter::install() {
         isc_throw(isc::InvalidOperation, "No data to install");
     }
 
-    ZoneTable* table(segment_->getHeader().getTable());
+    ZoneTable* table(segment_.getHeader().getTable());
     if (!table) {
         isc_throw(isc::Unexpected, "No zone table present");
     }
     const ZoneTable::AddResult result(table->addZone(
-                                          segment_->getMemorySegment(),
+                                          segment_.getMemorySegment(),
                                           rrclass_, origin_, zone_data_));
 
     state_ = ZW_INSTALLED;
@@ -85,7 +85,7 @@ ZoneWriter::cleanup() {
     // We eat the data (if any) now.
 
     if (zone_data_ != NULL) {
-        ZoneData::destroy(segment_->getMemorySegment(), zone_data_, rrclass_);
+        ZoneData::destroy(segment_.getMemorySegment(), zone_data_, rrclass_);
         zone_data_ = NULL;
         state_ = ZW_CLEANED;
     }
index c0369d3f25169bfe48da39782f82a43715bb7196..816370efb16afb70d7cf3a8427b054ac38b5e3ac 100644 (file)
@@ -48,7 +48,7 @@ public:
     /// \param load_action The callback used to load data.
     /// \param install_action The callback used to install the loaded zone.
     /// \param rrclass The class of the zone.
-    ZoneWriter(ZoneTableSegment* segment,
+    ZoneWriter(ZoneTableSegment& segment,
                const LoadAction& load_action, const dns::Name& name,
                const dns::RRClass& rrclass);
 
@@ -100,7 +100,7 @@ public:
     void cleanup();
 
 private:
-    ZoneTableSegment* const segment_;
+    ZoneTableSegment& segment_;
     const LoadAction load_action_;
     const dns::Name origin_;
     const dns::RRClass rrclass_;
index 0bd58ff9b3b682f4a0b7e929d7374c2dd81ddf59..2a6741888e0dcdeaf65feab9ca87ceeb4bd8003f 100644 (file)
@@ -166,9 +166,10 @@ public:
         // Load the data into the zone table.
         if (enabled) {
             boost::scoped_ptr<memory::ZoneWriter> writer(
-                new memory::ZoneWriter(&(*dsrc_info.ztable_segment_),
-                                       cache_conf->getLoadAction(rrclass_, zone),
-                                       zone, rrclass_));
+                new memory::ZoneWriter(
+                    *dsrc_info.ztable_segment_,
+                    cache_conf->getLoadAction(rrclass_, zone),
+                    zone, rrclass_));
             writer->load();
             writer->install();
             writer->cleanup(); // not absolutely necessary, but just in case
index 77f23fd7b026ef0ca3acbc174b2b8dd7e6b2f77c..0075a65cdc959b52f772437a779f6d7827f6f4b5 100644 (file)
@@ -44,7 +44,7 @@ loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname,
             " \"params\": {\"" + zname.toText() + "\": \"" + zone_file +
             "\"}}"), true);
     boost::scoped_ptr<memory::ZoneWriter> writer(
-        new memory::ZoneWriter(&zt_sgmt,
+        new memory::ZoneWriter(zt_sgmt,
                                cache_conf.getLoadAction(zclass, zname),
                                zname, zclass));
     writer->load();
@@ -77,7 +77,7 @@ loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname,
                   const dns::RRClass& zclass, ZoneIterator& iterator)
 {
     boost::scoped_ptr<memory::ZoneWriter> writer(
-        new memory::ZoneWriter(&zt_sgmt,
+        new memory::ZoneWriter(zt_sgmt,
                                IteratorLoader(zclass, zname, iterator),
                                zname, zclass));
     writer->load();
index 13a55374a30c024c531b1a4045cf67f277589d0c..a4b516dc550030135282fe2f4c04d6cc3cf677be 100644 (file)
@@ -43,7 +43,7 @@ public:
     ZoneWriterTest() :
         segment_(ZoneTableSegment::create(RRClass::IN(), "local")),
         writer_(new
-            ZoneWriter(segment_.get(),
+            ZoneWriter(*segment_,
                        bind(&ZoneWriterTest::loadAction, this, _1),
                        Name("example.org"), RRClass::IN())),
         load_called_(false),
@@ -106,7 +106,7 @@ public:
 TEST_F(ZoneWriterTest, constructForReadOnlySegment) {
     MemorySegmentTest mem_sgmt;
     ReadOnlySegment ztable_segment(RRClass::IN(), mem_sgmt);
-    EXPECT_THROW(ZoneWriter(&ztable_segment,
+    EXPECT_THROW(ZoneWriter(ztable_segment,
                             bind(&ZoneWriterTest::loadAction, this, _1),
                             Name("example.org"), RRClass::IN()),
                  isc::InvalidOperation);
index ef81896aad1c3c8c205f3795cbf6ae1b271402d8..409bdefde083680571c3bd53b21922c192d6f526 100644 (file)
@@ -80,7 +80,7 @@ createInMemoryClient(RRClass zclass, const Name& zname) {
     shared_ptr<ZoneTableSegment> ztable_segment(
         ZoneTableSegment::create(zclass, cache_conf.getSegmentType()));
     scoped_ptr<memory::ZoneWriter> writer(
-        new memory::ZoneWriter(&(*ztable_segment),
+        new memory::ZoneWriter(*ztable_segment,
                                cache_conf.getLoadAction(zclass, zname),
                                zname, zclass));
     writer->load();
index 5fd190b29138c6854eae96bc01728bb9fe3413f8..80d23b7908e481bcb31b3602bf5b6bd26db51e5d 100644 (file)
@@ -319,7 +319,7 @@ protected:
                                   rrclass_, cache_conf.getSegmentType()));
         if (filename) {
             boost::scoped_ptr<memory::ZoneWriter> writer(
-                new memory::ZoneWriter(&(*ztable_segment_),
+                new memory::ZoneWriter(*ztable_segment_,
                                        cache_conf.getLoadAction(rrclass_, zone),
                                        zone, rrclass_));
             writer->load();