2019-05-20 06:21:02 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019- Equinor ASA
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-05-27 00:29:20 -05:00
|
|
|
inline RiaGrpcCallbackInterface::RiaGrpcCallbackInterface()
|
2019-05-20 06:21:02 -05:00
|
|
|
: m_state(CREATE_HANDLER)
|
|
|
|
, m_status(Status::OK)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-05-27 00:29:20 -05:00
|
|
|
RiaGrpcCallbackInterface::CallState RiaGrpcCallbackInterface::callState() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-05-27 00:29:20 -05:00
|
|
|
const Status& RiaGrpcCallbackInterface::status() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
return m_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-05-27 00:29:20 -05:00
|
|
|
inline void RiaGrpcCallbackInterface::setNextCallState(CallState state)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
m_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>::RiaGrpcServiceCallback(ServiceT* service)
|
2019-05-20 06:21:02 -05:00
|
|
|
: m_service(service)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
QString RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>::name() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
QString fullName = QString("%1:%2(%3, %4)")
|
|
|
|
.arg(typeid(ServiceT).name())
|
|
|
|
.arg(methodType())
|
|
|
|
.arg(typeid(RequestT).name())
|
|
|
|
.arg(typeid(ReplyT).name());
|
|
|
|
return fullName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
const RequestT& RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>::request() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
return m_request;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
ReplyT& RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>::reply()
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
return m_reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
RiaGrpcUnaryCallback<ServiceT, RequestT, ReplyT>::RiaGrpcUnaryCallback(ServiceT* service,
|
2019-05-20 06:21:02 -05:00
|
|
|
MethodImplT methodImpl,
|
|
|
|
MethodRequestT methodRequest)
|
2019-05-27 00:29:20 -05:00
|
|
|
: RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>(service)
|
2019-05-20 06:21:02 -05:00
|
|
|
, m_responder(&m_context)
|
|
|
|
, m_methodImpl(methodImpl)
|
|
|
|
, m_methodRequest(methodRequest)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
RiaGrpcCallbackInterface* RiaGrpcUnaryCallback<ServiceT, RequestT, ReplyT>::createNewFromThis() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
2019-05-27 00:29:20 -05:00
|
|
|
return new RiaGrpcUnaryCallback<ServiceT, RequestT, ReplyT>(this->m_service, this->m_methodImpl, this->m_methodRequest);
|
2019-05-20 06:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
void RiaGrpcUnaryCallback<ServiceT, RequestT, ReplyT>::createRequestHandler(ServerCompletionQueue* completionQueue)
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
2019-05-23 02:58:04 -05:00
|
|
|
// The Request-method is where the service gets registered to respond to a given request.
|
2019-05-20 06:21:02 -05:00
|
|
|
m_methodRequest(*this->m_service, &m_context, &this->m_request, &m_responder, completionQueue, completionQueue, this);
|
2019-05-23 02:58:04 -05:00
|
|
|
// Simple unary requests don't need initialisation, so proceed to process as soon as a request turns up.
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::PROCESS_REQUEST);
|
2019-05-20 06:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
void RiaGrpcUnaryCallback<ServiceT, RequestT, ReplyT>::onProcessRequest()
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
2019-05-23 02:58:04 -05:00
|
|
|
// Call request handler method
|
2019-05-20 06:21:02 -05:00
|
|
|
this->m_status = m_methodImpl(*this->m_service, &m_context, &this->m_request, &this->m_reply);
|
2019-05-23 02:58:04 -05:00
|
|
|
// 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.
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST);
|
2019-05-23 02:58:04 -05:00
|
|
|
// Finish will push this callback back on the command queue (now with Finish as the call state).
|
2019-05-20 06:21:02 -05:00
|
|
|
m_responder.Finish(this->m_reply, this->m_status, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT>
|
2019-05-27 00:29:20 -05:00
|
|
|
QString RiaGrpcUnaryCallback<ServiceT, RequestT, ReplyT>::methodType() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
return "RegularMethod";
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::RiaGrpcServerToClientStreamCallback(ServiceT* service,
|
2019-05-20 06:21:02 -05:00
|
|
|
MethodImplT methodImpl,
|
|
|
|
MethodRequestT methodRequest,
|
|
|
|
StateHandlerT* stateHandler)
|
2019-05-27 00:29:20 -05:00
|
|
|
: RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>(service)
|
2019-05-20 06:21:02 -05:00
|
|
|
, m_responder(&m_context)
|
|
|
|
, m_methodImpl(methodImpl)
|
|
|
|
, m_methodRequest(methodRequest)
|
|
|
|
, m_stateHandler(stateHandler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
RiaGrpcCallbackInterface* RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::createNewFromThis() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
2019-08-13 01:23:03 -05:00
|
|
|
return new RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>(
|
2019-05-20 06:21:02 -05:00
|
|
|
this->m_service, m_methodImpl, m_methodRequest, new StateHandlerT);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::createRequestHandler(
|
2019-05-20 06:21:02 -05:00
|
|
|
ServerCompletionQueue* completionQueue)
|
|
|
|
{
|
2019-05-23 02:58:04 -05:00
|
|
|
// The Request-method is where the service gets registered to respond to a given request.
|
2019-05-20 06:21:02 -05:00
|
|
|
m_methodRequest(*this->m_service, &m_context, &this->m_request, &m_responder, completionQueue, completionQueue, this);
|
2019-05-23 02:58:04 -05:00
|
|
|
// Server->Client Streaming requests require initialisation. However, we receive the complete request immediately.
|
|
|
|
// So can proceed directly to completion of the init request.
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::INIT_REQUEST_COMPLETED);
|
2019-05-20 06:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-05-23 02:58:04 -05:00
|
|
|
/// Perform initialisation tasks at the time of receiving a complete request
|
2019-05-20 06:21:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::onInitRequestCompleted()
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
2019-05-23 02:58:04 -05:00
|
|
|
// Initialise streaming state handler
|
2019-05-20 06:21:02 -05:00
|
|
|
this->m_status = m_stateHandler->init(&this->m_request);
|
2019-05-23 02:58:04 -05:00
|
|
|
|
|
|
|
if (!this->m_status.ok())
|
|
|
|
{
|
|
|
|
// We have an error. Proceed to finish and report the status
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST);
|
2019-05-23 02:58:04 -05:00
|
|
|
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.
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::PROCESS_REQUEST);
|
2019-05-22 08:30:09 -05:00
|
|
|
this->onProcessRequest();
|
2019-05-20 06:21:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-05-23 02:58:04 -05:00
|
|
|
/// Process a streaming request and send one package
|
2019-05-20 06:21:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::onProcessRequest()
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
this->m_reply = ReplyT(); // Make sure it is reset
|
2019-05-23 02:58:04 -05:00
|
|
|
|
|
|
|
// Call request handler method
|
2019-05-20 06:21:02 -05:00
|
|
|
this->m_status = m_methodImpl(*this->m_service, &m_context, &this->m_request, &this->m_reply, m_stateHandler.get());
|
2019-05-23 02:58:04 -05:00
|
|
|
|
2019-05-20 06:21:02 -05:00
|
|
|
if (this->m_status.ok())
|
|
|
|
{
|
2019-05-23 02:58:04 -05:00
|
|
|
// The write call will send data to client AND put this callback back on the command queue
|
|
|
|
// so that this method gets called again to send the next stream package.
|
2019-05-20 06:21:02 -05:00
|
|
|
m_responder.Write(this->m_reply, this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST);
|
2019-05-20 06:21:02 -05:00
|
|
|
// Out of range means we're finished but it isn't an error
|
|
|
|
if (this->m_status.error_code() == grpc::OUT_OF_RANGE)
|
|
|
|
{
|
|
|
|
this->m_status = Status::OK;
|
|
|
|
}
|
2019-05-23 02:58:04 -05:00
|
|
|
// Finish will put this callback back on the command queue, now with a finish state.
|
2019-05-20 06:21:02 -05:00
|
|
|
m_responder.Finish(this->m_status, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
QString RiaGrpcServerToClientStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::methodType() const
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
return "StreamingMethod";
|
|
|
|
}
|
2019-05-22 08:30:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::RiaGrpcClientToServerStreamCallback(ServiceT* service,
|
2019-05-22 08:30:09 -05:00
|
|
|
MethodImplT methodImpl,
|
|
|
|
MethodRequestT methodRequest,
|
|
|
|
StateHandlerT* stateHandler)
|
2019-05-27 00:29:20 -05:00
|
|
|
: RiaGrpcServiceCallback<ServiceT, RequestT, ReplyT>(service)
|
2019-05-22 08:30:09 -05:00
|
|
|
, m_reader(&m_context)
|
|
|
|
, m_methodImpl(methodImpl)
|
|
|
|
, m_methodRequest(methodRequest)
|
|
|
|
, m_stateHandler(stateHandler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
RiaGrpcCallbackInterface* RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::createNewFromThis() const
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
2019-08-13 01:23:03 -05:00
|
|
|
return new RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>(
|
2019-05-30 11:52:16 -05:00
|
|
|
this->m_service, m_methodImpl, m_methodRequest, new StateHandlerT(true));
|
2019-05-22 08:30:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::createRequestHandler(
|
2019-05-22 08:30:09 -05:00
|
|
|
ServerCompletionQueue* completionQueue)
|
|
|
|
{
|
2019-05-23 02:58:04 -05:00
|
|
|
// The Request-method is where the service gets registered to respond to a given request.
|
2019-05-22 08:30:09 -05:00
|
|
|
m_methodRequest(*this->m_service, &m_context, &this->m_reader, completionQueue, completionQueue, this);
|
2019-05-23 02:58:04 -05:00
|
|
|
// The client->server streaming requires initialisation and each request package is streamed asynchronously
|
|
|
|
// So we need to start and complete the init request.
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::INIT_REQUEST_STARTED);
|
2019-05-22 08:30:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::onInitRequestStarted()
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::INIT_REQUEST_COMPLETED);
|
2019-05-23 02:58:04 -05:00
|
|
|
// The read call will start reading the request data and push this callback back onto the command queue
|
|
|
|
// when the read call is completed.
|
2019-05-24 00:55:15 -05:00
|
|
|
m_reader.Read(&this->m_request, this);
|
2019-05-22 08:30:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::onInitRequestCompleted()
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::PROCESS_REQUEST);
|
2019-05-23 02:58:04 -05:00
|
|
|
// Fully received the stream package so can now init
|
|
|
|
this->m_status = m_stateHandler->init(&this->m_request);
|
|
|
|
|
|
|
|
if (!this->m_status.ok())
|
|
|
|
{
|
|
|
|
// We have an error. Proceed to finish and report the status
|
|
|
|
m_reader.FinishWithError(this->m_status, this);
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST);
|
2019-05-23 02:58:04 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start reading and push this back onto the command queue.
|
2019-05-24 00:55:15 -05:00
|
|
|
m_reader.Read(&this->m_request, this);
|
2019-05-22 08:30:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::onProcessRequest()
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
|
|
|
this->m_reply = ReplyT(); // Make sure it is reset
|
2019-05-23 02:58:04 -05:00
|
|
|
|
|
|
|
// Call request handler method
|
2019-05-22 08:30:09 -05:00
|
|
|
this->m_status = m_methodImpl(*this->m_service, &m_context, &this->m_request, &this->m_reply, m_stateHandler.get());
|
2019-08-13 06:15:58 -05:00
|
|
|
|
2019-05-22 08:30:09 -05:00
|
|
|
if (!this->m_status.ok())
|
|
|
|
{
|
2019-05-27 00:29:20 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST);
|
2019-08-13 06:15:58 -05:00
|
|
|
m_reader.FinishWithError(this->m_status, this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-14 02:14:12 -05:00
|
|
|
CAF_ASSERT(m_stateHandler->streamedValueCount() <= m_stateHandler->cellCount());
|
|
|
|
if (m_stateHandler->streamedValueCount() == m_stateHandler->cellCount())
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
2019-08-13 06:15:58 -05:00
|
|
|
this->setNextCallState(RiaGrpcCallbackInterface::FINISH_REQUEST);
|
2019-05-22 08:30:09 -05:00
|
|
|
m_reader.Finish(this->m_reply, grpc::Status::OK, this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-13 06:15:58 -05:00
|
|
|
m_reader.Read(&this->m_request, this);
|
2019-05-22 08:30:09 -05:00
|
|
|
}
|
2019-08-13 06:15:58 -05:00
|
|
|
}
|
2019-05-22 08:30:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
void RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::onFinishRequest()
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
|
|
|
m_stateHandler->finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
template<typename ServiceT, typename RequestT, typename ReplyT, typename StateHandlerT>
|
2019-08-13 01:23:03 -05:00
|
|
|
QString RiaGrpcClientToServerStreamCallback<ServiceT, RequestT, ReplyT, StateHandlerT>::methodType() const
|
2019-05-22 08:30:09 -05:00
|
|
|
{
|
|
|
|
return "ClientStreamingMethod";
|
|
|
|
}
|