-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfake_libusb_wrapper.cc
More file actions
64 lines (48 loc) · 1.64 KB
/
fake_libusb_wrapper.cc
File metadata and controls
64 lines (48 loc) · 1.64 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2018 The Chromium OS 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 "permission_broker/fake_libusb_wrapper.h"
#include <memory>
#include <utility>
#include <vector>
#include <base/logging.h>
namespace permission_broker {
FakeUsbDevice::FakeUsbDevice(const UsbDeviceInfo& info,
const UsbDeviceInfo& parent_info,
State* state)
: info_(info), parent_info_(parent_info), state_(state) {
DCHECK(state);
}
FakeUsbDevice::~FakeUsbDevice() = default;
UsbDeviceInfo FakeUsbDevice::GetInfo() const {
return info_;
}
uint8_t FakeUsbDevice::GetPort() const {
return 0;
}
std::unique_ptr<UsbDeviceInterface> FakeUsbDevice::GetParent() const {
if (parent_info_.vid == 0 && parent_info_.pid == 0) {
return nullptr;
}
return std::make_unique<FakeUsbDevice>(
parent_info_,
UsbDeviceInfo(), /* we do not need a valid parent for this node. */
state_);
}
bool FakeUsbDevice::SetPowerState(bool enabled, uint16_t port) const {
if (enabled) {
state_->power_on_counter += 1;
return !state_->fail_power_on;
}
state_->power_off_counter += 1;
return !state_->fail_power_off;
}
FakeUsbDeviceManager::FakeUsbDeviceManager(
std::vector<std::unique_ptr<UsbDeviceInterface>> devices)
: devices_(std::move(devices)) {}
FakeUsbDeviceManager::~FakeUsbDeviceManager() = default;
std::vector<std::unique_ptr<UsbDeviceInterface>>
FakeUsbDeviceManager::GetDevicesByVidPid(uint16_t vid, uint16_t pid) {
return std::move(devices_);
}
} // namespace permission_broker