add .clang-format

Change-Id: I7c2a527b4751a560703a61fcbe9638b150546af5
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/storagehandler.cpp b/storagehandler.cpp
index f0997e8..72a0c08 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -1,49 +1,52 @@
-#include <algorithm>
 #include <arpa/inet.h>
+
+#include <algorithm>
 #include <chrono>
 #include <cstdio>
 #if __has_include(<filesystem>)
 #include <filesystem>
 #elif __has_include(<experimental/filesystem>)
 #include <experimental/filesystem>
-namespace std {
-  // splice experimental::filesystem into std
-  namespace filesystem = std::experimental::filesystem;
-}
+namespace std
+{
+// splice experimental::filesystem into std
+namespace filesystem = std::experimental::filesystem;
+} // namespace std
 #else
-#  error filesystem not available
+#error filesystem not available
 #endif
-#include <mapper.h>
-#include <string>
-#include <systemd/sd-bus.h>
-
-#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <sdbusplus/server.hpp>
-
 #include "fruread.hpp"
-#include "host-ipmid/ipmid-api.h"
 #include "read_fru_data.hpp"
 #include "selutility.hpp"
+#include "utils.hpp"
+
+#include <mapper.h>
+#include <systemd/sd-bus.h>
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/server.hpp>
+#include <string>
+#include <xyz/openbmc_project/Common/error.hpp>
+
+#include "host-ipmid/ipmid-api.h"
+#include "sensorhandler.h"
 #include "storageaddsel.h"
 #include "storagehandler.h"
-#include "utils.hpp"
-#include "xyz/openbmc_project/Common/error.hpp"
-#include "sensorhandler.h"
-
 
 void register_netfn_storage_functions() __attribute__((constructor));
 
-unsigned int   g_sel_time    = 0xFFFFFFFF;
+unsigned int g_sel_time = 0xFFFFFFFF;
 extern unsigned short g_sel_reserve;
 extern const ipmi::sensor::IdInfoMap sensors;
 extern const FruMap frus;
 
-namespace {
+namespace
+{
 constexpr auto TIME_INTERFACE = "xyz.openbmc_project.Time.EpochTime";
 constexpr auto HOST_TIME_PATH = "/xyz/openbmc_project/time/host";
 constexpr auto DBUS_PROPERTIES = "org.freedesktop.DBus.Properties";
-constexpr auto PROPERTY_ELAPSED= "Elapsed";
+constexpr auto PROPERTY_ELAPSED = "Elapsed";
 
 const char* getTimeString(const uint64_t& usecSinceEpoch)
 {
@@ -52,26 +55,26 @@
     auto t = system_clock::to_time_t(tp);
     return std::ctime(&t);
 }
-}
+} // namespace
 
 namespace cache
 {
-    /*
-     * This cache contains the object paths of the logging entries sorted in the
-     * order of the filename(numeric order). The cache is initialized by
-     * invoking readLoggingObjectPaths with the cache as the parameter. The
-     * cache is invoked in the execution of the Get SEL info and Delete SEL
-     * entry command. The Get SEL Info command is typically invoked before the
-     * Get SEL entry command, so the cache is utilized for responding to Get SEL
-     * entry command. The cache is invalidated by clearing after Delete SEL
-     * entry and Clear SEL command.
-     */
-    ipmi::sel::ObjectPaths paths;
+/*
+ * This cache contains the object paths of the logging entries sorted in the
+ * order of the filename(numeric order). The cache is initialized by
+ * invoking readLoggingObjectPaths with the cache as the parameter. The
+ * cache is invoked in the execution of the Get SEL info and Delete SEL
+ * entry command. The Get SEL Info command is typically invoked before the
+ * Get SEL entry command, so the cache is utilized for responding to Get SEL
+ * entry command. The cache is invalidated by clearing after Delete SEL
+ * entry and Clear SEL command.
+ */
+ipmi::sel::ObjectPaths paths;
 
-} // namespace objectPathsCache
+} // namespace cache
 
 using InternalFailure =
-        sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+    sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 using namespace phosphor::logging;
 using namespace ipmi::fru;
 
@@ -84,10 +87,11 @@
     words  ///< Device is accessed by words
 };
 
