Skip to content

Commit

Permalink
Merge pull request grpc#7798 from y-zeng/ServerReaderWriterInterface
Browse files Browse the repository at this point in the history
Add ServerReaderWriterInterface
  • Loading branch information
kpayson64 authored Aug 30, 2016
2 parents bacaceb + 59e835d commit d76ea83
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions include/grpc++/impl/codegen/sync_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class ClientStreamingInterface {
virtual Status Finish() = 0;
};

/// Common interface for all synchronous server side streaming.
class ServerStreamingInterface {
public:
virtual ~ServerStreamingInterface() {}

/// Blocking send initial metadata to client.
virtual void SendInitialMetadata() = 0;
};

/// An interface that yields a sequence of messages of type \a R.
template <class R>
class ReaderInterface {
Expand Down Expand Up @@ -336,12 +345,17 @@ class ClientReaderWriter GRPC_FINAL : public ClientReaderWriterInterface<W, R> {
Call call_;
};

/// Server-side interface for streaming reads of message of type \a R.
template <class R>
class ServerReaderInterface : public ServerStreamingInterface,
public ReaderInterface<R> {};

template <class R>
class ServerReader GRPC_FINAL : public ReaderInterface<R> {
class ServerReader GRPC_FINAL : public ServerReaderInterface<R> {
public:
ServerReader(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {}

void SendInitialMetadata() {
void SendInitialMetadata() GRPC_OVERRIDE {
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_);

CallOpSet<CallOpSendInitialMetadata> ops;
Expand All @@ -367,12 +381,17 @@ class ServerReader GRPC_FINAL : public ReaderInterface<R> {
ServerContext* const ctx_;
};

/// Server-side interface for streaming writes of message of type \a W.
template <class W>
class ServerWriter GRPC_FINAL : public WriterInterface<W> {
class ServerWriterInterface : public ServerStreamingInterface,
public WriterInterface<W> {};

template <class W>
class ServerWriter GRPC_FINAL : public ServerWriterInterface<W> {
public:
ServerWriter(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {}

void SendInitialMetadata() {
void SendInitialMetadata() GRPC_OVERRIDE {
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_);

CallOpSet<CallOpSendInitialMetadata> ops;
Expand Down Expand Up @@ -411,12 +430,16 @@ 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> {
class ServerReaderWriterInterface : public ServerStreamingInterface,
public WriterInterface<W>,
public ReaderInterface<R> {};

template <class W, class R>
class ServerReaderWriter GRPC_FINAL : public ServerReaderWriterInterface<W, R> {
public:
ServerReaderWriter(Call* call, ServerContext* ctx) : call_(call), ctx_(ctx) {}

void SendInitialMetadata() {
void SendInitialMetadata() GRPC_OVERRIDE {
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_);

CallOpSet<CallOpSendInitialMetadata> ops;
Expand Down

0 comments on commit d76ea83

Please sign in to comment.