GRPC Core  9.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 namespace grpc_core {
36 
49 class Resolver : public InternallyRefCounted<Resolver> {
50  public:
52  struct Result {
56  const grpc_channel_args* args = nullptr;
57 
58  // TODO(roth): Remove everything below once grpc_error and
59  // grpc_channel_args are convert to copyable and movable C++ objects.
60  Result() = default;
61  ~Result();
62  Result(const Result& other);
63  Result(Result&& other);
64  Result& operator=(const Result& other);
65  Result& operator=(Result&& other);
66  };
67 
70  class ResultHandler {
71  public:
72  virtual ~ResultHandler() {}
73 
76  virtual void ReturnResult(Result result) = 0; // NOLINT
77 
81  virtual void ReturnError(grpc_error* error) = 0;
82 
83  // TODO(yashkt): As part of the service config error handling
84  // changes, add a method to parse the service config JSON string.
85  };
86 
87  // Not copyable nor movable.
88  Resolver(const Resolver&) = delete;
89  Resolver& operator=(const Resolver&) = delete;
90  virtual ~Resolver();
91 
93  virtual void StartLocked() = 0;
94 
108  virtual void RequestReresolutionLocked() {}
109 
116  virtual void ResetBackoffLocked() {}
117 
118  // Note: This must be invoked while holding the combiner.
119  void Orphan() override {
120  ShutdownLocked();
121  Unref();
122  }
123 
124  protected:
126  // TODO(roth): Once we have a C++-like interface for combiners, this
127  // API should change to take a RefCountedPtr<>, so that we always take
128  // ownership of a new ref.
129  explicit Resolver(Combiner* combiner,
130  std::unique_ptr<ResultHandler> result_handler);
131 
133  virtual void ShutdownLocked() = 0;
134 
135  Combiner* combiner() const { return combiner_; }
136 
137  ResultHandler* result_handler() const { return result_handler_.get(); }
138 
139  private:
140  std::unique_ptr<ResultHandler> result_handler_;
141  Combiner* combiner_;
142 };
143 
144 } // namespace grpc_core
145 
146 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H */
Definition: combiner.h:33
Definition: orphanable.h:77
void Unref()
Definition: orphanable.h:107
Definition: ref_counted_ptr.h:35
A proxy object used by the resolver to return results to the client channel.
Definition: resolver.h:70
virtual void ReturnResult(Result result)=0
Returns a result to the channel.
virtual void ReturnError(grpc_error *error)=0
Returns a transient error to the channel.
virtual ~ResultHandler()
Definition: resolver.h:72
Interface for name resolution.
Definition: resolver.h:49
Combiner * combiner() const
Definition: resolver.h:135
virtual void ResetBackoffLocked()
Resets the re-resolution backoff, if any.
Definition: resolver.h:116
void Orphan() override
Definition: resolver.h:119
ResultHandler * result_handler() const
Definition: resolver.h:137
virtual void StartLocked()=0
Starts resolving.
virtual ~Resolver()
Definition: resolver.cc:39
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:108
Resolver(const Resolver &)=delete
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:125
Round Robin Policy.
Definition: backend_metric.cc:24
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:52
~Result()
Definition: resolver.cc:45
Result & operator=(const Result &other)
Definition: resolver.cc:66
grpc_error * service_config_error
Definition: resolver.h:55
ServerAddressList addresses
Definition: resolver.h:53
const grpc_channel_args * args
Definition: resolver.h:56
RefCountedPtr< ServiceConfig > service_config
Definition: resolver.h:54
Definition: error_internal.h:39