1 // 2 // Copyright 2018 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_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_H 18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_H 19 20 #include <grpc/support/port_platform.h> 21 22 #include "src/core/ext/filters/client_channel/server_address.h" 23 #include "src/core/ext/xds/xds_client_stats.h" 24 #include "src/core/lib/gprpp/ref_counted_ptr.h" 25 26 namespace grpc_core { 27 28 // Defined in the EDS policy. 29 extern const char* kXdsLocalityNameAttributeKey; 30 31 class XdsLocalityAttribute : public ServerAddress::AttributeInterface { 32 public: XdsLocalityAttribute(RefCountedPtr<XdsLocalityName> locality_name)33 explicit XdsLocalityAttribute(RefCountedPtr<XdsLocalityName> locality_name) 34 : locality_name_(std::move(locality_name)) {} 35 locality_name()36 RefCountedPtr<XdsLocalityName> locality_name() const { 37 return locality_name_; 38 } 39 Copy()40 std::unique_ptr<AttributeInterface> Copy() const override { 41 return absl::make_unique<XdsLocalityAttribute>(locality_name_->Ref()); 42 } 43 Cmp(const AttributeInterface * other)44 int Cmp(const AttributeInterface* other) const override { 45 const auto* other_locality_attr = 46 static_cast<const XdsLocalityAttribute*>(other); 47 return locality_name_->Compare(*other_locality_attr->locality_name_); 48 } 49 ToString()50 std::string ToString() const override { 51 return locality_name_->AsHumanReadableString(); 52 } 53 54 private: 55 RefCountedPtr<XdsLocalityName> locality_name_; 56 }; 57 58 } // namespace grpc_core 59 60 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_H */ 61