diff options
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/async_server_context.h | 2 | ||||
-rw-r--r-- | include/grpc++/client_context.h | 6 | ||||
-rw-r--r-- | include/grpc++/server_credentials.h | 77 | ||||
-rw-r--r-- | include/grpc++/stream.h | 52 | ||||
-rw-r--r-- | include/grpc++/stream_context_interface.h | 2 |
5 files changed, 137 insertions, 2 deletions
diff --git a/include/grpc++/async_server_context.h b/include/grpc++/async_server_context.h index dd4097b25c..237a6856a4 100644 --- a/include/grpc++/async_server_context.h +++ b/include/grpc++/async_server_context.h @@ -75,6 +75,8 @@ class AsyncServerContext { grpc::string host() const { return host_; } system_clock::time_point absolute_deadline() { return absolute_deadline_; } + grpc_call* call() { return call_; } + private: AsyncServerContext(const AsyncServerContext&); AsyncServerContext& operator=(const AsyncServerContext&); diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 8301b3c630..ec1a4c2782 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -39,6 +39,7 @@ #include <vector> #include <grpc++/config.h> +#include <grpc/support/log.h> using std::chrono::system_clock; @@ -69,7 +70,10 @@ class ClientContext { friend class StreamContext; grpc_call *call() { return call_; } - void set_call(grpc_call *call) { call_ = call; } + void set_call(grpc_call *call) { + GPR_ASSERT(call_ == nullptr); + call_ = call; + } grpc_completion_queue *cq() { return cq_; } void set_cq(grpc_completion_queue *cq) { cq_ = cq; } diff --git a/include/grpc++/server_credentials.h b/include/grpc++/server_credentials.h new file mode 100644 index 0000000000..f758ad5510 --- /dev/null +++ b/include/grpc++/server_credentials.h @@ -0,0 +1,77 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __GRPCPP_SERVER_CREDENTIALS_H_ +#define __GRPCPP_SERVER_CREDENTIALS_H_ + +#include <memory> + +#include <grpc++/config.h> + +struct grpc_server_credentials; + +namespace grpc { + +// grpc_server_credentials wrapper class. +class ServerCredentials final { + public: + ~ServerCredentials(); + + private: + explicit ServerCredentials(grpc_server_credentials* c_creds); + + grpc_server_credentials* GetRawCreds(); + + friend class ServerCredentialsFactory; + + grpc_server_credentials* creds_; +}; + +// Options to create ServerCredentials with SSL +struct SslServerCredentialsOptions { + grpc::string pem_root_certs; + grpc::string pem_private_key; + grpc::string pem_cert_chain; +}; + +// Factory for building different types of ServerCredentials +class ServerCredentialsFactory { + public: + // Builds SSL ServerCredentials given SSL specific options + static std::shared_ptr<ServerCredentials> SslCredentials( + const SslServerCredentialsOptions& options); +}; + +} // namespace grpc + +#endif // __GRPCPP_SERVER_CREDENTIALS_H_ diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index 50c21565b5..49f88a6f13 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -173,6 +173,58 @@ class ClientReaderWriter : public ClientStreamingInterface, StreamContextInterface* const context_; }; +template <class R> +class ServerReader : public ReaderInterface<R> { + public: + explicit ServerReader(StreamContextInterface* context) : context_(context) { + GPR_ASSERT(context_); + context_->Start(true); + } + + virtual bool Read(R* msg) { return context_->Read(msg); } + + private: + StreamContextInterface* const context_; // not owned +}; + +template <class W> +class ServerWriter : public WriterInterface<W> { + public: + explicit ServerWriter(StreamContextInterface* context) : context_(context) { + GPR_ASSERT(context_); + context_->Start(true); + context_->Read(context_->request()); + } + + virtual bool Write(const W& msg) { + return context_->Write(const_cast<W*>(&msg), false); + } + + private: + StreamContextInterface* const context_; // not owned +}; + +// Server-side interface for bi-directional streaming. +template <class W, class R> +class ServerReaderWriter : public WriterInterface<W>, + public ReaderInterface<R> { + public: + explicit ServerReaderWriter(StreamContextInterface* context) + : context_(context) { + GPR_ASSERT(context_); + context_->Start(true); + } + + virtual bool Read(R* msg) { return context_->Read(msg); } + + virtual bool Write(const W& msg) { + return context_->Write(const_cast<W*>(&msg), false); + } + + private: + StreamContextInterface* const context_; // not owned +}; + } // namespace grpc #endif // __GRPCPP_STREAM_H__ diff --git a/include/grpc++/stream_context_interface.h b/include/grpc++/stream_context_interface.h index eb5c092059..535c0048e6 100644 --- a/include/grpc++/stream_context_interface.h +++ b/include/grpc++/stream_context_interface.h @@ -55,7 +55,7 @@ class StreamContextInterface { virtual const Status& Wait() = 0; virtual void FinishStream(const Status& status, bool send) = 0; - virtual const google::protobuf::Message* request() = 0; + virtual google::protobuf::Message* request() = 0; virtual google::protobuf::Message* response() = 0; }; |