GRPC C++  1.30.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 
80 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
81  template <typename T>
85  void Set(const T& deadline, std::function<void(bool)> f) {
86  SetInternal(::grpc::TimePoint<T>(deadline).raw_time(), std::move(f));
87  }
88 #endif
89 
94  public:
95  explicit experimental_type(Alarm* alarm) : alarm_(alarm) {}
96 
100  template <typename T>
101  void Set(const T& deadline, std::function<void(bool)> f) {
102  alarm_->SetInternal(::grpc::TimePoint<T>(deadline).raw_time(),
103  std::move(f));
104  }
105 
106  private:
107  Alarm* alarm_;
108  };
109 
114 
115  private:
116  void SetInternal(::grpc::CompletionQueue* cq, gpr_timespec deadline,
117  void* tag);
118  void SetInternal(gpr_timespec deadline, std::function<void(bool)> f);
119 
121 };
122 
123 } // namespace grpc_impl
124 
125 #endif // GRPCPP_ALARM_IMPL_H
grpc::GrpcLibraryCodegen
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
grpc_impl::Alarm::Alarm
Alarm(Alarm &&rhs)
Alarms are movable.
Definition: alarm_impl.h:69
time.h
grpc_impl::Alarm::experimental_type::experimental_type
experimental_type(Alarm *alarm)
Definition: alarm_impl.h:95
grpc_impl::Alarm::Alarm
Alarm()
Create an unset completion queue alarm.
grpc_impl::Alarm::operator=
Alarm & operator=(const Alarm &)=delete
grpc_impl::Alarm::Alarm
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
grpc_impl::Alarm::Cancel
void Cancel()
Cancel a completion queue alarm.
grpc_impl::Alarm::experimental
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: alarm_impl.h:113
grpc_impl::Alarm::operator=
Alarm & operator=(Alarm &&rhs)
Definition: alarm_impl.h:70
grpc_impl::Alarm::experimental_type::Set
void Set(const T &deadline, std::function< void(bool)> f)
Set an alarm to invoke callback f.
Definition: alarm_impl.h:101
grpc_impl::Alarm::~Alarm
~Alarm()
Destroy the given completion queue alarm, cancelling it in the process.
grpc.h
completion_queue_tag.h
grpc_impl::Alarm
Definition: alarm_impl.h:35
grpc_impl::Alarm::Set
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
grpc::internal::CompletionQueueTag
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
grpc_library.h
grpc_library.h
grpc_impl::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue_impl.h:103
grpc_impl::Alarm::experimental_type
NOTE: class experimental_type is not part of the public API of this class TODO(vjpai): Move these con...
Definition: alarm_impl.h:93
grpc_impl
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
completion_queue.h
gpr_timespec
Analogous to struct timespec.
Definition: gpr_types.h:47
grpc::TimePoint
If you are trying to use CompletionQueue::AsyncNext with a time class that isn't either gpr_timespec ...
Definition: time.h:40