| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2017 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 |
#ifndef GRPC_CORE_LIB_HANDSHAKER_PROXY_MAPPER_REGISTRY_H |
| 20 |
#define GRPC_CORE_LIB_HANDSHAKER_PROXY_MAPPER_REGISTRY_H |
| 21 |
|
| 22 |
#include <grpc/support/port_platform.h> |
| 23 |
|
| 24 |
#include <algorithm> |
| 25 |
#include <memory> |
| 26 |
#include <string> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
#include "absl/strings/string_view.h" |
| 30 |
#include "absl/types/optional.h" |
| 31 |
|
| 32 |
#include "src/core/lib/channel/channel_args.h" |
| 33 |
#include "src/core/lib/handshaker/proxy_mapper.h" |
| 34 |
#include "src/core/lib/iomgr/resolved_address.h" |
| 35 |
|
| 36 |
namespace grpc_core { |
| 37 |
|
| 38 |
class ProxyMapperRegistry { |
| 39 |
using ProxyMapperList = std::vector<std::unique_ptr<ProxyMapperInterface>>; |
| 40 |
|
| 41 |
public: |
| 42 |
class Builder { |
| 43 |
public: |
| 44 |
/// Registers a new proxy mapper. |
| 45 |
/// If \a at_start is true, the new mapper will be at the beginning of |
| 46 |
/// the list. Otherwise, it will be added to the end. |
| 47 |
void Register(bool at_start, std::unique_ptr<ProxyMapperInterface> mapper); |
| 48 |
|
| 49 |
ProxyMapperRegistry Build(); |
| 50 |
|
| 51 |
private: |
| 52 |
ProxyMapperList mappers_; |
| 53 |
}; |
| 54 |
|
| 55 |
~ProxyMapperRegistry() = default; |
| 56 |
ProxyMapperRegistry(const ProxyMapperRegistry&) = delete; |
| 57 |
ProxyMapperRegistry& operator=(const ProxyMapperRegistry&) = delete; |
| 58 |
ProxyMapperRegistry(ProxyMapperRegistry&&) = default; |
| 59 |
ProxyMapperRegistry& operator=(ProxyMapperRegistry&&) = default; |
| 60 |
|
| 61 |
absl::optional<std::string> MapName(absl::string_view server_uri, |
| 62 |
ChannelArgs* args) const; |
| 63 |
|
| 64 |
absl::optional<grpc_resolved_address> MapAddress( |
| 65 |
const grpc_resolved_address& address, ChannelArgs* args) const; |
| 66 |
|
| 67 |
private: |
| 68 |
ProxyMapperRegistry() = default; |
| 69 |
|
| 70 |
ProxyMapperList mappers_; |
| 71 |
}; |
| 72 |
|
| 73 |
} // namespace grpc_core |
| 74 |
|
| 75 |
#endif /* GRPC_CORE_LIB_HANDSHAKER_PROXY_MAPPER_REGISTRY_H */ |