Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / src / core / ext / filters / client_channel / resolver_factory.h
1 /*
2  *
3  * Copyright 2015 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_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FACTORY_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FACTORY_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include <grpc/support/string_util.h>
25
26 #include "src/core/ext/filters/client_channel/resolver.h"
27 #include "src/core/lib/gprpp/abstract.h"
28 #include "src/core/lib/gprpp/memory.h"
29 #include "src/core/lib/gprpp/orphanable.h"
30 #include "src/core/lib/iomgr/pollset_set.h"
31 #include "src/core/lib/uri/uri_parser.h"
32
33 namespace grpc_core {
34
35 struct ResolverArgs {
36   /// The parsed URI to resolve.
37   grpc_uri* uri = nullptr;
38   /// Channel args to be included in resolver results.
39   const grpc_channel_args* args = nullptr;
40   /// Used to drive I/O in the name resolution process.
41   grpc_pollset_set* pollset_set = nullptr;
42   /// The combiner under which all resolver calls will be run.
43   grpc_combiner* combiner = nullptr;
44   /// The result handler to be used by the resolver.
45   UniquePtr<Resolver::ResultHandler> result_handler;
46 };
47
48 class ResolverFactory {
49  public:
50   /// Returns a bool indicating whether the input uri is valid to create a
51   /// resolver.
52   virtual bool IsValidUri(const grpc_uri* uri) const GRPC_ABSTRACT;
53
54   /// Returns a new resolver instance.
55   virtual OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const
56       GRPC_ABSTRACT;
57
58   /// Returns a string representing the default authority to use for this
59   /// scheme.
60   virtual UniquePtr<char> GetDefaultAuthority(grpc_uri* uri) const {
61     const char* path = uri->path;
62     if (path[0] == '/') ++path;
63     return UniquePtr<char>(gpr_strdup(path));
64   }
65
66   /// Returns the URI scheme that this factory implements.
67   /// Caller does NOT take ownership of result.
68   virtual const char* scheme() const GRPC_ABSTRACT;
69
70   virtual ~ResolverFactory() {}
71
72   GRPC_ABSTRACT_BASE_CLASS
73 };
74
75 }  // namespace grpc_core
76
77 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_FACTORY_H */