From 854a30c73a2ae7123e62291ec91666c29aa1c50d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Feb 2015 11:44:10 -0800 Subject: [PATCH] More implementation --- include/grpc++/server_context.h | 13 +++++++++---- src/cpp/common/completion_queue.cc | 2 ++ src/cpp/server/server_context.cc | 14 +++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index a58e63aff24..790dd7116b4 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -35,7 +35,7 @@ #define __GRPCPP_SERVER_CONTEXT_H_ #include -#include +#include #include "config.h" @@ -44,16 +44,21 @@ struct gpr_timespec; namespace grpc { +class Server; + // Interface of server side rpc context. class ServerContext { public: - ServerContext(gpr_timespec deadline, grpc_metadata *metadata, size_t metadata_count); virtual ~ServerContext() {} - std::chrono::system_clock::time_point absolute_deadline(); + std::chrono::system_clock::time_point absolute_deadline() { return deadline_; } private: - std::vector > metadata_; + friend class ::grpc::Server; + ServerContext(gpr_timespec deadline, grpc_metadata *metadata, size_t metadata_count); + + const std::chrono::system_clock::time_point deadline_; + std::multimap metadata_; }; } // namespace grpc diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index cbeda81a0bc..f69ddc3b7e0 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -43,6 +43,8 @@ namespace grpc { CompletionQueue::CompletionQueue() { cq_ = grpc_completion_queue_create(); } +CompletionQueue::CompletionQueue(grpc_completion_queue *take) : cq_(take) {} + CompletionQueue::~CompletionQueue() { grpc_completion_queue_destroy(cq_); } void CompletionQueue::Shutdown() { grpc_completion_queue_shutdown(cq_); } diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 0edadd87090..7e0bc4de36a 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -32,5 +32,17 @@ */ #include +#include +#include "src/cpp/util/time.h" -namespace grpc {} // namespace grpc +namespace grpc { + +ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata *metadata, size_t metadata_count) + : deadline_(Timespec2Timepoint(deadline)) { + for (size_t i = 0; i < metadata_count; i++) { + metadata_.insert(std::make_pair(grpc::string(metadata[i].key), + grpc::string(metadata[i].value, metadata[i].value + metadata[i].value_length))); + } +} + +} // namespace grpc