Imported Upstream version 1.33.1
[platform/upstream/grpc.git] / src / core / ext / filters / client_channel / resolver.cc
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 #include <grpc/support/port_platform.h>
20
21 #include "src/core/ext/filters/client_channel/resolver.h"
22
23 grpc_core::DebugOnlyTraceFlag grpc_trace_resolver_refcount(false,
24                                                            "resolver_refcount");
25
26 namespace grpc_core {
27
28 //
29 // Resolver
30 //
31
32 Resolver::Resolver(std::shared_ptr<WorkSerializer> work_serializer,
33                    std::unique_ptr<ResultHandler> result_handler)
34     : InternallyRefCounted(&grpc_trace_resolver_refcount),
35       work_serializer_(std::move(work_serializer)),
36       result_handler_(std::move(result_handler)) {}
37
38 //
39 // Resolver::Result
40 //
41
42 Resolver::Result::~Result() {
43   GRPC_ERROR_UNREF(service_config_error);
44   grpc_channel_args_destroy(args);
45 }
46
47 Resolver::Result::Result(const Result& other) {
48   addresses = other.addresses;
49   service_config = other.service_config;
50   service_config_error = GRPC_ERROR_REF(other.service_config_error);
51   args = grpc_channel_args_copy(other.args);
52 }
53
54 Resolver::Result::Result(Result&& other) noexcept {
55   addresses = std::move(other.addresses);
56   service_config = std::move(other.service_config);
57   service_config_error = other.service_config_error;
58   other.service_config_error = GRPC_ERROR_NONE;
59   args = other.args;
60   other.args = nullptr;
61 }
62
63 Resolver::Result& Resolver::Result::operator=(const Result& other) {
64   addresses = other.addresses;
65   service_config = other.service_config;
66   GRPC_ERROR_UNREF(service_config_error);
67   service_config_error = GRPC_ERROR_REF(other.service_config_error);
68   grpc_channel_args_destroy(args);
69   args = grpc_channel_args_copy(other.args);
70   return *this;
71 }
72
73 Resolver::Result& Resolver::Result::operator=(Result&& other) noexcept {
74   addresses = std::move(other.addresses);
75   service_config = std::move(other.service_config);
76   GRPC_ERROR_UNREF(service_config_error);
77   service_config_error = other.service_config_error;
78   other.service_config_error = GRPC_ERROR_NONE;
79   grpc_channel_args_destroy(args);
80   args = other.args;
81   other.args = nullptr;
82   return *this;
83 }
84
85 }  // namespace grpc_core