Parcourir la source

[2207] Change signature of LoadAction

We allocate the ZoneData in the LoadAction, to match what happens in
ticket #2268 -- there's a function to load zone which allocates it
itself, we want to use it.
Michal 'vorner' Vaner il y a 12 ans
Parent
commit
419020c407

+ 1 - 5
src/lib/datasrc/memory/zone_reloader.cc

@@ -27,12 +27,10 @@ namespace memory {
 ZoneReloaderLocal::ZoneReloaderLocal(ZoneTableSegment* segment,
                                      const LoadAction& load_action,
                                      const InstallAction& install_action,
-                                     const dns::Name& origin,
                                      const dns::RRClass& rrclass) :
     segment_(segment),
     load_action_(load_action),
     install_action_(install_action),
-    origin_(origin),
     rrclass_(rrclass),
     zone_data_(NULL),
     loaded_(false),
@@ -52,9 +50,7 @@ ZoneReloaderLocal::load() {
     }
     loaded_ = true;
 
-    zone_data_ = ZoneData::create(segment_->getMemorySegment(), origin_);
-
-    load_action_(zone_data_);
+    zone_data_ = load_action_(segment_->getMemorySegment());
 
     data_ready_ = true;
 }

+ 8 - 10
src/lib/datasrc/memory/zone_reloader.h

@@ -12,16 +12,17 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <dns/name.h>
 #include <dns/rrclass.h>
 
 #include <boost/function.hpp>
 
 namespace isc {
+// Forward declarations
+namespace util{
+class MemorySegment;
+}
 namespace datasrc {
 namespace memory {
-
-// Forward declarations
 class ZoneData;
 class ZoneTableSegment;
 
@@ -104,10 +105,10 @@ class ZoneSegmentID {};
 
 /// \brief Callback to load data into the memory
 ///
-/// This is called with a clean (empty) zone data. The goal of the
-/// callback is to get the data for the zone from somewhere and put
-/// them into the passed ZoneData parameter.
-typedef boost::function<void(ZoneData*)> LoadAction;
+/// This callback should create new ZoneData (allocated from the passed
+/// memory segment) and fill it with relevant loaded data. The caller
+/// of the callback takes ownership of the ZoneData.
+typedef boost::function<ZoneData*(util::MemorySegment&)> LoadAction;
 /// \brief Install the zone somewhere.
 ///
 /// The goal of the callback is to take the zone data (contained in the
@@ -133,11 +134,9 @@ public:
     /// \param segment The zone table segment to store the zone into.
     /// \param load_action The callback used to load data.
     /// \param install_action The callback used to install the loaded zone.
-    /// \param origin The origin name of the zone.
     /// \param rrclass The class of the zone.
     ZoneReloaderLocal(ZoneTableSegment* segment, const LoadAction& load_action,
                       const InstallAction& install_action,
-                      const dns::Name& origin,
                       const dns::RRClass& rrclass);
     /// \brief Destructor
     ~ZoneReloaderLocal();
@@ -169,7 +168,6 @@ private:
     ZoneTableSegment* segment_;
     LoadAction load_action_;
     InstallAction install_action_;
-    dns::Name origin_;
     dns::RRClass rrclass_;
     ZoneData* zone_data_;
     // The load was performed

+ 9 - 4
src/lib/datasrc/tests/memory/zone_reloader_unittest.cc

@@ -48,7 +48,7 @@ public:
                                    _1),
                               bind(&ZoneReloaderLocalTest::installAction, this,
                                    _1, _2),
-                              Name("example.org"), RRClass::IN())),
+                              RRClass::IN())),
         load_called_(false),
         install_called_(false),
         load_throw_(false),
@@ -68,14 +68,19 @@ protected:
     bool load_throw_;
     bool install_throw_;
 private:
-    void loadAction(ZoneData* data) {
-        // Make sure we get something.
-        EXPECT_NE(static_cast<const ZoneData*>(NULL), data);
+    ZoneData* loadAction(isc::util::MemorySegment& segment) {
+        // Make sure it is the correct segment passed. We know the
+        // exact instance, can compare pointers to them.
+        EXPECT_EQ(&segment_->getMemorySegment(), &segment);
         // We got called
         load_called_ = true;
         if (load_throw_) {
             throw TestException();
         }
+
+        // Create a new zone data. It may be empty for our tests, nothing
+        // goes inside.
+        return (ZoneData::create(segment, Name("example.org")));
     }
     ZoneData* installAction(const ZoneSegmentID&, ZoneSegment* segment) {
         install_called_ = true;