summaryrefslogtreecommitdiffstats
path: root/monitor.cpp
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.cpp
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.cpp')
-rw-r--r--monitor.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/monitor.cpp b/monitor.cpp
new file mode 100644
index 0000000..29d9d6d
--- /dev/null
+++ b/monitor.cpp
@@ -0,0 +1,41 @@
+/**
+ * Copyright © 2016 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <fcntl.h>
+#include <phosphor-logging/log.hpp>
+#include "monitor.hpp"
+namespace phosphor
+{
+namespace gpio
+{
+
+// Populate the file descriptor for passed in device
+int Monitor::openDevice()
+{
+ using namespace phosphor::logging;
+
+ int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ log<level::ERR>("Failed to open device",
+ entry("PATH=%s", path.c_str()));
+ throw std::runtime_error("Failed to open device");
+ }
+ return fd;
+}
+
+} // namespace gpio
+} // namespace phosphor
OpenPOWER on IntegriCloud