diff options
author | Gunnar Mills <gmills@us.ibm.com> | 2017-07-27 15:22:42 -0500 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2017-07-28 12:34:51 -0500 |
commit | 9925857a9ef0e47f105a21186a809a3b094461b3 (patch) | |
tree | 481de329c30d097c96e6aab93af86fff0f1d12e6 /monitor.hpp | |
parent | 835dfb8877fd2e78281e22b8b08dc29e0e9ef5a5 (diff) | |
download | phosphor-gpio-monitor-9925857a9ef0e47f105a21186a809a3b094461b3.tar.gz phosphor-gpio-monitor-9925857a9ef0e47f105a21186a809a3b094461b3.zip |
Refactor GPIO Monitor class
Refactor the GPIO Monitor class to use a common class, Evdev,
to inherit from. Evdev does the basic libevdev handling.
Change-Id: I427aa9720b0bbbea0284c0babcc03ece92e55f5e
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
Diffstat (limited to 'monitor.hpp')
-rw-r--r-- | monitor.hpp | 86 |
1 files changed, 6 insertions, 80 deletions
diff --git a/monitor.hpp b/monitor.hpp index bffb1d4..1dcef79 100644 --- a/monitor.hpp +++ b/monitor.hpp @@ -3,50 +3,20 @@ #include <unistd.h> #include <string> #include <linux/input.h> -#include <libevdev/libevdev.h> #include <systemd/sd-event.h> #include <sdbusplus/bus.hpp> -#include "file.hpp" +#include "evdev.hpp" + namespace phosphor { namespace gpio { -/* Need a custom deleter for freeing up sd_event */ -struct EventDeleter -{ - void operator()(sd_event* event) const - { - event = sd_event_unref(event); - } -}; -using EventPtr = std::unique_ptr<sd_event, EventDeleter>; - -/* Need a custom deleter for freeing up sd_event_source */ -struct EventSourceDeleter -{ - void operator()(sd_event_source* eventSource) const - { - eventSource = sd_event_source_unref(eventSource); - } -}; -using EventSourcePtr = std::unique_ptr<sd_event_source, EventSourceDeleter>; - -/* Need a custom deleter for freeing up evdev struct */ -struct EvdevDeleter -{ - void operator()(struct libevdev* device) const - { - libevdev_free(device); - } -}; -using EvdevPtr = std::unique_ptr<struct libevdev, EvdevDeleter>; - /** @class Monitor * @brief Responsible for catching GPIO state change - * condition and taking actions + * condition and starting systemd targets. */ -class Monitor +class Monitor : public Evdev { public: Monitor() = delete; @@ -75,23 +45,9 @@ class Monitor EventPtr& event, sd_event_io_handler_t handler = Monitor::processEvents, bool useEvDev = true) - : path(path), - key(key), + : Evdev(path, key, event, handler, useEvDev), polarity(polarity), - target(target), - event(event), - callbackHandler(handler), - fd(openDevice()) - { - if (useEvDev) - { - // If we are asked to use EvDev, do that initialization. - initEvDev(); - } - - // And register callback handler when FD has some data - registerCallback(); - } + target(target) {}; /** @brief Callback handler when the FD has some activity on it * @@ -113,47 +69,17 @@ class Monitor } 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 Monitor to sd_event */ - EventPtr& event; - - /** @brief event source */ - EventSourcePtr eventSource; - - /** @brief Callback handler when the FD has some data */ - sd_event_io_handler_t callbackHandler; - - /** @brief File descriptor manager */ - FileDescriptor fd; - - /** event structure */ - EvdevPtr device; - /** @brief Completion indicator */ bool complete = false; - /** @brief Opens the device and populates the descriptor */ - int openDevice(); - - /** @brief attaches FD to events and sets up callback handler */ - void registerCallback(); - /** @brief Analyzes the GPIO event and starts configured target */ void analyzeEvent(); - - /** @brief Initializes evdev handle with the fd */ - void initEvDev(); }; } // namespace gpio |