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