GRPC C++  1.66.0
time.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #ifndef GRPCPP_SUPPORT_TIME_H
20 #define GRPCPP_SUPPORT_TIME_H
21 
22 #include <chrono>
23 
24 #include <grpc/impl/grpc_types.h>
25 #include <grpcpp/support/config.h>
26 
27 namespace grpc {
28 
34 
39 template <typename T>
40 class TimePoint {
41  public:
42  // If you see the error with methods below, you may need either
43  // i) using the existing types having a conversion class such as
44  // gpr_timespec and std::chrono::system_clock::time_point or
45  // ii) writing a new TimePoint<YourType> to address your case.
46  TimePoint(const T& /*time*/) = delete;
47  gpr_timespec raw_time() = delete;
48 };
49 
50 template <>
52  public:
53  // NOLINTNEXTLINE(google-explicit-constructor)
54  TimePoint(const gpr_timespec& time) : time_(time) {}
55  gpr_timespec raw_time() { return time_; }
56 
57  private:
58  gpr_timespec time_;
59 };
60 
61 } // namespace grpc
62 
63 namespace grpc {
64 
65 // from and to should be absolute time.
66 void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
67  gpr_timespec* to);
69  const std::chrono::high_resolution_clock::time_point& from,
70  gpr_timespec* to);
71 
72 std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);
73 
74 template <>
75 class TimePoint<std::chrono::system_clock::time_point> {
76  public:
77  // NOLINTNEXTLINE(google-explicit-constructor)
78  TimePoint(const std::chrono::system_clock::time_point& time) {
79  Timepoint2Timespec(time, &time_);
80  }
81  gpr_timespec raw_time() const { return time_; }
82 
83  private:
84  gpr_timespec time_;
85 };
86 
87 } // namespace grpc
88 
89 #endif // GRPCPP_SUPPORT_TIME_H
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::TimePoint< std::chrono::system_clock::time_point >::TimePoint
TimePoint(const std::chrono::system_clock::time_point &time)
Definition: time.h:78
grpc::TimePoint< std::chrono::system_clock::time_point >::raw_time
gpr_timespec raw_time() const
Definition: time.h:81
grpc_types.h
grpc::TimePoint< gpr_timespec >::TimePoint
TimePoint(const gpr_timespec &time)
Definition: time.h:54
grpc::TimePoint::raw_time
gpr_timespec raw_time()=delete
config.h
std
Definition: async_unary_call.h:407
grpc::Timepoint2Timespec
void Timepoint2Timespec(const std::chrono::system_clock::time_point &from, gpr_timespec *to)
grpc::TimepointHR2Timespec
void TimepointHR2Timespec(const std::chrono::high_resolution_clock::time_point &from, gpr_timespec *to)
grpc::TimePoint< gpr_timespec >::raw_time
gpr_timespec raw_time()
Definition: time.h:55
grpc::TimePoint::TimePoint
TimePoint(const T &)=delete
gpr_timespec
Analogous to struct timespec.
Definition: time.h:48
grpc::Timespec2Timepoint
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
grpc::TimePoint
If you are trying to use CompletionQueue::AsyncNext with a time class that isn't either gpr_timespec ...
Definition: time.h:40