aboutsummaryrefslogtreecommitdiff
path: root/osp/public/service_info.cc
blob: ce423da723ed2e8611f73db135110b5fed3a9822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "osp/public/service_info.h"

#include <algorithm>
#include <utility>

#include "util/logging.h"

namespace openscreen {

bool ServiceInfo::operator==(const ServiceInfo& other) const {
  return (service_id == other.service_id &&
          friendly_name == other.friendly_name &&
          network_interface_index == other.network_interface_index &&
          v4_endpoint == other.v4_endpoint && v6_endpoint == other.v6_endpoint);
}

bool ServiceInfo::operator!=(const ServiceInfo& other) const {
  return !(*this == other);
}

bool ServiceInfo::Update(
    std::string new_friendly_name,
    platform::NetworkInterfaceIndex new_network_interface_index,
    const IPEndpoint& new_v4_endpoint,
    const IPEndpoint& new_v6_endpoint) {
  OSP_DCHECK(!new_v4_endpoint.address ||
             IPAddress::Version::kV4 == new_v4_endpoint.address.version());
  OSP_DCHECK(!new_v6_endpoint.address ||
             IPAddress::Version::kV6 == new_v6_endpoint.address.version());
  const bool changed =
      (friendly_name != new_friendly_name) ||
      (network_interface_index != new_network_interface_index) ||
      (v4_endpoint != new_v4_endpoint) || (v6_endpoint != new_v6_endpoint);

  friendly_name = std::move(new_friendly_name);
  network_interface_index = new_network_interface_index;
  v4_endpoint = new_v4_endpoint;
  v6_endpoint = new_v6_endpoint;
  return changed;
}

}  // namespace openscreen