GRPC C++  1.19.0-dev
alarm_impl.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 
21 #ifndef GRPCPP_ALARM_IMPL_H
22 #define GRPCPP_ALARM_IMPL_H
23 
24 #include <functional>
25 
26 #include <grpc/grpc.h>
32 
33 namespace grpc_impl {
34 
37  public:
39  Alarm();
40 
42  ~Alarm();
43 
51  template <typename T>
52  Alarm(::grpc::CompletionQueue* cq, const T& deadline, void* tag) : Alarm() {
53  SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag);
54  }
55 
60  template <typename T>
61  void Set(::grpc::CompletionQueue* cq, const T& deadline, void* tag) {
62  SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag);
63  }
64 
66  Alarm(const Alarm&) = delete;
67  Alarm& operator=(const Alarm&) = delete;
68 
70  Alarm(Alarm&& rhs) : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; }
71  Alarm& operator=(Alarm&& rhs) {
72  alarm_ = rhs.alarm_;
73  rhs.alarm_ = nullptr;
74  return *this;
75  }
76 
79  void Cancel();
80 
85  public:
86  explicit experimental_type(Alarm* alarm) : alarm_(alarm) {}
87 
91  template <typename T>
92  void Set(const T& deadline, std::function<void(bool)> f) {
93  alarm_->SetInternal(::grpc::TimePoint<T>(deadline).raw_time(),
94  std::move(f));
95  }
96 
97  private:
98  Alarm* alarm_;
99  };
100 
105 
106  private:
107  void SetInternal(::grpc::CompletionQueue* cq, gpr_timespec deadline,
108  void* tag);
109  void SetInternal(gpr_timespec deadline, std::function<void(bool)> f);
110 
112 };
113 
114 } // namespace grpc_impl
115 
116 #endif // GRPCPP_ALARM_IMPL_H
Alarm(::grpc::CompletionQueue *cq, const T &deadline, void *tag)
DEPRECATED: Create and set a completion queue alarm instance associated to cq.
Definition: alarm_impl.h:52
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
Alarm()
Create an unset completion queue alarm.
void Cancel()
Cancel a completion queue alarm.
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
If you are trying to use CompletionQueue::AsyncNext with a time class that isn&#39;t either gpr_timespec ...
Definition: time.h:40
experimental_type(Alarm *alarm)
Definition: alarm_impl.h:86
void Set(const T &deadline, std::function< void(bool)> f)
Set an alarm to invoke callback f.
Definition: alarm_impl.h:92
A thin wrapper around grpc_alarm (see / / src/core/surface/alarm.h).
Definition: alarm_impl.h:36
Alarm(Alarm &&rhs)
Alarms are movable.
Definition: alarm_impl.h:70
NOTE: class experimental_type is not part of the public API of this class TODO(vjpai): Move these con...
Definition: alarm_impl.h:84
Alarm & operator=(const Alarm &)=delete
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:95
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm_impl.h:33
~Alarm()
Destroy the given completion queue alarm, cancelling it in the process.
void Set(::grpc::CompletionQueue *cq, const T &deadline, void *tag)
Trigger an alarm instance on completion queue cq at the specified time.
Definition: alarm_impl.h:61
Analogous to struct timespec.
Definition: gpr_types.h:47
Alarm & operator=(Alarm &&rhs)
Definition: alarm_impl.h:71
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: alarm_impl.h:104