Add OpenBMC C++ clang-format file and format code

Change-Id: Ib3a388bf5392159440682265b577fba023c3c3aa
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..ea71ad6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,99 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      true
+  AfterControlStatement: true
+  AfterEnum:       true
+  AfterFunction:   true
+  AfterNamespace:  true
+  AfterObjCDeclaration: true
+  AfterStruct:     true
+  AfterUnion:      true
+  BeforeCatch:     true
+  BeforeElse:      true
+  IndentBraces:    false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+  - Regex:           '^[<"](gtest|gmock)'
+    Priority:        5
+  - Regex:           '^"config.h"'
+    Priority:        -1
+  - Regex:           '^".*\.hpp"'
+    Priority:        1
+  - Regex:           '^<.*\.h>'
+    Priority:        2
+  - Regex:           '^<.*'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        4
+IndentCaseLabels: true
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        4
+UseTab:          Never
+...
+
diff --git a/argument.cpp b/argument.cpp
index b70a0dd..fd0c50d 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 
-#include <iostream>
-#include <iterator>
+#include "argument.hpp"
+
 #include <algorithm>
 #include <cassert>
-#include "argument.hpp"
+#include <iostream>
+#include <iterator>
 
 namespace phosphor
 {
@@ -29,17 +30,17 @@
 const std::string ArgumentParser::empty_string = "";
 
 const char* ArgumentParser::optionstr = "p:?h";
-const option ArgumentParser::options[] =
-{
-    { "path",   required_argument,  nullptr,   'p' },
-    { "help",   no_argument,        nullptr,   'h' },
-    { 0, 0, 0, 0},
+const option ArgumentParser::options[] = {
+    {"path", required_argument, nullptr, 'p'},
+    {"help", no_argument, nullptr, 'h'},
+    {0, 0, 0, 0},
 };
 
 ArgumentParser::ArgumentParser(int argc, char** argv)
 {
     int 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'))
         {
@@ -48,7 +49,8 @@
         }
 
         auto i = &options[0];
-        while ((i->val != option) && (i->val != 0)) ++i;
+        while ((i->val != option) && (i->val != 0))
+            ++i;
 
         if (i->val)
             arguments[i->name] = (i->has_arg ? optarg : true_string);
@@ -74,8 +76,7 @@
     std::cerr << "Options:" << std::endl;
     std::cerr << "    --help               Print this menu" << std::endl;
     std::cerr << "    --path=<path>        absolute path of LED in sysfs; like";
-    std::cerr <<                           " /sys/class/leds/<name>"
-              << std::endl;
+    std::cerr << " /sys/class/leds/<name>" << std::endl;
 }
 } // namespace led
 } // namespace phosphor
diff --git a/argument.hpp b/argument.hpp
index 9c91615..81876da 100644
--- a/argument.hpp
+++ b/argument.hpp
@@ -1,6 +1,7 @@
 #ifndef __ARGUMENT_H
 #define __ARGUMENT_H
 #include <getopt.h>
+
 #include <map>
 #include <string>
 
@@ -13,43 +14,43 @@
  */
 class ArgumentParser
 {
-    public:
-        ArgumentParser() = delete;
-        ~ArgumentParser() = default;
-        ArgumentParser(const ArgumentParser&) = delete;
-        ArgumentParser& operator=(const ArgumentParser&) = delete;
-        ArgumentParser(ArgumentParser&&) = default;
-        ArgumentParser& operator=(ArgumentParser&&) = default;
+  public:
+    ArgumentParser() = delete;
+    ~ArgumentParser() = default;
+    ArgumentParser(const ArgumentParser&) = delete;
+    ArgumentParser& operator=(const ArgumentParser&) = delete;
+    ArgumentParser(ArgumentParser&&) = default;
+    ArgumentParser& operator=(ArgumentParser&&) = default;
 
-        /** @brief Constructs Argument object
-         *
-         *  @param argc - the main function's argc passed as is
-         *  @param argv - the main function's argv passed as is
-         *  @return Object constructed
-         */
-        ArgumentParser(int argc, char** argv);
+    /** @brief Constructs Argument object
+     *
+     *  @param argc - the main function's argc passed as is
+     *  @param argv - the main function's argv passed as is
+     *  @return Object constructed
+     */
+    ArgumentParser(int argc, char** argv);
 
-        /** @brief Given a option, returns its argument(optarg) */
-        const std::string& operator[](const std::string& opt);
+    /** @brief Given a option, returns its argument(optarg) */
+    const std::string& operator[](const std::string& opt);
 
-        /** @brief Displays usage */
-        static void usage(char** argv);
+    /** @brief Displays usage */
+    static void usage(char** argv);
 
-        /** @brief Set to 'true' when an option is passed */
-        static const std::string true_string;
+    /** @brief Set to 'true' when an option is passed */
+    static const std::string true_string;
 
-        /** @brief Set to '' when an option is not passed */
-        static const std::string empty_string;
+    /** @brief Set to '' when an option is not passed */
+    static const std::string empty_string;
 
-    private:
-        /** @brief Option to argument mapping */
-        std::map<const std::string, std::string> arguments;
+  private:
+    /** @brief Option to argument mapping */
+    std::map<const std::string, std::string> arguments;
 
-        /** @brief Array of struct options as needed by getopt_long */
-        static const option options[];
+    /** @brief Array of struct options as needed by getopt_long */
+    static const option options[];
 
-        /** @brief optstring as needed by getopt_long */
-        static const char* optionstr;
+    /** @brief optstring as needed by getopt_long */
+    static const char* optionstr;
 };
 
 } // namespace led
