diff --git a/GrpcInterface/.clang-format b/GrpcInterface/.clang-format new file mode 100644 index 0000000000..78ba6a0887 --- /dev/null +++ b/GrpcInterface/.clang-format @@ -0,0 +1,79 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: true +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '$' +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +JavaScriptQuotes: Leave +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +PenaltyBreakAssignment: 13 +PenaltyBreakBeforeFirstCallParameter: 10000 +PenaltyBreakComment: 20 +PenaltyBreakFirstLessLess: 12 +PenaltyBreakString: 100 +PenaltyExcessCharacter: 5 +PenaltyReturnTypeOnItsOwnLine: 30 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: true +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... diff --git a/GrpcInterface/RiaGrpcApplicationInterface.cpp b/GrpcInterface/RiaGrpcApplicationInterface.cpp index c7b7881d2d..bc413eff30 100644 --- a/GrpcInterface/RiaGrpcApplicationInterface.cpp +++ b/GrpcInterface/RiaGrpcApplicationInterface.cpp @@ -15,8 +15,8 @@ // for more details. // ///////////////////////////////////////////////////////////////////////////////// -#include "RiaGrpcApplicationInterface.h" +#include "RiaGrpcApplicationInterface.h" #include "RiaPreferences.h" #include "cvfProgramOptions.h" @@ -54,10 +54,9 @@ bool RiaGrpcApplicationInterface::initializeGrpcServer( const cvf::ProgramOption //-------------------------------------------------------------------------------------------------- void RiaGrpcApplicationInterface::launchGrpcServer() { - m_grpcServer->runInThread(); + if ( m_grpcServer ) m_grpcServer->runInThread(); } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -73,23 +72,26 @@ QProcessEnvironment RiaGrpcApplicationInterface::grpcProcessEnvironment() const { QProcessEnvironment penv = QProcessEnvironment::systemEnvironment(); - penv.insert( "RESINSIGHT_GRPC_PORT", QString( "%1" ).arg( m_grpcServer->portNumber() ) ); - penv.insert( "RESINSIGHT_EXECUTABLE", QCoreApplication::applicationFilePath() ); + if ( m_grpcServer ) + { + penv.insert( "RESINSIGHT_GRPC_PORT", QString( "%1" ).arg( m_grpcServer->portNumber() ) ); + penv.insert( "RESINSIGHT_EXECUTABLE", QCoreApplication::applicationFilePath() ); - QStringList ripsLocations; - QString separator; + QStringList ripsLocations; + QString separator; #ifdef WIN32 - ripsLocations << QCoreApplication::applicationDirPath() + "\\Python" - << QCoreApplication::applicationDirPath() + "\\..\\..\\Python"; - separator = ";"; + ripsLocations << QCoreApplication::applicationDirPath() + "\\Python" + << QCoreApplication::applicationDirPath() + "\\..\\..\\Python"; + separator = ";"; #else - ripsLocations << QCoreApplication::applicationDirPath() + "/Python" - << QCoreApplication::applicationDirPath() + "/../../Python"; - separator = ":"; + ripsLocations << QCoreApplication::applicationDirPath() + "/Python" + << QCoreApplication::applicationDirPath() + "/../../Python"; + separator = ":"; #endif - penv.insert( "PYTHONPATH", - QString( "%1%2%3" ).arg( penv.value( "PYTHONPATH" ) ).arg( separator ).arg( ripsLocations.join( separator ) ) ); + penv.insert( "PYTHONPATH", + QString( "%1%2%3" ).arg( penv.value( "PYTHONPATH" ) ).arg( separator ).arg( ripsLocations.join( separator ) ) ); + } return penv; } @@ -97,14 +99,19 @@ QProcessEnvironment RiaGrpcApplicationInterface::grpcProcessEnvironment() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -int RiaGrpcApplicationInterface::processRequests() +int RiaGrpcApplicationInterface::processRequests() { if ( RiaGrpcServer::receivedExitRequest() ) { - m_grpcServer->quit(); + if ( m_grpcServer ) m_grpcServer->quit(); return -1; } - size_t requestsProcessed = m_grpcServer->processAllQueuedRequests(); - return static_cast(requestsProcessed); + if ( m_grpcServer ) + { + size_t requestsProcessed = m_grpcServer->processAllQueuedRequests(); + return static_cast( requestsProcessed ); + } + + return 0; } diff --git a/GrpcInterface/RiaGrpcApplicationInterface.h b/GrpcInterface/RiaGrpcApplicationInterface.h index be38aeefb2..44f784c816 100644 --- a/GrpcInterface/RiaGrpcApplicationInterface.h +++ b/GrpcInterface/RiaGrpcApplicationInterface.h @@ -37,7 +37,7 @@ public: RiaGrpcServer* grpcServer() const; QProcessEnvironment grpcProcessEnvironment() const; - int processRequests(); + int processRequests(); protected: std::unique_ptr m_grpcServer; diff --git a/GrpcInterface/RiaGrpcServer.cpp b/GrpcInterface/RiaGrpcServer.cpp index 6df27e9f64..f89ba9af87 100644 --- a/GrpcInterface/RiaGrpcServer.cpp +++ b/GrpcInterface/RiaGrpcServer.cpp @@ -315,6 +315,8 @@ bool RiaGrpcServer::isRunning() const //-------------------------------------------------------------------------------------------------- void RiaGrpcServer::run() { + CVF_ASSERT( m_serverImpl ); + m_serverImpl->run(); } @@ -323,6 +325,8 @@ void RiaGrpcServer::run() //-------------------------------------------------------------------------------------------------- void RiaGrpcServer::runInThread() { + CVF_ASSERT( m_serverImpl ); + m_serverImpl->runInThread(); } @@ -336,6 +340,8 @@ bool RiaGrpcServer::s_receivedExitRequest = false; //-------------------------------------------------------------------------------------------------- void RiaGrpcServer::initialize() { + CVF_ASSERT( m_serverImpl ); + m_serverImpl->initialize(); } @@ -344,6 +350,8 @@ void RiaGrpcServer::initialize() //-------------------------------------------------------------------------------------------------- size_t RiaGrpcServer::processAllQueuedRequests() { + CVF_ASSERT( m_serverImpl ); + return m_serverImpl->processAllQueuedRequests(); }