]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2207] Implementation of the zone updater
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 11 Oct 2012 17:52:12 +0000 (19:52 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 11 Oct 2012 17:52:12 +0000 (19:52 +0200)
The interface was slightly updated, to suit the needs (added some more
parameters). Some of it might be wrong, but I'm not sure about it.

src/lib/datasrc/memory/zone_updater.cc
src/lib/datasrc/memory/zone_updater.h

index 03c8ece123f4428aa49f7dd52313b5fda213e46c..40d55eeb12c4afba4913f8849f1d985d268268a4 100644 (file)
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include "zone_updater.h"
+#include "zone_data.h"
+#include "zone_table_segment.h"
+
+#include <memory>
+
+using std::auto_ptr;
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+ZoneUpdaterLocal::ZoneUpdaterLocal(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),
+    data_ready_(false)
+{}
+
+ZoneUpdaterLocal::~ZoneUpdaterLocal() {
+    // Clean up everything there might be left if someone forgot, just
+    // in case. Or should we assert instead?
+    cleanup();
+}
+
+void
+ZoneUpdaterLocal::load() {
+    if (loaded_) {
+        isc_throw(isc::Unexpected, "Trying to load twice");
+    }
+    loaded_ = true;
+
+    zone_data_ = ZoneData::create(segment_->getMemorySegment(), origin_);
+
+    load_action_(zone_data_);
+
+    data_ready_ = true;
+}
+
+void
+ZoneUpdaterLocal::install() {
+    if (!data_ready_) {
+        isc_throw(isc::Unexpected, "No data to install");
+    }
+
+    data_ready_ = false;
+    auto_ptr<ZoneSegment> zone_segment(new ZoneSegment(zone_data_));
+
+    zone_data_ = install_action_(ZoneSegmentID(), zone_segment.get());
+
+    // The ownership was passed to the callback, no need to clear it now.
+    zone_segment.release();
+}
+
+void
+ZoneUpdaterLocal::cleanup() {
+    // We eat the data (if any) now.
+    data_ready_ = false;
+
+    if (zone_data_ != NULL) {
+        ZoneData::destroy(segment_->getMemorySegment(), zone_data_, rrclass_);
+        zone_data_ = NULL;
+    }
+}
+
+}
+}
+}
index 96588661252708be43d46f365f379b524f9e441f..5d445ddbe9a5a3e083bbd05463ebc93d63d63a93 100644 (file)
@@ -12,6 +12,9 @@
 // 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 {
@@ -130,8 +133,12 @@ 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.
     ZoneUpdaterLocal(ZoneTableSegment* segment, const LoadAction& load_action,
-                     const InstallAction& install_action);
+                     const InstallAction& install_action,
+                     const dns::Name& origin,
+                     const dns::RRClass& rrclass);
     /// \brief Destructor
     ~ZoneUpdaterLocal();
     /// \brief Loads the data.
@@ -158,6 +165,17 @@ public:
     /// Cleans up the memory used by load()ed zone if not yet installed, or
     /// the old zone replaced by install().
     virtual void cleanup();
+private:
+    ZoneTableSegment* segment_;
+    LoadAction load_action_;
+    InstallAction install_action_;
+    dns::Name origin_;
+    dns::RRClass rrclass_;
+    ZoneData* zone_data_;
+    // The load was performed
+    bool loaded_;
+    // The data are ready to be installed
+    bool data_ready_;
 };
 
 }