Add --continue argument
The monitor will exit when key is pressed.
Add --continue argument and if it is set to "true", the monitor will
continue after key is pressed.
This is useful in cases to monitor a button presses.
E.g. It can be used to monitor ID button and start a system unit
everytime when the button is pressed.
This argument is optional so it does not break the current code.
Tested: With "--continue=true", the monitor does not exit when the key
is pressed.
Without the argument of if it is set to other strings, the
monitor exits after the key is pressed.
Change-Id: I4f2ca16d7b26e10397181c83c2c5947ed5ce091f
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/monitor.hpp b/monitor.hpp
index 1dcef79..f4b07de 100644
--- a/monitor.hpp
+++ b/monitor.hpp
@@ -34,6 +34,7 @@
* @param[in] target - systemd unit to be started on GPIO
* value change
* @param[in] event - sd_event handler
+ * @param[in] continueRun - Whether to continue after key pressed
* @param[in] handler - IO callback handler. Defaults to one in this
* class
* @param[in] useEvDev - Whether to use EvDev to retrieve events
@@ -43,11 +44,13 @@
decltype(input_event::value) polarity,
const std::string& target,
EventPtr& event,
+ bool continueRun,
sd_event_io_handler_t handler = Monitor::processEvents,
bool useEvDev = true)
: Evdev(path, key, event, handler, useEvDev),
polarity(polarity),
- target(target) {};
+ target(target),
+ continueAfterKeyPress(continueRun) {};
/** @brief Callback handler when the FD has some activity on it
*
@@ -75,6 +78,9 @@
/** @brief Systemd unit to be started when the condition is met */
const std::string& target;
+ /** @brief If the monitor should continue after key press */
+ bool continueAfterKeyPress;
+
/** @brief Completion indicator */
bool complete = false;