Parcourir la source

[2850] Add ZoneTableSegment::isWritable() method

Mukund Sivaraman il y a 12 ans
Parent
commit
8469967206

+ 8 - 0
src/lib/datasrc/memory/zone_table_segment.h

@@ -104,6 +104,14 @@ public:
     /// \brief Return the MemorySegment for the zone table segment.
     virtual isc::util::MemorySegment& getMemorySegment() = 0;
 
+    /// \brief Return true if the segment is writable.
+    ///
+    /// The user of the zone table segment will load or update zones
+    /// into the segment only for writable ones.  "local" segments will
+    /// always be writable.  a "mapped" segment will be writable if a
+    /// mapped memory segment in read-write mode has been set.
+    virtual bool isWritable() const = 0;
+
     /// \brief Create an instance depending on the memory segment model
     ///
     /// This is a factory method to create a derived ZoneTableSegment

+ 7 - 0
src/lib/datasrc/memory/zone_table_segment_local.h

@@ -53,6 +53,13 @@ public:
     /// implementation (a MemorySegmentLocal instance).
     virtual isc::util::MemorySegment& getMemorySegment();
 
+    /// \brief Return true if the segment is writable.
+    ///
+    /// This implementation always returns true.
+    virtual bool isWritable() const {
+        return (true);
+    }
+
 private:
     isc::util::MemorySegmentLocal mem_sgmt_;
     ZoneTableHeader header_;

+ 4 - 0
src/lib/datasrc/tests/memory/zone_table_segment_test.h

@@ -53,6 +53,10 @@ public:
         return (mem_sgmt_);
     }
 
+    virtual bool isWritable() const {
+        return (true);
+    }
+
     virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
                                       const dns::Name& name,
                                       const dns::RRClass& rrclass)

+ 5 - 0
src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc

@@ -94,4 +94,9 @@ TEST_F(ZoneTableSegmentTest, getZoneWriter) {
     EXPECT_NE(static_cast<void*>(NULL), writer.get());
 }
 
+TEST_F(ZoneTableSegmentTest, isWritable) {
+    // Local segments are always writable.
+    EXPECT_TRUE(ztable_segment_->isWritable());
+}
+
 } // anonymous namespace