mirror of
https://github.com/binary-kitchen/doorlockd
synced 2025-01-02 22:45:23 +01:00
Door: Refactor system() to own function
Preparatory work for script logging Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
573d9e7c65
commit
7e522e59af
@ -44,10 +44,10 @@
|
|||||||
#define SOUND_LOCK_BUTTON SOUNDS_LOCATION "lock_button.wav"
|
#define SOUND_LOCK_BUTTON SOUNDS_LOCATION "lock_button.wav"
|
||||||
#define SOUND_UNLOCK_BUTTON SOUNDS_LOCATION "unlock_button.wav"
|
#define SOUND_UNLOCK_BUTTON SOUNDS_LOCATION "unlock_button.wav"
|
||||||
|
|
||||||
#define PRE_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_lock &"
|
#define PRE_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_lock"
|
||||||
#define POST_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_lock &"
|
#define POST_LOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_lock"
|
||||||
#define PRE_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_unlock &"
|
#define PRE_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/pre_unlock"
|
||||||
#define POST_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_unlock &"
|
#define POST_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/post_unlock"
|
||||||
#define EMERGENCY_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/emergency_unlock &"
|
#define EMERGENCY_UNLOCK_SCRIPT "@CMAKE_INSTALL_PREFIX@/etc/doorlockd/emergency_unlock"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,7 +88,7 @@ void Door::_asyncRead()
|
|||||||
goto out;
|
goto out;
|
||||||
} else if (recvBuf == DOOR_EMERGENCY_UNLOCK) {
|
} else if (recvBuf == DOOR_EMERGENCY_UNLOCK) {
|
||||||
_logger(LogLevel::warning, "Someone did an emergency unlock!");
|
_logger(LogLevel::warning, "Someone did an emergency unlock!");
|
||||||
system(EMERGENCY_UNLOCK_SCRIPT);
|
_exec_and_log(EMERGENCY_UNLOCK_SCRIPT);
|
||||||
if (_doorCallback) {
|
if (_doorCallback) {
|
||||||
_doorCallback(Doormessage(false, false, true));
|
_doorCallback(Doormessage(false, false, true));
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ void Door::lock()
|
|||||||
|
|
||||||
|
|
||||||
_logger(LogLevel::notice, "Executing Pre Lock Script");
|
_logger(LogLevel::notice, "Executing Pre Lock Script");
|
||||||
system(PRE_LOCK_SCRIPT);
|
_exec_and_log(PRE_LOCK_SCRIPT);
|
||||||
|
|
||||||
if (_state == State::Locked) {
|
if (_state == State::Locked) {
|
||||||
_stateMutex.unlock();
|
_stateMutex.unlock();
|
||||||
@ -131,7 +131,7 @@ void Door::lock()
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
_logger(LogLevel::notice, "Executing Post Lock Script");
|
_logger(LogLevel::notice, "Executing Post Lock Script");
|
||||||
system(POST_LOCK_SCRIPT);
|
_exec_and_log(POST_LOCK_SCRIPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Door::unlock()
|
void Door::unlock()
|
||||||
@ -140,7 +140,7 @@ void Door::unlock()
|
|||||||
_schnapper = true;
|
_schnapper = true;
|
||||||
|
|
||||||
_logger(LogLevel::notice, "Executing Pre Unlock Script");
|
_logger(LogLevel::notice, "Executing Pre Unlock Script");
|
||||||
system(PRE_UNLOCK_SCRIPT);
|
_exec_and_log(PRE_UNLOCK_SCRIPT);
|
||||||
|
|
||||||
if(_state == State::Unlocked) {
|
if(_state == State::Unlocked) {
|
||||||
_stateMutex.unlock();
|
_stateMutex.unlock();
|
||||||
@ -173,7 +173,7 @@ void Door::unlock()
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
_logger(LogLevel::notice, "Executing Post Unlock Script");
|
_logger(LogLevel::notice, "Executing Post Unlock Script");
|
||||||
system(POST_UNLOCK_SCRIPT);
|
_exec_and_log(POST_UNLOCK_SCRIPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Door::_writeCMD(char c)
|
bool Door::_writeCMD(char c)
|
||||||
@ -198,3 +198,9 @@ void Door::setDoorCallback(DoorCallback doorCallback)
|
|||||||
{
|
{
|
||||||
_doorCallback = doorCallback;
|
_doorCallback = doorCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Door::_exec_and_log(const std::string &filename)
|
||||||
|
{
|
||||||
|
const std::string cmd = filename + " &";
|
||||||
|
::system(cmd.c_str());
|
||||||
|
}
|
||||||
|
@ -72,6 +72,8 @@ private:
|
|||||||
bool _writeCMD(char c);
|
bool _writeCMD(char c);
|
||||||
// Receives one byte and returns true or returns false on timeout
|
// Receives one byte and returns true or returns false on timeout
|
||||||
bool _readByte(char &byte, Milliseconds timeout);
|
bool _readByte(char &byte, Milliseconds timeout);
|
||||||
|
|
||||||
|
void _exec_and_log(const std::string &filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user