GRPC C++  1.26.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_IMPL_CODEGEN_TIME_H
20 #define GRPCPP_IMPL_CODEGEN_TIME_H
21 
22 #include <chrono>
23 
26 
27 namespace grpc {
28 
39 template <typename T>
40 class TimePoint {
41  public:
42  TimePoint(const T& /*time*/) { you_need_a_specialization_of_TimePoint(); }
44  gpr_timespec t;
45  return t;
46  }
47 
48  private:
49  void you_need_a_specialization_of_TimePoint();
50 };
51 
52 template <>
54  public:
55  TimePoint(const gpr_timespec& time) : time_(time) {}
56  gpr_timespec raw_time() { return time_; }
57 
58  private:
59  gpr_timespec time_;
60 };
61 
62 } // namespace grpc
63 
64 namespace grpc {
65 
66 // from and to should be absolute time.
67 void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
68  gpr_timespec* to);
70  const std::chrono::high_resolution_clock::time_point& from,
71  gpr_timespec* to);
72 
73 std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);
74 
75 template <>
76 class TimePoint<std::chrono::system_clock::time_point> {
77  public:
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_IMPL_CODEGEN_TIME_H
void TimepointHR2Timespec(const std::chrono::high_resolution_clock::time_point &from, gpr_timespec *to)
Definition: async_unary_call_impl.h:301
gpr_timespec raw_time()
Definition: time.h:43
If you are trying to use CompletionQueue::AsyncNext with a time class that isn&#39;t either gpr_timespec ...
Definition: time.h:40
TimePoint(const gpr_timespec &time)
Definition: time.h:55
TimePoint(const std::chrono::system_clock::time_point &time)
Definition: time.h:78
void Timepoint2Timespec(const std::chrono::system_clock::time_point &from, gpr_timespec *to)
TimePoint(const T &)
Definition: time.h:42
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
gpr_timespec raw_time()
Definition: time.h:56
Analogous to struct timespec.
Definition: gpr_types.h:47
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
gpr_timespec raw_time() const
Definition: time.h:81