GRPC C++  1.26.0
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 
36  public:
38  Alarm();
39 
41  ~Alarm();
42 
50  template <typename T>
51  Alarm(::grpc::CompletionQueue* cq, const T& deadline, void* tag) : Alarm() {
52  SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag);
53  }
54 
59  template <typename T>
60  void Set(::grpc::CompletionQueue* cq, const T& deadline, void* tag) {
61  SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag);
62  }
63 
65  Alarm(const Alarm&) = delete;
66  Alarm& operator=(const Alarm&) = delete;
67 
69  Alarm(Alarm&& rhs) : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; }
70  Alarm& operator=(Alarm&& rhs) {
71  alarm_ = rhs.alarm_;
72  rhs.alarm_ = nullptr;
73  return *this;
74  }
75 
78  void Cancel();
79 
84  public:
85  explicit experimental_type(Alarm* alarm) : alarm_(alarm) {}
86 
90  template <typename T>
91  void Set(const T& deadline, std::function<void(bool)> f) {
92  alarm_->SetInternal(::grpc::TimePoint<T>(deadline).raw_time(),
93  std::move(f));
94  }
95 
96  private:
97  Alarm* alarm_;
98  };
99 
104 
105  private:
106  void SetInternal(::grpc::CompletionQueue* cq, gpr_timespec deadline,
107  void* tag);
108  void SetInternal(gpr_timespec deadline, std::function<void(bool)> f);
109 
111 };
112 
113 } // namespace grpc_impl
114 
115 #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:51
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:85
void Set(const T &deadline, std::function< void(bool)> f)
Set an alarm to invoke callback f.
Definition: alarm_impl.h:91
Definition: alarm_impl.h:35
Alarm(Alarm &&rhs)
Alarms are movable.
Definition: alarm_impl.h:69
NOTE: class experimental_type is not part of the public API of this class TODO(vjpai): Move these con...
Definition: alarm_impl.h:83
Alarm & operator=(const Alarm &)=delete
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
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:60
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:100
Analogous to struct timespec.
Definition: gpr_types.h:47
Alarm & operator=(Alarm &&rhs)
Definition: alarm_impl.h:70
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: alarm_impl.h:103