// 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;
+ }
+}
+
+}
+}
+}
// 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 {
/// \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.
/// 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_;
};
}