blob: 8ce6faf7f8afc9067620c54bc0784a881f75692b (
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
47
48
49
50
|
// 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/impl/testing/fake_mdns_platform_service.h"
#include <algorithm>
#include "util/osp_logging.h"
namespace openscreen {
namespace osp {
FakeMdnsPlatformService::FakeMdnsPlatformService() = default;
FakeMdnsPlatformService::~FakeMdnsPlatformService() = default;
std::vector<MdnsPlatformService::BoundInterface>
FakeMdnsPlatformService::RegisterInterfaces(
const std::vector<NetworkInterfaceIndex>& allowlist) {
OSP_CHECK(registered_interfaces_.empty());
if (allowlist.empty()) {
registered_interfaces_ = interfaces_;
} else {
for (const auto& interface : interfaces_) {
if (std::find(allowlist.begin(), allowlist.end(),
interface.interface_info.index) != allowlist.end()) {
registered_interfaces_.push_back(interface);
}
}
}
return registered_interfaces_;
}
void FakeMdnsPlatformService::DeregisterInterfaces(
const std::vector<BoundInterface>& interfaces) {
for (const auto& interface : interfaces) {
auto index = interface.interface_info.index;
auto it = std::find_if(registered_interfaces_.begin(),
registered_interfaces_.end(),
[index](const BoundInterface& interface) {
return interface.interface_info.index == index;
});
OSP_CHECK(it != registered_interfaces_.end())
<< "Must deregister a previously returned interface: " << index;
registered_interfaces_.erase(it);
}
}
} // namespace osp
} // namespace openscreen
|