summaryrefslogtreecommitdiffstats
path: root/monitor.hpp
diff options
context:
space:
mode:
authorVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-04-04 14:05:09 +0530
committerVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-04-26 12:02:26 +0530
commit4902a10c9fabcdf5e1f2868f28cba2d571d55f03 (patch)
tree9f0662ade186a796fec8bb9d69338c5e55f19b79 /monitor.hpp
parentaffea8bfc77162d8631b48f1eb5e79c06b96302f (diff)
downloadphosphor-gpio-monitor-4902a10c9fabcdf5e1f2868f28cba2d571d55f03.tar.gz
phosphor-gpio-monitor-4902a10c9fabcdf5e1f2868f28cba2d571d55f03.zip
Populate the file descriptor for the device
On a GPIO chip, there could be many gpio lines and for each line, there would be a corresponding input device event file. To know the assertion state of a GPIO line, a descriptor is needed. This descriptor will later be plugged into sd_event so that the GPIO state changes can be caught and handled. Change-Id: Idc8c2b429688fea2a5124b96677085b1be48128b Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'monitor.hpp')
-rw-r--r--monitor.hpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/monitor.hpp b/monitor.hpp
new file mode 100644
index 0000000..9e3992d
--- /dev/null
+++ b/monitor.hpp
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <unistd.h>
+#include <string>
+#include <linux/input.h>
+#include "file.hpp"
+namespace phosphor
+{
+namespace gpio
+{
+/** @class Monitor
+ * @brief Responsible for catching GPIO state change
+ * condition and taking actions
+ */
+class Monitor
+{
+ public:
+ Monitor() = delete;
+ Monitor(const Monitor&) = delete;
+ Monitor& operator=(const Monitor&) = delete;
+ Monitor(Monitor&&) = delete;
+ Monitor& operator=(Monitor&&) = delete;
+
+ /** @brief Constructs Monitor object.
+ *
+ * @param[in] path - Path to gpio input device
+ * @param[in] key - GPIO key to monitor
+ * @param[in] polarity - GPIO assertion polarity to look for
+ * @param[in] target - systemd unit to be started on GPIO
+ * value change
+ */
+ Monitor(const std::string& path,
+ decltype(input_event::code) key,
+ decltype(input_event::value) polarity,
+ const std::string& target)
+ : path(path),
+ key(key),
+ polarity(polarity),
+ target(target),
+ fd(openDevice())
+ {
+ // Nothing
+ }
+
+ private:
+ /** @brief Absolute path of GPIO input device */
+ const std::string& path;
+
+ /** @brief GPIO key code that is of interest */
+ decltype(input_event::code) key;
+
+ /** @brief GPIO key value that is of interest */
+ decltype(input_event::value) polarity;
+
+ /** @brief Systemd unit to be started when the condition is met */
+ const std::string& target;
+
+ /** @brief Manages File descriptor */
+ FileDescriptor fd;
+
+ /** @brief Opens the device and populates the descriptor */
+ int openDevice();
+};
+
+} // namespace gpio
+} // namespace phosphor
OpenPOWER on IntegriCloud