grpcpp/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 <functional>
25 
26 #include <grpc/grpc.h>
32 
33 namespace grpc {
34 
36  public:
38  Alarm();
39 
41  ~Alarm() override;
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  //
60  // USAGE NOTE: This is frequently used to inject arbitrary tags into \a cq by
61  // setting an immediate deadline. Such usage allows synchronizing an external
62  // event with an application's \a grpc::CompletionQueue::Next loop.
63  template <typename T>
64  void Set(grpc::CompletionQueue* cq, const T& deadline, void* tag) {
65  SetInternal(cq, grpc::TimePoint<T>(deadline).raw_time(), tag);
66  }
67 
69  Alarm(const Alarm&) = delete;
70  Alarm& operator=(const Alarm&) = delete;
71 
73  Alarm(Alarm&& rhs) noexcept : alarm_(rhs.alarm_) { rhs.alarm_ = nullptr; }
74  Alarm& operator=(Alarm&& rhs) noexcept {
75  alarm_ = rhs.alarm_;
76  rhs.alarm_ = nullptr;
77  return *this;
78  }
79 
82  void Cancel();
83 
87  template <typename T>
88  void Set(const T& deadline, std::function<void(bool)> f) {
89  SetInternal(grpc::TimePoint<T>(deadline).raw_time(), std::move(f));
90  }
91 
92  private:
93  void SetInternal(grpc::CompletionQueue* cq, gpr_timespec deadline, void* tag);
94  void SetInternal(gpr_timespec deadline, std::function<void(bool)> f);
95 
97 };
98 
99 } // namespace grpc
100 
101 #endif // GRPCPP_ALARM_H
grpc::Alarm::operator=
Alarm & operator=(Alarm &&rhs) noexcept
Definition: grpcpp/alarm.h:74
grpc
Definition: grpcpp/alarm.h:33
grpc::Alarm::Set
void Set(const T &deadline, std::function< void(bool)> f)
Definition: grpcpp/alarm.h:88
grpc::GrpcLibraryCodegen
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpcpp/impl/codegen/grpc_library.h:40
grpc::TimePoint
Definition: include/grpcpp/impl/codegen/time.h:42
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc::Alarm::SetInternal
void SetInternal(grpc::CompletionQueue *cq, gpr_timespec deadline, void *tag)
Definition: alarm.cc:142
grpc::Alarm::alarm_
grpc::internal::CompletionQueueTag * alarm_
Definition: grpcpp/alarm.h:96
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc::Alarm::Set
void Set(grpc::CompletionQueue *cq, const T &deadline, void *tag)
Definition: grpcpp/alarm.h:64
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
grpc.h
completion_queue_tag.h
completion_queue.h
grpc::Alarm::Alarm
Alarm()
Create an unset completion queue alarm.
Definition: alarm.cc:138
grpc_library.h
grpc::Alarm::Alarm
Alarm(Alarm &&rhs) noexcept
Alarms are movable.
Definition: grpcpp/alarm.h:73
grpc_library.h
grpc::Alarm::~Alarm
~Alarm() override
Destroy the given completion queue alarm, cancelling it in the process.
Definition: alarm.cc:161
grpc::Alarm::Alarm
Alarm(grpc::CompletionQueue *cq, const T &deadline, void *tag)
Definition: grpcpp/alarm.h:51
time.h
grpc::CompletionQueue
Definition: include/grpcpp/impl/codegen/completion_queue.h:104
gpr_timespec
Definition: gpr_types.h:50
grpc::internal::CompletionQueueTag
An interface allowing implementors to process and filter event tags.
Definition: grpcpp/impl/codegen/completion_queue_tag.h:28
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
grpc::Alarm
Definition: grpcpp/alarm.h:35
grpc::Alarm::Cancel
void Cancel()
Definition: alarm.cc:167
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
grpc::Alarm::operator=
Alarm & operator=(const Alarm &)=delete


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:29