OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DEVICE_USB_DEVICE_IMPL_H_ | |
6 #define DEVICE_USB_DEVICE_IMPL_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "device/usb/public/interfaces/device.mojom.h" | |
13 #include "device/usb/usb_device_handle.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" | |
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
17 | |
18 namespace net { | |
19 class IOBuffer; | |
20 } | |
21 | |
22 namespace device { | |
23 namespace usb { | |
24 | |
25 // Implementation of the public Device interface. Instances of this class are | |
26 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe | |
27 // lifetime. | |
28 class DeviceImpl : public Device { | |
29 public: | |
30 DeviceImpl(scoped_refptr<UsbDeviceHandle> device_handle, | |
31 mojo::InterfaceRequest<Device> request); | |
32 ~DeviceImpl() override; | |
33 | |
34 private: | |
35 using MojoTransferInCallback = | |
36 mojo::Callback<void(TransferStatus, mojo::Array<uint8_t>)>; | |
37 | |
38 using MojoTransferOutCallback = mojo::Callback<void(TransferStatus)>; | |
39 | |
40 // Closes the device if it's open. This will always set |handle_| to null. | |
41 void CloseHandle(); | |
42 | |
43 // Handles a UsbDeviceHandle::ClaimInterface response. | |
44 void OnClaimInterface(uint8_t interface_number, | |
45 const ClaimInterfaceCallback& callback, | |
46 bool result); | |
47 | |
48 // Handles completion of an inbound transfer on the UsbDeviceHandle. | |
49 void OnTransferIn(const MojoTransferInCallback& callback, | |
50 UsbTransferStatus status, | |
51 scoped_refptr<net::IOBuffer> data, | |
52 size_t size); | |
53 | |
54 // Handles completion of an outbound transfer on the UsbDeviceHandle. | |
55 void OnTransferOut(const MojoTransferOutCallback& callback, | |
56 UsbTransferStatus status, | |
57 scoped_refptr<net::IOBuffer> data, | |
58 size_t size); | |
59 | |
60 // Handles completion of an inbound isochronous transfer on the | |
61 // UsbDeviceHandle. | |
62 void OnIsochronousTransferIn(const IsochronousTransferInCallback& callback, | |
63 uint32_t packet_length, | |
64 UsbTransferStatus status, | |
65 scoped_refptr<net::IOBuffer> data, | |
66 size_t size); | |
67 | |
68 // Handles completion of an outbound isochronous transfer on the | |
69 // UsbDeviceHandle. | |
70 void OnIsochronousTransferOut(const MojoTransferOutCallback& callback, | |
71 UsbTransferStatus status, | |
72 scoped_refptr<net::IOBuffer> data, | |
73 size_t size); | |
74 | |
75 // Device implementation: | |
76 void Close(const CloseCallback& callback) override; | |
77 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override; | |
78 void SetConfiguration(uint8_t value, | |
79 const SetConfigurationCallback& callback) override; | |
80 void ClaimInterface(uint8_t interface_number, | |
81 const ClaimInterfaceCallback& callback) override; | |
82 void ReleaseInterface(uint8_t interface_number, | |
83 const ReleaseInterfaceCallback& callback) override; | |
84 void SetInterfaceAlternateSetting( | |
85 uint8_t interface_number, | |
86 uint8_t alternate_setting, | |
87 const SetInterfaceAlternateSettingCallback& callback) override; | |
88 void Reset(const ResetCallback& callback) override; | |
89 void ControlTransferIn(ControlTransferParamsPtr params, | |
90 uint32_t length, | |
91 uint32_t timeout, | |
92 const ControlTransferInCallback& callback) override; | |
93 void ControlTransferOut(ControlTransferParamsPtr params, | |
94 mojo::Array<uint8_t> data, | |
95 uint32_t timeout, | |
96 const ControlTransferOutCallback& callback) override; | |
97 void BulkTransferIn(uint8_t endpoint_number, | |
98 uint32_t length, | |
99 uint32_t timeout, | |
100 const BulkTransferInCallback& callback) override; | |
101 void BulkTransferOut(uint8_t endpoint_number, | |
102 mojo::Array<uint8_t> data, | |
103 uint32_t timeout, | |
104 const BulkTransferOutCallback& callback) override; | |
105 void InterruptTransferIn( | |
106 uint8_t endpoint_number, | |
107 uint32_t length, | |
108 uint32_t timeout, | |
109 const InterruptTransferInCallback& callback) override; | |
110 void InterruptTransferOut( | |
111 uint8_t endpoint_number, | |
112 mojo::Array<uint8_t> data, | |
113 uint32_t timeout, | |
114 const InterruptTransferOutCallback& callback) override; | |
115 void IsochronousTransferIn( | |
116 uint8_t endpoint_number, | |
117 uint32_t num_packets, | |
118 uint32_t packet_length, | |
119 uint32_t timeout, | |
120 const IsochronousTransferInCallback& callback) override; | |
121 void IsochronousTransferOut( | |
122 uint8_t endpoint_number, | |
123 mojo::Array<mojo::Array<uint8_t>> packets, | |
124 uint32_t timeout, | |
125 const IsochronousTransferOutCallback& callback) override; | |
126 | |
127 mojo::StrongBinding<Device> binding_; | |
128 | |
129 // The opened device handle. May be null if the device has been closed. | |
130 scoped_refptr<UsbDeviceHandle> device_handle_; | |
131 | |
132 base::WeakPtrFactory<DeviceImpl> weak_factory_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); | |
135 }; | |
136 | |
137 } // namespace usb | |
138 } // namespace device | |
139 | |
140 #endif // DEVICE_USB_DEVICE_IMPL_H_ | |
OLD | NEW |