Add clang-format to repo
Add clang-format to repo.
Change-Id: I5cc1e4ed3fcbf41a28e16cf929a86cf54a3c5efb
Signed-off-by: Patrick Venture <venture@google.com>
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/inc/common.hpp b/inc/common.hpp
index 387b626..82746ee 100644
--- a/inc/common.hpp
+++ b/inc/common.hpp
@@ -15,6 +15,11 @@
*/
#pragma once
+
+#include <systemd/sd-event.h>
+
+#include <memory>
+
struct EventDeleter
{
void operator()(sd_event* event) const
@@ -22,4 +27,4 @@
event = sd_event_unref(event);
}
};
-using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
\ No newline at end of file
+using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
diff --git a/inc/gpio.hpp b/inc/gpio.hpp
index 6387c93..98df21b 100644
--- a/inc/gpio.hpp
+++ b/inc/gpio.hpp
@@ -14,5 +14,8 @@
// limitations under the License.
*/
#pragma once
+
+#include <sdbusplus/bus.hpp>
+
int configGpio(const char* gpioName, int* fd, sdbusplus::bus::bus& bus);
-void closeGpio(int fd);
\ No newline at end of file
+void closeGpio(int fd);
diff --git a/inc/id_button.hpp b/inc/id_button.hpp
index cc664b2..a5c4180 100644
--- a/inc/id_button.hpp
+++ b/inc/id_button.hpp
@@ -15,22 +15,23 @@
*/
#pragma once
-#include <phosphor-logging/elog-errors.hpp>
-#include <unistd.h>
-#include "xyz/openbmc_project/Chassis/Common/error.hpp"
-#include "xyz/openbmc_project/Chassis/Buttons/ID/server.hpp"
#include "common.hpp"
#include "gpio.hpp"
+#include "xyz/openbmc_project/Chassis/Buttons/ID/server.hpp"
+#include "xyz/openbmc_project/Chassis/Common/error.hpp"
-const static constexpr char *ID_BUTTON = "ID_BTN";
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
+
+const static constexpr char* ID_BUTTON = "ID_BTN";
struct IDButton
: sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID>
+ sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID>
{
- IDButton(sdbusplus::bus::bus& bus, const char* path,
- EventPtr& event,
+ IDButton(sdbusplus::bus::bus& bus, const char* path, EventPtr& event,
sd_event_io_handler_t handler = IDButton::EventHandler) :
sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::ID>(
@@ -46,8 +47,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ID_BUTTON: failed to config GPIO");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
ret = sd_event_add_io(event.get(), nullptr, fd, EPOLLPRI,
@@ -57,8 +58,8 @@
phosphor::logging::log<phosphor::logging::level::ERR>(
"ID_BUTTON: failed to add to event loop");
::closeGpio(fd);
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
}
@@ -69,8 +70,8 @@
void simPress() override;
- static int EventHandler(sd_event_source* es, int fd,
- uint32_t revents, void* userdata)
+ static int EventHandler(sd_event_source* es, int fd, uint32_t revents,
+ void* userdata)
{
int n = -1;
@@ -80,8 +81,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ID_BUTTON: userdata null!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
IDButton* idButton = static_cast<IDButton*>(userdata);
@@ -90,8 +91,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ID_BUTTON: null pointer!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
n = ::lseek(fd, 0, SEEK_SET);
@@ -100,8 +101,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ID_BUTTON: lseek error!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
n = ::read(fd, &buf, sizeof(buf));
@@ -109,8 +110,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"ID_BUTTON: read error!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
if (buf == '0')
diff --git a/inc/power_button.hpp b/inc/power_button.hpp
index 94d15c6..d00f1c6 100644
--- a/inc/power_button.hpp
+++ b/inc/power_button.hpp
@@ -15,12 +15,14 @@
*/
#pragma once
-#include <phosphor-logging/elog-errors.hpp>
-#include <unistd.h>
-#include "xyz/openbmc_project/Chassis/Common/error.hpp"
-#include "xyz/openbmc_project/Chassis/Buttons/Power/server.hpp"
#include "common.hpp"
#include "gpio.hpp"
+#include "xyz/openbmc_project/Chassis/Buttons/Power/server.hpp"
+#include "xyz/openbmc_project/Chassis/Common/error.hpp"
+
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
const static constexpr char* POWER_BUTTON = "POWER_BUTTON";
@@ -29,8 +31,7 @@
sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>
{
- PowerButton(sdbusplus::bus::bus& bus, const char* path,
- EventPtr& event,
+ PowerButton(sdbusplus::bus::bus& bus, const char* path, EventPtr& event,
sd_event_io_handler_t handler = PowerButton::EventHandler) :
sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Power>(
@@ -46,8 +47,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"POWER_BUTTON: failed to config GPIO");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
ret = sd_event_add_io(event.get(), nullptr, fd, EPOLLPRI,
@@ -57,8 +58,8 @@
phosphor::logging::log<phosphor::logging::level::ERR>(
"POWER_BUTTON: failed to add to event loop");
::closeGpio(fd);
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
}
@@ -70,8 +71,8 @@
void simPress() override;
void simLongPress() override;
- static int EventHandler(sd_event_source* es, int fd,
- uint32_t revents, void* userdata)
+ static int EventHandler(sd_event_source* es, int fd, uint32_t revents,
+ void* userdata)
{
int n = -1;
@@ -81,8 +82,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"POWER_BUTTON: userdata null!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
PowerButton* powerButton = static_cast<PowerButton*>(userdata);
@@ -91,8 +92,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"POWER_BUTTON: null pointer!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
n = ::lseek(fd, 0, SEEK_SET);
@@ -101,8 +102,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"POWER_BUTTON: lseek error!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
n = ::read(fd, &buf, sizeof(buf));
@@ -110,8 +111,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"POWER_BUTTON: read error!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
if (buf == '0')
diff --git a/inc/reset_button.hpp b/inc/reset_button.hpp
index 8cf0545..b10f241 100644
--- a/inc/reset_button.hpp
+++ b/inc/reset_button.hpp
@@ -15,12 +15,14 @@
*/
#pragma once
-#include <phosphor-logging/elog-errors.hpp>
-#include <unistd.h>
-#include "xyz/openbmc_project/Chassis/Common/error.hpp"
-#include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
#include "common.hpp"
#include "gpio.hpp"
+#include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
+#include "xyz/openbmc_project/Chassis/Common/error.hpp"
+
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
const static constexpr char* RESET_BUTTON = "RESET_BUTTON";
@@ -29,8 +31,7 @@
sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Reset>
{
- ResetButton(sdbusplus::bus::bus& bus, const char* path,
- EventPtr& event,
+ ResetButton(sdbusplus::bus::bus& bus, const char* path, EventPtr& event,
sd_event_io_handler_t handler = ResetButton::EventHandler) :
sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Chassis::Buttons::server::Reset>(
@@ -46,8 +47,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"RESET_BUTTON: failed to config GPIO");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
ret = sd_event_add_io(event.get(), nullptr, fd, EPOLLPRI,
@@ -57,8 +58,8 @@
phosphor::logging::log<phosphor::logging::level::ERR>(
"RESET_BUTTON: failed to add to event loop");
::closeGpio(fd);
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
}
@@ -69,8 +70,8 @@
void simPress() override;
- static int EventHandler(sd_event_source* es, int fd,
- uint32_t revents, void* userdata)
+ static int EventHandler(sd_event_source* es, int fd, uint32_t revents,
+ void* userdata)
{
int n = -1;
@@ -80,8 +81,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"RESET_BUTTON: userdata null!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
ResetButton* resetButton = static_cast<ResetButton*>(userdata);
@@ -90,8 +91,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"RESET_BUTTON: null pointer!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
n = ::lseek(fd, 0, SEEK_SET);
@@ -100,8 +101,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"RESET_BUTTON: lseek error!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
n = ::read(fd, &buf, sizeof(buf));
@@ -109,8 +110,8 @@
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"RESET_BUTTON: read error!");
- throw sdbusplus::xyz::openbmc_project::Chassis::Common::
- Error::IOError();
+ throw sdbusplus::xyz::openbmc_project::Chassis::Common::Error::
+ IOError();
}
if (buf == '0')
diff --git a/src/gpio.cpp b/src/gpio.cpp
index 72c569a..b78d2bc 100644
--- a/src/gpio.cpp
+++ b/src/gpio.cpp
@@ -14,13 +14,15 @@
// limitations under the License.
*/
-#include <experimental/filesystem>
+#include "gpio.hpp"
+
#include <fcntl.h>
+#include <unistd.h>
+
+#include <experimental/filesystem>
#include <fstream>
#include <phosphor-logging/elog-errors.hpp>
-#include <unistd.h>
#include <xyz/openbmc_project/Common/error.hpp>
-#include "gpio.hpp"
const static constexpr char* SYSMGR_SERVICE = "org.openbmc.managers.System";
const static constexpr char* SYSMGR_OBJ_PATH = "/org/openbmc/managers/System";
@@ -85,7 +87,7 @@
stream.close();
}
- catch (const std::exception &e)
+ catch (const std::exception& e)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"Error in writing!",
diff --git a/src/main.cpp b/src/main.cpp
index bd4ec2a..6107949 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,9 +14,9 @@
// limitations under the License.
*/
-#include "reset_button.hpp"
-#include "power_button.hpp"
#include "id_button.hpp"
+#include "power_button.hpp"
+#include "reset_button.hpp"
int main(int argc, char* argv[])
{
diff --git a/src/reset_button.cpp b/src/reset_button.cpp
index 1747b71..31e01e1 100644
--- a/src/reset_button.cpp
+++ b/src/reset_button.cpp
@@ -14,10 +14,10 @@
// limitations under the License.
*/
-#include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
-
#include "reset_button.hpp"
+#include "xyz/openbmc_project/Chassis/Buttons/Reset/server.hpp"
+
void ResetButton::simPress()
{
pressed();