aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++/impl
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2016-08-04 10:50:51 -0700
committerGravatar Vijay Pai <vpai@google.com>2016-08-04 10:50:51 -0700
commit581097fe0dc321a31cedae97057838fa1eadf8b2 (patch)
tree927cfc9f70724b0a8f6187f4b7b6ad8a2fa8b21d /include/grpc++/impl
parent666681612e47db3b09ccf5f69af23fa278cb1d94 (diff)
Make FCUnary and ServerReaderWriter derived classes of a new
ServerReaderWriterInterface so that some functions can be made to accept either.
Diffstat (limited to 'include/grpc++/impl')
-rw-r--r--include/grpc++/impl/codegen/completion_queue.h8
-rw-r--r--include/grpc++/impl/codegen/fc_unary.h44
-rw-r--r--include/grpc++/impl/codegen/server_context.h8
-rw-r--r--include/grpc++/impl/codegen/sync_stream.h26
4 files changed, 31 insertions, 55 deletions
diff --git a/include/grpc++/impl/codegen/completion_queue.h b/include/grpc++/impl/codegen/completion_queue.h
index 1d00bf2d1b..95ece77ce5 100644
--- a/include/grpc++/impl/codegen/completion_queue.h
+++ b/include/grpc++/impl/codegen/completion_queue.h
@@ -69,9 +69,7 @@ class ServerReader;
template <class W>
class ServerWriter;
template <class W, class R>
-class ServerReaderWriter;
-template <class Req, class Resp>
-class FCUnary;
+class ServerReaderWriterInterface;
template <class ServiceType, class RequestType, class ResponseType>
class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
@@ -182,9 +180,7 @@ class CompletionQueue : private GrpcLibraryCodegen {
template <class W>
friend class ::grpc::ServerWriter;
template <class W, class R>
- friend class ::grpc::ServerReaderWriter;
- template <class Req, class Resp>
- friend class ::grpc::FCUnary;
+ friend class ::grpc::ServerReaderWriterInterface;
template <class ServiceType, class RequestType, class ResponseType>
friend class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
diff --git a/include/grpc++/impl/codegen/fc_unary.h b/include/grpc++/impl/codegen/fc_unary.h
index 768443912b..9dbc4024bf 100644
--- a/include/grpc++/impl/codegen/fc_unary.h
+++ b/include/grpc++/impl/codegen/fc_unary.h
@@ -37,11 +37,10 @@
#include <grpc++/impl/codegen/call.h>
#include <grpc++/impl/codegen/completion_queue.h>
#include <grpc++/impl/codegen/core_codegen_interface.h>
-#include <grpc++/impl/codegen/method_handler_impl.h>
#include <grpc++/impl/codegen/server_context.h>
+#include <grpc++/impl/codegen/sync_stream.h>
namespace grpc {
-
/// A class to represent a flow-controlled unary call. This is something
/// of a hybrid between conventional unary and streaming. This is invoked
/// through a unary call on the client side, but the server responds to it
@@ -52,51 +51,32 @@ namespace grpc {
/// and exactly 1 Write, in that order, to function correctly.
/// Otherwise, the RPC is in error.
template <class RequestType, class ResponseType>
- class FCUnary GRPC_FINAL {
- public:
- FCUnary(Call* call, ServerContext* ctx): call_(call), ctx_(ctx), read_done_(false), write_done_(false) {}
+ class FCUnary GRPC_FINAL : public ServerReaderWriterInterface<ResponseType, RequestType> {
+public:
+ FCUnary(Call* call, ServerContext* ctx): ServerReaderWriterInterface<ResponseType,RequestType>(call, ctx) , read_done_(false), write_done_(false) {}
+
~FCUnary() {}
- bool NextMessageSize(uint32_t *sz) {
- *sz = call_->max_message_size();
- return true;
- }
- bool Read(RequestType *request) {
+
+ bool Read(RequestType *request) GRPC_OVERRIDE {
if (read_done_) {
return false;
}
read_done_ = true;
- CallOpSet<CallOpRecvMessage<RequestType>> ops;
- ops.RecvMessage(request);
- call_->PerformOps(&ops);
- return call_->cq()->Pluck(&ops) && ops.got_message;
+ return ServerReaderWriterInterface<ResponseType,RequestType>::Read(request);
}
- bool Write(const ResponseType& response) {return Write(response, WriteOptions());}
- bool Write(const ResponseType& response, const WriteOptions& options) {
+
+ using WriterInterface<ResponseType>::Write;
+ bool Write(const ResponseType& response, const WriteOptions& options) GRPC_OVERRIDE {
if (write_done_ || !read_done_) {
return false;
}
write_done_ = true;
- CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> ops;
- if (!ops.SendMessage(response, options).ok()) {
- return false;
- }
- if (!ctx_->sent_initial_metadata_) {
- ops.SendInitialMetadata(ctx_->initial_metadata_,
- ctx_->initial_metadata_flags());
- ctx_->sent_initial_metadata_ = true;
- } else {
- return false;
- }
- call_->PerformOps(&ops);
- return call_->cq()->Pluck(&ops);
+ return ServerReaderWriterInterface<ResponseType,RequestType>::Write(response, options);
}
private:
- Call* const call_;
- ServerContext* const ctx_;
bool read_done_;
bool write_done_;
};
-
} // namespace grpc
#endif // GRPCXX_IMPL_CODEGEN_FC_UNARY_H
diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h
index e1d7e980a1..aadae893ad 100644
--- a/include/grpc++/impl/codegen/server_context.h
+++ b/include/grpc++/impl/codegen/server_context.h
@@ -66,9 +66,7 @@ class ServerReader;
template <class W>
class ServerWriter;
template <class W, class R>
-class ServerReaderWriter;
-template <class Req, class Resp>
-class FCUnary;
+class ServerReaderWriterInterface;
template <class ServiceType, class RequestType, class ResponseType>
class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
@@ -187,9 +185,7 @@ class ServerContext {
template <class W>
friend class ::grpc::ServerWriter;
template <class W, class R>
- friend class ::grpc::ServerReaderWriter;
- template <class Req, class Resp>
- friend class ::grpc::FCUnary;
+ friend class ::grpc::ServerReaderWriterInterface;
template <class ServiceType, class RequestType, class ResponseType>
friend class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
diff --git a/include/grpc++/impl/codegen/sync_stream.h b/include/grpc++/impl/codegen/sync_stream.h
index 31da2cbbe9..2e63479961 100644
--- a/include/grpc++/impl/codegen/sync_stream.h
+++ b/include/grpc++/impl/codegen/sync_stream.h
@@ -429,12 +429,11 @@ class ServerWriter GRPC_FINAL : public WriterInterface<W> {
/// Server-side interface for bi-directional streaming.
template <class W, class R>
-class ServerReaderWriter GRPC_FINAL : public WriterInterface<W>,
- public ReaderInterface<R> {
- public:
- ServerReaderWriter(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {}
-
- void SendInitialMetadata() {
+class ServerReaderWriterInterface : public WriterInterface<W>,
+ public ReaderInterface<R> {
+public:
+ ServerReaderWriterInterface(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {}
+ virtual void SendInitialMetadata() {
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_);
CallOpSet<CallOpSendInitialMetadata> ops;
@@ -448,12 +447,12 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface<W>,
call_->cq()->Pluck(&ops);
}
- bool NextMessageSize(uint32_t *sz) GRPC_OVERRIDE {
+ virtual bool NextMessageSize(uint32_t *sz) GRPC_OVERRIDE {
*sz = call_->max_message_size();
return true;
}
- bool Read(R* msg) GRPC_OVERRIDE {
+ virtual bool Read(R* msg) GRPC_OVERRIDE {
CallOpSet<CallOpRecvMessage<R>> ops;
ops.RecvMessage(msg);
call_->PerformOps(&ops);
@@ -461,7 +460,7 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface<W>,
}
using WriterInterface<W>::Write;
- bool Write(const W& msg, const WriteOptions& options) GRPC_OVERRIDE {
+ virtual bool Write(const W& msg, const WriteOptions& options) GRPC_OVERRIDE {
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> ops;
if (!ops.SendMessage(msg, options).ok()) {
return false;
@@ -477,12 +476,17 @@ class ServerReaderWriter GRPC_FINAL : public WriterInterface<W>,
call_->PerformOps(&ops);
return call_->cq()->Pluck(&ops);
}
-
- private:
+private:
Call* const call_;
ServerContext* const ctx_;
};
+template <class W, class R>
+class ServerReaderWriter GRPC_FINAL : public ServerReaderWriterInterface<W,R> {
+public:
+ ServerReaderWriter(Call* call, ServerContext* ctx) : ServerReaderWriterInterface<W,R>(call, ctx) {}
+};
+
} // namespace grpc
#endif // GRPCXX_IMPL_CODEGEN_SYNC_STREAM_H