-
 ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                              ipmi_request_t request, ipmi_response_t response,
-                              ipmi_data_len_t data_len, ipmi_context_t context)
+                                 ipmi_request_t request,
+                                 ipmi_response_t response,
+                                 ipmi_data_len_t data_len,
+                                 ipmi_context_t context)
 {
     // Status code.
     ipmi_ret_t rc = IPMI_CC_INVALID;
@@ -100,8 +104,8 @@
                       ipmi_data_len_t data_len, ipmi_context_t context)
 {
     std::vector<uint8_t> outPayload(sizeof(ipmi::sel::GetSELInfoResponse));
-    auto responseData = reinterpret_cast<ipmi::sel::GetSELInfoResponse*>
-            (outPayload.data());
+    auto responseData =
+        reinterpret_cast<ipmi::sel::GetSELInfoResponse*>(outPayload.data());
 
     responseData->selVersion = ipmi::sel::selVersion;
     // Last erase timestamp is not available from log manager.
@@ -119,8 +123,7 @@
         try
         {
             responseData->addTimeStamp = static_cast<uint32_t>(
-                    (ipmi::sel::getEntryTimeStamp(cache::paths.back())
-                    .count()));
+                (ipmi::sel::getEntryTimeStamp(cache::paths.back()).count()));
         }
         catch (InternalFailure& e)
         {
@@ -141,8 +144,8 @@
                        ipmi_request_t request, ipmi_response_t response,
                        ipmi_data_len_t data_len, ipmi_context_t context)
 {
-    auto requestData = reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>
-                   (request);
+    auto requestData =
+        reinterpret_cast<const ipmi::sel::GetSELEntryRequest*>(request);
 
     if (requestData->reservationID != 0)
     {
@@ -183,7 +186,7 @@
         }
     }
 
-    ipmi::sel::GetSELEntryResponse record {};
+    ipmi::sel::GetSELEntryResponse record{};
 
     // Convert the log entry into SEL record.
     try
@@ -202,9 +205,8 @@
         return IPMI_CC_UNSPECIFIED_ERROR;
     }
 
-
     // Identify the next SEL record ID
-    if(iter != cache::paths.end())
+    if (iter != cache::paths.end())
     {
         ++iter;
         if (iter == cache::paths.end())
@@ -215,8 +217,8 @@
         {
             namespace fs = std::filesystem;
             fs::path path(*iter);
-            record.nextRecordID = static_cast<uint16_t>
-                     (std::stoul(std::string(path.filename().c_str())));
+            record.nextRecordID = static_cast<uint16_t>(
+                std::stoul(std::string(path.filename().c_str())));
         }
     }
     else
@@ -239,8 +241,8 @@
         }
 
         auto diff = ipmi::sel::selRecordSize - requestData->offset;
