Debian Codegraph @

src/core/ext/xds/xds_cluster_specifier_plugin.h

raw
1 //
2 // Copyright 2022 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #ifndef GRPC_CORE_EXT_XDS_XDS_CLUSTER_SPECIFIER_PLUGIN_H
18 #define GRPC_CORE_EXT_XDS_XDS_CLUSTER_SPECIFIER_PLUGIN_H
19
20 #include <grpc/support/port_platform.h>
21
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <utility>
26
27 #include "absl/status/statusor.h"
28 #include "absl/strings/string_view.h"
29 #include "upb/arena.h"
30 #include "upb/def.h"
31
32 #include "src/core/ext/xds/xds_common_types.h"
33
34 namespace grpc_core {
35
36 class XdsClusterSpecifierPluginImpl {
37 public:
38 virtual ~XdsClusterSpecifierPluginImpl() = default;
39
40 // Loads the proto message into the upb symtab.
41 virtual void PopulateSymtab(upb_DefPool* symtab) const = 0;
42
43 // Returns the LB policy config in JSON form.
44 virtual absl::StatusOr<std::string> GenerateLoadBalancingPolicyConfig(
45 XdsExtension extension, upb_Arena* arena, upb_DefPool* symtab) const = 0;
46 };
47
48 class XdsRouteLookupClusterSpecifierPlugin
49 : public XdsClusterSpecifierPluginImpl {
50 void PopulateSymtab(upb_DefPool* symtab) const override;
51
52 absl::StatusOr<std::string> GenerateLoadBalancingPolicyConfig(
53 XdsExtension extension, upb_Arena* arena,
54 upb_DefPool* symtab) const override;
55 };
56
57 class XdsClusterSpecifierPluginRegistry {
58 public:
59 XdsClusterSpecifierPluginRegistry();
60
61 // Not copyable.
62 XdsClusterSpecifierPluginRegistry(const XdsClusterSpecifierPluginRegistry&) =
63 delete;
64 XdsClusterSpecifierPluginRegistry& operator=(
65 const XdsClusterSpecifierPluginRegistry&) = delete;
66
67 // Movable.
68 XdsClusterSpecifierPluginRegistry(
69 XdsClusterSpecifierPluginRegistry&& other) noexcept
70 : registry_(std::move(other.registry_)) {}
71 XdsClusterSpecifierPluginRegistry& operator=(
72 XdsClusterSpecifierPluginRegistry&& other) noexcept {
73 registry_ = std::move(other.registry_);
74 return *this;
75 }
76
77 void RegisterPlugin(std::unique_ptr<XdsClusterSpecifierPluginImpl> plugin,
78 absl::string_view config_proto_type_name);
79
80 void PopulateSymtab(upb_DefPool* symtab) const;
81
82 const XdsClusterSpecifierPluginImpl* GetPluginForType(
83 absl::string_view config_proto_type_name) const;
84
85 private:
86 std::map<absl::string_view, std::unique_ptr<XdsClusterSpecifierPluginImpl>>
87 registry_;
88 };
89
90 } // namespace grpc_core
91
92 #endif // GRPC_CORE_EXT_XDS_XDS_CLUSTER_SPECIFIER_PLUGIN_H