Skip to content

Commit

Permalink
Run clang-format over whole codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
cinemast committed Oct 23, 2021
1 parent c87417e commit d5ede22
Show file tree
Hide file tree
Showing 144 changed files with 2,883 additions and 3,560 deletions.
115 changes: 115 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
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: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
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: Cpp11
TabWidth: 2
UseTab: Never
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ coverage: test
gcovr -r . -d -e "build" -e "src/test" -e "src/examples" -e "src/stubgenerator/main.cpp" --html --html-details -o reports/coverage.html

format:
find . -name "*.h" -o -name "*.cpp" -exec clang-format -style=LLVM -i {} \;
find src/ -name "*.h" -o -name "*.cpp" -exec clang-format -i {} \;

check-format: format
git diff --exit-code
Expand Down
14 changes: 7 additions & 7 deletions src/catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ project(catch_builder CXX)
include(ExternalProject)

ExternalProject_Add(
catch
PREFIX ${CMAKE_BINARY_DIR}/catch
URL https://github.com/catchorg/Catch2/archive/v2.7.0.tar.gz
URL_HASH SHA1=6df37d5b64a71b840a6a9d8c79c3705aa8a3f56e
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
catch
PREFIX ${CMAKE_BINARY_DIR}/catch
URL https://github.com/catchorg/Catch2/archive/v2.7.0.tar.gz
URL_HASH SHA1=6df37d5b64a71b840a6a9d8c79c3705aa8a3f56e
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

ExternalProject_Get_Property(catch source_dir)
Expand Down
90 changes: 45 additions & 45 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/gen)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-server=AbstractStubServer --cpp-server-file=${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Server Stubfiles"
VERBATIM
OUTPUT ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-server=AbstractStubServer --cpp-server-file=${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Server Stubfiles"
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/gen/stubclient.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-client=StubClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/stubclient.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Client Stubfile"
VERBATIM
OUTPUT ${CMAKE_BINARY_DIR}/gen/stubclient.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-client=StubClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/stubclient.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Client Stubfile"
VERBATIM
)

add_custom_target(common_stubs
DEPENDS ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h ${CMAKE_BINARY_DIR}/gen/stubclient.h
)
DEPENDS ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h ${CMAKE_BINARY_DIR}/gen/stubclient.h
)

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/gen/xbmcremote.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/xbmc_remote.json --cpp-client=XbmcRemoteClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/xbmcremote.h
MAIN_DEPENDENCY xbmc_remote.json
DEPENDS jsonrpcstub
COMMENT "Generating Client XBMC Stubfile"
VERBATIM
OUTPUT ${CMAKE_BINARY_DIR}/gen/xbmcremote.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/xbmc_remote.json --cpp-client=XbmcRemoteClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/xbmcremote.h
MAIN_DEPENDENCY xbmc_remote.json
DEPENDS jsonrpcstub
COMMENT "Generating Client XBMC Stubfile"
VERBATIM
)

include_directories(..)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${MHD_INCLUDE_DIRS})

if(UNIX)
if(UNIX_DOMAIN_SOCKET_SERVER AND UNIX_DOMAIN_SOCKET_CLIENT)
if (UNIX)
if (UNIX_DOMAIN_SOCKET_SERVER AND UNIX_DOMAIN_SOCKET_CLIENT)
add_executable(unixdomainsocketserversample unixdomainsocketserver.cpp)
target_link_libraries(unixdomainsocketserversample jsonrpcserver)
add_executable(unixdomainsocketclientsample unixdomainsocketclient.cpp)
target_link_libraries(unixdomainsocketclientsample jsonrpcclient)
endif()
endif ()

if(FILE_DESCRIPTOR_SERVER AND FILE_DESCRIPTOR_CLIENT)
add_executable(filedescriptorserversample filedescriptorserver.cpp)
target_link_libraries(filedescriptorserversample jsonrpcserver)
add_executable(filedescriptorclientsample filedescriptorclient.cpp)
target_link_libraries(filedescriptorclientsample jsonrpcclient)
endif()
endif(UNIX)
if (FILE_DESCRIPTOR_SERVER AND FILE_DESCRIPTOR_CLIENT)
add_executable(filedescriptorserversample filedescriptorserver.cpp)
target_link_libraries(filedescriptorserversample jsonrpcserver)
add_executable(filedescriptorclientsample filedescriptorclient.cpp)
target_link_libraries(filedescriptorclientsample jsonrpcclient)
endif ()
endif (UNIX)

if (TCP_SOCKET_SERVER AND TCP_SOCKET_CLIENT)
add_executable(tcpsocketclient tcpsocketclient.cpp)
target_link_libraries(tcpsocketclient jsonrpcclient)
add_executable(tcpsocketserver tcpsocketserver.cpp)
target_link_libraries(tcpsocketserver jsonrpcserver)
endif()
endif ()

