diff options
author | reillyg <reillyg@chromium.org> | 2015-09-16 20:06:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-17 03:06:45 +0000 |
commit | df1fddb49ebae7a192a7f44b90150b5d3fa8d1f6 (patch) | |
tree | 16e70e1d8e325d70c90229d90e74cf6f50fa3fe7 /device/devices_app/usb | |
parent | 74102a00a66d11c890b706b052d018ea21b38bba (diff) | |
download | chromium_src-df1fddb49ebae7a192a7f44b90150b5d3fa8d1f6.zip chromium_src-df1fddb49ebae7a192a7f44b90150b5d3fa8d1f6.tar.gz chromium_src-df1fddb49ebae7a192a7f44b90150b5d3fa8d1f6.tar.bz2 |
Convert between endpoint number and endpoint address in DeviceImpl.
The Mojo interface for USB devices refers to endpoints by number while
the underlying implementation in UsbDeviceHandle refers to them by
address. Make the conversion explicit to avoid mistakes.
Review URL: https://codereview.chromium.org/1349943002
Cr-Commit-Position: refs/heads/master@{#349339}
Diffstat (limited to 'device/devices_app/usb')
-rw-r--r-- | device/devices_app/usb/device_impl.cc | 12 | ||||
-rw-r--r-- | device/devices_app/usb/device_impl_unittest.cc | 16 |
2 files changed, 16 insertions, 12 deletions
diff --git a/device/devices_app/usb/device_impl.cc b/device/devices_app/usb/device_impl.cc index 8cf6dbd..54a7c2b 100644 --- a/device/devices_app/usb/device_impl.cc +++ b/device/devices_app/usb/device_impl.cc @@ -243,9 +243,10 @@ void DeviceImpl::GenericTransferIn(uint8_t endpoint_number, return; } + uint8_t endpoint_address = endpoint_number | 0x80; scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(length); device_handle_->GenericTransfer( - USB_DIRECTION_INBOUND, endpoint_number, buffer, length, timeout, + USB_DIRECTION_INBOUND, endpoint_address, buffer, length, timeout, base::Bind(&DeviceImpl::OnTransferIn, weak_factory_.GetWeakPtr(), callback)); } @@ -260,11 +261,12 @@ void DeviceImpl::GenericTransferOut( return; } + uint8_t endpoint_address = endpoint_number; scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(data.size()); const std::vector<uint8_t>& storage = data.storage(); std::copy(storage.begin(), storage.end(), buffer->data()); device_handle_->GenericTransfer( - USB_DIRECTION_OUTBOUND, endpoint_number, buffer, data.size(), timeout, + USB_DIRECTION_OUTBOUND, endpoint_address, buffer, data.size(), timeout, base::Bind(&DeviceImpl::OnTransferOut, weak_factory_.GetWeakPtr(), callback)); } @@ -280,10 +282,11 @@ void DeviceImpl::IsochronousTransferIn( return; } + uint8_t endpoint_address = endpoint_number | 0x80; size_t transfer_size = static_cast<size_t>(num_packets) * packet_length; scoped_refptr<net::IOBuffer> buffer = CreateTransferBuffer(transfer_size); device_handle_->IsochronousTransfer( - USB_DIRECTION_INBOUND, endpoint_number, buffer, transfer_size, + USB_DIRECTION_INBOUND, endpoint_address, buffer, transfer_size, num_packets, packet_length, timeout, base::Bind(&DeviceImpl::OnIsochronousTransferIn, weak_factory_.GetWeakPtr(), callback, packet_length)); @@ -299,6 +302,7 @@ void DeviceImpl::IsochronousTransferOut( return; } + uint8_t endpoint_address = endpoint_number; uint32_t packet_size = 0; for (size_t i = 0; i < packets.size(); ++i) { packet_size = @@ -314,7 +318,7 @@ void DeviceImpl::IsochronousTransferOut( memcpy(packet, packets[i].storage().data(), packets[i].size()); } device_handle_->IsochronousTransfer( - USB_DIRECTION_OUTBOUND, endpoint_number, buffer, transfer_size, + USB_DIRECTION_OUTBOUND, endpoint_address, buffer, transfer_size, static_cast<uint32_t>(packets.size()), packet_size, timeout, base::Bind(&DeviceImpl::OnIsochronousTransferOut, weak_factory_.GetWeakPtr(), callback)); diff --git a/device/devices_app/usb/device_impl_unittest.cc b/device/devices_app/usb/device_impl_unittest.cc index 433cbff..639b0d4 100644 --- a/device/devices_app/usb/device_impl_unittest.cc +++ b/device/devices_app/usb/device_impl_unittest.cc @@ -567,25 +567,25 @@ TEST_F(USBDeviceImplTest, GenericTransfer) { AddMockOutboundData(fake_outbound_data); AddMockInboundData(fake_inbound_data); - EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_OUTBOUND, 0, _, + EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_OUTBOUND, 0x01, _, fake_outbound_data.size(), 0, _)); { base::RunLoop loop; device->GenericTransferOut( - 0, mojo::Array<uint8_t>::From(fake_outbound_data), 0, + 1, mojo::Array<uint8_t>::From(fake_outbound_data), 0, base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED, loop.QuitClosure())); loop.Run(); } - EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_INBOUND, 0, _, + EXPECT_CALL(mock_handle(), GenericTransfer(USB_DIRECTION_INBOUND, 0x81, _, fake_inbound_data.size(), 0, _)); { base::RunLoop loop; device->GenericTransferIn( - 0, static_cast<uint32_t>(fake_inbound_data.size()), 0, + 1, static_cast<uint32_t>(fake_inbound_data.size()), 0, base::Bind(&ExpectTransferInAndThen, TRANSFER_STATUS_COMPLETED, fake_inbound_data, loop.QuitClosure())); loop.Run(); @@ -612,7 +612,7 @@ TEST_F(USBDeviceImplTest, IsochronousTransfer) { AddMockInboundData(fake_inbound_packets); EXPECT_CALL(mock_handle(), - IsochronousTransfer(USB_DIRECTION_OUTBOUND, 0, _, + IsochronousTransfer(USB_DIRECTION_OUTBOUND, 0x01, _, fake_outbound_packets.size(), 4, 8, 0, _)); { @@ -626,14 +626,14 @@ TEST_F(USBDeviceImplTest, IsochronousTransfer) { packets[i].Swap(&bytes); } device->IsochronousTransferOut( - 0, packets.Pass(), 0, + 1, packets.Pass(), 0, base::Bind(&ExpectTransferStatusAndThen, TRANSFER_STATUS_COMPLETED, loop.QuitClosure())); loop.Run(); } EXPECT_CALL(mock_handle(), - IsochronousTransfer(USB_DIRECTION_INBOUND, 0, _, + IsochronousTransfer(USB_DIRECTION_INBOUND, 0x81, _, fake_inbound_packets.size(), 4, 8, 0, _)); { @@ -645,7 +645,7 @@ TEST_F(USBDeviceImplTest, IsochronousTransfer) { inbound_packet_data.begin() + i * 8 + 8, packets[i].begin()); } device->IsochronousTransferIn( - 0, 4, 8, 0, base::Bind(&ExpectPacketsAndThen, TRANSFER_STATUS_COMPLETED, + 1, 4, 8, 0, base::Bind(&ExpectPacketsAndThen, TRANSFER_STATUS_COMPLETED, packets, loop.QuitClosure())); loop.Run(); } |