| 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_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H |
| 16 |
#define GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H |
| 17 |
|
| 18 |
#include <grpc/support/port_platform.h> |
| 19 |
|
| 20 |
#include <functional> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
#include <grpc/impl/codegen/grpc_types.h> |
| 24 |
|
| 25 |
#include "src/core/lib/channel/channel_args.h" |
| 26 |
|
| 27 |
namespace grpc_core { |
| 28 |
|
| 29 |
// Registry of mutators for channel args. |
| 30 |
// Surface APIs should call into this with channel args received from outside |
| 31 |
// of gRPC, in order to prepare those channel args for the expections of the |
| 32 |
// gRPC internals. |
| 33 |
class ChannelArgsPreconditioning { |
| 34 |
public: |
| 35 |
// Take channel args and mutate them. |
| 36 |
// Does not take ownership of the channel args passed in. |
| 37 |
// Returns a new channel args object that is owned by the caller. |
| 38 |
using Stage = std::function<ChannelArgs(ChannelArgs)>; |
| 39 |
|
| 40 |
class Builder { |
| 41 |
public: |
| 42 |
// Register a new channel args preconditioner. |
| 43 |
void RegisterStage(Stage stage); |
| 44 |
// Build out the preconditioners. |
| 45 |
ChannelArgsPreconditioning Build(); |
| 46 |
|
| 47 |
private: |
| 48 |
std::vector<Stage> stages_; |
| 49 |
}; |
| 50 |
|
| 51 |
// Take channel args and precondition them. |
| 52 |
// Does not take ownership of the channel args passed in. |
| 53 |
// Returns a new channel args object that is owned by the caller. |
| 54 |
ChannelArgs PreconditionChannelArgs(const grpc_channel_args* args) const; |
| 55 |
|
| 56 |
private: |
| 57 |
std::vector<Stage> stages_; |
| 58 |
}; |
| 59 |
|
| 60 |
} // namespace grpc_core |
| 61 |
|
| 62 |
#endif // GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H |