Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / src / core / ext / filters / client_channel / server_address.h
1 /*
2  *
3  * Copyright 2018 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_SERVER_ADDRESS_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/lib/channel/channel_args.h"
25 #include "src/core/lib/gprpp/inlined_vector.h"
26 #include "src/core/lib/iomgr/resolve_address.h"
27
28 // Channel arg key for a bool indicating whether an address is a grpclb
29 // load balancer (as opposed to a backend).
30 #define GRPC_ARG_ADDRESS_IS_BALANCER "grpc.address_is_balancer"
31
32 // Channel arg key for a string indicating an address's balancer name.
33 #define GRPC_ARG_ADDRESS_BALANCER_NAME "grpc.address_balancer_name"
34
35 namespace grpc_core {
36
37 //
38 // ServerAddress
39 //
40
41 // A server address is a grpc_resolved_address with an associated set of
42 // channel args.  Any args present here will be merged into the channel
43 // args when a subchannel is created for this address.
44 class ServerAddress {
45  public:
46   // Takes ownership of args.
47   ServerAddress(const grpc_resolved_address& address, grpc_channel_args* args);
48   ServerAddress(const void* address, size_t address_len,
49                 grpc_channel_args* args);
50
51   ~ServerAddress() { grpc_channel_args_destroy(args_); }
52
53   // Copyable.
54   ServerAddress(const ServerAddress& other)
55       : address_(other.address_), args_(grpc_channel_args_copy(other.args_)) {}
56   ServerAddress& operator=(const ServerAddress& other) {
57     address_ = other.address_;
58     grpc_channel_args_destroy(args_);
59     args_ = grpc_channel_args_copy(other.args_);
60     return *this;
61   }
62
63   // Movable.
64   ServerAddress(ServerAddress&& other)
65       : address_(other.address_), args_(other.args_) {
66     other.args_ = nullptr;
67   }
68   ServerAddress& operator=(ServerAddress&& other) {
69     address_ = other.address_;
70     grpc_channel_args_destroy(args_);
71     args_ = other.args_;
72     other.args_ = nullptr;
73     return *this;
74   }
75
76   bool operator==(const ServerAddress& other) const;
77
78   const grpc_resolved_address& address() const { return address_; }
79   const grpc_channel_args* args() const { return args_; }
80
81   bool IsBalancer() const;
82
83  private:
84   grpc_resolved_address address_;
85   grpc_channel_args* args_;
86 };
87
88 //
89 // ServerAddressList
90 //
91
92 typedef InlinedVector<ServerAddress, 1> ServerAddressList;
93
94 }  // namespace grpc_core
95
96 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SERVER_ADDRESS_H */