| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/mojo/device_impl.h" | 5 #include "device/usb/mojo/device_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <numeric> | 10 #include <numeric> |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { | 244 void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { |
| 245 callback.Run(DeviceInfo::From(*device_)); | 245 callback.Run(DeviceInfo::From(*device_)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) { | 248 void DeviceImpl::GetConfiguration(const GetConfigurationCallback& callback) { |
| 249 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); | 249 const UsbConfigDescriptor* config = device_->GetActiveConfiguration(); |
| 250 callback.Run(config ? config->configuration_value : 0); | 250 callback.Run(config ? config->configuration_value : 0); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void DeviceImpl::Open(const OpenCallback& callback) { | 253 void DeviceImpl::Open(const OpenCallback& callback) { |
| 254 device_->Open( | 254 if (device_handle_) |
| 255 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); | 255 callback.Run(OpenDeviceError::ALREADY_OPEN); |
| 256 else |
| 257 device_->Open( |
| 258 base::Bind(&DeviceImpl::OnOpen, weak_factory_.GetWeakPtr(), callback)); |
| 256 } | 259 } |
| 257 | 260 |
| 258 void DeviceImpl::Close(const CloseCallback& callback) { | 261 void DeviceImpl::Close(const CloseCallback& callback) { |
| 259 CloseHandle(); | 262 CloseHandle(); |
| 260 callback.Run(); | 263 callback.Run(); |
| 261 } | 264 } |
| 262 | 265 |
| 263 void DeviceImpl::SetConfiguration(uint8_t value, | 266 void DeviceImpl::SetConfiguration(uint8_t value, |
| 264 const SetConfigurationCallback& callback) { | 267 const SetConfigurationCallback& callback) { |
| 265 if (!device_handle_) { | 268 if (!device_handle_) { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 const std::vector<uint8_t>& storage = data.storage(); | 458 const std::vector<uint8_t>& storage = data.storage(); |
| 456 std::copy(storage.begin(), storage.end(), buffer->data()); | 459 std::copy(storage.begin(), storage.end(), buffer->data()); |
| 457 } | 460 } |
| 458 device_handle_->IsochronousTransferOut( | 461 device_handle_->IsochronousTransferOut( |
| 459 endpoint_address, buffer, packet_lengths.storage(), timeout, | 462 endpoint_address, buffer, packet_lengths.storage(), timeout, |
| 460 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); | 463 base::Bind(&OnIsochronousTransferOut, base::Passed(&callback_ptr))); |
| 461 } | 464 } |
| 462 | 465 |
| 463 } // namespace usb | 466 } // namespace usb |
| 464 } // namespace device | 467 } // namespace device |
| OLD | NEW |