1 // Copyright 2021 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GRPC_SRC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H 16 #define GRPC_SRC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H 17 18 #include <grpc/grpc.h> 19 #include <grpc/support/port_platform.h> 20 21 #include <functional> 22 #include <vector> 23 24 #include "src/core/lib/channel/channel_args.h" 25 26 namespace grpc_core { 27 28 // Registry of mutators for channel args. 29 // Surface APIs should call into this with channel args received from outside 30 // of gRPC, in order to prepare those channel args for the expectations of the 31 // gRPC internals. 32 class ChannelArgsPreconditioning { 33 public: 34 // Take channel args and mutate them. 35 // Does not take ownership of the channel args passed in. 36 // Returns a new channel args object that is owned by the caller. 37 using Stage = std::function<ChannelArgs(ChannelArgs)>; 38 39 class Builder { 40 public: 41 // Register a new channel args preconditioner. 42 void RegisterStage(Stage stage); 43 // Build out the preconditioners. 44 ChannelArgsPreconditioning Build(); 45 46 private: 47 std::vector<Stage> stages_; 48 }; 49 50 // Take channel args and precondition them. 51 // Does not take ownership of the channel args passed in. 52 // Returns a new channel args object that is owned by the caller. 53 ChannelArgs PreconditionChannelArgs(const grpc_channel_args* args) const; 54 55 private: 56 std::vector<Stage> stages_; 57 }; 58 59 } // namespace grpc_core 60 61 #endif // GRPC_SRC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H 62