diff options
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/channel_interface.h | 4 | ||||
-rw-r--r-- | include/grpc++/client_context.h | 7 | ||||
-rw-r--r-- | include/grpc++/impl/call.h | 18 | ||||
-rw-r--r-- | include/grpc++/server.h | 11 |
4 files changed, 27 insertions, 13 deletions
diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h index 3631ea4d5d..b0366faabb 100644 --- a/include/grpc++/channel_interface.h +++ b/include/grpc++/channel_interface.h @@ -35,6 +35,7 @@ #define __GRPCPP_CHANNEL_INTERFACE_H__ #include <grpc++/status.h> +#include <grpc++/impl/call.h> namespace google { namespace protobuf { @@ -52,13 +53,12 @@ class CompletionQueue; class RpcMethod; class CallInterface; -class ChannelInterface { +class ChannelInterface : public CallHook { public: virtual ~ChannelInterface() {} virtual Call CreateCall(const RpcMethod &method, ClientContext *context, CompletionQueue *cq) = 0; - virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) = 0; }; } // namespace grpc diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 0cf6bdc647..a6e8ccc67c 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -35,8 +35,8 @@ #define __GRPCPP_CLIENT_CONTEXT_H__ #include <chrono> +#include <map> #include <string> -#include <vector> #include <grpc/support/log.h> #include <grpc/support/time.h> @@ -49,6 +49,8 @@ struct grpc_completion_queue; namespace grpc { +class CallOpBuffer; + class ClientContext { public: ClientContext(); @@ -67,6 +69,7 @@ class ClientContext { ClientContext(const ClientContext &); ClientContext &operator=(const ClientContext &); + friend class CallOpBuffer; friend class Channel; friend class StreamContext; @@ -84,7 +87,7 @@ class ClientContext { grpc_call *call_; grpc_completion_queue *cq_; gpr_timespec absolute_deadline_; - std::vector<std::pair<grpc::string, grpc::string> > metadata_; + std::multimap<grpc::string, grpc::string> metadata_; }; } // namespace grpc diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index 40939e458f..8fed305ac6 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -52,7 +52,7 @@ struct grpc_op; namespace grpc { -class ChannelInterface; +class Call; class CallOpBuffer final : public CompletionQueueTag { public: @@ -63,6 +63,7 @@ class CallOpBuffer final : public CompletionQueueTag { // Does not take ownership. void AddSendInitialMetadata( std::multimap<grpc::string, grpc::string> *metadata); + void AddSendInitialMetadata(ClientContext *ctx); void AddRecvInitialMetadata( std::multimap<grpc::string, grpc::string> *metadata); void AddSendMessage(const google::protobuf::Message &message); @@ -102,12 +103,12 @@ class CallOpBuffer final : public CompletionQueueTag { Status* recv_status_ = nullptr; grpc_metadata_array recv_trailing_metadata_arr_ = {0, 0, nullptr}; grpc_status_code status_code_ = GRPC_STATUS_OK; - char* status_details_ = nullptr; + char *status_details_ = nullptr; size_t status_details_capacity_ = 0; // Server send status Status* send_status_ = nullptr; size_t trailing_metadata_count_ = 0; - grpc_metadata* trailing_metadata_ = nullptr; + grpc_metadata *trailing_metadata_ = nullptr; }; class CCallDeleter { @@ -115,10 +116,17 @@ class CCallDeleter { void operator()(grpc_call *c); }; +// Channel and Server implement this to allow them to hook performing ops +class CallHook { + public: + virtual ~CallHook() {} + virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) = 0; +}; + // Straightforward wrapping of the C call object class Call final { public: - Call(grpc_call *call, ChannelInterface *channel, CompletionQueue *cq); + Call(grpc_call *call, CallHook *call_hook_, CompletionQueue *cq); void PerformOps(CallOpBuffer *buffer); @@ -126,7 +134,7 @@ class Call final { CompletionQueue *cq() { return cq_; } private: - ChannelInterface *channel_; + CallHook *call_hook_; CompletionQueue *cq_; std::unique_ptr<grpc_call, CCallDeleter> call_; }; diff --git a/include/grpc++/server.h b/include/grpc++/server.h index b02c4130d9..98f3f17197 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -41,6 +41,7 @@ #include <grpc++/completion_queue.h> #include <grpc++/config.h> +#include <grpc++/impl/call.h> #include <grpc++/status.h> struct grpc_server; @@ -59,7 +60,7 @@ class ServerCredentials; class ThreadPoolInterface; // Currently it only supports handling rpcs in a single thread. -class Server { +class Server final : private CallHook { public: ~Server(); @@ -72,7 +73,8 @@ class Server { class MethodRequestData; // ServerBuilder use only - Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, ServerCredentials* creds); + Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, + ServerCredentials* creds); Server(); // Register a service. This call does not take ownership of the service. // The service must exist for the lifetime of the Server instance. @@ -86,9 +88,10 @@ class Server { void RunRpc(); void ScheduleCallback(); + void PerformOpsOnCall(CallOpBuffer* ops, Call* call) override; + // Completion queue. - std::unique_ptr<CompletionQueue> cq_sync_; - std::unique_ptr<CompletionQueue> cq_async_; + CompletionQueue cq_; // Sever status std::mutex mu_; |