1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 02:14:26 +01: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;
}
const Door::State &Door::state() const
{
return _state;
}
void Door::lock()
{
_l(LogLevel::notice, "Executing Pre Lock Script");

View File

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

View File

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

View File

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