From: Michal 'vorner' Vaner Date: Thu, 11 Oct 2012 17:52:12 +0000 (+0200) Subject: [2207] Implementation of the zone updater X-Git-Tag: trac2402_base~12^2~31 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e5ad36f38f6066c50059ea02e06245d7bc5c7efd;p=thirdparty%2Fkea.git [2207] Implementation of the zone updater 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. --- diff --git a/src/lib/datasrc/memory/zone_updater.cc b/src/lib/datasrc/memory/zone_updater.cc index 03c8ece123..40d55eeb12 100644 --- a/src/lib/datasrc/memory/zone_updater.cc +++ b/src/lib/datasrc/memory/zone_updater.cc @@ -13,3 +13,78 @@ // PERFORMANCE OF THIS SOFTWARE. #include "zone_updater.h" +#include "zone_data.h" +#include "zone_table_segment.h" + +#include + +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 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; + } +} + +} +} +} diff --git a/src/lib/datasrc/memory/zone_updater.h b/src/lib/datasrc/memory/zone_updater.h index 9658866125..5d445ddbe9 100644 --- a/src/lib/datasrc/memory/zone_updater.h +++ b/src/lib/datasrc/memory/zone_updater.h @@ -12,6 +12,9 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. +#include +#include + #include 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_; }; }