diff --git a/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.h b/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.h index 53a6986dac..d830280c39 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.h @@ -39,7 +39,7 @@ class RiaGrpcServiceInterface; // Base class for all gRPC-callbacks // //================================================================================================== -class RiaAbstractGrpcCallback +class RiaGrpcCallbackInterface { public: enum CallState @@ -52,16 +52,16 @@ public: }; public: - inline RiaAbstractGrpcCallback(); + inline RiaGrpcCallbackInterface(); - virtual ~RiaAbstractGrpcCallback() {} - virtual QString name() const = 0; - virtual RiaAbstractGrpcCallback* createNewFromThis() const = 0; - virtual void createRequestHandler(ServerCompletionQueue* completionQueue) = 0; - virtual void onInitRequestStarted() {} - virtual void onInitRequestCompleted() {} - virtual void onProcessRequest() = 0; - virtual void onFinishRequest() {} + virtual ~RiaGrpcCallbackInterface() {} + virtual QString name() const = 0; + virtual RiaGrpcCallbackInterface* createNewFromThis() const = 0; + virtual void createRequestHandler(ServerCompletionQueue* completionQueue) = 0; + virtual void onInitRequestStarted() {} + virtual void onInitRequestCompleted() {} + virtual void onProcessRequest() = 0; + virtual void onFinishRequest() {} inline CallState callState() const; inline const Status& status() const; @@ -80,10 +80,10 @@ protected: // //================================================================================================== template -class RiaGrpcRequestCallback : public RiaAbstractGrpcCallback +class RiaGrpcServiceCallback : public RiaGrpcCallbackInterface { public: - RiaGrpcRequestCallback(ServiceT* service); + RiaGrpcServiceCallback(ServiceT* service); QString name() const override; const RequestT& request() const; @@ -104,7 +104,7 @@ protected: // //================================================================================================== template -class RiaGrpcCallback : public RiaGrpcRequestCallback +class RiaGrpcUnaryCallback : public RiaGrpcServiceCallback { public: typedef ServerAsyncResponseWriter ResponseWriterT; @@ -113,9 +113,9 @@ public: void(ServiceT&, ServerContext*, RequestT*, ResponseWriterT*, CompletionQueue*, ServerCompletionQueue*, void*)> MethodRequestT; - RiaGrpcCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest); + RiaGrpcUnaryCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest); - RiaAbstractGrpcCallback* createNewFromThis() const override; + RiaGrpcCallbackInterface* createNewFromThis() const override; void createRequestHandler(ServerCompletionQueue* completionQueue) override; void onProcessRequest() override; @@ -141,7 +141,7 @@ private: // //================================================================================================== template -class RiaGrpcStreamCallback : public RiaGrpcRequestCallback +class RiaGrpcServerStreamCallback : public RiaGrpcServiceCallback { public: typedef ServerAsyncWriter ResponseWriterT; @@ -150,9 +150,9 @@ public: void(ServiceT&, ServerContext*, RequestT*, ResponseWriterT*, CompletionQueue*, ServerCompletionQueue*, void*)> MethodRequestT; - RiaGrpcStreamCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest, StateHandlerT* stateHandler); + RiaGrpcServerStreamCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest, StateHandlerT* stateHandler); - RiaAbstractGrpcCallback* createNewFromThis() const override; + RiaGrpcCallbackInterface* createNewFromThis() const override; void createRequestHandler(ServerCompletionQueue* completionQueue) override; void onInitRequestCompleted() override; void onProcessRequest() override; @@ -181,7 +181,7 @@ private: // //================================================================================================== template -class RiaGrpcClientStreamCallback : public RiaGrpcRequestCallback +class RiaGrpcClientStreamCallback : public RiaGrpcServiceCallback { public: typedef ServerAsyncReader RequestReaderT; @@ -192,7 +192,7 @@ public: RiaGrpcClientStreamCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest, StateHandlerT* stateHandler); - RiaAbstractGrpcCallback* createNewFromThis() const override; + RiaGrpcCallbackInterface* createNewFromThis() const override; void createRequestHandler(ServerCompletionQueue* completionQueue) override; void onInitRequestStarted() override; void onInitRequestCompleted() override; diff --git a/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.inl b/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.inl index 4bc11a8bdb..2cbeb7798e 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.inl +++ b/ApplicationCode/GrpcInterface/RiaGrpcCallbacks.inl @@ -16,7 +16,7 @@ // ////////////////////////////////////////////////////////////////////////////////// -inline RiaAbstractGrpcCallback::RiaAbstractGrpcCallback() +inline RiaGrpcCallbackInterface::RiaGrpcCallbackInterface() : m_state(CREATE_HANDLER) , m_status(Status::OK) { @@ -25,7 +25,7 @@ inline RiaAbstractGrpcCallback::RiaAbstractGrpcCallback() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiaAbstractGrpcCallback::CallState RiaAbstractGrpcCallback::callState() const +RiaGrpcCallbackInterface::CallState RiaGrpcCallbackInterface::callState() const { return m_state; } @@ -33,7 +33,7 @@ RiaAbstractGrpcCallback::CallState RiaAbstractGrpcCallback::callState() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const Status& RiaAbstractGrpcCallback::status() const +const Status& RiaGrpcCallbackInterface::status() const { return m_status; } @@ -41,7 +41,7 @@ const Status& RiaAbstractGrpcCallback::status() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -inline void RiaAbstractGrpcCallback::setNextCallState(CallState state) +inline void RiaGrpcCallbackInterface::setNextCallState(CallState state) { m_state = state; } @@ -50,7 +50,7 @@ inline void RiaAbstractGrpcCallback::setNextCallState(CallState state) /// //-------------------------------------------------------------------------------------------------- template -RiaGrpcRequestCallback::RiaGrpcRequestCallback(ServiceT* service) +RiaGrpcServiceCallback::RiaGrpcServiceCallback(ServiceT* service) : m_service(service) { } @@ -59,7 +59,7 @@ RiaGrpcRequestCallback::RiaGrpcRequestCallback(Servi /// //-------------------------------------------------------------------------------------------------- template -QString RiaGrpcRequestCallback::name() const +QString RiaGrpcServiceCallback::name() const { QString fullName = QString("%1:%2(%3, %4)") .arg(typeid(ServiceT).name()) @@ -73,7 +73,7 @@ QString RiaGrpcRequestCallback::name() const /// //-------------------------------------------------------------------------------------------------- template -const RequestT& RiaGrpcRequestCallback::request() const +const RequestT& RiaGrpcServiceCallback::request() const { return m_request; } @@ -82,7 +82,7 @@ const RequestT& RiaGrpcRequestCallback::request() co /// //-------------------------------------------------------------------------------------------------- template -ReplyT& RiaGrpcRequestCallback::reply() +ReplyT& RiaGrpcServiceCallback::reply() { return m_reply; } @@ -91,10 +91,10 @@ ReplyT& RiaGrpcRequestCallback::reply() /// //-------------------------------------------------------------------------------------------------- template -RiaGrpcCallback::RiaGrpcCallback(ServiceT* service, +RiaGrpcUnaryCallback::RiaGrpcUnaryCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest) - : RiaGrpcRequestCallback(service) + : RiaGrpcServiceCallback(service) , m_responder(&m_context) , m_methodImpl(methodImpl) , m_methodRequest(methodRequest) @@ -105,34 +105,34 @@ RiaGrpcCallback::RiaGrpcCallback(ServiceT* serv /// //-------------------------------------------------------------------------------------------------- template -RiaAbstractGrpcCallback* RiaGrpcCallback::createNewFromThis() const +RiaGrpcCallbackInterface* RiaGrpcUnaryCallback::createNewFromThis() const { - return new RiaGrpcCallback(this->m_service, this->m_methodImpl, this->m_methodRequest); + return new RiaGrpcUnaryCallback(this->m_service, this->m_methodImpl, this->m_methodRequest); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- template -void RiaGrpcCallback::createRequestHandler(ServerCompletionQueue* completionQueue) +void RiaGrpcUnaryCallback::createRequestHandler(ServerCompletionQueue* completionQueue) { // The Request-method is where the service gets registered to respond to a given request. m_methodRequest(*this->m_service, &m_context, &this->m_request, &m_responder, completionQueue, completionQueue, this); // Simple unary requests don't need initialisation, so proceed to process as soon as a request turns up. - this->setNextCallState(RiaAbstractGrpcCallback::PROCESS_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::PROCESS_REQUEST); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- template -void RiaGrpcCallback::onProcessRequest() +void RiaGrpcUnaryCallback::onProcessRequest() { // Call request handler method this->m_status = m_methodImpl(*this->m_service, &m_context, &this->m_request, &this->m_reply); // Simply unary requests are finished as soon as you've done any processing. // So next time we receive a new tag on the command queue we should proceed to finish. - this->setNextCallState(RiaAbstractGrpcCallback::FINISH_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST); // Finish will push this callback back on the command queue (now with Finish as the call state). m_responder.Finish(this->m_reply, this->m_status, this); } @@ -141,7 +141,7 @@ void RiaGrpcCallback::onProcessRequest() /// //-------------------------------------------------------------------------------------------------- template -QString RiaGrpcCallback::methodType() const +QString RiaGrpcUnaryCallback::methodType() const { return "RegularMethod"; } @@ -150,11 +150,11 @@ QString RiaGrpcCallback::methodType() const /// //-------------------------------------------------------------------------------------------------- template -RiaGrpcStreamCallback::RiaGrpcStreamCallback(ServiceT* service, +RiaGrpcServerStreamCallback::RiaGrpcServerStreamCallback(ServiceT* service, MethodImplT methodImpl, MethodRequestT methodRequest, StateHandlerT* stateHandler) - : RiaGrpcRequestCallback(service) + : RiaGrpcServiceCallback(service) , m_responder(&m_context) , m_methodImpl(methodImpl) , m_methodRequest(methodRequest) @@ -166,9 +166,9 @@ RiaGrpcStreamCallback::RiaGrpcStreamC /// //-------------------------------------------------------------------------------------------------- template -RiaAbstractGrpcCallback* RiaGrpcStreamCallback::createNewFromThis() const +RiaGrpcCallbackInterface* RiaGrpcServerStreamCallback::createNewFromThis() const { - return new RiaGrpcStreamCallback( + return new RiaGrpcServerStreamCallback( this->m_service, m_methodImpl, m_methodRequest, new StateHandlerT); } @@ -176,21 +176,21 @@ RiaAbstractGrpcCallback* RiaGrpcStreamCallback -void RiaGrpcStreamCallback::createRequestHandler( +void RiaGrpcServerStreamCallback::createRequestHandler( ServerCompletionQueue* completionQueue) { // The Request-method is where the service gets registered to respond to a given request. m_methodRequest(*this->m_service, &m_context, &this->m_request, &m_responder, completionQueue, completionQueue, this); // Server->Client Streaming requests require initialisation. However, we receive the complete request immediately. // So can proceed directly to completion of the init request. - this->setNextCallState(RiaAbstractGrpcCallback::INIT_REQUEST_COMPLETED); + this->setNextCallState(RiaGrpcCallbackInterface::INIT_REQUEST_COMPLETED); } //-------------------------------------------------------------------------------------------------- /// Perform initialisation tasks at the time of receiving a complete request //-------------------------------------------------------------------------------------------------- template -void RiaGrpcStreamCallback::onInitRequestCompleted() +void RiaGrpcServerStreamCallback::onInitRequestCompleted() { // Initialise streaming state handler this->m_status = m_stateHandler->init(&this->m_request); @@ -198,14 +198,14 @@ void RiaGrpcStreamCallback::onInitReq if (!this->m_status.ok()) { // We have an error. Proceed to finish and report the status - this->setNextCallState(RiaAbstractGrpcCallback::FINISH_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST); m_responder.Finish(this->m_status, this); return; } // Move on to processing and perform the first processing immediately since the client will // not request anything more. - this->setNextCallState(RiaAbstractGrpcCallback::PROCESS_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::PROCESS_REQUEST); this->onProcessRequest(); } @@ -213,7 +213,7 @@ void RiaGrpcStreamCallback::onInitReq /// Process a streaming request and send one package //-------------------------------------------------------------------------------------------------- template -void RiaGrpcStreamCallback::onProcessRequest() +void RiaGrpcServerStreamCallback::onProcessRequest() { this->m_reply = ReplyT(); // Make sure it is reset @@ -228,7 +228,7 @@ void RiaGrpcStreamCallback::onProcess } else { - this->setNextCallState(RiaAbstractGrpcCallback::FINISH_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST); // Out of range means we're finished but it isn't an error if (this->m_status.error_code() == grpc::OUT_OF_RANGE) { @@ -243,7 +243,7 @@ void RiaGrpcStreamCallback::onProcess /// //-------------------------------------------------------------------------------------------------- template -QString RiaGrpcStreamCallback::methodType() const +QString RiaGrpcServerStreamCallback::methodType() const { return "StreamingMethod"; } @@ -257,7 +257,7 @@ RiaGrpcClientStreamCallback::RiaGrpcC MethodImplT methodImpl, MethodRequestT methodRequest, StateHandlerT* stateHandler) - : RiaGrpcRequestCallback(service) + : RiaGrpcServiceCallback(service) , m_reader(&m_context) , m_methodImpl(methodImpl) , m_methodRequest(methodRequest) @@ -269,7 +269,7 @@ RiaGrpcClientStreamCallback::RiaGrpcC /// //-------------------------------------------------------------------------------------------------- template -RiaAbstractGrpcCallback* RiaGrpcClientStreamCallback::createNewFromThis() const +RiaGrpcCallbackInterface* RiaGrpcClientStreamCallback::createNewFromThis() const { return new RiaGrpcClientStreamCallback( this->m_service, m_methodImpl, m_methodRequest, new StateHandlerT); @@ -286,7 +286,7 @@ void RiaGrpcClientStreamCallback::cre m_methodRequest(*this->m_service, &m_context, &this->m_reader, completionQueue, completionQueue, this); // The client->server streaming requires initialisation and each request package is streamed asynchronously // So we need to start and complete the init request. - this->setNextCallState(RiaAbstractGrpcCallback::INIT_REQUEST_STARTED); + this->setNextCallState(RiaGrpcCallbackInterface::INIT_REQUEST_STARTED); } //-------------------------------------------------------------------------------------------------- @@ -295,7 +295,7 @@ void RiaGrpcClientStreamCallback::cre template void RiaGrpcClientStreamCallback::onInitRequestStarted() { - this->setNextCallState(RiaAbstractGrpcCallback::INIT_REQUEST_COMPLETED); + this->setNextCallState(RiaGrpcCallbackInterface::INIT_REQUEST_COMPLETED); // The read call will start reading the request data and push this callback back onto the command queue // when the read call is completed. m_reader.Read(&this->m_request, this); @@ -307,7 +307,7 @@ void RiaGrpcClientStreamCallback::onI template void RiaGrpcClientStreamCallback::onInitRequestCompleted() { - this->setNextCallState(RiaAbstractGrpcCallback::PROCESS_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::PROCESS_REQUEST); // Fully received the stream package so can now init this->m_status = m_stateHandler->init(&this->m_request); @@ -315,7 +315,7 @@ void RiaGrpcClientStreamCallback::onI { // We have an error. Proceed to finish and report the status m_reader.FinishWithError(this->m_status, this); - this->setNextCallState(RiaAbstractGrpcCallback::FINISH_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST); return; } @@ -336,7 +336,7 @@ void RiaGrpcClientStreamCallback::onP if (!this->m_status.ok()) { - this->setNextCallState(RiaAbstractGrpcCallback::FINISH_REQUEST); + this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST); if (this->m_status.error_code() == grpc::OUT_OF_RANGE) { m_reader.Finish(this->m_reply, grpc::Status::OK, this); diff --git a/ApplicationCode/GrpcInterface/RiaGrpcCommandService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcCommandService.cpp index 683187c066..cf65a5d44e 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcCommandService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcCommandService.cpp @@ -32,6 +32,7 @@ using namespace rips; using namespace google::protobuf; +// Windows may define GetMessage as a Macro and this is in direct conflict with the gRPC GetMessage calls. #ifdef WIN32 #ifdef GetMessage #undef GetMessage @@ -96,11 +97,11 @@ grpc::Status RiaGrpcCommandService::Execute(grpc::ServerContext* context, const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaGrpcCommandService::createCallbacks() +std::vector RiaGrpcCommandService::createCallbacks() { typedef RiaGrpcCommandService Self; - return {new RiaGrpcCallback(this, &Self::Execute, &Self::RequestExecute)}; + return {new RiaGrpcUnaryCallback(this, &Self::Execute, &Self::RequestExecute)}; } diff --git a/ApplicationCode/GrpcInterface/RiaGrpcCommandService.h b/ApplicationCode/GrpcInterface/RiaGrpcCommandService.h index d763f5b751..5ddb222afd 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcCommandService.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcCommandService.h @@ -41,13 +41,13 @@ namespace protobuf } // namespace protobuf } // namespace google -class RiaAbstractGrpcCallback; +class RiaGrpcCallbackInterface; class RiaGrpcCommandService : public rips::Commands::AsyncService, public RiaGrpcServiceInterface { public: grpc::Status Execute(grpc::ServerContext* context, const rips::CommandParams* request, rips::CommandReply* reply) override; - std::vector createCallbacks() override; + std::vector createCallbacks() override; private: template diff --git a/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.cpp index 9f04df35b6..e7be462ad4 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.cpp @@ -316,15 +316,15 @@ grpc::Status RiaGrpcGridInfoService::GetCellInfoForActiveCells(grpc::ServerConte //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaGrpcGridInfoService::createCallbacks() +std::vector RiaGrpcGridInfoService::createCallbacks() { typedef RiaGrpcGridInfoService Self; - return {new RiaGrpcCallback(this, &Self::GetGridCount, &Self::RequestGetGridCount), - new RiaGrpcCallback(this, &Self::GetGridDimensions, &Self::RequestGetGridDimensions), - new RiaGrpcCallback(this, &Self::GetCellCount, &Self::RequestGetCellCount), - new RiaGrpcCallback(this, &Self::GetTimeSteps, &Self::RequestGetTimeSteps), - new RiaGrpcStreamCallback( + return {new RiaGrpcUnaryCallback(this, &Self::GetGridCount, &Self::RequestGetGridCount), + new RiaGrpcUnaryCallback(this, &Self::GetGridDimensions, &Self::RequestGetGridDimensions), + new RiaGrpcUnaryCallback(this, &Self::GetCellCount, &Self::RequestGetCellCount), + new RiaGrpcUnaryCallback(this, &Self::GetTimeSteps, &Self::RequestGetTimeSteps), + new RiaGrpcServerStreamCallback( this, &Self::GetCellInfoForActiveCells, &Self::RequestGetCellInfoForActiveCells, new RiaActiveCellInfoStateHandler)}; } diff --git a/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.h b/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.h index 828dd9e1da..104efd439b 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcGridInfoService.h @@ -29,7 +29,7 @@ namespace rips class Case; } -class RiaAbstractGrpcCallback; +class RiaGrpcCallbackInterface; class RigCell; class RigActiveCellInfo; class RimEclipseCase; @@ -78,5 +78,5 @@ public: const rips::CellInfoRequest* request, rips::CellInfoArray* reply, RiaActiveCellInfoStateHandler* stateHandler); - std::vector createCallbacks() override; + std::vector createCallbacks() override; }; diff --git a/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.cpp index 1e60b77b44..bd802730f3 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.cpp @@ -231,18 +231,18 @@ grpc::Status //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaGrpcProjectInfoService::createCallbacks() +std::vector RiaGrpcProjectInfoService::createCallbacks() { typedef RiaGrpcProjectInfoService Self; return { - new RiaGrpcCallback(this, &Self::CurrentCase, &Self::RequestCurrentCase), - new RiaGrpcCallback(this, &Self::CurrentCaseInfo, &Self::RequestCurrentCaseInfo), - new RiaGrpcCallback(this, &Self::CaseInfoFromCase, &Self::RequestCaseInfoFromCase), - new RiaGrpcCallback(this, &Self::SelectedCases, &Self::RequestSelectedCases), - new RiaGrpcCallback(this, &Self::AllCaseGroups, &Self::RequestAllCaseGroups), - new RiaGrpcCallback(this, &Self::AllCases, &Self::RequestAllCases), - new RiaGrpcCallback(this, &Self::CasesInGroup, &Self::RequestCasesInGroup)}; + new RiaGrpcUnaryCallback(this, &Self::CurrentCase, &Self::RequestCurrentCase), + new RiaGrpcUnaryCallback(this, &Self::CurrentCaseInfo, &Self::RequestCurrentCaseInfo), + new RiaGrpcUnaryCallback(this, &Self::CaseInfoFromCase, &Self::RequestCaseInfoFromCase), + new RiaGrpcUnaryCallback(this, &Self::SelectedCases, &Self::RequestSelectedCases), + new RiaGrpcUnaryCallback(this, &Self::AllCaseGroups, &Self::RequestAllCaseGroups), + new RiaGrpcUnaryCallback(this, &Self::AllCases, &Self::RequestAllCases), + new RiaGrpcUnaryCallback(this, &Self::CasesInGroup, &Self::RequestCasesInGroup)}; } static bool RiaGrpcProjectInfoService_init = diff --git a/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.h b/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.h index b9db1a5375..92ab551cf7 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcProjectInfoService.h @@ -28,7 +28,7 @@ class Empty; class CaseInfo; } // namespace rips -class RiaAbstractGrpcCallback; +class RiaGrpcCallbackInterface; //================================================================================================== // @@ -47,5 +47,5 @@ public: grpc::Status CasesInGroup(grpc::ServerContext* context, const rips::CaseGroup* request, rips::CaseInfos* reply) override; public: - std::vector createCallbacks() override; + std::vector createCallbacks() override; }; diff --git a/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.cpp index c59c4e560a..8b3a4be4c3 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.cpp @@ -302,15 +302,15 @@ grpc::Status RiaGrpcPropertiesService::SetGridResults(grpc::ServerContext* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaGrpcPropertiesService::createCallbacks() +std::vector RiaGrpcPropertiesService::createCallbacks() { typedef RiaGrpcPropertiesService Self; - return {new RiaGrpcCallback( + return {new RiaGrpcUnaryCallback( this, &Self::GetAvailableProperties, &Self::RequestGetAvailableProperties), - new RiaGrpcStreamCallback( + new RiaGrpcServerStreamCallback( this, &Self::GetActiveCellResults, &Self::RequestGetActiveCellResults, new RiaActiveCellResultsStateHandler), - new RiaGrpcStreamCallback( + new RiaGrpcServerStreamCallback( this, &Self::GetGridResults, &Self::RequestGetGridResults, new RiaGridCellResultsStateHandler), new RiaGrpcClientStreamCallback( this, &Self::SetActiveCellResults, &Self::RequestSetActiveCellResults, new RiaActiveCellResultsStateHandler), diff --git a/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.h b/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.h index 2fee1d0833..827b5a8b66 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcPropertiesService.h @@ -54,5 +54,5 @@ public: rips::Empty* reply, RiaGridCellResultsStateHandler* stateHandler); - std::vector createCallbacks() override; + std::vector createCallbacks() override; }; diff --git a/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.cpp index 6523f12073..c9503b40c7 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.cpp @@ -34,10 +34,10 @@ grpc::Status RiaGrpcResInfoService::GetVersion(grpc::ServerContext* context, con //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaGrpcResInfoService::createCallbacks() +std::vector RiaGrpcResInfoService::createCallbacks() { typedef RiaGrpcResInfoService Self; - return { new RiaGrpcCallback(this, &Self::GetVersion, &Self::RequestGetVersion) }; + return { new RiaGrpcUnaryCallback(this, &Self::GetVersion, &Self::RequestGetVersion) }; } static bool RiaGrpcResInfoService_init = diff --git a/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.h b/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.h index 0f48ff3485..41b1fbaf20 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcResInfoService.h @@ -37,13 +37,13 @@ namespace caf class PdmValueField; } -class RiaAbstractGrpcCallback; +class RiaGrpcCallbackInterface; class RiaGrpcResInfoService : public rips::ResInfo::AsyncService, public RiaGrpcServiceInterface { public: grpc::Status GetVersion(grpc::ServerContext* context, const rips::Empty* request, rips::Version* reply) override; - std::vector createCallbacks() override; + std::vector createCallbacks() override; }; diff --git a/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp b/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp index dfba26d327..4af25b1eff 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp @@ -63,18 +63,17 @@ public: void initialize(); void processAllQueuedRequests(); void quit(); - int currentPortNumber; private: void waitForNextRequest(); - void process(RiaAbstractGrpcCallback* method); + void process(RiaGrpcCallbackInterface* method); private: int m_portNumber; std::unique_ptr m_completionQueue; std::unique_ptr m_server; std::list> m_services; - std::list m_unprocessedRequests; + std::list m_unprocessedRequests; std::mutex m_requestMutex; std::thread m_thread; }; @@ -171,12 +170,17 @@ void RiaGrpcServerImpl::initialize() //-------------------------------------------------------------------------------------------------- void RiaGrpcServerImpl::processAllQueuedRequests() { - std::lock_guard requestLock(m_requestMutex); - - while (!m_unprocessedRequests.empty()) + std::list waitingRequests; { - RiaAbstractGrpcCallback* method = m_unprocessedRequests.front(); - m_unprocessedRequests.pop_front(); + // Block only while transferring the unprocessed requests to a local function list + std::lock_guard requestLock(m_requestMutex); + waitingRequests.swap(m_unprocessedRequests); + } + // Now free to receive new requests from client while processing the current ones. + while (!waitingRequests.empty()) + { + RiaGrpcCallbackInterface* method = waitingRequests.front(); + waitingRequests.pop_front(); process(method); } } @@ -193,7 +197,7 @@ void RiaGrpcServerImpl::quit() // Clear unhandled requests while (!m_unprocessedRequests.empty()) { - RiaAbstractGrpcCallback* method = m_unprocessedRequests.front(); + RiaGrpcCallbackInterface* method = m_unprocessedRequests.front(); m_unprocessedRequests.pop_front(); delete method; } @@ -225,7 +229,7 @@ void RiaGrpcServerImpl::waitForNextRequest() while (m_completionQueue->Next(&tag, &ok)) { - RiaAbstractGrpcCallback* method = static_cast(tag); + RiaGrpcCallbackInterface* method = static_cast(tag); if (ok) { std::lock_guard requestLock(m_requestMutex); @@ -239,24 +243,24 @@ void RiaGrpcServerImpl::waitForNextRequest() /// The gRPC calls triggered in the callback will see each callback pushed back onto the command queue. /// The call state will then determine what the callback should do next. //-------------------------------------------------------------------------------------------------- -void RiaGrpcServerImpl::process(RiaAbstractGrpcCallback* method) +void RiaGrpcServerImpl::process(RiaGrpcCallbackInterface* method) { - if (method->callState() == RiaAbstractGrpcCallback::CREATE_HANDLER) + if (method->callState() == RiaGrpcCallbackInterface::CREATE_HANDLER) { RiaLogging::debug(QString("Creating request handler for: %1").arg(method->name())); method->createRequestHandler(m_completionQueue.get()); } - else if (method->callState() == RiaAbstractGrpcCallback::INIT_REQUEST_STARTED) + else if (method->callState() == RiaGrpcCallbackInterface::INIT_REQUEST_STARTED) { method->onInitRequestStarted(); } - else if (method->callState() == RiaAbstractGrpcCallback::INIT_REQUEST_COMPLETED) + else if (method->callState() == RiaGrpcCallbackInterface::INIT_REQUEST_COMPLETED) { RiaLogging::info(QString("Initialising handling: %1").arg(method->name())); method->onInitRequestCompleted(); } - else if (method->callState() == RiaAbstractGrpcCallback::PROCESS_REQUEST) + else if (method->callState() == RiaGrpcCallbackInterface::PROCESS_REQUEST) { method->onProcessRequest(); } diff --git a/ApplicationCode/GrpcInterface/RiaGrpcServiceInterface.h b/ApplicationCode/GrpcInterface/RiaGrpcServiceInterface.h index 0d5383ed39..3795ea57f1 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcServiceInterface.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcServiceInterface.h @@ -21,7 +21,7 @@ #include -class RiaAbstractGrpcCallback; +class RiaGrpcCallbackInterface; class RimCase; //================================================================================================== @@ -32,7 +32,7 @@ class RimCase; class RiaGrpcServiceInterface { public: - virtual std::vector createCallbacks() = 0; + virtual std::vector createCallbacks() = 0; virtual ~RiaGrpcServiceInterface() = default; static RimCase* findCase(int caseId); static size_t numberOfMessagesForByteCount(size_t messageSize, size_t byteCount = 64 * 1024u);