GRPC C++  1.16.0-dev
callback_common.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 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 
19 #ifndef GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H
20 #define GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H
21 
22 #include <functional>
23 
29 
30 // Forward declarations
31 namespace grpc_core {
32 class CQCallbackInterface;
33 };
34 
35 namespace grpc {
36 namespace internal {
37 
39  public:
40  // always allocated against a call arena, no memory free required
41  static void operator delete(void* ptr, std::size_t size) {
42  assert(size == sizeof(CallbackWithStatusTag));
43  }
44 
45  // This operator should never be called as the memory should be freed as part
46  // of the arena destruction. It only exists to provide a matching operator
47  // delete to the operator new so that some compilers will not complain (see
48  // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
49  // there are no tests catching the compiler warning.
50  static void operator delete(void*, void*) { assert(0); }
51 
52  CallbackWithStatusTag(grpc_call* call, std::function<void(Status)> f,
53  CompletionQueueTag* ops);
55  void* tag() { return static_cast<void*>(impl_); }
56  Status* status_ptr() { return status_; }
57  CompletionQueueTag* ops() { return ops_; }
58 
59  // force_run can not be performed on a tag if operations using this tag
60  // have been sent to PerformOpsOnCall. It is intended for error conditions
61  // that are detected before the operations are internally processed.
62  void force_run(Status s);
63 
64  private:
65  grpc_core::CQCallbackInterface* impl_;
66  Status* status_;
67  CompletionQueueTag* ops_;
68 };
69 
71  public:
72  // always allocated against a call arena, no memory free required
73  static void operator delete(void* ptr, std::size_t size) {
74  assert(size == sizeof(CallbackWithSuccessTag));
75  }
76 
77  // This operator should never be called as the memory should be freed as part
78  // of the arena destruction. It only exists to provide a matching operator
79  // delete to the operator new so that some compilers will not complain (see
80  // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
81  // there are no tests catching the compiler warning.
82  static void operator delete(void*, void*) { assert(0); }
83 
84  CallbackWithSuccessTag(grpc_call* call, std::function<void(bool)> f,
85  CompletionQueueTag* ops);
86 
87  void* tag() { return static_cast<void*>(impl_); }
88  CompletionQueueTag* ops() { return ops_; }
89 
90  // force_run can not be performed on a tag if operations using this tag
91  // have been sent to PerformOpsOnCall. It is intended for error conditions
92  // that are detected before the operations are internally processed.
93  void force_run(bool ok);
94 
95  private:
96  grpc_core::CQCallbackInterface* impl_;
97  CompletionQueueTag* ops_;
98 };
99 
100 } // namespace internal
101 } // namespace grpc
102 
103 #endif // GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
CompletionQueueTag * ops()
Definition: callback_common.h:88
void * tag()
Definition: callback_common.h:87
Definition: callback_common.h:31
Status * status_ptr()
Definition: callback_common.h:56
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
~CallbackWithStatusTag()
Definition: callback_common.h:54
void * tag()
Definition: callback_common.h:55
Definition: callback_common.h:70
CompletionQueueTag * ops()
Definition: callback_common.h:57
Did it work? If it didn&#39;t, why?
Definition: status.h:31
Definition: callback_common.h:38