GRPC C++  1.13.0-dev
alarm.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_H
22 #define GRPCPP_ALARM_H
23 
24 #include <grpc/grpc.h>
30 
31 namespace grpc {
32 
34 class Alarm : private GrpcLibraryCodegen {
35  public:
37  Alarm();
38 
40  ~Alarm();
41 
49  template <typename T>
50  Alarm(CompletionQueue* cq, const T& deadline, void* tag) : Alarm() {
51  SetInternal(cq, TimePoint<T>(deadline).raw_time(), tag);
52  }
53 
58  template <typename T>
59  void Set(CompletionQueue* cq, const T& deadline, void* tag) {
60  SetInternal(cq, TimePoint<T>(deadline).raw_time(), tag);
61  }
62 
64  Alarm(const Alarm&) = delete;
65  Alarm& operator=(const Alarm&) = delete;
66 
68  Alarm(Alarm&& rhs) : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; }
69  Alarm& operator=(Alarm&& rhs) {
70  alarm_ = rhs.alarm_;
71  rhs.alarm_ = nullptr;
72  return *this;
73  }
74 
77  void Cancel();
78 
79  private:
80  void SetInternal(CompletionQueue* cq, gpr_timespec deadline, void* tag);
81 
83 };
84 
85 } // namespace grpc
86 
87 #endif // GRPCPP_ALARM_H
void Set(CompletionQueue *cq, const T &deadline, void *tag)
Trigger an alarm instance on completion queue cq at the specified time.
Definition: alarm.h:59
A thin wrapper around grpc_alarm (see / / src/core/surface/alarm.h).
Definition: alarm.h:34
Alarm(CompletionQueue *cq, const T &deadline, void *tag)
DEPRECATED: Create and set a completion queue alarm instance associated to cq.
Definition: alarm.h:50
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
Alarm & operator=(const Alarm &)=delete
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
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:94
Alarm(Alarm &&rhs)
Alarms are movable.
Definition: alarm.h:68
Alarm()
Create an unset completion queue alarm.
void Cancel()
Cancel a completion queue alarm.
Analogous to struct timespec.
Definition: gpr_types.h:47
Alarm & operator=(Alarm &&rhs)
Definition: alarm.h:69
~Alarm()
Destroy the given completion queue alarm, cancelling it in the process.