3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_REGISTRY_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_REGISTRY_H
22 #include <grpc/support/port_platform.h>
24 #include "src/core/ext/filters/client_channel/resolver_factory.h"
25 #include "src/core/lib/gprpp/inlined_vector.h"
26 #include "src/core/lib/gprpp/memory.h"
27 #include "src/core/lib/gprpp/orphanable.h"
28 #include "src/core/lib/iomgr/pollset_set.h"
32 class ResolverRegistry {
34 /// Methods used to create and populate the ResolverRegistry.
35 /// NOT THREAD SAFE -- to be used only during global gRPC
36 /// initialization and shutdown.
39 /// Global initialization and shutdown hooks.
40 static void InitRegistry();
41 static void ShutdownRegistry();
43 /// Sets the default URI prefix to \a default_prefix.
44 /// Calls InitRegistry() if it has not already been called.
45 static void SetDefaultPrefix(const char* default_prefix);
47 /// Registers a resolver factory. The factory will be used to create a
48 /// resolver for any URI whose scheme matches that of the factory.
49 /// Calls InitRegistry() if it has not already been called.
50 static void RegisterResolverFactory(UniquePtr<ResolverFactory> factory);
53 /// Checks whether the user input \a target is valid to create a resolver.
54 static bool IsValidTarget(const char* target);
56 /// Creates a resolver given \a target.
57 /// First tries to parse \a target as a URI. If this succeeds, tries
58 /// to locate a registered resolver factory based on the URI scheme.
59 /// If parsing fails or there is no factory for the URI's scheme,
60 /// prepends default_prefix to target and tries again.
61 /// If a resolver factory is found, uses it to instantiate a resolver and
62 /// returns it; otherwise, returns nullptr.
63 /// \a args, \a pollset_set, and \a combiner are passed to the factory's
64 /// \a CreateResolver() method.
65 /// \a args are the channel args to be included in resolver results.
66 /// \a pollset_set is used to drive I/O in the name resolution process.
67 /// \a combiner is the combiner under which all resolver calls will be run.
68 /// \a result_handler is used to return results from the resolver.
69 static OrphanablePtr<Resolver> CreateResolver(
70 const char* target, const grpc_channel_args* args,
71 grpc_pollset_set* pollset_set, grpc_combiner* combiner,
72 UniquePtr<Resolver::ResultHandler> result_handler);
74 /// Returns the default authority to pass from a client for \a target.
75 static UniquePtr<char> GetDefaultAuthority(const char* target);
77 /// Returns \a target with the default prefix prepended, if needed.
78 static UniquePtr<char> AddDefaultPrefixIfNeeded(const char* target);
80 /// Returns the resolver factory for \a scheme.
81 /// Caller does NOT own the return value.
82 static ResolverFactory* LookupResolverFactory(const char* scheme);
85 } // namespace grpc_core
87 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_REGISTRY_H */