diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-04-04 14:08:26 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2017-04-27 14:42:10 +0530 |
commit | ba7301300ef8f3950fa02b4675422cba6a98ee4b (patch) | |
tree | 489d5d55afeaf6399f700f88d1b0fe11670f8bff /monitor.cpp | |
parent | 0b95603eb48a72234b8fc618dcc4db13b6f4d079 (diff) | |
download | phosphor-gpio-monitor-ba7301300ef8f3950fa02b4675422cba6a98ee4b.tar.gz phosphor-gpio-monitor-ba7301300ef8f3950fa02b4675422cba6a98ee4b.zip |
Call defined target when GPIO line is asserted
Change-Id: Ia5445a8d6585acfec69783ba158c8d866d526e97
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'monitor.cpp')
-rw-r--r-- | monitor.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/monitor.cpp b/monitor.cpp index 5428c09..99eed03 100644 --- a/monitor.cpp +++ b/monitor.cpp @@ -17,11 +17,18 @@ #include <fcntl.h> #include <phosphor-logging/log.hpp> #include "monitor.hpp" +#include "config.h" + namespace phosphor { namespace gpio { +// systemd service to kick start a target. +constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; +constexpr auto SYSTEMD_ROOT = "/org/freedesktop/systemd1"; +constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; + using namespace phosphor::logging; // Populate the file descriptor for passed in device @@ -59,8 +66,32 @@ void Monitor::registerCallback() int Monitor::processEvents(sd_event_source* es, int fd, uint32_t revents, void* userData) { - // TODO. This calls into starting configured target - log<level::INFO>("Callback handler called"); + log<level::INFO>("GPIO line altered"); + auto monitor = static_cast<Monitor*>(userData); + // TODO : Need a way to check if the GPIO state change is what we wanted + return monitor->analyzeEvent(); +} + +// Analyzes the GPIO event +int Monitor::analyzeEvent() +{ + if(!target.empty()) + { + auto bus = sdbusplus::bus::new_default(); + auto method = bus.new_method_call(SYSTEMD_SERVICE, + SYSTEMD_ROOT, + SYSTEMD_INTERFACE, + "StartUnit"); + method.append(target); + method.append("replace"); + + // If there is any error, an exception would be thrown from here. + bus.call_noreply(method); + } + + // This marks the completion of handling the checkstop and app can exit + complete = true; + return 0; } |