|
|
@ -93,9 +93,67 @@ class CallbackUnaryCallImpl { |
|
|
|
|
|
|
|
|
|
|
|
namespace experimental { |
|
|
|
namespace experimental { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
|
|
|
|
template <class Request, class Response> |
|
|
|
|
|
|
|
class ClientBidiReactor; |
|
|
|
|
|
|
|
template <class Response> |
|
|
|
|
|
|
|
class ClientReadReactor; |
|
|
|
|
|
|
|
template <class Request> |
|
|
|
|
|
|
|
class ClientWriteReactor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: The streaming objects are not actually implemented in the public API.
|
|
|
|
|
|
|
|
// These interfaces are provided for mocking only. Typical applications
|
|
|
|
|
|
|
|
// will interact exclusively with the reactors that they define.
|
|
|
|
|
|
|
|
template <class Request, class Response> |
|
|
|
|
|
|
|
class ClientCallbackReaderWriter { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
virtual ~ClientCallbackReaderWriter() {} |
|
|
|
|
|
|
|
virtual void StartCall() = 0; |
|
|
|
|
|
|
|
virtual void Write(const Request* req, WriteOptions options) = 0; |
|
|
|
|
|
|
|
virtual void WritesDone() = 0; |
|
|
|
|
|
|
|
virtual void Read(Response* resp) = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
void BindReactor(ClientBidiReactor<Request, Response>* reactor) { |
|
|
|
|
|
|
|
reactor->BindStream(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Response> |
|
|
|
|
|
|
|
class ClientCallbackReader { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
virtual ~ClientCallbackReader() {} |
|
|
|
|
|
|
|
virtual void StartCall() = 0; |
|
|
|
|
|
|
|
virtual void Read(Response* resp) = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
void BindReactor(ClientReadReactor<Response>* reactor) { |
|
|
|
|
|
|
|
reactor->BindReader(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Request> |
|
|
|
|
|
|
|
class ClientCallbackWriter { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
virtual ~ClientCallbackWriter() {} |
|
|
|
|
|
|
|
virtual void StartCall() = 0; |
|
|
|
|
|
|
|
void Write(const Request* req) { Write(req, WriteOptions()); } |
|
|
|
|
|
|
|
virtual void Write(const Request* req, WriteOptions options) = 0; |
|
|
|
|
|
|
|
void WriteLast(const Request* req, WriteOptions options) { |
|
|
|
|
|
|
|
Write(req, options.set_last_message()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
virtual void WritesDone() = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
|
|
|
void BindReactor(ClientWriteReactor<Request>* reactor) { |
|
|
|
|
|
|
|
reactor->BindWriter(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// The user must implement this reactor interface with reactions to each event
|
|
|
|
// The user must implement this reactor interface with reactions to each event
|
|
|
|
// type that gets called by the library. An empty reaction is provided by
|
|
|
|
// type that gets called by the library. An empty reaction is provided by
|
|
|
|
// default
|
|
|
|
// default
|
|
|
|
|
|
|
|
template <class Request, class Response> |
|
|
|
class ClientBidiReactor { |
|
|
|
class ClientBidiReactor { |
|
|
|
public: |
|
|
|
public: |
|
|
|
virtual ~ClientBidiReactor() {} |
|
|
|
virtual ~ClientBidiReactor() {} |
|
|
@ -104,16 +162,44 @@ class ClientBidiReactor { |
|
|
|
virtual void OnReadDone(bool ok) {} |
|
|
|
virtual void OnReadDone(bool ok) {} |
|
|
|
virtual void OnWriteDone(bool ok) {} |
|
|
|
virtual void OnWriteDone(bool ok) {} |
|
|
|
virtual void OnWritesDoneDone(bool ok) {} |
|
|
|
virtual void OnWritesDoneDone(bool ok) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StartCall() { stream_->StartCall(); } |
|
|
|
|
|
|
|
void StartRead(Response* resp) { stream_->Read(resp); } |
|
|
|
|
|
|
|
void StartWrite(const Request* req) { StartWrite(req, WriteOptions()); } |
|
|
|
|
|
|
|
void StartWrite(const Request* req, WriteOptions options) { |
|
|
|
|
|
|
|
stream_->Write(req, std::move(options)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void StartWriteLast(const Request* req, WriteOptions options) { |
|
|
|
|
|
|
|
StartWrite(req, std::move(options.set_last_message())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void StartWritesDone() { stream_->WritesDone(); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
friend class ClientCallbackReaderWriter<Request, Response>; |
|
|
|
|
|
|
|
void BindStream(ClientCallbackReaderWriter<Request, Response>* stream) { |
|
|
|
|
|
|
|
stream_ = stream; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ClientCallbackReaderWriter<Request, Response>* stream_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Response> |
|
|
|
class ClientReadReactor { |
|
|
|
class ClientReadReactor { |
|
|
|
public: |
|
|
|
public: |
|
|
|
virtual ~ClientReadReactor() {} |
|
|
|
virtual ~ClientReadReactor() {} |
|
|
|
virtual void OnDone(Status s) {} |
|
|
|
virtual void OnDone(Status s) {} |
|
|
|
virtual void OnReadInitialMetadataDone(bool ok) {} |
|
|
|
virtual void OnReadInitialMetadataDone(bool ok) {} |
|
|
|
virtual void OnReadDone(bool ok) {} |
|
|
|
virtual void OnReadDone(bool ok) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void StartCall() { reader_->StartCall(); } |
|
|
|
|
|
|
|
void StartRead(Response* resp) { reader_->Read(resp); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
friend class ClientCallbackReader<Response>; |
|
|
|
|
|
|
|
void BindReader(ClientCallbackReader<Response>* reader) { reader_ = reader; } |
|
|
|
|
|
|
|
ClientCallbackReader<Response>* reader_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Request> |
|
|
|
class ClientWriteReactor { |
|
|
|
class ClientWriteReactor { |
|
|
|
public: |
|
|
|
public: |
|
|
|
virtual ~ClientWriteReactor() {} |
|
|
|
virtual ~ClientWriteReactor() {} |
|
|
@ -121,41 +207,21 @@ class ClientWriteReactor { |
|
|
|
virtual void OnReadInitialMetadataDone(bool ok) {} |
|
|
|
virtual void OnReadInitialMetadataDone(bool ok) {} |
|
|
|
virtual void OnWriteDone(bool ok) {} |
|
|
|
virtual void OnWriteDone(bool ok) {} |
|
|
|
virtual void OnWritesDoneDone(bool ok) {} |
|
|
|
virtual void OnWritesDoneDone(bool ok) {} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Request, class Response> |
|
|
|
void StartCall() { writer_->StartCall(); } |
|
|
|
class ClientCallbackReaderWriter { |
|
|
|
void StartWrite(const Request* req) { StartWrite(req, WriteOptions()); } |
|
|
|
public: |
|
|
|
void StartWrite(const Request* req, WriteOptions options) { |
|
|
|
virtual ~ClientCallbackReaderWriter() {} |
|
|
|
writer_->Write(req, std::move(options)); |
|
|
|
virtual void StartCall() = 0; |
|
|
|
|
|
|
|
void Write(const Request* req) { Write(req, WriteOptions()); } |
|
|
|
|
|
|
|
virtual void Write(const Request* req, WriteOptions options) = 0; |
|
|
|
|
|
|
|
void WriteLast(const Request* req, WriteOptions options) { |
|
|
|
|
|
|
|
Write(req, options.set_last_message()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
virtual void WritesDone() = 0; |
|
|
|
void StartWriteLast(const Request* req, WriteOptions options) { |
|
|
|
virtual void Read(Response* resp) = 0; |
|
|
|
StartWrite(req, std::move(options.set_last_message())); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Response> |
|
|
|
|
|
|
|
class ClientCallbackReader { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
virtual ~ClientCallbackReader() {} |
|
|
|
|
|
|
|
virtual void StartCall() = 0; |
|
|
|
|
|
|
|
virtual void Read(Response* resp) = 0; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Request> |
|
|
|
|
|
|
|
class ClientCallbackWriter { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
virtual ~ClientCallbackWriter() {} |
|
|
|
|
|
|
|
virtual void StartCall() = 0; |
|
|
|
|
|
|
|
void Write(const Request* req) { Write(req, WriteOptions()); } |
|
|
|
|
|
|
|
virtual void Write(const Request* req, WriteOptions options) = 0; |
|
|
|
|
|
|
|
void WriteLast(const Request* req, WriteOptions options) { |
|
|
|
|
|
|
|
Write(req, options.set_last_message()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
virtual void WritesDone() = 0; |
|
|
|
void StartWritesDone() { writer_->WritesDone(); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
friend class ClientCallbackWriter<Request>; |
|
|
|
|
|
|
|
void BindWriter(ClientCallbackWriter<Request>* writer) { writer_ = writer; } |
|
|
|
|
|
|
|
ClientCallbackWriter<Request>* writer_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} // namespace experimental
|
|
|
|
} // namespace experimental
|
|
|
@ -204,7 +270,8 @@ class ClientCallbackReaderWriterImpl |
|
|
|
// 4. Any write backlog
|
|
|
|
// 4. Any write backlog
|
|
|
|
started_ = true; |
|
|
|
started_ = true; |
|
|
|
|
|
|
|
|
|
|
|
start_tag_.Set(call_.call(), |
|
|
|
start_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnReadInitialMetadataDone(ok); |
|
|
|
reactor_->OnReadInitialMetadataDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -220,7 +287,8 @@ class ClientCallbackReaderWriterImpl |
|
|
|
|
|
|
|
|
|
|
|
// Also set up the read and write tags so that they don't have to be set up
|
|
|
|
// Also set up the read and write tags so that they don't have to be set up
|
|
|
|
// each time
|
|
|
|
// each time
|
|
|
|
write_tag_.Set(call_.call(), |
|
|
|
write_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnWriteDone(ok); |
|
|
|
reactor_->OnWriteDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -228,7 +296,8 @@ class ClientCallbackReaderWriterImpl |
|
|
|
&write_ops_); |
|
|
|
&write_ops_); |
|
|
|
write_ops_.set_core_cq_tag(&write_tag_); |
|
|
|
write_ops_.set_core_cq_tag(&write_tag_); |
|
|
|
|
|
|
|
|
|
|
|
read_tag_.Set(call_.call(), |
|
|
|
read_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnReadDone(ok); |
|
|
|
reactor_->OnReadDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -239,8 +308,8 @@ class ClientCallbackReaderWriterImpl |
|
|
|
call_.PerformOps(&read_ops_); |
|
|
|
call_.PerformOps(&read_ops_); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
finish_tag_.Set(call_.call(), [this](bool ok) { MaybeFinish(); }, |
|
|
|
finish_tag_.Set( |
|
|
|
&finish_ops_); |
|
|
|
call_.call(), [this](bool ok) { MaybeFinish(); }, &finish_ops_); |
|
|
|
finish_ops_.ClientRecvStatus(context_, &finish_status_); |
|
|
|
finish_ops_.ClientRecvStatus(context_, &finish_status_); |
|
|
|
finish_ops_.set_core_cq_tag(&finish_tag_); |
|
|
|
finish_ops_.set_core_cq_tag(&finish_tag_); |
|
|
|
call_.PerformOps(&finish_ops_); |
|
|
|
call_.PerformOps(&finish_ops_); |
|
|
@ -291,7 +360,8 @@ class ClientCallbackReaderWriterImpl |
|
|
|
start_corked_ = false; |
|
|
|
start_corked_ = false; |
|
|
|
} |
|
|
|
} |
|
|
|
writes_done_ops_.ClientSendClose(); |
|
|
|
writes_done_ops_.ClientSendClose(); |
|
|
|
writes_done_tag_.Set(call_.call(), |
|
|
|
writes_done_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnWritesDoneDone(ok); |
|
|
|
reactor_->OnWritesDoneDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -311,15 +381,17 @@ class ClientCallbackReaderWriterImpl |
|
|
|
|
|
|
|
|
|
|
|
ClientCallbackReaderWriterImpl( |
|
|
|
ClientCallbackReaderWriterImpl( |
|
|
|
Call call, ClientContext* context, |
|
|
|
Call call, ClientContext* context, |
|
|
|
::grpc::experimental::ClientBidiReactor* reactor) |
|
|
|
::grpc::experimental::ClientBidiReactor<Request, Response>* reactor) |
|
|
|
: context_(context), |
|
|
|
: context_(context), |
|
|
|
call_(call), |
|
|
|
call_(call), |
|
|
|
reactor_(reactor), |
|
|
|
reactor_(reactor), |
|
|
|
start_corked_(context_->initial_metadata_corked_) {} |
|
|
|
start_corked_(context_->initial_metadata_corked_) { |
|
|
|
|
|
|
|
this->BindReactor(reactor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ClientContext* context_; |
|
|
|
ClientContext* context_; |
|
|
|
Call call_; |
|
|
|
Call call_; |
|
|
|
::grpc::experimental::ClientBidiReactor* reactor_; |
|
|
|
::grpc::experimental::ClientBidiReactor<Request, Response>* reactor_; |
|
|
|
|
|
|
|
|
|
|
|
CallOpSet<CallOpSendInitialMetadata, CallOpRecvInitialMetadata> start_ops_; |
|
|
|
CallOpSet<CallOpSendInitialMetadata, CallOpRecvInitialMetadata> start_ops_; |
|
|
|
CallbackWithSuccessTag start_tag_; |
|
|
|
CallbackWithSuccessTag start_tag_; |
|
|
@ -350,14 +422,14 @@ class ClientCallbackReaderWriterImpl |
|
|
|
template <class Request, class Response> |
|
|
|
template <class Request, class Response> |
|
|
|
class ClientCallbackReaderWriterFactory { |
|
|
|
class ClientCallbackReaderWriterFactory { |
|
|
|
public: |
|
|
|
public: |
|
|
|
static experimental::ClientCallbackReaderWriter<Request, Response>* Create( |
|
|
|
static void Create( |
|
|
|
ChannelInterface* channel, const ::grpc::internal::RpcMethod& method, |
|
|
|
ChannelInterface* channel, const ::grpc::internal::RpcMethod& method, |
|
|
|
ClientContext* context, |
|
|
|
ClientContext* context, |
|
|
|
::grpc::experimental::ClientBidiReactor* reactor) { |
|
|
|
::grpc::experimental::ClientBidiReactor<Request, Response>* reactor) { |
|
|
|
Call call = channel->CreateCall(method, context, channel->CallbackCQ()); |
|
|
|
Call call = channel->CreateCall(method, context, channel->CallbackCQ()); |
|
|
|
|
|
|
|
|
|
|
|
g_core_codegen_interface->grpc_call_ref(call.call()); |
|
|
|
g_core_codegen_interface->grpc_call_ref(call.call()); |
|
|
|
return new (g_core_codegen_interface->grpc_call_arena_alloc( |
|
|
|
new (g_core_codegen_interface->grpc_call_arena_alloc( |
|
|
|
call.call(), sizeof(ClientCallbackReaderWriterImpl<Request, Response>))) |
|
|
|
call.call(), sizeof(ClientCallbackReaderWriterImpl<Request, Response>))) |
|
|
|
ClientCallbackReaderWriterImpl<Request, Response>(call, context, |
|
|
|
ClientCallbackReaderWriterImpl<Request, Response>(call, context, |
|
|
|
reactor); |
|
|
|
reactor); |
|
|
@ -396,7 +468,8 @@ class ClientCallbackReaderImpl |
|
|
|
// 3. Recv trailing metadata, on_completion callback
|
|
|
|
// 3. Recv trailing metadata, on_completion callback
|
|
|
|
started_ = true; |
|
|
|
started_ = true; |
|
|
|
|
|
|
|
|
|
|
|
start_tag_.Set(call_.call(), |
|
|
|
start_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnReadInitialMetadataDone(ok); |
|
|
|
reactor_->OnReadInitialMetadataDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -409,7 +482,8 @@ class ClientCallbackReaderImpl |
|
|
|
call_.PerformOps(&start_ops_); |
|
|
|
call_.PerformOps(&start_ops_); |
|
|
|
|
|
|
|
|
|
|
|
// Also set up the read tag so it doesn't have to be set up each time
|
|
|
|
// Also set up the read tag so it doesn't have to be set up each time
|
|
|
|
read_tag_.Set(call_.call(), |
|
|
|
read_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnReadDone(ok); |
|
|
|
reactor_->OnReadDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -420,8 +494,8 @@ class ClientCallbackReaderImpl |
|
|
|
call_.PerformOps(&read_ops_); |
|
|
|
call_.PerformOps(&read_ops_); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
finish_tag_.Set(call_.call(), [this](bool ok) { MaybeFinish(); }, |
|
|
|
finish_tag_.Set( |
|
|
|
&finish_ops_); |
|
|
|
call_.call(), [this](bool ok) { MaybeFinish(); }, &finish_ops_); |
|
|
|
finish_ops_.ClientRecvStatus(context_, &finish_status_); |
|
|
|
finish_ops_.ClientRecvStatus(context_, &finish_status_); |
|
|
|
finish_ops_.set_core_cq_tag(&finish_tag_); |
|
|
|
finish_ops_.set_core_cq_tag(&finish_tag_); |
|
|
|
call_.PerformOps(&finish_ops_); |
|
|
|
call_.PerformOps(&finish_ops_); |
|
|
@ -441,9 +515,11 @@ class ClientCallbackReaderImpl |
|
|
|
friend class ClientCallbackReaderFactory<Response>; |
|
|
|
friend class ClientCallbackReaderFactory<Response>; |
|
|
|
|
|
|
|
|
|
|
|
template <class Request> |
|
|
|
template <class Request> |
|
|
|
ClientCallbackReaderImpl(Call call, ClientContext* context, Request* request, |
|
|
|
ClientCallbackReaderImpl( |
|
|
|
::grpc::experimental::ClientReadReactor* reactor) |
|
|
|
Call call, ClientContext* context, Request* request, |
|
|
|
|
|
|
|
::grpc::experimental::ClientReadReactor<Response>* reactor) |
|
|
|
: context_(context), call_(call), reactor_(reactor) { |
|
|
|
: context_(context), call_(call), reactor_(reactor) { |
|
|
|
|
|
|
|
this->BindReactor(reactor); |
|
|
|
// TODO(vjpai): don't assert
|
|
|
|
// TODO(vjpai): don't assert
|
|
|
|
GPR_CODEGEN_ASSERT(start_ops_.SendMessage(*request).ok()); |
|
|
|
GPR_CODEGEN_ASSERT(start_ops_.SendMessage(*request).ok()); |
|
|
|
start_ops_.ClientSendClose(); |
|
|
|
start_ops_.ClientSendClose(); |
|
|
@ -451,7 +527,7 @@ class ClientCallbackReaderImpl |
|
|
|
|
|
|
|
|
|
|
|
ClientContext* context_; |
|
|
|
ClientContext* context_; |
|
|
|
Call call_; |
|
|
|
Call call_; |
|
|
|
::grpc::experimental::ClientReadReactor* reactor_; |
|
|
|
::grpc::experimental::ClientReadReactor<Response>* reactor_; |
|
|
|
|
|
|
|
|
|
|
|
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, CallOpClientSendClose, |
|
|
|
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, CallOpClientSendClose, |
|
|
|
CallOpRecvInitialMetadata> |
|
|
|
CallOpRecvInitialMetadata> |
|
|
@ -475,14 +551,14 @@ template <class Response> |
|
|
|
class ClientCallbackReaderFactory { |
|
|
|
class ClientCallbackReaderFactory { |
|
|
|
public: |
|
|
|
public: |
|
|
|
template <class Request> |
|
|
|
template <class Request> |
|
|
|
static experimental::ClientCallbackReader<Response>* Create( |
|
|
|
static void Create( |
|
|
|
ChannelInterface* channel, const ::grpc::internal::RpcMethod& method, |
|
|
|
ChannelInterface* channel, const ::grpc::internal::RpcMethod& method, |
|
|
|
ClientContext* context, const Request* request, |
|
|
|
ClientContext* context, const Request* request, |
|
|
|
::grpc::experimental::ClientReadReactor* reactor) { |
|
|
|
::grpc::experimental::ClientReadReactor<Response>* reactor) { |
|
|
|
Call call = channel->CreateCall(method, context, channel->CallbackCQ()); |
|
|
|
Call call = channel->CreateCall(method, context, channel->CallbackCQ()); |
|
|
|
|
|
|
|
|
|
|
|
g_core_codegen_interface->grpc_call_ref(call.call()); |
|
|
|
g_core_codegen_interface->grpc_call_ref(call.call()); |
|
|
|
return new (g_core_codegen_interface->grpc_call_arena_alloc( |
|
|
|
new (g_core_codegen_interface->grpc_call_arena_alloc( |
|
|
|
call.call(), sizeof(ClientCallbackReaderImpl<Response>))) |
|
|
|
call.call(), sizeof(ClientCallbackReaderImpl<Response>))) |
|
|
|
ClientCallbackReaderImpl<Response>(call, context, request, reactor); |
|
|
|
ClientCallbackReaderImpl<Response>(call, context, request, reactor); |
|
|
|
} |
|
|
|
} |
|
|
@ -520,7 +596,8 @@ class ClientCallbackWriterImpl |
|
|
|
// 3. Any backlog
|
|
|
|
// 3. Any backlog
|
|
|
|
started_ = true; |
|
|
|
started_ = true; |
|
|
|
|
|
|
|
|
|
|
|
start_tag_.Set(call_.call(), |
|
|
|
start_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnReadInitialMetadataDone(ok); |
|
|
|
reactor_->OnReadInitialMetadataDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -536,7 +613,8 @@ class ClientCallbackWriterImpl |
|
|
|
|
|
|
|
|
|
|
|
// Also set up the read and write tags so that they don't have to be set up
|
|
|
|
// Also set up the read and write tags so that they don't have to be set up
|
|
|
|
// each time
|
|
|
|
// each time
|
|
|
|
write_tag_.Set(call_.call(), |
|
|
|
write_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnWriteDone(ok); |
|
|
|
reactor_->OnWriteDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -544,8 +622,8 @@ class ClientCallbackWriterImpl |
|
|
|
&write_ops_); |
|
|
|
&write_ops_); |
|
|
|
write_ops_.set_core_cq_tag(&write_tag_); |
|
|
|
write_ops_.set_core_cq_tag(&write_tag_); |
|
|
|
|
|
|
|
|
|
|
|
finish_tag_.Set(call_.call(), [this](bool ok) { MaybeFinish(); }, |
|
|
|
finish_tag_.Set( |
|
|
|
&finish_ops_); |
|
|
|
call_.call(), [this](bool ok) { MaybeFinish(); }, &finish_ops_); |
|
|
|
finish_ops_.ClientRecvStatus(context_, &finish_status_); |
|
|
|
finish_ops_.ClientRecvStatus(context_, &finish_status_); |
|
|
|
finish_ops_.set_core_cq_tag(&finish_tag_); |
|
|
|
finish_ops_.set_core_cq_tag(&finish_tag_); |
|
|
|
call_.PerformOps(&finish_ops_); |
|
|
|
call_.PerformOps(&finish_ops_); |
|
|
@ -586,7 +664,8 @@ class ClientCallbackWriterImpl |
|
|
|
start_corked_ = false; |
|
|
|
start_corked_ = false; |
|
|
|
} |
|
|
|
} |
|
|
|
writes_done_ops_.ClientSendClose(); |
|
|
|
writes_done_ops_.ClientSendClose(); |
|
|
|
writes_done_tag_.Set(call_.call(), |
|
|
|
writes_done_tag_.Set( |
|
|
|
|
|
|
|
call_.call(), |
|
|
|
[this](bool ok) { |
|
|
|
[this](bool ok) { |
|
|
|
reactor_->OnWritesDoneDone(ok); |
|
|
|
reactor_->OnWritesDoneDone(ok); |
|
|
|
MaybeFinish(); |
|
|
|
MaybeFinish(); |
|
|
@ -605,20 +684,21 @@ class ClientCallbackWriterImpl |
|
|
|
friend class ClientCallbackWriterFactory<Request>; |
|
|
|
friend class ClientCallbackWriterFactory<Request>; |
|
|
|
|
|
|
|
|
|
|
|
template <class Response> |
|
|
|
template <class Response> |
|
|
|
ClientCallbackWriterImpl(Call call, ClientContext* context, |
|
|
|
ClientCallbackWriterImpl( |
|
|
|
Response* response, |
|
|
|
Call call, ClientContext* context, Response* response, |
|
|
|
::grpc::experimental::ClientWriteReactor* reactor) |
|
|
|
::grpc::experimental::ClientWriteReactor<Request>* reactor) |
|
|
|
: context_(context), |
|
|
|
: context_(context), |
|
|
|
call_(call), |
|
|
|
call_(call), |
|
|
|
reactor_(reactor), |
|
|
|
reactor_(reactor), |
|
|
|
start_corked_(context_->initial_metadata_corked_) { |
|
|
|
start_corked_(context_->initial_metadata_corked_) { |
|
|
|
|
|
|
|
this->BindReactor(reactor); |
|
|
|
finish_ops_.RecvMessage(response); |
|
|
|
finish_ops_.RecvMessage(response); |
|
|
|
finish_ops_.AllowNoMessage(); |
|
|
|
finish_ops_.AllowNoMessage(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ClientContext* context_; |
|
|
|
ClientContext* context_; |
|
|
|
Call call_; |
|
|
|
Call call_; |
|
|
|
::grpc::experimental::ClientWriteReactor* reactor_; |
|
|
|
::grpc::experimental::ClientWriteReactor<Request>* reactor_; |
|
|
|
|
|
|
|
|
|
|
|
CallOpSet<CallOpSendInitialMetadata, CallOpRecvInitialMetadata> start_ops_; |
|
|
|
CallOpSet<CallOpSendInitialMetadata, CallOpRecvInitialMetadata> start_ops_; |
|
|
|
CallbackWithSuccessTag start_tag_; |
|
|
|
CallbackWithSuccessTag start_tag_; |
|
|
@ -646,14 +726,14 @@ template <class Request> |
|
|
|
class ClientCallbackWriterFactory { |
|
|
|
class ClientCallbackWriterFactory { |
|
|
|
public: |
|
|
|
public: |
|
|
|
template <class Response> |
|
|
|
template <class Response> |
|
|
|
static experimental::ClientCallbackWriter<Request>* Create( |
|
|
|
static void Create( |
|
|
|
ChannelInterface* channel, const ::grpc::internal::RpcMethod& method, |
|
|
|
ChannelInterface* channel, const ::grpc::internal::RpcMethod& method, |
|
|
|
ClientContext* context, Response* response, |
|
|
|
ClientContext* context, Response* response, |
|
|
|
::grpc::experimental::ClientWriteReactor* reactor) { |
|
|
|
::grpc::experimental::ClientWriteReactor<Request>* reactor) { |
|
|
|
Call call = channel->CreateCall(method, context, channel->CallbackCQ()); |
|
|
|
Call call = channel->CreateCall(method, context, channel->CallbackCQ()); |
|
|
|
|
|
|
|
|
|
|
|
g_core_codegen_interface->grpc_call_ref(call.call()); |
|
|
|
g_core_codegen_interface->grpc_call_ref(call.call()); |
|
|
|
return new (g_core_codegen_interface->grpc_call_arena_alloc( |
|
|
|
new (g_core_codegen_interface->grpc_call_arena_alloc( |
|
|
|
call.call(), sizeof(ClientCallbackWriterImpl<Request>))) |
|
|
|
call.call(), sizeof(ClientCallbackWriterImpl<Request>))) |
|
|
|
ClientCallbackWriterImpl<Request>(call, context, response, reactor); |
|
|
|
ClientCallbackWriterImpl<Request>(call, context, response, reactor); |
|
|
|
} |
|
|
|
} |
|
|
|