1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-06-11 10:42:35 +02:00

Removed Door State from Logic

Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
Ralf Ramsauer 2015-08-27 20:30:32 +02:00
parent a17fb4930f
commit e884dd87c4
4 changed files with 18 additions and 14 deletions

View File

@ -32,6 +32,11 @@ Door &Door::get()
return d; return d;
} }
const Door::State &Door::state() const
{
return _state;
}
void Door::lock() void Door::lock()
{ {
_l(LogLevel::notice, "Executing Pre Lock Script"); _l(LogLevel::notice, "Executing Pre Lock Script");

View File

@ -28,6 +28,9 @@ public:
enum class State {Locked, Unlocked}; enum class State {Locked, Unlocked};
// Current state of the door
const State &state() const;
// Lock the door // Lock the door
void lock(); void lock();
// Unlock the door // Unlock the door

View File

@ -117,14 +117,13 @@ out:
Logic::Response Logic::_lock() Logic::Response Logic::_lock()
{ {
if (_state == Door::State::Locked) if (_door.state() == Door::State::Locked)
{ {
_logger(LogLevel::warning, "Unable to lock: already closed"); _logger(LogLevel::warning, "Unable to lock: already closed");
return AlreadyLocked; return AlreadyLocked;
} }
_door.lock(); _door.lock();
_state = Door::State::Locked;
_createNewToken(false); _createNewToken(false);
return Success; return Success;
@ -132,18 +131,17 @@ Logic::Response Logic::_lock()
Logic::Response Logic::_unlock() Logic::Response Logic::_unlock()
{ {
_door.unlock(); const auto state = _door.state();
_createNewToken(false); _door.unlock();
_createNewToken(false);
if (_state == Door::State::Unlocked) if (state == Door::State::Unlocked)
{ {
_logger(LogLevel::warning, "Unable to unlock: already unlocked"); _logger(LogLevel::warning, "Unable to unlock: already unlocked");
return AlreadyUnlocked; return AlreadyUnlocked;
} else { }
_state = Door::State::Unlocked;
}
return Success; return Success;
} }
bool Logic::_checkToken(const string &strToken) bool Logic::_checkToken(const string &strToken)

View File

@ -97,8 +97,6 @@ private:
const std::string _bindDN; const std::string _bindDN;
// Prefix of the website // Prefix of the website
const std::string _webPrefix; const std::string _webPrefix;
Door::State _state = { Door::State::Locked };
}; };
#endif #endif