mirror of https://github.com/grpc/grpc.git
Channel args preconditioning (#28132)
* Channel args preconditioning * docs * fixes * Automated change: Fix sanity tests * fix * fix this again after merge error Co-authored-by: ctiller <ctiller@users.noreply.github.com>pull/28181/head
parent
8e0a361cce
commit
672f31c6ac
92 changed files with 624 additions and 339 deletions
@ -0,0 +1,47 @@ |
||||
// Copyright 2021 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args_preconditioning.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
|
||||
namespace grpc_core { |
||||
|
||||
void ChannelArgsPreconditioning::Builder::RegisterStage(Stage stage) { |
||||
stages_.emplace_back(std::move(stage)); |
||||
} |
||||
|
||||
ChannelArgsPreconditioning ChannelArgsPreconditioning::Builder::Build() { |
||||
// TODO(ctiller): should probably make this registered too.
|
||||
stages_.emplace_back(RemoveGrpcInternalArgs); |
||||
|
||||
ChannelArgsPreconditioning preconditioning; |
||||
preconditioning.stages_ = std::move(stages_); |
||||
return preconditioning; |
||||
} |
||||
|
||||
const grpc_channel_args* ChannelArgsPreconditioning::PreconditionChannelArgs( |
||||
const grpc_channel_args* args) const { |
||||
const grpc_channel_args* owned_args = nullptr; |
||||
for (auto& stage : stages_) { |
||||
args = stage(args); |
||||
grpc_channel_args_destroy(owned_args); |
||||
owned_args = args; |
||||
} |
||||
return args; |
||||
} |
||||
|
||||
} // namespace grpc_core
|
@ -0,0 +1,62 @@ |
||||
// Copyright 2021 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H |
||||
#define GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <functional> |
||||
#include <vector> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
// Registry of mutators for channel args.
|
||||
// Surface APIs should call into this with channel args received from outside
|
||||
// of gRPC, in order to prepare those channel args for the expections of the
|
||||
// gRPC internals.
|
||||
class ChannelArgsPreconditioning { |
||||
public: |
||||
// Take channel args and mutate them.
|
||||
// Does not take ownership of the channel args passed in.
|
||||
// Returns a new channel args object that is owned by the caller.
|
||||
using Stage = |
||||
std::function<const grpc_channel_args*(const grpc_channel_args*)>; |
||||
|
||||
class Builder { |
||||
public: |
||||
// Register a new channel args preconditioner.
|
||||
void RegisterStage(Stage stage); |
||||
// Build out the preconditioners.
|
||||
ChannelArgsPreconditioning Build(); |
||||
|
||||
private: |
||||
std::vector<Stage> stages_; |
||||
}; |
||||
|
||||
// Take channel args and precondition them.
|
||||
// Does not take ownership of the channel args passed in.
|
||||
// Returns a new channel args object that is owned by the caller.
|
||||
const grpc_channel_args* PreconditionChannelArgs( |
||||
const grpc_channel_args* args) const; |
||||
|
||||
private: |
||||
std::vector<Stage> stages_; |
||||
}; |
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif // GRPC_CORE_LIB_CHANNEL_CHANNEL_ARGS_PRECONDITIONING_H
|
Loading…
Reference in new issue