• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "osp/public/service_info.h"
6 
7 #include <algorithm>
8 #include <utility>
9 
10 #include "util/osp_logging.h"
11 
12 namespace openscreen {
13 namespace osp {
14 
operator ==(const ServiceInfo & other) const15 bool ServiceInfo::operator==(const ServiceInfo& other) const {
16   return (service_id == other.service_id &&
17           friendly_name == other.friendly_name &&
18           network_interface_index == other.network_interface_index &&
19           v4_endpoint == other.v4_endpoint && v6_endpoint == other.v6_endpoint);
20 }
21 
operator !=(const ServiceInfo & other) const22 bool ServiceInfo::operator!=(const ServiceInfo& other) const {
23   return !(*this == other);
24 }
25 
Update(std::string new_friendly_name,NetworkInterfaceIndex new_network_interface_index,const IPEndpoint & new_v4_endpoint,const IPEndpoint & new_v6_endpoint)26 bool ServiceInfo::Update(std::string new_friendly_name,
27                          NetworkInterfaceIndex new_network_interface_index,
28                          const IPEndpoint& new_v4_endpoint,
29                          const IPEndpoint& new_v6_endpoint) {
30   OSP_DCHECK(!new_v4_endpoint.address ||
31              IPAddress::Version::kV4 == new_v4_endpoint.address.version());
32   OSP_DCHECK(!new_v6_endpoint.address ||
33              IPAddress::Version::kV6 == new_v6_endpoint.address.version());
34   const bool changed =
35       (friendly_name != new_friendly_name) ||
36       (network_interface_index != new_network_interface_index) ||
37       (v4_endpoint != new_v4_endpoint) || (v6_endpoint != new_v6_endpoint);
38 
39   friendly_name = std::move(new_friendly_name);
40   network_interface_index = new_network_interface_index;
41   v4_endpoint = new_v4_endpoint;
42   v6_endpoint = new_v6_endpoint;
43   return changed;
44 }
45 
46 }  // namespace osp
47 }  // namespace openscreen
48