diff options
author | 2015-04-07 18:01:18 -0700 | |
---|---|---|
committer | 2015-04-08 05:42:08 +0200 | |
commit | 89219162dd613b58da8f3cd418f4825a5d566da5 (patch) | |
tree | 3c3a4b0a299e7df62caff4562863bde6377d965a /include | |
parent | 9973aa3aa6e29e5949f9a330cc3c1eb92c0a5830 (diff) |
Refactoring std::chrono out.
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/client_context.h | 23 | ||||
-rw-r--r-- | include/grpc++/completion_queue.h | 13 | ||||
-rw-r--r-- | include/grpc++/credentials.h | 5 | ||||
-rw-r--r-- | include/grpc++/server_context.h | 13 | ||||
-rw-r--r-- | include/grpc++/time.h | 81 |
5 files changed, 115 insertions, 20 deletions
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 4e7f5a7be0..19630c9b54 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -34,15 +34,13 @@ #ifndef GRPCXX_CLIENT_CONTEXT_H #define GRPCXX_CLIENT_CONTEXT_H -#include <chrono> #include <map> #include <string> #include <grpc/support/log.h> #include <grpc/support/time.h> #include <grpc++/config.h> - -using std::chrono::system_clock; +#include <grpc++/time.h> struct grpc_call; struct grpc_completion_queue; @@ -87,8 +85,19 @@ class ClientContext { return trailing_metadata_; } - void set_absolute_deadline(const system_clock::time_point& deadline); - system_clock::time_point absolute_deadline(); + template <typename T> + void set_deadline(const T& deadline) { + TimePoint<T> deadline_tp(deadline); + deadline_ = deadline_tp.raw_time(); + } + +#ifndef GRPC_CXX0X_NO_CHRONO + std::chrono::system_clock::time_point deadline() { + return Timespec2Timepoint(deadline_); + } +#endif // !GRPC_CXX0X_NO_CHRONO + + gpr_timespec raw_deadline() { return deadline_; } void set_authority(const grpc::string& authority) { authority_ = authority; } @@ -125,14 +134,12 @@ class ClientContext { grpc_completion_queue* cq() { return cq_; } void set_cq(grpc_completion_queue* cq) { cq_ = cq; } - gpr_timespec RawDeadline() { return absolute_deadline_; } - grpc::string authority() { return authority_; } bool initial_metadata_received_; grpc_call* call_; grpc_completion_queue* cq_; - gpr_timespec absolute_deadline_; + gpr_timespec deadline_; grpc::string authority_; std::multimap<grpc::string, grpc::string> send_initial_metadata_; std::multimap<grpc::string, grpc::string> recv_initial_metadata_; diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index e6a8c6fe55..ba390c96e9 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -34,9 +34,9 @@ #ifndef GRPCXX_COMPLETION_QUEUE_H #define GRPCXX_COMPLETION_QUEUE_H -#include <chrono> -#include <grpc++/impl/client_unary_call.h> #include <grpc/support/time.h> +#include <grpc++/impl/client_unary_call.h> +#include <grpc++/time.h> struct grpc_completion_queue; @@ -82,10 +82,13 @@ class CompletionQueue { // Nonblocking (until deadline) read from queue. // Cannot rely on result of tag or ok if return is TIMEOUT - NextStatus AsyncNext(void** tag, bool* ok, - std::chrono::system_clock::time_point deadline); + template<typename T> + NextStatus AsyncNext(void** tag, bool* ok, const T& deadline) { + TimePoint<T> deadline_tp(deadline); + return AsyncNextInternal(tag, ok, deadline_tp.raw_time()); + } - // Blocking (until deadline) read from queue. + // Blocking read from queue. // Returns false if the queue is ready for destruction, true if event bool Next(void** tag, bool* ok) { diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h index 2ac3eec95c..15bfef55ab 100644 --- a/include/grpc++/credentials.h +++ b/include/grpc++/credentials.h @@ -34,7 +34,6 @@ #ifndef GRPCXX_CREDENTIALS_H #define GRPCXX_CREDENTIALS_H -#include <chrono> #include <memory> #include <grpc++/config.h> @@ -103,7 +102,7 @@ std::unique_ptr<Credentials> ComputeEngineCredentials(); // grpc_max_auth_token_lifetime or will be cropped to this value. std::unique_ptr<Credentials> ServiceAccountCredentials( const grpc::string& json_key, const grpc::string& scope, - std::chrono::seconds token_lifetime); + long token_lifetime); // Builds JWT credentials. // json_key is the JSON key string containing the client's private key. @@ -111,7 +110,7 @@ std::unique_ptr<Credentials> ServiceAccountCredentials( // this credentials. It should not exceed grpc_max_auth_token_lifetime or // will be cropped to this value. std::unique_ptr<Credentials> JWTCredentials( - const grpc::string& json_key, std::chrono::seconds token_lifetime); + const grpc::string& json_key, long token_lifetime); // Builds refresh token credentials. // json_refresh_token is the JSON string containing the refresh token along diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 9e3b80c641..a62babd931 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -34,10 +34,11 @@ #ifndef GRPCXX_SERVER_CONTEXT_H #define GRPCXX_SERVER_CONTEXT_H -#include <chrono> #include <map> +#include <grpc/support/time.h> #include <grpc++/config.h> +#include <grpc++/time.h> struct gpr_timespec; struct grpc_metadata; @@ -71,9 +72,13 @@ class ServerContext { ServerContext(); // for async calls ~ServerContext(); - std::chrono::system_clock::time_point absolute_deadline() { - return deadline_; +#ifndef GRPC_CXX0X_NO_CHRONO + std::chrono::system_clock::time_point deadline() { + return Timespec2Timepoint(deadline_); } +#endif // !GRPC_CXX0X_NO_CHRONO + + gpr_timespec raw_deadline() { return deadline_; } void AddInitialMetadata(const grpc::string& key, const grpc::string& value); void AddTrailingMetadata(const grpc::string& key, const grpc::string& value); @@ -110,7 +115,7 @@ class ServerContext { CompletionOp* completion_op_; - std::chrono::system_clock::time_point deadline_; + gpr_timespec deadline_; grpc_call* call_; CompletionQueue* cq_; bool sent_initial_metadata_; diff --git a/include/grpc++/time.h b/include/grpc++/time.h new file mode 100644 index 0000000000..470471ab8b --- /dev/null +++ b/include/grpc++/time.h @@ -0,0 +1,81 @@ +/* + * + * Copyright 2015, 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 GRPC_INTERNAL_CPP_UTIL_TIME_H +#define GRPC_INTERNAL_CPP_UTIL_TIME_H + +#include <grpc++/config.h> + +namespace grpc { + +template <typename T> +class TimePoint { + public: + TimePoint(const T& time) : time_(time) { } + gpr_timespec raw_time() const { return time_; } + private: + gpr_timespec time_; +}; + +} // namespace grpc + +#ifndef GRPC_CXX0X_NO_CHRONO + +#include <chrono> + +#include <grpc/support/time.h> + +namespace grpc { + +// from and to should be absolute time. +void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, + gpr_timespec* to); + +std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); + +template <> +class TimePoint<std::chrono::system_clock::time_point> { + public: + TimePoint(const std::chrono::system_clock::time_point& time) { + Timepoint2Timespec(time, &time_); + } + gpr_timespec raw_time() const { return time_; } + private: + gpr_timespec time_; +}; + +} // namespace grpc + +#endif // !GRPC_CXX0X_NO_CHRONO + +#endif // GRPC_INTERNAL_CPP_UTIL_TIME_H |