Browse Source

[2850] Pass ZoneTableSegment by reference to the ZoneWriter constructor

Mukund Sivaraman 12 years ago
parent
commit
c45efc1b12

+ 2 - 2
src/lib/datasrc/client_list.cc

@@ -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_))));
 }
 

+ 6 - 6
src/lib/datasrc/memory/zone_writer.cc

@@ -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;
     }

+ 2 - 2
src/lib/datasrc/memory/zone_writer.h

@@ -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_;

+ 4 - 3
src/lib/datasrc/tests/client_list_unittest.cc

@@ -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

+ 2 - 2
src/lib/datasrc/tests/memory/zone_loader_util.cc

@@ -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();

+ 2 - 2
src/lib/datasrc/tests/memory/zone_writer_unittest.cc

@@ -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);

+ 1 - 1
src/lib/datasrc/tests/zone_finder_context_unittest.cc

@@ -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();

+ 1 - 1
src/lib/datasrc/tests/zone_loader_unittest.cc

@@ -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();