Add clang-format to repo

Add clang-format to repo.

Change-Id: I3f8704d80dd0bdde0706ab189c68cffe6d347995
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/presence/argument.cpp b/presence/argument.cpp
index a4b664e..e256426 100644
--- a/presence/argument.cpp
+++ b/presence/argument.cpp
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
+#include "argument.hpp"
+
+#include <algorithm>
 #include <iostream>
 #include <iterator>
-#include <algorithm>
-#include "argument.hpp"
 
 namespace phosphor
 {
@@ -30,22 +31,21 @@
 const std::string ArgumentParser::emptyString = ""s;
 
 const char* ArgumentParser::optionStr = "p:k:n:i:d:?h";
-const option ArgumentParser::options[] =
-{
-    { "path",      required_argument,  nullptr,   'p' },
-    { "key",       required_argument,  nullptr,   'k' },
-    { "name",      required_argument,  nullptr,   'n' },
-    { "inventory", required_argument,  nullptr,   'i' },
-    { "drivers",   required_argument,  nullptr,   'd' },
-    { "help",      no_argument,        nullptr,   'h' },
-    { 0, 0, 0, 0},
+const option ArgumentParser::options[] = {
+    {"path", required_argument, nullptr, 'p'},
+    {"key", required_argument, nullptr, 'k'},
+    {"name", required_argument, nullptr, 'n'},
+    {"inventory", required_argument, nullptr, 'i'},
+    {"drivers", required_argument, nullptr, 'd'},
+    {"help", no_argument, nullptr, 'h'},
+    {0, 0, 0, 0},
 };
 
 ArgumentParser::ArgumentParser(int argc, char** argv)
 {
     auto option = 0;
-    while (-1 != (option = getopt_long(argc, argv,
-                                       optionStr, options, nullptr)))
+    while (-1 !=
+           (option = getopt_long(argc, argv, optionStr, options, nullptr)))
     {
         if ((option == '?') || (option == 'h'))
         {
@@ -85,16 +85,16 @@
     std::cerr << "Options:\n";
     std::cerr << "  --help                  Print this menu\n";
     std::cerr << "  --inventory=<inventory> Object path under inventory"
-              " that will be created\n";
+                 " that will be created\n";
     std::cerr << "  --path=<path>           Path of device to read for GPIO pin"
-              " state to determine presence of inventory item\n";
+                 " state to determine presence of inventory item\n";
     std::cerr << "  --key=<key>             Input GPIO key number\n";
     std::cerr << "  --name=<name>           Pretty name of the inventory"
-              " item\n";
+                 " item\n";
     std::cerr << "  --drivers=<drivers>     List of drivers to bind when card"
-              " is added and unbind when card is removed\n";
+                 " is added and unbind when card is removed\n";
     std::cerr << "                          Format is a space separated list"
-              " of path,device pairs.  For example:\n";
+                 " of path,device pairs.  For example:\n";
     std::cerr << "                          "
                  "/sys/bus/i2c/drivers/some-driver,3-0068\n";
     std::cerr << std::flush;
diff --git a/presence/gpio_presence.cpp b/presence/gpio_presence.cpp
index 4a11d98..1671721 100644
--- a/presence/gpio_presence.cpp
+++ b/presence/gpio_presence.cpp
@@ -1,11 +1,14 @@
+#include "gpio_presence.hpp"
+
+#include "xyz/openbmc_project/Common/error.hpp"
+
 #include <fcntl.h>
-#include <fstream>
 #include <libevdev/libevdev.h>
+
+#include <fstream>
+#include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include "xyz/openbmc_project/Common/error.hpp"
-#include "gpio_presence.hpp"
 
 namespace phosphor
 {
@@ -24,14 +27,11 @@
 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
 
-std::string getService(const std::string& path,
-                       const std::string& interface,
+std::string getService(const std::string& path, const std::string& interface,
                        sdbusplus::bus::bus& bus)
 {
-    auto mapperCall = bus.new_method_call(MAPPER_BUSNAME,
-                                          MAPPER_PATH,
-                                          MAPPER_INTERFACE,
-                                          "GetObject");
+    auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+                                          MAPPER_INTERFACE, "GetObject");
 
     mapperCall.append(path);
     mapperCall.append(std::vector<std::string>({interface}));
@@ -45,16 +45,14 @@
         elog<InternalFailure>();
     }
 
-
     std::map<std::string, std::vector<std::string>> mapperResponse;
     mapperResponseMsg.read(mapperResponse);
 
     if (mapperResponse.empty())
     {
-        log<level::ERR>(
-            "Error in mapper response for getting service name",
-            entry("PATH=%s", path.c_str()),
-            entry("INTERFACE=%s", interface.c_str()));
+        log<level::ERR>("Error in mapper response for getting service name",
+                        entry("PATH=%s", path.c_str()),
+                        entry("INTERFACE=%s", interface.c_str()));
         elog<InternalFailure>();
     }
 
@@ -65,8 +63,8 @@
 {
     auto present = false;
     auto value = static_cast<int>(0);
-    auto fetch_rc = libevdev_fetch_event_value(devicePtr.get(), EV_KEY,
-                    key, &value);
+    auto fetch_rc =
+        libevdev_fetch_event_value(devicePtr.get(), EV_KEY, key, &value);
     if (0 == fetch_rc)
     {
         log<level::ERR>("Device does not support event type",
@@ -83,8 +81,8 @@
 }
 
 // Callback handler when there is an activity on the FD
-int Presence::processEvents(sd_event_source* es, int fd,
-                            uint32_t revents, void* userData)
+int Presence::processEvents(sd_event_source* es, int fd, uint32_t revents,
+                            void* userData)
 {
     auto presence = static_cast<Presence*>(userData);
 
@@ -92,13 +90,14 @@
     return 0;
 }
 
-
 // Analyzes the GPIO event
 void Presence::analyzeEvent()
 {
 
     // Data returned
-    struct input_event ev {};
+    struct input_event ev
+    {
+    };
     int rc = 0;
 
     // While testing, observed that not having a loop here was leading
@@ -106,8 +105,8 @@
     while (rc >= 0)
     {
         // Wait until no more events are available on the device.
-        rc = libevdev_next_event(devicePtr.get(),
-                                 LIBEVDEV_READ_FLAG_NORMAL, &ev);
+        rc = libevdev_next_event(devicePtr.get(), LIBEVDEV_READ_FLAG_NORMAL,
+                                 &ev);
         if (rc < 0)
         {
             // There was an error waiting for events, mostly that there are no
@@ -145,8 +144,7 @@
 
     invProp.emplace("Present", present);
     invProp.emplace("PrettyName", name);
-    invIntf.emplace("xyz.openbmc_project.Inventory.Item",
-                    std::move(invProp));
+    invIntf.emplace("xyz.openbmc_project.Inventory.Item", std::move(invProp));
     invObj.emplace(std::move(inventory), std::move(invIntf));
 
     return invObj;
@@ -163,19 +161,15 @@
     auto invService = getService(INVENTORY_PATH, INVENTORY_INTF, bus);
 
     // Update inventory
-    auto invMsg = bus.new_method_call(invService.c_str(),
-                                      INVENTORY_PATH,
-                                      INVENTORY_INTF,
-                                      "Notify");
+    auto invMsg = bus.new_method_call(invService.c_str(), INVENTORY_PATH,
+                                      INVENTORY_INTF, "Notify");
     invMsg.append(std::move(invObj));
     auto invMgrResponseMsg = bus.call(invMsg);
     if (invMgrResponseMsg.is_method_error())
     {
-        log<level::ERR>(
-            "Error in inventory manager call to update inventory");
+        log<level::ERR>("Error in inventory manager call to update inventory");
         elog<InternalFailure>();
     }
-
 }
 
 void Presence::bindOrUnbindDrivers(bool present)
@@ -189,25 +183,21 @@
 
         if (present)
         {
-            log<level::INFO>(
-                    "Binding a device driver",
-                    entry("PATH=%s", path.c_str()),
-                    entry("DEVICE=%s", device.c_str()));
+            log<level::INFO>("Binding a device driver",
+                             entry("PATH=%s", path.c_str()),
+                             entry("DEVICE=%s", device.c_str()));
         }
         else
         {
-            log<level::INFO>(
-                    "Unbinding a device driver",
-                    entry("PATH=%s", path.c_str()),
-                    entry("DEVICE=%s", device.c_str()));
+            log<level::INFO>("Unbinding a device driver",
+                             entry("PATH=%s", path.c_str()),
+                             entry("DEVICE=%s", device.c_str()));
         }
 
         std::ofstream file;
 
-        file.exceptions(
-                std::ofstream::failbit |
-                std::ofstream::badbit |
-                std::ofstream::eofbit);
+        file.exceptions(std::ofstream::failbit | std::ofstream::badbit |
+                        std::ofstream::eofbit);
 
         try
         {
@@ -228,8 +218,6 @@
     }
 }
 
-
 } // namespace presence
 } // namespace gpio
 } // namespace phosphor
-
diff --git a/presence/gpio_presence.hpp b/presence/gpio_presence.hpp
index b5feddd..834a171 100644
--- a/presence/gpio_presence.hpp
+++ b/presence/gpio_presence.hpp
@@ -1,8 +1,10 @@
 #pragma once
+#include "evdev.hpp"
+
+#include <systemd/sd-event.h>
+
 #include <experimental/filesystem>
 #include <string>
-#include <systemd/sd-event.h>
-#include "evdev.hpp"
 
 namespace phosphor
 {
@@ -25,120 +27,114 @@
 class Presence : public 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>;
+    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:
-        Presence() = delete;
-        ~Presence() = default;
-        Presence(const Presence&) = delete;
-        Presence& operator=(const Presence&) = delete;
-        Presence(Presence&&) = delete;
-        Presence& operator=(Presence&&) = delete;
+  public:
+    Presence() = delete;
+    ~Presence() = default;
+    Presence(const Presence&) = delete;
+    Presence& operator=(const Presence&) = delete;
+    Presence(Presence&&) = delete;
+    Presence& operator=(Presence&&) = delete;
 
-        /** @brief Constructs Presence object.
-         *
-         *  @param[in] bus       - D-Bus bus Object
-         *  @param[in] inventory - Object path under inventory
-                                   to display this inventory item
-         *  @param[in] path      - Device path to read for GPIO pin state
-                                   to determine presence of inventory item
-         *  @param[in] key       - GPIO key to monitor
-         *  @param[in] name      - Pretty name of the inventory item
-         *  @param[in] event     - sd_event handler
-         *  @param[in] drivers   - list of device drivers to bind and unbind
-         *  @param[in] handler   - IO callback handler. Defaults to one in this
-         *                        class
-         */
-        Presence(sdbusplus::bus::bus& bus,
-                 const std::string& inventory,
-                 const std::string& path,
-                 const unsigned int key,
-                 const std::string& name,
-                 EventPtr& event,
-                 const std::vector<Driver>& drivers,
-                 sd_event_io_handler_t handler = Presence::processEvents) :
-            Evdev(path, key, event, handler, true),
-            bus(bus),
-            inventory(inventory),
-            name(name),
-            drivers(drivers)
-        {
-            determinePresence();
-        }
+    /** @brief Constructs Presence object.
+     *
+     *  @param[in] bus       - D-Bus bus Object
+     *  @param[in] inventory - Object path under inventory
+                               to display this inventory item
+     *  @param[in] path      - Device path to read for GPIO pin state
+                               to determine presence of inventory item
+     *  @param[in] key       - GPIO key to monitor
+     *  @param[in] name      - Pretty name of the inventory item
+     *  @param[in] event     - sd_event handler
+     *  @param[in] drivers   - list of device drivers to bind and unbind
+     *  @param[in] handler   - IO callback handler. Defaults to one in this
+     *                        class
+     */
+    Presence(sdbusplus::bus::bus& bus, const std::string& inventory,
+             const std::string& path, const unsigned int key,
+             const std::string& name, EventPtr& event,
+             const std::vector<Driver>& drivers,
+             sd_event_io_handler_t handler = Presence::processEvents) :
+        Evdev(path, key, event, handler, true),
+        bus(bus), inventory(inventory), name(name), drivers(drivers)
+    {
+        determinePresence();
+    }
 
-        /** @brief Callback handler when the FD has some activity on it
-         *
-         *  @param[in] es       - Populated event source
-         *  @param[in] fd       - Associated File descriptor
-         *  @param[in] revents  - Type of event
-         *  @param[in] userData - User data that was passed during registration
-         *
-         *  @return             - 0 or positive number on success and negative
-         *                        errno otherwise
-         */
-        static int processEvents(sd_event_source* es, int fd,
-                                 uint32_t revents, void* userData);
+    /** @brief Callback handler when the FD has some activity on it
+     *
+     *  @param[in] es       - Populated event source
+     *  @param[in] fd       - Associated File descriptor
+     *  @param[in] revents  - Type of event
+     *  @param[in] userData - User data that was passed during registration
+     *
+     *  @return             - 0 or positive number on success and negative
+     *                        errno otherwise
+     */
+    static int processEvents(sd_event_source* es, int fd, uint32_t revents,
+                             void* userData);
 
-    private:
-        /**
-         * @brief Update the present property for the inventory item.
-         *
-         * @param[in] present - What the present property should be set to.
-         */
-        void updateInventory(bool present);
+  private:
+    /**
+     * @brief Update the present property for the inventory item.
+     *
+     * @param[in] present - What the present property should be set to.
+     */
+    void updateInventory(bool present);
 
-        /**
-         * @brief Construct the inventory object map for the inventory item.
-         *
-         * @param[in] present - What the present property should be set to.
-         *
-         * @return The inventory object map to update inventory
-         */
-        ObjectMap getObjectMap(bool present);
+    /**
+     * @brief Construct the inventory object map for the inventory item.
+     *
+     * @param[in] present - What the present property should be set to.
+     *
+     * @return The inventory object map to update inventory
+     */
+    ObjectMap getObjectMap(bool present);
 
-        /** @brief Connection for sdbusplus bus */
-        sdbusplus::bus::bus& bus;
+    /** @brief Connection for sdbusplus bus */
+    sdbusplus::bus::bus& bus;
 
-        /**
-         * @brief Read the GPIO device to determine initial presence and set
-         *        present property at D-Bus path.
-         */
-        void determinePresence();
+    /**
+     * @brief Read the GPIO device to determine initial presence and set
+     *        present property at D-Bus path.
+     */
+    void determinePresence();
 
-        /** @brief Object path under inventory to display this inventory item */
-        const std::string inventory;
+    /** @brief Object path under inventory to display this inventory item */
+    const std::string inventory;
 
-        /** @brief Pretty name of the inventory item*/
-        const std::string name;
+    /** @brief Pretty name of the inventory item*/
+    const std::string name;
 
-        /** @brief Analyzes the GPIO event and update present property*/
-        void analyzeEvent();
+    /** @brief Analyzes the GPIO event and update present property*/
+    void analyzeEvent();
 
-        /** @brief  Vector of path and device tuples to bind/unbind*/
-        const std::vector<Driver> drivers;
+    /** @brief  Vector of path and device tuples to bind/unbind*/
+    const std::vector<Driver> drivers;
 
-        /**
-         * @brief Binds or unbinds drivers
-         *
-         * Called when a presence change is detected to either
-         * bind the drivers for the new card or unbind them for
-         * the just removed card.  Operates on the drivers vector.
-         *
-         * Writes <device> to <path>/bind (or unbind)
-         *
-         * @param present - when true, will bind the drivers
-         *                  when false, will unbind them
-         */
-        void bindOrUnbindDrivers(bool present);
+    /**
+     * @brief Binds or unbinds drivers
+     *
+     * Called when a presence change is detected to either
+     * bind the drivers for the new card or unbind them for
+     * the just removed card.  Operates on the drivers vector.
+     *
+     * Writes <device> to <path>/bind (or unbind)
+     *
+     * @param present - when true, will bind the drivers
+     *                  when false, will unbind them
+     */
+    void bindOrUnbindDrivers(bool present);
 };
 
 /**
@@ -151,11 +147,9 @@
  *
  * @return The service name
  */
-std::string getService(const std::string& path,
-                       const std::string& interface,
+std::string getService(const std::string& path, const std::string& interface,
                        sdbusplus::bus::bus& bus);
 
 } // namespace presence
 } // namespace gpio
 } // namespace phosphor
-
diff --git a/presence/main.cpp b/presence/main.cpp
index 1eaa18b..16866d4 100644
--- a/presence/main.cpp
+++ b/presence/main.cpp
@@ -1,9 +1,11 @@
-#include <iostream>
-#include <systemd/sd-event.h>
-#include <phosphor-logging/log.hpp>
 #include "argument.hpp"
 #include "gpio_presence.hpp"
 
+#include <systemd/sd-event.h>
+
+#include <iostream>
+#include <phosphor-logging/log.hpp>
+
 using namespace phosphor::logging;
 using namespace phosphor::gpio;
 using namespace phosphor::gpio::presence;
@@ -27,7 +29,7 @@
     {
         std::string entry;
 
-        //Extract each path,device pair
+        // Extract each path,device pair
         stream >> entry;
 
         if (entry.empty())
@@ -35,7 +37,7 @@
             break;
         }
 
-        //Extract the path and device and save them
+        // Extract the path and device and save them
         auto pos = entry.rfind(',');
         if (pos != std::string::npos)
         {
@@ -88,7 +90,7 @@
 
     std::vector<Driver> driverList;
 
-    //Driver list is optional
+    // Driver list is optional
     if (drivers != ArgumentParser::emptyString)
     {
         if (getDrivers(drivers, driverList) < 0)
@@ -110,13 +112,13 @@
     event = nullptr;
 
     auto name = options["name"];
-    Presence presence(
-            bus, inventory, path, std::stoul(key), name, eventP, driverList);
+    Presence presence(bus, inventory, path, std::stoul(key), name, eventP,
+                      driverList);
 
     while (true)
     {
         // -1 denotes wait forever
-        rc = sd_event_run(eventP.get(), (uint64_t) - 1);
+        rc = sd_event_run(eventP.get(), (uint64_t)-1);
         if (rc < 0)
         {
             log<level::ERR>("Failure in processing request",
@@ -126,4 +128,3 @@
     }
     return rc;
 }
-