-        auto readLength = std::min(diff,
-                                   static_cast<int>(requestData->readLength));
+        auto readLength =
+            std::min(diff, static_cast<int>(requestData->readLength));
 
         memcpy(response, &record.nextRecordID, sizeof(record.nextRecordID));
         memcpy(static_cast<uint8_t*>(response) + sizeof(record.nextRecordID),
@@ -256,8 +258,8 @@
                           ipmi_data_len_t data_len, ipmi_context_t context)
 {
     namespace fs = std::experimental::filesystem;
-    auto requestData = reinterpret_cast<const ipmi::sel::DeleteSELEntryRequest*>
-            (request);
+    auto requestData =
+        reinterpret_cast<const ipmi::sel::DeleteSELEntryRequest*>(request);
 
     if (g_sel_reserve != requestData->reservationID)
     {
@@ -280,15 +282,15 @@
     {
         iter = cache::paths.begin();
         fs::path path(*iter);
-        delRecordID = static_cast<uint16_t>
-                (std::stoul(std::string(path.filename().c_str())));
+        delRecordID = static_cast<uint16_t>(
+            std::stoul(std::string(path.filename().c_str())));
     }
     else if (requestData->selRecordID == ipmi::sel::lastEntry)
     {
         iter = cache::paths.end();
         fs::path path(*iter);
-        delRecordID = static_cast<uint16_t>
-                (std::stoul(std::string(path.filename().c_str())));
+        delRecordID = static_cast<uint16_t>(
+            std::stoul(std::string(path.filename().c_str())));
     }
     else
     {
@@ -318,10 +320,8 @@
         return IPMI_CC_UNSPECIFIED_ERROR;
     }
 
-    auto methodCall = bus.new_method_call(service.c_str(),
-                                          (*iter).c_str(),
-                                          ipmi::sel::logDeleteIntf,
-                                          "Delete");
+    auto methodCall = bus.new_method_call(service.c_str(), (*iter).c_str(),
+                                          ipmi::sel::logDeleteIntf, "Delete");
     auto reply = bus.call(methodCall);
     if (reply.is_method_error())
     {
@@ -341,8 +341,8 @@
                     ipmi_response_t response, ipmi_data_len_t data_len,
                     ipmi_context_t context)
 {
-    auto requestData = reinterpret_cast<const ipmi::sel::ClearSELRequest*>
-            (request);
+    auto requestData =
+        reinterpret_cast<const ipmi::sel::ClearSELRequest*>(request);
 
     if (g_sel_reserve != requestData->reservationID)
     {
@@ -350,8 +350,7 @@
         return IPMI_CC_INVALID_RESERVATION_ID;
     }
 
-    if (requestData->charC != 'C' ||
-        requestData->charL != 'L' ||
+    if (requestData->charC != 'C' || requestData->charL != 'L' ||
         requestData->charR != 'R')
     {
         *data_len = 0;
@@ -374,10 +373,9 @@
     sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
     auto depth = 0;
 
-    auto mapperCall = bus.new_method_call(ipmi::sel::mapperBusName,
-                                          ipmi::sel::mapperObjPath,
-                                          ipmi::sel::mapperIntf,
-                                          "GetSubTreePaths");
+    auto mapperCall =
+        bus.new_method_call(ipmi::sel::mapperBusName, ipmi::sel::mapperObjPath,
+                            ipmi::sel::mapperIntf, "GetSubTreePaths");
     mapperCall.append(ipmi::sel::logBasePath);
     mapperCall.append(depth);
     mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf}));
@@ -403,8 +401,7 @@
 
     try
     {
-        service = ipmi::getService(bus,
-                                   ipmi::sel::logDeleteIntf,
+        service = ipmi::getService(bus, ipmi::sel::logDeleteIntf,
                                    objectPaths.front());
     }
     catch (const std::runtime_error& e)
@@ -416,10 +413,8 @@
 
     for (const auto& iter : objectPaths)
     {
-        auto methodCall = bus.new_method_call(service.c_str(),
-                                              iter.c_str(),
-                                              ipmi::sel::logDeleteIntf,
-                                              "Delete");
+        auto methodCall = bus.new_method_call(
+            service.c_str(), iter.c_str(), ipmi::sel::logDeleteIntf, "Delete");
 
         auto reply = bus.call(methodCall);
         if (reply.is_method_error())
@@ -437,8 +432,10 @@
 }
 
 ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                              ipmi_request_t request, ipmi_response_t response,
-                              ipmi_data_len_t data_len, ipmi_context_t context)
+                                     ipmi_request_t request,
+                                     ipmi_response_t response,
+                                     ipmi_data_len_t data_len,
+                                     ipmi_context_t context)
 {
     using namespace std::chrono;
     uint64_t host_time_usec = 0;
@@ -452,10 +449,8 @@
         sdbusplus::message::variant<uint64_t> value;
 
         // Get host time
-        auto method = bus.new_method_call(service.c_str(),
-                                          HOST_TIME_PATH,
-                                          DBUS_PROPERTIES,
-                                          "Get");
+        auto method = bus.new_method_call(service.c_str(), HOST_TIME_PATH,
+                                          DBUS_PROPERTIES, "Get");
 
         method.append(TIME_INTERFACE, PROPERTY_ELAPSED);
         auto reply = bus.call(method);
@@ -483,7 +478,6 @@
     hostTime << "Host time:" << getTimeString(host_time_usec);
     log<level::DEBUG>(hostTime.str().c_str());
 
-
     // Time is really long int but IPMI wants just uint32. This works okay until
     // the number of seconds since 1970 overflows uint32 size.. Still a whole
     // lot of time here to even think about that.
@@ -500,8 +494,10 @@
 }
 
 ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                              ipmi_request_t request, ipmi_response_t response,
-                              ipmi_data_len_t data_len, ipmi_context_t context)
+                                     ipmi_request_t request,
+                                     ipmi_response_t response,
+                                     ipmi_data_len_t data_len,
+                                     ipmi_context_t context)
 {
     using namespace std::chrono;
     ipmi_ret_t rc = IPMI_CC_OK;
@@ -518,10 +514,8 @@
         sdbusplus::message::variant<uint64_t> value{usec.count()};
 
         // Set host time
-        auto method = bus.new_method_call(service.c_str(),
-                                          HOST_TIME_PATH,
-                                          DBUS_PROPERTIES,
-                                          "Set");
+        auto method = bus.new_method_call(service.c_str(), HOST_TIME_PATH,
+                                          DBUS_PROPERTIES, "Set");
 
         method.append(TIME_INTERFACE, PROPERTY_ELAPSED, value);
         auto reply = bus.call(method);
@@ -548,13 +542,16 @@
 }
 
 ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                              ipmi_request_t request, ipmi_response_t response,
