Add clang-format
Refer:https://github.com/openbmc/docs/blob/ac5d544553934f8083c61c5986a1420261bc8a4c/style/cpp/.clang-format
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I931503febf4e17af5c328a6496e499992bc4e381
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..79a474d
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,116 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Right
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterCaseLabel: true
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ AfterExternBlock: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+BreakInheritanceList: AfterColon
+BreakStringLiterals: false
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: false
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 7
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.h"'
+ Priority: 1
+ - Regex: '^".*\.hpp"'
+ Priority: 2
+ - Regex: '^<.*\.h>'
+ Priority: 3
+ - Regex: '^<.*\.hpp>'
+ Priority: 4
+ - Regex: '^<.*'
+ Priority: 5
+ - Regex: '.*'
+ Priority: 6
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+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
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Latest
+TabWidth: 4
+UseCRLF: false
+UseTab: Never
+...
diff --git a/ikvm_args.cpp b/ikvm_args.cpp
index 19642af..f9401ac 100644
--- a/ikvm_args.cpp
+++ b/ikvm_args.cpp
@@ -8,19 +8,16 @@
namespace ikvm
{
-Args::Args(int argc, char* argv[]) : frameRate(30), subsampling(0), calcFrameCRC{false},
- commandLine(argc, argv)
+Args::Args(int argc, char* argv[]) :
+ frameRate(30), subsampling(0), calcFrameCRC{false}, commandLine(argc, argv)
{
int option;
const char* opts = "f:s:h:k:p:v:c";
- struct option lopts[] = {{"frameRate", 1, 0, 'f'},
- {"subsampling", 1, 0, 's'},
- {"help", 0, 0, 'h'},
- {"keyboard", 1, 0, 'k'},
- {"mouse", 1, 0, 'p'},
- {"videoDevice", 1, 0, 'v'},
- {"calcCRC", 0, 0, 'c'},
- {0, 0, 0, 0}};
+ struct option lopts[] = {
+ {"frameRate", 1, 0, 'f'}, {"subsampling", 1, 0, 's'},
+ {"help", 0, 0, 'h'}, {"keyboard", 1, 0, 'k'},
+ {"mouse", 1, 0, 'p'}, {"videoDevice", 1, 0, 'v'},
+ {"calcCRC", 0, 0, 'c'}, {0, 0, 0, 0}};
while ((option = getopt_long(argc, argv, opts, lopts, NULL)) != -1)
{
@@ -66,7 +63,9 @@
fprintf(stderr, "-k device HID keyboard gadget device\n");
fprintf(stderr, "-p device HID mouse gadget device\n");
fprintf(stderr, "-v device V4L2 device\n");
- fprintf(stderr, "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
+ fprintf(
+ stderr,
+ "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
rfbUsage();
}
diff --git a/ikvm_args.hpp b/ikvm_args.hpp
index bfd5507..565d9c0 100644
--- a/ikvm_args.hpp
+++ b/ikvm_args.hpp
@@ -25,8 +25,7 @@
* @param[in] v - Array of arguments
*/
CommandLine(int c, char** v) : argc(c), argv(v)
- {
- }
+ {}
~CommandLine() = default;
CommandLine(const CommandLine&) = default;
CommandLine& operator=(const CommandLine&) = default;
diff --git a/ikvm_input.cpp b/ikvm_input.cpp
index cbbfdc4..e9bd151 100644
--- a/ikvm_input.cpp
+++ b/ikvm_input.cpp
@@ -1,6 +1,7 @@
#include "ikvm_input.hpp"
#include "ikvm_server.hpp"
+#include "scancodes.hpp"
#include <err.h>
#include <errno.h>
@@ -14,8 +15,6 @@
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
-#include "scancodes.hpp"
-
namespace fs = std::filesystem;
namespace ikvm
@@ -78,8 +77,8 @@
if (!keyboardPath.empty())
{
- keyboardFd = open(keyboardPath.c_str(),
- O_RDWR | O_CLOEXEC | O_NONBLOCK);
+ keyboardFd =
+ open(keyboardPath.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK);
if (keyboardFd < 0)
{
log<level::ERR>("Failed to open input device",
@@ -228,7 +227,8 @@
else
{
input->pointerReport[0] = ((buttonMask & 0x4) >> 1) |
- ((buttonMask & 0x2) << 1) | (buttonMask & 0x1);
+ ((buttonMask & 0x2) << 1) |
+ (buttonMask & 0x1);
input->pointerReport[5] = 0;
}
@@ -502,7 +502,7 @@
return scancode;
}
-bool Input::writeKeyboard(const uint8_t *report)
+bool Input::writeKeyboard(const uint8_t* report)
{
std::unique_lock<std::mutex> lk(keyMutex);
uint retryCount = HID_REPORT_RETRY_MAX;
@@ -534,7 +534,7 @@
return false;
}
-void Input::writePointer(const uint8_t *report)
+void Input::writePointer(const uint8_t* report)
{
std::unique_lock<std::mutex> lk(ptrMutex);
uint retryCount = HID_REPORT_RETRY_MAX;
diff --git a/ikvm_input.hpp b/ikvm_input.hpp
index ac54220..295fb12 100644
--- a/ikvm_input.hpp
+++ b/ikvm_input.hpp
@@ -98,8 +98,8 @@
*/
static uint8_t keyToScancode(rfbKeySym key);
- bool writeKeyboard(const uint8_t *report);
- void writePointer(const uint8_t *report);
+ bool writeKeyboard(const uint8_t* report);
+ void writePointer(const uint8_t* report);
/* @brief File descriptor for the USB keyboard device */
int keyboardFd;
diff --git a/ikvm_manager.cpp b/ikvm_manager.cpp
index 33e7b17..11afcb7 100644
--- a/ikvm_manager.cpp
+++ b/ikvm_manager.cpp
@@ -8,10 +8,10 @@
Manager::Manager(const Args& args) :
continueExecuting(true), serverDone(false), videoDone(true),
input(args.getKeyboardPath(), args.getPointerPath()),
- video(args.getVideoPath(), input, args.getFrameRate(), args.getSubsampling()),
+ video(args.getVideoPath(), input, args.getFrameRate(),
+ args.getSubsampling()),
server(args, input, video)
-{
-}
+{}
void Manager::run()
{
diff --git a/ikvm_server.cpp b/ikvm_server.cpp
index 804eb39..141f6c6 100644
--- a/ikvm_server.cpp
+++ b/ikvm_server.cpp
@@ -2,13 +2,12 @@
#include <rfb/rfbproto.h>
+#include <boost/crc.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
-#include <boost/crc.hpp>
-
namespace ikvm
{
@@ -133,9 +132,9 @@
{
/* JFIF header contains some varying data so skip it for
* checksum calculation */
- frame_crc = boost::crc<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF,
- true, true>(data + 0x30,
- video.getFrameSize() - 0x30);
+ frame_crc =
+ boost::crc<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true,
+ true>(data + 0x30, video.getFrameSize() - 0x30);
}
if (cd->last_crc == frame_crc)
@@ -179,9 +178,9 @@
}
void Server::clientFramebufferUpdateRequest(
- rfbClientPtr cl, rfbFramebufferUpdateRequestMsg *furMsg)
+ rfbClientPtr cl, rfbFramebufferUpdateRequestMsg* furMsg)
{
- ClientData *cd = (ClientData *)cl->clientData;
+ ClientData* cd = (ClientData*)cl->clientData;
if (!cd)
return;
diff --git a/ikvm_server.hpp b/ikvm_server.hpp
index bfeb73b..dcb984a 100644
--- a/ikvm_server.hpp
+++ b/ikvm_server.hpp
@@ -94,8 +94,8 @@
* @param[in] furMsg - Pointer of the FUR message
*/
static void
- clientFramebufferUpdateRequest(rfbClientPtr cl,
- rfbFramebufferUpdateRequestMsg *furMsg);
+ clientFramebufferUpdateRequest(rfbClientPtr cl,
+ rfbFramebufferUpdateRequestMsg* furMsg);
/*
* @brief Handler for a client disconnecting
*
diff --git a/ikvm_video.cpp b/ikvm_video.cpp
index 5159b25..734294e 100644
--- a/ikvm_video.cpp
+++ b/ikvm_video.cpp
@@ -32,10 +32,9 @@
Video::Video(const std::string& p, Input& input, int fr, int sub) :
resizeAfterOpen(false), timingsError(false), fd(-1), frameRate(fr),
- lastFrameIndex(-1), height(600), width(800), subSampling(sub),
- input(input), path(p)
-{
-}
+ lastFrameIndex(-1), height(600), width(800), subSampling(sub), input(input),
+ path(p)
+{}
Video::~Video()
{
@@ -447,8 +446,8 @@
}
ctrl.id = V4L2_CID_JPEG_CHROMA_SUBSAMPLING;
- ctrl.value = subSampling
- ? V4L2_JPEG_CHROMA_SUBSAMPLING_420 : V4L2_JPEG_CHROMA_SUBSAMPLING_444;
+ ctrl.value = subSampling ? V4L2_JPEG_CHROMA_SUBSAMPLING_420
+ : V4L2_JPEG_CHROMA_SUBSAMPLING_444;
rc = ioctl(fd, VIDIOC_S_CTRL, &ctrl);
if (rc < 0)
{
diff --git a/ikvm_video.hpp b/ikvm_video.hpp
index 23c58a7..17477df 100644
--- a/ikvm_video.hpp
+++ b/ikvm_video.hpp
@@ -128,8 +128,7 @@
struct Buffer
{
Buffer() : data(nullptr), queued(false), payload(0), size(0)
- {
- }
+ {}
~Buffer() = default;
Buffer(const Buffer&) = default;
Buffer& operator=(const Buffer&) = default;