| 1 |
// |
| 2 |
// Copyright 2015 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_LIB_RESOLVER_RESOLVER_FACTORY_H |
| 18 |
#define GRPC_CORE_LIB_RESOLVER_RESOLVER_FACTORY_H |
| 19 |
|
| 20 |
#include <grpc/support/port_platform.h> |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include "absl/strings/string_view.h" |
| 26 |
#include "absl/strings/strip.h" |
| 27 |
|
| 28 |
#include "src/core/lib/channel/channel_args.h" |
| 29 |
#include "src/core/lib/gprpp/orphanable.h" |
| 30 |
#include "src/core/lib/iomgr/iomgr_fwd.h" |
| 31 |
#include "src/core/lib/resolver/resolver.h" |
| 32 |
#include "src/core/lib/uri/uri_parser.h" |
| 33 |
|
| 34 |
namespace grpc_core { |
| 35 |
|
| 36 |
// TODO(yashkt): Move WorkSerializer to its own Bazel target, depend on that |
| 37 |
// target from this one, and remove this forward declaration. |
| 38 |
class WorkSerializer; |
| 39 |
|
| 40 |
struct ResolverArgs { |
| 41 |
/// The parsed URI to resolve. |
| 42 |
URI uri; |
| 43 |
/// Channel args to be included in resolver results. |
| 44 |
ChannelArgs args; |
| 45 |
/// Used to drive I/O in the name resolution process. |
| 46 |
grpc_pollset_set* pollset_set = nullptr; |
| 47 |
/// The work_serializer under which all resolver calls will be run. |
| 48 |
std::shared_ptr<WorkSerializer> work_serializer; |
| 49 |
/// The result handler to be used by the resolver. |
| 50 |
std::unique_ptr<Resolver::ResultHandler> result_handler; |
| 51 |
}; |
| 52 |
|
| 53 |
class ResolverFactory { |
| 54 |
public: |
| 55 |
virtual ~ResolverFactory() {} |
| 56 |
|
| 57 |
/// Returns the URI scheme that this factory implements. |
| 58 |
/// Caller does NOT take ownership of result. |
| 59 |
virtual absl::string_view scheme() const = 0; |
| 60 |
|
| 61 |
/// Returns a bool indicating whether the input uri is valid to create a |
| 62 |
/// resolver. |
| 63 |
virtual bool IsValidUri(const URI& uri) const = 0; |
| 64 |
|
| 65 |
/// Returns a new resolver instance. |
| 66 |
virtual OrphanablePtr<Resolver> CreateResolver(ResolverArgs args) const = 0; |
| 67 |
|
| 68 |
/// Returns a string representing the default authority to use for this |
| 69 |
/// scheme. |
| 70 |
virtual std::string GetDefaultAuthority(const URI& uri) const { |
| 71 |
return std::string(absl::StripPrefix(uri.path(), "/")); |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
} // namespace grpc_core |
| 76 |
|
| 77 |
#endif // GRPC_CORE_LIB_RESOLVER_RESOLVER_FACTORY_H |