-                              ipmi_data_len_t data_len, ipmi_context_t context)
+                                    ipmi_request_t request,
+                                    ipmi_response_t response,
+                                    ipmi_data_len_t data_len,
+                                    ipmi_context_t context)
 {
     ipmi_ret_t rc = IPMI_CC_OK;
 
-    // IPMI spec, Reservation ID, the value simply increases against each execution of reserve_sel command.
-    if( ++g_sel_reserve == 0)
+    // IPMI spec, Reservation ID, the value simply increases against each
+    // execution of reserve_sel command.
+    if (++g_sel_reserve == 0)
         g_sel_reserve = 1;
 
     *data_len = sizeof(g_sel_reserve);
@@ -566,12 +563,14 @@
 }
 
 ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                              ipmi_request_t request, ipmi_response_t response,
-                              ipmi_data_len_t data_len, ipmi_context_t context)
+                                ipmi_request_t request,
+                                ipmi_response_t response,
+                                ipmi_data_len_t data_len,
+                                ipmi_context_t context)
 {
 
     ipmi_ret_t rc = IPMI_CC_OK;
-    ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request;
+    ipmi_add_sel_request_t* p = (ipmi_add_sel_request_t*)request;
     uint16_t recordid;
 
     recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2];
@@ -598,11 +597,10 @@
     return rc;
 }
 
-//Read FRU info area
+// Read FRU info area
 ipmi_ret_t ipmi_storage_get_fru_inv_area_info(
-        ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request,
-        ipmi_response_t response, ipmi_data_len_t data_len,
-        ipmi_context_t context)
+    ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request,
+    ipmi_response_t response, ipmi_data_len_t data_len, ipmi_context_t context)
 {
     ipmi_ret_t rc = IPMI_CC_OK;
     const FruInvenAreaInfoRequest* reqptr =
@@ -629,7 +627,7 @@
         // Pack the actual response
         memcpy(response, &resp, *data_len);
     }
-    catch(const InternalFailure& e)
+    catch (const InternalFailure& e)
     {
         rc = IPMI_CC_UNSPECIFIED_ERROR;
         *data_len = 0;
@@ -638,17 +636,17 @@
     return rc;
 }
 
-//Read FRU data
-ipmi_ret_t ipmi_storage_read_fru_data(
-        ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t request,
-        ipmi_response_t response, ipmi_data_len_t data_len,
-        ipmi_context_t context)
+// Read FRU data
+ipmi_ret_t ipmi_storage_read_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
+                                      ipmi_request_t request,
+                                      ipmi_response_t response,
+                                      ipmi_data_len_t data_len,
+                                      ipmi_context_t context)
 {
     ipmi_ret_t rc = IPMI_CC_OK;
     const ReadFruDataRequest* reqptr =
         reinterpret_cast<const ReadFruDataRequest*>(request);
-    auto resptr =
-        reinterpret_cast<ReadFruDataResponse*>(response);
+    auto resptr = reinterpret_cast<ReadFruDataResponse*>(response);
 
     auto iter = frus.find(reqptr->fruID);
     if (iter == frus.end())
@@ -680,8 +678,7 @@
         }
 
         std::copy((fruArea.begin() + offset),
-                  (fruArea.begin() + offset + resptr->count),
-                  resptr->data);
+                  (fruArea.begin() + offset + resptr->count), resptr->data);
 
         *data_len = resptr->count + 1; // additional one byte for count
     }
