123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- // Copyright 2016 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 "services/device/usb/fake_usb_device_handle.h"
- #include <algorithm>
- #include <utility>
- #include "base/callback.h"
- #include "base/memory/ref_counted_memory.h"
- #include "base/notreached.h"
- #include "services/device/usb/usb_device.h"
- namespace device {
- using mojom::UsbControlTransferRecipient;
- using mojom::UsbControlTransferType;
- using mojom::UsbTransferDirection;
- using mojom::UsbTransferStatus;
- FakeUsbDeviceHandle::FakeUsbDeviceHandle(const uint8_t* data, size_t size)
- : data_(data), size_(size), position_(0) {}
- scoped_refptr<UsbDevice> FakeUsbDeviceHandle::GetDevice() const {
- NOTIMPLEMENTED();
- return nullptr;
- }
- void FakeUsbDeviceHandle::Close() {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::SetConfiguration(int configuration_value,
- ResultCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::ClaimInterface(int interface_number,
- ResultCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::ReleaseInterface(int interface_number,
- ResultCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::SetInterfaceAlternateSetting(
- int interface_number,
- int alternate_setting,
- ResultCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::ResetDevice(ResultCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::ClearHalt(mojom::UsbTransferDirection direction,
- uint8_t endpoint_number,
- ResultCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::ControlTransfer(
- UsbTransferDirection direction,
- UsbControlTransferType request_type,
- UsbControlTransferRecipient recipient,
- uint8_t request,
- uint16_t value,
- uint16_t index,
- scoped_refptr<base::RefCountedBytes> buffer,
- unsigned int timeout,
- UsbDeviceHandle::TransferCallback callback) {
- if (position_ == size_) {
- std::move(callback).Run(UsbTransferStatus::DISCONNECT, buffer, 0);
- return;
- }
- if (data_[position_++] % 2) {
- size_t bytes_transferred = 0;
- if (position_ + 2 <= size_) {
- bytes_transferred = data_[position_] | data_[position_ + 1] << 8;
- position_ += 2;
- bytes_transferred = std::min(bytes_transferred, buffer->size());
- bytes_transferred = std::min(bytes_transferred, size_ - position_);
- }
- if (direction == UsbTransferDirection::INBOUND) {
- memcpy(buffer->front(), &data_[position_], bytes_transferred);
- position_ += bytes_transferred;
- }
- std::move(callback).Run(UsbTransferStatus::COMPLETED, buffer,
- bytes_transferred);
- } else {
- std::move(callback).Run(UsbTransferStatus::TRANSFER_ERROR, buffer, 0);
- }
- }
- void FakeUsbDeviceHandle::IsochronousTransferIn(
- uint8_t endpoint_number,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- IsochronousTransferCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::IsochronousTransferOut(
- uint8_t endpoint_number,
- scoped_refptr<base::RefCountedBytes> buffer,
- const std::vector<uint32_t>& packet_lengths,
- unsigned int timeout,
- IsochronousTransferCallback callback) {
- NOTIMPLEMENTED();
- }
- void FakeUsbDeviceHandle::GenericTransfer(
- UsbTransferDirection direction,
- uint8_t endpoint_number,
- scoped_refptr<base::RefCountedBytes> buffer,
- unsigned int timeout,
- TransferCallback callback) {
- NOTIMPLEMENTED();
- }
- const mojom::UsbInterfaceInfo* FakeUsbDeviceHandle::FindInterfaceByEndpoint(
- uint8_t endpoint_address) {
- NOTIMPLEMENTED();
- return nullptr;
- }
- FakeUsbDeviceHandle::~FakeUsbDeviceHandle() = default;
- } // namespace device
|