diff --git a/controller.cpp b/controller.cpp
index f0ba4c2..f945034 100644
--- a/controller.cpp
+++ b/controller.cpp
@@ -14,12 +14,14 @@
  * limitations under the License.
  */
 
-#include <iostream>
-#include <string>
-#include <algorithm>
+#include "config.h"
+
 #include "argument.hpp"
 #include "physical.hpp"
-#include "config.h"
+
+#include <algorithm>
+#include <iostream>
+#include <string>
 
 static void ExitWithError(const char* err, char** argv)
 {
@@ -68,8 +70,8 @@
     std::replace(name.begin(), name.end(), '-', '_');
 
     // Unique bus name representing a single LED.
-    auto busName =  std::string(BUSNAME) + '.' + name;
-    auto objPath =  std::string(OBJPATH) + '/' + name;
+    auto busName = std::string(BUSNAME) + '.' + name;
+    auto objPath = std::string(OBJPATH) + '/' + name;
 
     // Get a handle to system dbus.
     auto bus = std::move(sdbusplus::bus::new_default());
@@ -85,7 +87,7 @@
     bus.request_name(busName.c_str());
 
     /** @brief Wait for client requests */
-    while(true)
+    while (true)
     {
         // Handle dbus message / signals discarding unhandled
         bus.process_discard();
diff --git a/physical.cpp b/physical.cpp
index 38c69b0..e7ca582 100644
--- a/physical.cpp
+++ b/physical.cpp
@@ -14,9 +14,10 @@
  * limitations under the License.
  */
 
+#include "physical.hpp"
+
 #include <iostream>
 #include <string>
-#include "physical.hpp"
 namespace phosphor
 {
 namespace led
@@ -27,7 +28,7 @@
 {
     // Control files in /sys/class/leds/<led-name>
     brightCtrl = path + BRIGHTNESS;
-    blinkCtrl =  path + BLINKCTRL;
+    blinkCtrl = path + BLINKCTRL;
 
     delayOnCtrl = path + DELAYON;
     delayOffCtrl = path + DELAYOFF;
@@ -66,14 +67,14 @@
         if (brightness == std::string(ASSERT))
         {
             // LED is in Solid ON
-            sdbusplus::xyz::openbmc_project::Led::server
-                          ::Physical::state(Action::On);
+            sdbusplus::xyz::openbmc_project::Led::server ::Physical::state(
+                Action::On);
         }
         else
         {
             // LED is in OFF state
-            sdbusplus::xyz::openbmc_project::Led::server
-                          ::Physical::state(Action::Off);
+            sdbusplus::xyz::openbmc_project::Led::server ::Physical::state(
+                Action::Off);
         }
     }
     return;
@@ -83,12 +84,12 @@
 auto Physical::state(Action value) -> Action
 {
     // Obtain current operation
-    auto current = sdbusplus::xyz::openbmc_project::Led::server
-                                   ::Physical::state();
+    auto current =
+        sdbusplus::xyz::openbmc_project::Led::server ::Physical::state();
 
     // Update requested operation into base class
-    auto requested = sdbusplus::xyz::openbmc_project::Led::server
-                                   ::Physical::state(value);
+    auto requested =
+        sdbusplus::xyz::openbmc_project::Led::server ::Physical::state(value);
 
     // Apply the action.
     driveLED(current, requested);
@@ -112,7 +113,7 @@
     }
 
     // Transition TO Stable states.
-    if(request == Action::On || request == Action::Off)
+    if (request == Action::On || request == Action::Off)
     {
         return stableStateOperation(request);
     }
diff --git a/physical.hpp b/physical.hpp
index 36fbedc..47ad7d5 100644
--- a/physical.hpp
+++ b/physical.hpp
@@ -1,9 +1,9 @@
 #pragma once
 
-#include <string>
 #include <fstream>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
+#include <string>
 #include <xyz/openbmc_project/Led/Physical/server.hpp>
 namespace phosphor
 {
@@ -50,141 +50,140 @@
  *  @brief Responsible for applying actions on a particular physical LED
  */
 class Physical : public sdbusplus::server::object::object<
-    sdbusplus::xyz::openbmc_project::Led::server::Physical>
+                     sdbusplus::xyz::openbmc_project::Led::server::Physical>
 {
-    public:
-        Physical() = delete;
-        ~Physical() = default;
-        Physical(const Physical&) = delete;
-        Physical& operator=(const Physical&) = delete;
-        Physical(Physical&&) = delete;
-        Physical& operator=(Physical&&) = delete;
+  public:
+    Physical() = delete;
+    ~Physical() = default;
+    Physical(const Physical&) = delete;
+    Physical& operator=(const Physical&) = delete;
+    Physical(Physical&&) = delete;
+    Physical& operator=(Physical&&) = delete;
 
-        /** @brief Constructs LED object. Argument 'true' says that we hold off
-         *   from sending the signals since we need to do some house keeping and
-         *   only when we finish that, we are considered active and can then
-         *   broadcast the signal.
-         *
-         * @param[in] bus       - system dbus handler
-         * @param[in] objPath   - The Dbus path that hosts physical LED
-         * @param[in] ledPath   - sysfs path where this LED is exported
-         */
-        Physical(sdbusplus::bus::bus& bus,
-                const std::string& objPath,
-                const std::string& ledPath) :
+    /** @brief Constructs LED object. Argument 'true' says that we hold off
+     *   from sending the signals since we need to do some house keeping and
+     *   only when we finish that, we are considered active and can then
+     *   broadcast the signal.
+     *
+     * @param[in] bus       - system dbus handler
+     * @param[in] objPath   - The Dbus path that hosts physical LED
+     * @param[in] ledPath   - sysfs path where this LED is exported
+     */
+    Physical(sdbusplus::bus::bus& bus, const std::string& objPath,
+             const std::string& ledPath) :
 
-            sdbusplus::server::object::object<
-                sdbusplus::xyz::openbmc_project::Led::server::Physical>(
-                        bus, objPath.c_str(), true),
-            path(ledPath)
+        sdbusplus::server::object::object<
+            sdbusplus::xyz::openbmc_project::Led::server::Physical>(
+            bus, objPath.c_str(), true),
+        path(ledPath)
+    {
+        // Suppose this is getting launched as part of BMC reboot, then we
+        // need to save what the micro-controller currently has.
+        setInitialState();
+
+        // We are now ready.
+        emit_object_added();
+    }
+
+    /** @brief Overloaded State Property Setter function
+     *
+     *  @param[in] value   -  One of OFF / ON / BLINK
+     *  @return            -  Success or exception thrown
+     */
+    Action state(Action value) override;
+
+  private:
+    /** @brief File system location where this LED is exposed
+     *   Typically /sys/class/leds/<Led-Name>
+     */
+    std::string path;
+
+    /** @brief Frequency range that the LED can operate on.
+     *  Will be removed when frequency is put into interface
+     */
+    uint32_t frequency;
+
+    /** @brief Brightness described above */
+    std::string brightCtrl;
+
+    /** @brief BlinkCtrl described above */
+    std::string blinkCtrl;
+
+    /** @brief delay_on described above */
+    std::string delayOnCtrl;
+
+    /** @brief delay_ff described above */
+    std::string delayOffCtrl;
+
+    /** @brief reads sysfs and then setsup the parameteres accordingly
+     *
+     *  @return None
+     */
+    void setInitialState();
+
+    /** @brief Applies the user triggered action on the LED
+     *   by writing to sysfs
+     *
+     *  @param [in] current - Current state of LED
+     *  @param [in] request - Requested state
+     *
+     *  @return None
+     */
+    void driveLED(Action current, Action request);
+
+    /** @brief Sets the LED to either ON or OFF state
+     *
+     *  @param [in] action - Requested action. Could be OFF or ON
+     *  @return None
+     */
+    void stableStateOperation(Action action);
+
+    /** @brief Sets the LED to BLINKING
+     *
+     *  @return None
+     */
+    void blinkOperation();
+
+    /** @brief Generic file writer.
+     *   There are files like "brightness", "trigger" , "delay_on" and
+     *   "delay_off" that will tell what the LED driver needs to do.
+     *
+     *  @param[in] filename - Name of file to be written
+     *  @param[in] data     - Data to be written to
+     *  @return             - None
+     */
+    template <typename T>
+    auto write(const std::string& fileName, T&& data)
+    {
+        if (std::ifstream(fileName))
         {
-            // Suppose this is getting launched as part of BMC reboot, then we
-            // need to save what the micro-controller currently has.
-            setInitialState();
-
-            // We are now ready.
-            emit_object_added();
+            std::ofstream file(fileName, std::ios::out);
+            file << data;
+            file.close();
         }
+        return;
+    }
 
-        /** @brief Overloaded State Property Setter function
-         *
-         *  @param[in] value   -  One of OFF / ON / BLINK
-         *  @return            -  Success or exception thrown
-         */
-        Action state(Action value) override;
-
-    private:
-        /** @brief File system location where this LED is exposed
-         *   Typically /sys/class/leds/<Led-Name>
-         */
-        std::string path;
-
-        /** @brief Frequency range that the LED can operate on.
-         *  Will be removed when frequency is put into interface
-         */
-        uint32_t frequency;
-
-        /** @brief Brightness described above */
-        std::string brightCtrl;
-
-        /** @brief BlinkCtrl described above */
-        std::string blinkCtrl;
-
-        /** @brief delay_on described above */
-        std::string delayOnCtrl;
-
-        /** @brief delay_ff described above */
-        std::string delayOffCtrl;
-
-        /** @brief reads sysfs and then setsup the parameteres accordingly
-         *
-         *  @return None
-         */
-        void setInitialState();
-
-        /** @brief Applies the user triggered action on the LED
-         *   by writing to sysfs
-         *
-         *  @param [in] current - Current state of LED
-         *  @param [in] request - Requested state
-         *
-         *  @return None
-         */
-        void driveLED(Action current, Action request);
-
-        /** @brief Sets the LED to either ON or OFF state
-         *
-         *  @param [in] action - Requested action. Could be OFF or ON
-         *  @return None
-         */
-        void stableStateOperation(Action action);
-
-        /** @brief Sets the LED to BLINKING
-         *
-         *  @return None
-         */
-        void blinkOperation();
-
-        /** @brief Generic file writer.
-         *   There are files like "brightness", "trigger" , "delay_on" and
-         *   "delay_off" that will tell what the LED driver needs to do.
-         *
-         *  @param[in] filename - Name of file to be written
-         *  @param[in] data     - Data to be written to
-         *  @return             - None
-         */
-        template <typename T>
-        auto write(const std::string& fileName, T&& data)
+    /** @brief Generic file reader.
+     *   There are files like "brightness", "trigger" , "delay_on" and
+     *   "delay_off" that will tell what the LED driver needs to do.
+     *
+     *  @param[in] filename - Name of file to be read
+     *  @return             - File content
+     */
+    template <typename T>
+    T read(const std::string& fileName)
+    {
+        T data = T();
+        if (std::ifstream(fileName))
         {
-            if(std::ifstream(fileName))
-            {
-                std::ofstream file(fileName, std::ios::out);
-                file << data;
-                file.close();
-            }
-            return;
+            std::ifstream file(fileName, std::ios::in);
+            file >> data;
+            file.close();
         }
-
-        /** @brief Generic file reader.
-         *   There are files like "brightness", "trigger" , "delay_on" and
-         *   "delay_off" that will tell what the LED driver needs to do.
-         *
-         *  @param[in] filename - Name of file to be read
-         *  @return             - File content
-         */
-        template <typename T>
-        T read(const std::string& fileName)
-        {
-            T data = T();
-            if(std::ifstream(fileName))
-            {
-                std::ifstream file(fileName, std::ios::in);
-                file >> data;
-                file.close();
-            }
-            return data;
-        }
+        return data;
+    }
 };
 
 } // namespace led
-}
+} // namespace phosphor