GRPC Core  18.0.0
resolver.h
Go to the documentation of this file.
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_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H
21 
23 
25 
32 
34 
35 // Name associated with individual address, if available.
36 #define GRPC_ARG_ADDRESS_NAME "grpc.address_name"
37 
38 namespace grpc_core {
39 
52 class Resolver : public InternallyRefCounted<Resolver> {
53  public:
55  struct Result {
59  const grpc_channel_args* args = nullptr;
60 
61  // TODO(roth): Remove everything below once grpc_error and
62  // grpc_channel_args are convert to copyable and movable C++ objects.
63  Result() = default;
64  ~Result();
65  Result(const Result& other);
66  Result(Result&& other) noexcept;
67  Result& operator=(const Result& other);
68  Result& operator=(Result&& other) noexcept;
69  };
70 
73  class ResultHandler {
74  public:
75  virtual ~ResultHandler() {}
76 
79  virtual void ReturnResult(Result result) = 0; // NOLINT
80 
84  virtual void ReturnError(grpc_error_handle error) = 0;
85 
86  // TODO(yashkt): As part of the service config error handling
87  // changes, add a method to parse the service config JSON string.
88  };
89 
90  // Not copyable nor movable.
91  Resolver(const Resolver&) = delete;
92  Resolver& operator=(const Resolver&) = delete;
93  ~Resolver() override = default;
94 
96  virtual void StartLocked() = 0;
97 
111  virtual void RequestReresolutionLocked() {}
112 
119  virtual void ResetBackoffLocked() {}
120 
121  // Note: This must be invoked while holding the work_serializer.
122  void Orphan() override {
123  ShutdownLocked();
124  Unref();
125  }
126 
127  protected:
128  Resolver();
129 
131  virtual void ShutdownLocked() = 0;
132 };
133 
134 } // namespace grpc_core
135 
136 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H */
Definition: orphanable.h:76
void Unref()
Definition: orphanable.h:103
Definition: ref_counted_ptr.h:35
A proxy object used by the resolver to return results to the client channel.
Definition: resolver.h:73
virtual void ReturnError(grpc_error_handle error)=0
Returns a transient error to the channel.
virtual void ReturnResult(Result result)=0
Returns a result to the channel.
virtual ~ResultHandler()
Definition: resolver.h:75
Interface for name resolution.
Definition: resolver.h:52
Resolver()
Definition: resolver.cc:32
virtual void ResetBackoffLocked()
Resets the re-resolution backoff, if any.
Definition: resolver.h:119
void Orphan() override
Definition: resolver.h:122
virtual void StartLocked()=0
Starts resolving.
virtual void ShutdownLocked()=0
Shuts down the resolver.
virtual void RequestReresolutionLocked()
Asks the resolver to obtain an updated resolver result, if applicable.
Definition: resolver.h:111
Resolver(const Resolver &)=delete
~Resolver() override=default
Resolver & operator=(const Resolver &)=delete
Definition: trace.h:61
#define GRPC_ERROR_NONE
The following "special" errors can be propagated without allocating memory.
Definition: error.h:228
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
absl::InlinedVector< ServerAddress, 1 > ServerAddressList
Definition: server_address.h:111
grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Results returned by the resolver.
Definition: resolver.h:55
~Result()
Definition: resolver.cc:41
Result & operator=(const Result &other)
Definition: resolver.cc:62
ServerAddressList addresses
Definition: resolver.h:56
const grpc_channel_args * args
Definition: resolver.h:59
grpc_error_handle service_config_error
Definition: resolver.h:58
RefCountedPtr< ServiceConfig > service_config
Definition: resolver.h:57
Definition: error_internal.h:41