OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/usb/fake_usb_device_handle.h" | 5 #include "device/usb/fake_usb_device_handle.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "device/usb/usb_device.h" | 9 #include "device/usb/usb_device.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 void FakeUsbDeviceHandle::ResetDevice(const ResultCallback& callback) { | 48 void FakeUsbDeviceHandle::ResetDevice(const ResultCallback& callback) { |
49 NOTIMPLEMENTED(); | 49 NOTIMPLEMENTED(); |
50 } | 50 } |
51 | 51 |
52 void FakeUsbDeviceHandle::ClearHalt(uint8_t endpoint, | 52 void FakeUsbDeviceHandle::ClearHalt(uint8_t endpoint, |
53 const ResultCallback& callback) { | 53 const ResultCallback& callback) { |
54 NOTIMPLEMENTED(); | 54 NOTIMPLEMENTED(); |
55 } | 55 } |
56 | 56 |
57 void FakeUsbDeviceHandle::ControlTransfer( | 57 void FakeUsbDeviceHandle::ControlTransfer( |
58 UsbEndpointDirection direction, | 58 UsbTransferDirection direction, |
59 UsbDeviceHandle::TransferRequestType request_type, | 59 UsbControlTransferType request_type, |
60 UsbDeviceHandle::TransferRecipient recipient, | 60 UsbControlTransferRecipient recipient, |
61 uint8_t request, | 61 uint8_t request, |
62 uint16_t value, | 62 uint16_t value, |
63 uint16_t index, | 63 uint16_t index, |
64 scoped_refptr<net::IOBuffer> buffer, | 64 scoped_refptr<net::IOBuffer> buffer, |
65 size_t length, | 65 size_t length, |
66 unsigned int timeout, | 66 unsigned int timeout, |
67 const UsbDeviceHandle::TransferCallback& callback) { | 67 const UsbDeviceHandle::TransferCallback& callback) { |
68 if (position_ == size_) { | 68 if (position_ == size_) { |
69 callback.Run(USB_TRANSFER_DISCONNECT, buffer, 0); | 69 callback.Run(UsbTransferStatus::DISCONNECT, buffer, 0); |
70 return; | 70 return; |
71 } | 71 } |
72 | 72 |
73 if (data_[position_++] % 2) { | 73 if (data_[position_++] % 2) { |
74 size_t bytes_transferred = 0; | 74 size_t bytes_transferred = 0; |
75 if (position_ + 2 <= size_) { | 75 if (position_ + 2 <= size_) { |
76 bytes_transferred = data_[position_] | data_[position_ + 1] << 8; | 76 bytes_transferred = data_[position_] | data_[position_ + 1] << 8; |
77 position_ += 2; | 77 position_ += 2; |
78 bytes_transferred = std::min(bytes_transferred, length); | 78 bytes_transferred = std::min(bytes_transferred, length); |
79 bytes_transferred = std::min(bytes_transferred, size_ - position_); | 79 bytes_transferred = std::min(bytes_transferred, size_ - position_); |
80 } | 80 } |
81 | 81 |
82 if (direction == USB_DIRECTION_INBOUND) { | 82 if (direction == UsbTransferDirection::INBOUND) { |
83 memcpy(buffer->data(), &data_[position_], bytes_transferred); | 83 memcpy(buffer->data(), &data_[position_], bytes_transferred); |
84 position_ += bytes_transferred; | 84 position_ += bytes_transferred; |
85 } | 85 } |
86 | 86 |
87 callback.Run(USB_TRANSFER_COMPLETED, buffer, bytes_transferred); | 87 callback.Run(UsbTransferStatus::COMPLETED, buffer, bytes_transferred); |
88 } else { | 88 } else { |
89 callback.Run(USB_TRANSFER_ERROR, buffer, 0); | 89 callback.Run(UsbTransferStatus::TRANSFER_ERROR, buffer, 0); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 void FakeUsbDeviceHandle::IsochronousTransferIn( | 93 void FakeUsbDeviceHandle::IsochronousTransferIn( |
94 uint8_t endpoint_number, | 94 uint8_t endpoint_number, |
95 const std::vector<uint32_t>& packet_lengths, | 95 const std::vector<uint32_t>& packet_lengths, |
96 unsigned int timeout, | 96 unsigned int timeout, |
97 const IsochronousTransferCallback& callback) { | 97 const IsochronousTransferCallback& callback) { |
98 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
99 } | 99 } |
100 | 100 |
101 void FakeUsbDeviceHandle::IsochronousTransferOut( | 101 void FakeUsbDeviceHandle::IsochronousTransferOut( |
102 uint8_t endpoint_number, | 102 uint8_t endpoint_number, |
103 scoped_refptr<net::IOBuffer> buffer, | 103 scoped_refptr<net::IOBuffer> buffer, |
104 const std::vector<uint32_t>& packet_lengths, | 104 const std::vector<uint32_t>& packet_lengths, |
105 unsigned int timeout, | 105 unsigned int timeout, |
106 const IsochronousTransferCallback& callback) { | 106 const IsochronousTransferCallback& callback) { |
107 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
108 } | 108 } |
109 | 109 |
110 void FakeUsbDeviceHandle::GenericTransfer(UsbEndpointDirection direction, | 110 void FakeUsbDeviceHandle::GenericTransfer(UsbTransferDirection direction, |
111 uint8_t endpoint_number, | 111 uint8_t endpoint_number, |
112 scoped_refptr<net::IOBuffer> buffer, | 112 scoped_refptr<net::IOBuffer> buffer, |
113 size_t length, | 113 size_t length, |
114 unsigned int timeout, | 114 unsigned int timeout, |
115 const TransferCallback& callback) { | 115 const TransferCallback& callback) { |
116 NOTIMPLEMENTED(); | 116 NOTIMPLEMENTED(); |
117 } | 117 } |
118 | 118 |
119 const UsbInterfaceDescriptor* FakeUsbDeviceHandle::FindInterfaceByEndpoint( | 119 const UsbInterfaceDescriptor* FakeUsbDeviceHandle::FindInterfaceByEndpoint( |
120 uint8_t endpoint_address) { | 120 uint8_t endpoint_address) { |
121 NOTIMPLEMENTED(); | 121 NOTIMPLEMENTED(); |
122 return nullptr; | 122 return nullptr; |
123 } | 123 } |
124 | 124 |
125 FakeUsbDeviceHandle::~FakeUsbDeviceHandle() {} | 125 FakeUsbDeviceHandle::~FakeUsbDeviceHandle() {} |
126 | 126 |
127 } // namespace device | 127 } // namespace device |
OLD | NEW |