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 #ifndef DEVICE_USB_DEVICE_IMPL_H_ | 5 #ifndef DEVICE_USB_DEVICE_IMPL_H_ |
6 #define DEVICE_USB_DEVICE_IMPL_H_ | 6 #define DEVICE_USB_DEVICE_IMPL_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "device/devices_app/usb/public/interfaces/device.mojom.h" | 12 #include "device/devices_app/usb/public/interfaces/device.mojom.h" |
13 #include "device/usb/usb_device_handle.h" | 13 #include "device/usb/usb_device_handle.h" |
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" | 14 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" |
15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | 16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class IOBuffer; | 19 class IOBuffer; |
20 } | 20 } |
21 | 21 |
22 namespace device { | 22 namespace device { |
23 namespace usb { | 23 namespace usb { |
24 | 24 |
25 // Implementation of the public Device interface. Instances of this class are | 25 // Implementation of the public Device interface. Instances of this class are |
26 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe | 26 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe |
27 // lifetime. | 27 // lifetime. |
28 class DeviceImpl : public Device { | 28 class DeviceImpl : public Device { |
29 public: | 29 public: |
30 DeviceImpl(scoped_refptr<UsbDeviceHandle> device_handle, | 30 DeviceImpl(scoped_refptr<UsbDevice> device, |
31 mojo::InterfaceRequest<Device> request); | 31 mojo::InterfaceRequest<Device> request); |
32 ~DeviceImpl() override; | 32 ~DeviceImpl() override; |
33 | 33 |
34 private: | 34 private: |
35 using MojoTransferInCallback = | 35 using MojoTransferInCallback = |
36 mojo::Callback<void(TransferStatus, mojo::Array<uint8_t>)>; | 36 mojo::Callback<void(TransferStatus, mojo::Array<uint8_t>)>; |
37 | 37 |
38 using MojoTransferOutCallback = mojo::Callback<void(TransferStatus)>; | 38 using MojoTransferOutCallback = mojo::Callback<void(TransferStatus)>; |
39 | 39 |
40 // Closes the device if it's open. This will always set |handle_| to null. | 40 // Closes the device if it's open. This will always set |device_handle_| to |
| 41 // null. |
41 void CloseHandle(); | 42 void CloseHandle(); |
42 | 43 |
43 // Handles a UsbDeviceHandle::ClaimInterface response. | 44 // Handles completion of an open request. |
44 void OnClaimInterface(uint8_t interface_number, | 45 void OnOpen(const OpenCallback& callback, |
45 const ClaimInterfaceCallback& callback, | 46 scoped_refptr<device::UsbDeviceHandle> handle); |
46 bool result); | |
47 | 47 |
48 // Handles completion of an inbound transfer on the UsbDeviceHandle. | 48 // Handles completion of an inbound transfer on the UsbDeviceHandle. |
49 void OnTransferIn(const MojoTransferInCallback& callback, | 49 void OnTransferIn(const MojoTransferInCallback& callback, |
50 UsbTransferStatus status, | 50 UsbTransferStatus status, |
51 scoped_refptr<net::IOBuffer> data, | 51 scoped_refptr<net::IOBuffer> data, |
52 size_t size); | 52 size_t size); |
53 | 53 |
54 // Handles completion of an outbound transfer on the UsbDeviceHandle. | 54 // Handles completion of an outbound transfer on the UsbDeviceHandle. |
55 void OnTransferOut(const MojoTransferOutCallback& callback, | 55 void OnTransferOut(const MojoTransferOutCallback& callback, |
56 UsbTransferStatus status, | 56 UsbTransferStatus status, |
57 scoped_refptr<net::IOBuffer> data, | 57 scoped_refptr<net::IOBuffer> data, |
58 size_t size); | 58 size_t size); |
59 | 59 |
60 // Handles completion of an inbound isochronous transfer on the | 60 // Handles completion of an inbound isochronous transfer on the |
61 // UsbDeviceHandle. | 61 // UsbDeviceHandle. |
62 void OnIsochronousTransferIn(const IsochronousTransferInCallback& callback, | 62 void OnIsochronousTransferIn(const IsochronousTransferInCallback& callback, |
63 uint32_t packet_length, | 63 uint32_t packet_length, |
64 UsbTransferStatus status, | 64 UsbTransferStatus status, |
65 scoped_refptr<net::IOBuffer> data, | 65 scoped_refptr<net::IOBuffer> data, |
66 size_t size); | 66 size_t size); |
67 | 67 |
68 // Handles completion of an outbound isochronous transfer on the | 68 // Handles completion of an outbound isochronous transfer on the |
69 // UsbDeviceHandle. | 69 // UsbDeviceHandle. |
70 void OnIsochronousTransferOut(const MojoTransferOutCallback& callback, | 70 void OnIsochronousTransferOut(const MojoTransferOutCallback& callback, |
71 UsbTransferStatus status, | 71 UsbTransferStatus status, |
72 scoped_refptr<net::IOBuffer> data, | 72 scoped_refptr<net::IOBuffer> data, |
73 size_t size); | 73 size_t size); |
74 | 74 |
75 // Device implementation: | 75 // Device implementation: |
| 76 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override; |
| 77 void GetConfiguration(const GetConfigurationCallback& callback) override; |
| 78 void Open(const OpenCallback& callback) override; |
76 void Close(const CloseCallback& callback) override; | 79 void Close(const CloseCallback& callback) override; |
77 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override; | |
78 void SetConfiguration(uint8_t value, | 80 void SetConfiguration(uint8_t value, |
79 const SetConfigurationCallback& callback) override; | 81 const SetConfigurationCallback& callback) override; |
80 void ClaimInterface(uint8_t interface_number, | 82 void ClaimInterface(uint8_t interface_number, |
81 const ClaimInterfaceCallback& callback) override; | 83 const ClaimInterfaceCallback& callback) override; |
82 void ReleaseInterface(uint8_t interface_number, | 84 void ReleaseInterface(uint8_t interface_number, |
83 const ReleaseInterfaceCallback& callback) override; | 85 const ReleaseInterfaceCallback& callback) override; |
84 void SetInterfaceAlternateSetting( | 86 void SetInterfaceAlternateSetting( |
85 uint8_t interface_number, | 87 uint8_t interface_number, |
86 uint8_t alternate_setting, | 88 uint8_t alternate_setting, |
87 const SetInterfaceAlternateSettingCallback& callback) override; | 89 const SetInterfaceAlternateSettingCallback& callback) override; |
(...skipping 22 matching lines...) Expand all Loading... |
110 uint32_t timeout, | 112 uint32_t timeout, |
111 const IsochronousTransferInCallback& callback) override; | 113 const IsochronousTransferInCallback& callback) override; |
112 void IsochronousTransferOut( | 114 void IsochronousTransferOut( |
113 uint8_t endpoint_number, | 115 uint8_t endpoint_number, |
114 mojo::Array<mojo::Array<uint8_t>> packets, | 116 mojo::Array<mojo::Array<uint8_t>> packets, |
115 uint32_t timeout, | 117 uint32_t timeout, |
116 const IsochronousTransferOutCallback& callback) override; | 118 const IsochronousTransferOutCallback& callback) override; |
117 | 119 |
118 mojo::StrongBinding<Device> binding_; | 120 mojo::StrongBinding<Device> binding_; |
119 | 121 |
120 // The opened device handle. May be null if the device has been closed. | 122 scoped_refptr<UsbDevice> device_; |
| 123 // The device handle. Will be null before the device is opened and after it |
| 124 // has been closed. |
121 scoped_refptr<UsbDeviceHandle> device_handle_; | 125 scoped_refptr<UsbDeviceHandle> device_handle_; |
122 | 126 |
123 base::WeakPtrFactory<DeviceImpl> weak_factory_; | 127 base::WeakPtrFactory<DeviceImpl> weak_factory_; |
124 | 128 |
125 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); | 129 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); |
126 }; | 130 }; |
127 | 131 |
128 } // namespace usb | 132 } // namespace usb |
129 } // namespace device | 133 } // namespace device |
130 | 134 |
131 #endif // DEVICE_USB_DEVICE_IMPL_H_ | 135 #endif // DEVICE_USB_DEVICE_IMPL_H_ |
OLD | NEW |