summaryrefslogtreecommitdiffstats
path: root/evdev.hpp
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-11-01 16:52:10 -0700
committerPatrick Venture <venture@google.com>2018-11-01 16:59:54 -0700
commitdace680fa404d7c02a68db105fd7b958b4681442 (patch)
tree6d447ced41a2d1ef9bbd8206d52099609cd973d1 /evdev.hpp
parent3c4a23e7764c7785d18cb30340a6d185022a797a (diff)
downloadphosphor-gpio-monitor-dace680fa404d7c02a68db105fd7b958b4681442.tar.gz
phosphor-gpio-monitor-dace680fa404d7c02a68db105fd7b958b4681442.zip
Add clang-format to repo
Add clang-format to repo. Change-Id: I3f8704d80dd0bdde0706ab189c68cffe6d347995 Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'evdev.hpp')
-rw-r--r--evdev.hpp137
1 files changed, 68 insertions, 69 deletions
diff --git a/evdev.hpp b/evdev.hpp
index 353c593..eb7781b 100644
--- a/evdev.hpp
+++ b/evdev.hpp
@@ -1,9 +1,14 @@
#pragma once
-#include <string>
-#include <systemd/sd-event.h>
-#include <libevdev/libevdev.h>
#include "file.hpp"
+#include <libevdev/libevdev.h>
+#include <systemd/sd-event.h>
+
+#include <map>
+#include <memory>
+#include <sdbusplus/message.hpp>
+#include <string>
+
namespace phosphor
{
namespace gpio
@@ -46,85 +51,79 @@ using EvdevPtr = std::unique_ptr<struct libevdev, FreeEvDev>;
class Evdev
{
- using Property = std::string;
- using Value = sdbusplus::message::variant<bool, std::string>;
- // Association between property and its value
- using PropertyMap = std::map<Property, Value>;
- using Interface = std::string;
- // Association between interface and the D-Bus property
- using InterfaceMap = std::map<Interface, PropertyMap>;
- using Object = sdbusplus::message::object_path;
- // Association between object and the interface
- using ObjectMap = std::map<Object, InterfaceMap>;
-
- public:
- Evdev() = delete;
- ~Evdev() = default;
- Evdev(const Evdev&) = delete;
- Evdev& operator=(const Evdev&) = delete;
- Evdev(Evdev&&) = delete;
- Evdev& operator=(Evdev&&) = delete;
-
- /** @brief Constructs Evdev object.
- *
- * @param[in] path - Device path to read for GPIO pin state
- * @param[in] key - GPIO key to monitor
- * @param[in] event - sd_event handler
- * @param[in] handler - IO callback handler.
- * @param[in] useEvDev - Whether to use EvDev to retrieve events
- */
- Evdev(const std::string& path,
- const unsigned int key,
- EventPtr& event,
- sd_event_io_handler_t handler,
- bool useEvDev = true) :
- path(path),
- key(key),
- event(event),
- callbackHandler(handler),
- fd(openDevice())
+ using Property = std::string;
+ using Value = sdbusplus::message::variant<bool, std::string>;
+ // Association between property and its value
+ using PropertyMap = std::map<Property, Value>;
+ using Interface = std::string;
+ // Association between interface and the D-Bus property
+ using InterfaceMap = std::map<Interface, PropertyMap>;
+ using Object = sdbusplus::message::object_path;
+ // Association between object and the interface
+ using ObjectMap = std::map<Object, InterfaceMap>;
+
+ public:
+ Evdev() = delete;
+ ~Evdev() = default;
+ Evdev(const Evdev&) = delete;
+ Evdev& operator=(const Evdev&) = delete;
+ Evdev(Evdev&&) = delete;
+ Evdev& operator=(Evdev&&) = delete;
+
+ /** @brief Constructs Evdev object.
+ *
+ * @param[in] path - Device path to read for GPIO pin state
+ * @param[in] key - GPIO key to monitor
+ * @param[in] event - sd_event handler
+ * @param[in] handler - IO callback handler.
+ * @param[in] useEvDev - Whether to use EvDev to retrieve events
+ */
+ Evdev(const std::string& path, const unsigned int key, EventPtr& event,
+ sd_event_io_handler_t handler, bool useEvDev = true) :
+ path(path),
+ key(key), event(event), callbackHandler(handler), fd(openDevice())
+ {
+ if (useEvDev)
{
- if (useEvDev)
- {
- // If we are asked to use EvDev, do that initialization.
- initEvDev();
- }
-
- // Register callback handler when FD has some data
- registerCallback();
+ // If we are asked to use EvDev, do that initialization.
+ initEvDev();
}
- protected:
- /** @brief Device path to read for GPIO pin state */
- const std::string path;
+ // Register callback handler when FD has some data
+ registerCallback();
+ }
+
+ protected:
+ /** @brief Device path to read for GPIO pin state */
+ const std::string path;
- /** @brief GPIO key to monitor */
- const unsigned int key;
+ /** @brief GPIO key to monitor */
+ const unsigned int key;
- /** @brief Event structure */
- EvdevPtr devicePtr;
+ /** @brief Event structure */
+ EvdevPtr devicePtr;
- /** @brief Monitor to sd_event */
- EventPtr& event;
+ /** @brief Monitor to sd_event */
+ EventPtr& event;
- /** @brief Callback handler when the FD has some data */
- sd_event_io_handler_t callbackHandler;
+ /** @brief Callback handler when the FD has some data */
+ sd_event_io_handler_t callbackHandler;
- /** @brief event source */
- EventSourcePtr eventSource;
+ /** @brief event source */
+ EventSourcePtr eventSource;
- /** @brief Opens the device and populates the descriptor */
- int openDevice();
+ /** @brief Opens the device and populates the descriptor */
+ int openDevice();
- /** @brief attaches FD to events and sets up callback handler */
- void registerCallback();
+ /** @brief attaches FD to events and sets up callback handler */
+ void registerCallback();
- /** @brief File descriptor manager */
- FileDescriptor fd;
+ /** @brief File descriptor manager */
+ FileDescriptor fd;
- /** @brief Initializes evdev handle with the fd */
- void initEvDev();
+ /** @brief Initializes evdev handle with the fd */
+ void initEvDev();
};
} // namespace gpio
OpenPOWER on IntegriCloud