certificate_provider_registry.cc
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2020 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 <string.h>
24 
25 #include <algorithm>
26 #include <utility>
27 #include <vector>
28 
29 #include <grpc/support/log.h>
30 
31 namespace grpc_core {
32 
33 namespace {
34 
35 class RegistryState {
36  public:
37  void RegisterCertificateProviderFactory(
38  std::unique_ptr<CertificateProviderFactory> factory) {
39  gpr_log(GPR_DEBUG, "registering certificate provider factory for \"%s\"",
40  factory->name());
41  for (size_t i = 0; i < factories_.size(); ++i) {
42  GPR_ASSERT(strcmp(factories_[i]->name(), factory->name()) != 0);
43  }
44  factories_.push_back(std::move(factory));
45  }
46 
47  CertificateProviderFactory* LookupCertificateProviderFactory(
48  absl::string_view name) const {
49  for (size_t i = 0; i < factories_.size(); ++i) {
50  if (name == factories_[i]->name()) {
51  return factories_[i].get();
52  }
53  }
54  return nullptr;
55  }
56 
57  private:
58  std::vector<std::unique_ptr<CertificateProviderFactory>> factories_;
59 };
60 
61 RegistryState* g_state = nullptr;
62 
63 } // namespace
64 
65 //
66 // CertificateProviderRegistry
67 //
68 
69 CertificateProviderFactory*
72  GPR_ASSERT(g_state != nullptr);
73  return g_state->LookupCertificateProviderFactory(name);
74 }
75 
77  if (g_state == nullptr) g_state = new RegistryState();
78 }
79 
81  delete g_state;
82  g_state = nullptr;
83 }
84 
86  std::unique_ptr<CertificateProviderFactory> factory) {
87  InitRegistry();
88  g_state->RegisterCertificateProviderFactory(std::move(factory));
89 }
90 
91 } // namespace grpc_core
92 
93 //
94 // Plugin registration
95 //
96 
99 }
100 
103 }
log.h
grpc_core::CertificateProviderRegistry::RegisterCertificateProviderFactory
static void RegisterCertificateProviderFactory(std::unique_ptr< CertificateProviderFactory > factory)
Definition: certificate_provider_registry.cc:85
grpc_core::CertificateProviderRegistry::ShutdownRegistry
static void ShutdownRegistry()
Definition: certificate_provider_registry.cc:80
grpc_core
Definition: call_metric_recorder.h:31
string.h
grpc_core::CertificateProviderRegistry::InitRegistry
static void InitRegistry()
Definition: certificate_provider_registry.cc:76
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
setup.name
name
Definition: setup.py:542
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
certificate_provider_registry.h
grpc_certificate_provider_registry_init
void grpc_certificate_provider_registry_init()
Definition: certificate_provider_registry.cc:97
g_state
static struct test_state g_state
Definition: invalid_call_argument_test.cc:55
grpc_certificate_provider_registry_shutdown
void grpc_certificate_provider_registry_shutdown()
Definition: certificate_provider_registry.cc:101
GPR_DEBUG
#define GPR_DEBUG
Definition: include/grpc/impl/codegen/log.h:55
grpc_core::CertificateProviderRegistry::LookupCertificateProviderFactory
static CertificateProviderFactory * LookupCertificateProviderFactory(absl::string_view name)
Definition: certificate_provider_registry.cc:70
factories_
std::vector< std::unique_ptr< CertificateProviderFactory > > factories_
Definition: certificate_provider_registry.cc:58
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:52