diff --git a/include/grpcpp/alarm.h b/include/grpcpp/alarm.h index 2be5d54903b..589d884416b 100644 --- a/include/grpcpp/alarm.h +++ b/include/grpcpp/alarm.h @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include namespace grpc { diff --git a/include/grpcpp/impl/codegen/time.h b/include/grpcpp/impl/codegen/time.h index f2021f51edf..6c9bb7b30fe 100644 --- a/include/grpcpp/impl/codegen/time.h +++ b/include/grpcpp/impl/codegen/time.h @@ -19,73 +19,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_TIME_H #define GRPCPP_IMPL_CODEGEN_TIME_H -// IWYU pragma: private, include +// IWYU pragma: private -#include - -#include -#include - -namespace grpc { - -/** If you are trying to use CompletionQueue::AsyncNext with a time class that - isn't either gpr_timespec or std::chrono::system_clock::time_point, you - will most likely be looking at this comment as your compiler will have - fired an error below. In order to fix this issue, you have two potential - solutions: - - 1. Use gpr_timespec or std::chrono::system_clock::time_point instead - 2. Specialize the TimePoint class with whichever time class that you - want to use here. See below for two examples of how to do this. - */ -template -class TimePoint { - public: - // If you see the error with methods below, you may need either - // i) using the existing types having a conversion class such as - // gpr_timespec and std::chrono::system_clock::time_point or - // ii) writing a new TimePoint to address your case. - TimePoint(const T& /*time*/) = delete; - gpr_timespec raw_time() = delete; -}; - -template <> -class TimePoint { - public: - /* NOLINTNEXTLINE(google-explicit-constructor) */ - TimePoint(const gpr_timespec& time) : time_(time) {} - gpr_timespec raw_time() { return time_; } - - private: - gpr_timespec time_; -}; - -} // namespace grpc - -namespace grpc { - -// from and to should be absolute time. -void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, - gpr_timespec* to); -void TimepointHR2Timespec( - const std::chrono::high_resolution_clock::time_point& from, - gpr_timespec* to); - -std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); - -template <> -class TimePoint { - public: - /* NOLINTNEXTLINE(google-explicit-constructor) */ - 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 +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif // GRPCPP_IMPL_CODEGEN_TIME_H diff --git a/include/grpcpp/support/time.h b/include/grpcpp/support/time.h index b5e07b68f22..df5d4149a60 100644 --- a/include/grpcpp/support/time.h +++ b/include/grpcpp/support/time.h @@ -19,6 +19,71 @@ #ifndef GRPCPP_SUPPORT_TIME_H #define GRPCPP_SUPPORT_TIME_H -#include // IWYU pragma: export +#include + +#include +#include + +namespace grpc { + +/** If you are trying to use CompletionQueue::AsyncNext with a time class that + isn't either gpr_timespec or std::chrono::system_clock::time_point, you + will most likely be looking at this comment as your compiler will have + fired an error below. In order to fix this issue, you have two potential + solutions: + + 1. Use gpr_timespec or std::chrono::system_clock::time_point instead + 2. Specialize the TimePoint class with whichever time class that you + want to use here. See below for two examples of how to do this. + */ +template +class TimePoint { + public: + // If you see the error with methods below, you may need either + // i) using the existing types having a conversion class such as + // gpr_timespec and std::chrono::system_clock::time_point or + // ii) writing a new TimePoint to address your case. + TimePoint(const T& /*time*/) = delete; + gpr_timespec raw_time() = delete; +}; + +template <> +class TimePoint { + public: + /* NOLINTNEXTLINE(google-explicit-constructor) */ + TimePoint(const gpr_timespec& time) : time_(time) {} + gpr_timespec raw_time() { return time_; } + + private: + gpr_timespec time_; +}; + +} // namespace grpc + +namespace grpc { + +// from and to should be absolute time. +void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, + gpr_timespec* to); +void TimepointHR2Timespec( + const std::chrono::high_resolution_clock::time_point& from, + gpr_timespec* to); + +std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); + +template <> +class TimePoint { + public: + /* NOLINTNEXTLINE(google-explicit-constructor) */ + 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 // GRPCPP_SUPPORT_TIME_H