proxy_mapper_registry.cc
Go to the documentation of this file.
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 
20 
22 
23 #include <memory>
24 #include <utility>
25 #include <vector>
26 
27 namespace grpc_core {
28 
29 namespace {
30 
31 using ProxyMapperList = std::vector<std::unique_ptr<ProxyMapperInterface>>;
32 ProxyMapperList* g_proxy_mapper_list;
33 
34 } // namespace
35 
37  if (g_proxy_mapper_list == nullptr) {
38  g_proxy_mapper_list = new ProxyMapperList();
39  }
40 }
41 
43  delete g_proxy_mapper_list;
44  // Clean up in case we re-initialze later.
45  // TODO(roth): This should ideally live in Init(). However, if we did this
46  // there, then we would do it AFTER we start registering proxy mappers from
47  // third-party plugins, so they'd never show up (and would leak memory).
48  // We probably need some sort of dependency system for plugins to fix
49  // this.
50  g_proxy_mapper_list = nullptr;
51 }
52 
54  bool at_start, std::unique_ptr<ProxyMapperInterface> mapper) {
55  Init();
56  if (at_start) {
57  g_proxy_mapper_list->insert(g_proxy_mapper_list->begin(),
58  std::move(mapper));
59  } else {
60  g_proxy_mapper_list->emplace_back(std::move(mapper));
61  }
62 }
63 
65  const grpc_channel_args* args,
66  char** name_to_resolve,
67  grpc_channel_args** new_args) {
68  Init();
69  for (const auto& mapper : *g_proxy_mapper_list) {
70  if (mapper->MapName(server_uri, args, name_to_resolve, new_args)) {
71  return true;
72  }
73  }
74  return false;
75 }
76 
78  const grpc_channel_args* args,
79  grpc_resolved_address** new_address,
80  grpc_channel_args** new_args) {
81  Init();
82  for (const auto& mapper : *g_proxy_mapper_list) {
83  if (mapper->MapAddress(address, args, new_address, new_args)) {
84  return true;
85  }
86  }
87  return false;
88 }
89 
90 } // namespace grpc_core
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::ProxyMapperRegistry::MapName
static bool MapName(const char *server_uri, const grpc_channel_args *args, char **name_to_resolve, grpc_channel_args **new_args)
Definition: proxy_mapper_registry.cc:64
grpc_resolved_address
Definition: resolved_address.h:34
run_xds_tests.server_uri
string server_uri
Definition: run_xds_tests.py:3320
grpc_channel_args
Definition: grpc_types.h:132
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::ProxyMapperRegistry::MapAddress
static bool MapAddress(const grpc_resolved_address &address, const grpc_channel_args *args, grpc_resolved_address **new_address, grpc_channel_args **new_args)
Definition: proxy_mapper_registry.cc:77
grpc_core::ProxyMapperRegistry::Shutdown
static void Shutdown()
Definition: proxy_mapper_registry.cc:42
grpc_core::ProxyMapperRegistry::Init
static void Init()
Definition: proxy_mapper_registry.cc:36
grpc_core::ProxyMapperRegistry::Register
static void Register(bool at_start, std::unique_ptr< ProxyMapperInterface > mapper)
Definition: proxy_mapper_registry.cc:53
proxy_mapper_registry.h
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:49