if (SERIAL_PORT_SERVER AND SERIAL_PORT_CLIENT)
add_executable(serialportclient serialportclient.cpp)
target_link_libraries(serialportclient jsonrpcclient)
add_executable(serialportserver serialportserver.cpp)
target_link_libraries(serialportserver jsonrpcserver)
endif()
endif ()

if(HTTP_SERVER)
if (HTTP_SERVER)
add_executable(simpleserversample simpleserver.cpp)
target_link_libraries(simpleserversample jsonrpcserver)
endif()
endif ()

if(HTTP_CLIENT)
if (HTTP_CLIENT)
add_executable(simpleclientsample simpleclient.cpp)
target_link_libraries(simpleclientsample jsonrpcclient)
endif()
endif ()

if(REDIS_SERVER)
if (REDIS_SERVER)
add_executable(redisserversample redisserver.cpp)
target_link_libraries(redisserversample jsonrpcserver)
endif()
endif ()

if(REDIS_CLIENT)
if (REDIS_CLIENT)
add_executable(redisclientsample redisclient.cpp)
target_link_libraries(redisclientsample jsonrpcclient)
endif()
endif ()

if (COMPILE_STUBGEN)
if(HTTP_CLIENT)
if (HTTP_CLIENT)
add_executable(stubclientsample stubclient.cpp ${CMAKE_BINARY_DIR}/gen/stubclient.h)
target_link_libraries(stubclientsample jsonrpcclient)
add_executable(xbmcremote xbmcremote.cpp ${CMAKE_BINARY_DIR}/gen/xbmcremote.h)
target_link_libraries(xbmcremote jsonrpcclient)
endif()
endif ()

if(HTTP_SERVER)
if (HTTP_SERVER)
add_executable(stubserversample stubserver.cpp ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h)
target_link_libraries(stubserversample jsonrpcserver)
endif()
endif()
endif ()
endif ()

15 changes: 4 additions & 11 deletions src/examples/filedescriptorserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,13 @@ using namespace std;

class SampleServer : public AbstractServer<SampleServer> {
public:
SampleServer(FileDescriptorServer &server)
: AbstractServer<SampleServer>(server) {
this->bindAndAddMethod(Procedure("sayHello", PARAMS_BY_NAME, JSON_STRING,
"name", JSON_STRING, NULL),
&SampleServer::sayHello);
this->bindAndAddNotification(
Procedure("notifyServer", PARAMS_BY_NAME, NULL),
&SampleServer::notifyServer);
SampleServer(FileDescriptorServer &server) : AbstractServer<SampleServer>(server) {
this->bindAndAddMethod(Procedure("sayHello", PARAMS_BY_NAME, JSON_STRING, "name", JSON_STRING, NULL), &SampleServer::sayHello);
this->bindAndAddNotification(Procedure("notifyServer", PARAMS_BY_NAME, NULL), &SampleServer::notifyServer);
}

// method
void sayHello(const Json::Value &request, Json::Value &response) {
response = "Hello: " + request["name"].asString();
}
void sayHello(const Json::Value &request, Json::Value &response) { response = "Hello: " + request["name"].asString(); }

// notification
void notifyServer(const Json::Value &request) {
Expand Down
59 changes: 30 additions & 29 deletions src/examples/index.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>Title of the document</title>
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<!--
This file needs to be generated using jsonrpcstub:
cd build
./bin/jsonrpcstub ../src/examples/spec.json --js-client=StubClient --js-client-file=../src/examples/stubclient.js
-->
<script src="stubclient.js" type="text/javascript"></script>
<script type="text/javascript">
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>Title of the document</title>
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<!--
This file needs to be generated using jsonrpcstub:
cd build
./bin/jsonrpcstub ../src/examples/spec.json --js-client=StubClient --js-client-file=../src/examples/stubclient.js
-->
<script src="stubclient.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function () {
function showResult(id, result) {
alert("ID: " + id + " Result: " + result);
}
$(document).ready(function () {
function showResult(id, result) {
alert("ID: " + id + " Result: " + result);
}

function showError(code, message) {
alert("Error: " + code + " -> " + message);
}
function showError(code, message) {
alert("Error: " + code + " -> " + message);
}

var client = new StubClient("http://localhost:8383");
var client = new StubClient("http://localhost:8383");

client.sayHello("Peter", showResult, showError);
client.addNumbers(3,4,showResult, showError);
client.isEqual("3","3",showResult,showError);
client.isEqual("3",4,showResult,showError); //invalid params error
client.notifyServer();
});
function displayResult(result) {
alert(JSON.stringify(result));
}
</script>
client.sayHello("Peter", showResult, showError);
client.addNumbers(3, 4, showResult, showError);
client.isEqual("3", "3", showResult, showError);
client.isEqual("3", 4, showResult, showError); //invalid params error
client.notifyServer();
});

function displayResult(result) {
alert(JSON.stringify(result));
}
</script>
</head>
<body>
</body>
Expand Down
Loading

0 comments on commit d5ede22

Please sign in to comment.