mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
[2207] Use state variable
Instead of several boolean variables.
This commit is contained in:
@@ -33,8 +33,7 @@ ZoneWriterLocal::ZoneWriterLocal(ZoneTableSegmentLocal* segment,
|
||||
origin_(origin),
|
||||
rrclass_(rrclass),
|
||||
zone_data_(NULL),
|
||||
loaded_(false),
|
||||
data_ready_(false)
|
||||
state_(ZW_UNUSED)
|
||||
{}
|
||||
|
||||
ZoneWriterLocal::~ZoneWriterLocal() {
|
||||
@@ -45,7 +44,7 @@ ZoneWriterLocal::~ZoneWriterLocal() {
|
||||
|
||||
void
|
||||
ZoneWriterLocal::load() {
|
||||
if (loaded_) {
|
||||
if (state_ != ZW_UNUSED) {
|
||||
isc_throw(isc::InvalidOperation, "Trying to load twice");
|
||||
}
|
||||
|
||||
@@ -56,13 +55,12 @@ ZoneWriterLocal::load() {
|
||||
isc_throw(isc::InvalidOperation, "No data returned from load action");
|
||||
}
|
||||
|
||||
loaded_ = true;
|
||||
data_ready_ = true;
|
||||
state_ = ZW_LOADED;
|
||||
}
|
||||
|
||||
void
|
||||
ZoneWriterLocal::install() {
|
||||
if (!data_ready_) {
|
||||
if (state_ != ZW_LOADED) {
|
||||
isc_throw(isc::InvalidOperation, "No data to install");
|
||||
}
|
||||
|
||||
@@ -75,7 +73,7 @@ ZoneWriterLocal::install() {
|
||||
segment_->getMemorySegment(),
|
||||
rrclass_, origin_, zone_data_));
|
||||
|
||||
data_ready_ = false;
|
||||
state_ = ZW_INSTALLED;
|
||||
zone_data_ = result.zone_data;
|
||||
}
|
||||
|
||||
@@ -86,7 +84,7 @@ ZoneWriterLocal::cleanup() {
|
||||
if (zone_data_ != NULL) {
|
||||
ZoneData::destroy(segment_->getMemorySegment(), zone_data_, rrclass_);
|
||||
zone_data_ = NULL;
|
||||
data_ready_ = false;
|
||||
state_ = ZW_CLEANED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -79,10 +79,13 @@ private:
|
||||
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_;
|
||||
enum State {
|
||||
ZW_UNUSED,
|
||||
ZW_LOADED,
|
||||
ZW_INSTALLED,
|
||||
ZW_CLEANED
|
||||
};
|
||||
State state_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user