Debian Codegraph @

src/cpp/common/channel_filter.cc

raw
1 /*
2 *
3 * Copyright 2016 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 #include "src/cpp/common/channel_filter.h"
20
21 #include <memory>
22
23 #include "absl/strings/str_cat.h"
24 #include "absl/strings/string_view.h"
25
26 #include <grpc/support/log.h>
27
28 #include "src/core/lib/channel/channel_args.h"
29 #include "src/core/lib/channel/channel_stack.h"
30 #include "src/core/lib/channel/channel_stack_builder.h"
31 #include "src/core/lib/config/core_configuration.h"
32 #include "src/core/lib/slice/slice.h"
33
34 namespace grpc {
35
36 // MetadataBatch
37
38 void MetadataBatch::AddMetadata(const string& key, const string& value) {
39 batch_->Append(key, grpc_core::Slice::FromCopiedString(value),
40 [&](absl::string_view error, const grpc_core::Slice&) {
41 gpr_log(GPR_INFO, "%s",
42 absl::StrCat("MetadataBatch::AddMetadata error:",
43 error, " key=", key, " value=", value)
44 .c_str());
45 });
46 }
47
48 // ChannelData
49
50 void ChannelData::StartTransportOp(grpc_channel_element* elem,
51 TransportOp* op) {
52 grpc_channel_next_op(elem, op->op());
53 }
54
55 void ChannelData::GetInfo(grpc_channel_element* elem,
56 const grpc_channel_info* channel_info) {
57 grpc_channel_next_get_info(elem, channel_info);
58 }
59
60 // CallData
61
62 void CallData::StartTransportStreamOpBatch(grpc_call_element* elem,
63 TransportStreamOpBatch* op) {
64 grpc_call_next_op(elem, op->op());
65 }
66
67 void CallData::SetPollsetOrPollsetSet(grpc_call_element* elem,
68 grpc_polling_entity* pollent) {
69 grpc_call_stack_ignore_set_pollset_or_pollset_set(elem, pollent);
70 }
71
72 namespace internal {
73
74 void RegisterChannelFilter(
75 grpc_channel_stack_type stack_type, int priority,
76 std::function<bool(const grpc_channel_args&)> include_filter,
77 const grpc_channel_filter* filter) {
78 auto maybe_add_filter = [include_filter,
79 filter](grpc_core::ChannelStackBuilder* builder) {
80 if (include_filter != nullptr) {
81 if (!include_filter(*builder->channel_args().ToC())) {
82 return true;
83 }
84 }
85 builder->PrependFilter(filter);
86 return true;
87 };
88 grpc_core::CoreConfiguration::RegisterBuilder(
89 [stack_type, priority,
90 maybe_add_filter](grpc_core::CoreConfiguration::Builder* builder) {
91 builder->channel_init()->RegisterStage(stack_type, priority,
92 maybe_add_filter);
93 });
94 }
95
96 } // namespace internal
97
98 } // namespace grpc