@@ -695,14 +692,15 @@
 }
 
 ipmi_ret_t ipmi_get_repository_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                             ipmi_request_t request, ipmi_response_t response,
-                             ipmi_data_len_t data_len, ipmi_context_t context)
+                                    ipmi_request_t request,
+                                    ipmi_response_t response,
+                                    ipmi_data_len_t data_len,
+                                    ipmi_context_t context)
 {
     constexpr auto sdrVersion = 0x51;
-    auto responseData =
-        reinterpret_cast<GetRepositoryInfoResponse*>(response);
+    auto responseData = reinterpret_cast<GetRepositoryInfoResponse*>(response);
 
-    memset(responseData, 0 , sizeof(GetRepositoryInfoResponse));
+    memset(responseData, 0, sizeof(GetRepositoryInfoResponse));
 
     responseData->sdrVersion = sdrVersion;
 
@@ -721,63 +719,60 @@
 void register_netfn_storage_functions()
 {
     // <Wildcard Command>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL,
+                           ipmi_storage_wildcard, PRIVILEGE_USER);
 
     // <Get SEL Info>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, getSELInfo,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL,
+                           getSELInfo, PRIVILEGE_USER);
 
     // <Get SEL Time>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL,
+                           ipmi_storage_get_sel_time, PRIVILEGE_USER);
 
     // <Set SEL Time>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time,
-                           PRIVILEGE_OPERATOR);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL,
+                           ipmi_storage_set_sel_time, PRIVILEGE_OPERATOR);
 
     // <Reserve SEL>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL,
+                           ipmi_storage_reserve_sel, PRIVILEGE_USER);
 
     // <Get SEL Entry>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL, getSELEntry,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
+                           getSELEntry, PRIVILEGE_USER);
 
     // <Delete SEL Entry>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL, deleteSELEntry,
-                           PRIVILEGE_OPERATOR);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_DELETE_SEL, NULL,
+                           deleteSELEntry, PRIVILEGE_OPERATOR);
 
     // <Add SEL Entry>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel,
-                           PRIVILEGE_OPERATOR);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL,
+                           ipmi_storage_add_sel, PRIVILEGE_OPERATOR);
     // <Clear SEL>
     ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_CLEAR_SEL, NULL, clearSEL,
                            PRIVILEGE_OPERATOR);
     // <Get FRU Inventory Area Info>
     ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_FRU_INV_AREA_INFO, NULL,
-            ipmi_storage_get_fru_inv_area_info, PRIVILEGE_OPERATOR);
+                           ipmi_storage_get_fru_inv_area_info,
+                           PRIVILEGE_OPERATOR);
 
     // <Add READ FRU Data
     ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_READ_FRU_DATA, NULL,
-            ipmi_storage_read_fru_data, PRIVILEGE_OPERATOR);
+                           ipmi_storage_read_fru_data, PRIVILEGE_OPERATOR);
 
     // <Get Repository Info>
     ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_REPOSITORY_INFO,
-                           nullptr, ipmi_get_repository_info,
-                           PRIVILEGE_USER);
+                           nullptr, ipmi_get_repository_info, PRIVILEGE_USER);
 
     // <Reserve SDR Repository>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SDR,
-                           nullptr, ipmi_sen_reserve_sdr,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SDR, nullptr,
+                           ipmi_sen_reserve_sdr, PRIVILEGE_USER);
 
     // <Get SDR>
-    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR,
-                           nullptr, ipmi_sen_get_sdr,
-                           PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
+                           ipmi_sen_get_sdr, PRIVILEGE_USER);
 
     ipmi::fru::registerCallbackHandler();
     return;
 }
-