GRPC C++  1.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GRPCXX_IMPL_CODEGEN_TIME_H
20 #define GRPCXX_IMPL_CODEGEN_TIME_H
21 
24 
25 namespace grpc {
26 
37 template <typename T>
38 class TimePoint {
39  public:
40  TimePoint(const T& time) { you_need_a_specialization_of_TimePoint(); }
42  gpr_timespec t;
43  return t;
44  }
45 
46  private:
47  void you_need_a_specialization_of_TimePoint();
48 };
49 
50 template <>
52  public:
53  TimePoint(const gpr_timespec& time) : time_(time) {}
54  gpr_timespec raw_time() { return time_; }
55 
56  private:
57  gpr_timespec time_;
58 };
59 
60 } // namespace grpc
61 
62 #include <chrono>
63 
65 
66 namespace grpc {
67 
68 // from and to should be absolute time.
69 void Timepoint2Timespec(const std::chrono::system_clock::time_point& from,
70  gpr_timespec* to);
72  const std::chrono::high_resolution_clock::time_point& from,
73  gpr_timespec* to);
74 
75 std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t);
76 
77 template <>
78 class TimePoint<std::chrono::system_clock::time_point> {
79  public:
80  TimePoint(const std::chrono::system_clock::time_point& time) {
81  Timepoint2Timespec(time, &time_);
82  }
83  gpr_timespec raw_time() const { return time_; }
84 
85  private:
86  gpr_timespec time_;
87 };
88 
89 } // namespace grpc
90 
91 #endif // GRPCXX_IMPL_CODEGEN_TIME_H
void TimepointHR2Timespec(const std::chrono::high_resolution_clock::time_point &from, gpr_timespec *to)
gpr_timespec raw_time()
Definition: time.h:41
If you are trying to use CompletionQueue::AsyncNext with a time class that isn't either gpr_timespec ...
Definition: time.h:38
TimePoint(const gpr_timespec &time)
Definition: time.h:53
TimePoint(const std::chrono::system_clock::time_point &time)
Definition: time.h:80
void Timepoint2Timespec(const std::chrono::system_clock::time_point &from, gpr_timespec *to)
TimePoint(const T &time)
Definition: time.h:40
gpr_timespec raw_time()
Definition: time.h:54
gpr_timespec raw_time() const
Definition: time.h:83
Analogous to struct timespec.
Definition: gpr_types.h:47
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)