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_DEVICES_APP_USB_DEVICE_IMPL_H_ | |
6 #define DEVICE_DEVICES_APP_USB_DEVICE_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "device/devices_app/usb/public/interfaces/device.mojom.h" | |
15 #include "device/devices_app/usb/public/interfaces/permission_provider.mojom.h" | |
16 #include "device/usb/usb_device_handle.h" | |
17 #include "mojo/public/cpp/bindings/binding.h" | |
18 #include "mojo/public/cpp/bindings/callback.h" | |
19 #include "mojo/public/cpp/bindings/interface_request.h" | |
20 | |
21 namespace net { | |
22 class IOBuffer; | |
23 } | |
24 | |
25 namespace device { | |
26 namespace usb { | |
27 | |
28 // Implementation of the public Device interface. Instances of this class are | |
29 // constructed by DeviceManagerImpl and are strongly bound to their MessagePipe | |
30 // lifetime. | |
31 class DeviceImpl : public Device { | |
32 public: | |
33 DeviceImpl(scoped_refptr<UsbDevice> device, | |
34 PermissionProviderPtr permission_provider, | |
35 mojo::InterfaceRequest<Device> request); | |
36 ~DeviceImpl() override; | |
37 | |
38 private: | |
39 // Closes the device if it's open. This will always set |device_handle_| to | |
40 // null. | |
41 void CloseHandle(); | |
42 | |
43 // Checks interface permissions for control transfers. | |
44 void HasControlTransferPermission(ControlTransferRecipient recipient, | |
45 uint16_t index, | |
46 const base::Callback<void(bool)>& callback); | |
47 | |
48 // Handles completion of an open request. | |
49 void OnOpen(const OpenCallback& callback, | |
50 scoped_refptr<device::UsbDeviceHandle> handle); | |
51 | |
52 // Device implementation: | |
53 void GetDeviceInfo(const GetDeviceInfoCallback& callback) override; | |
54 void GetConfiguration(const GetConfigurationCallback& callback) override; | |
55 void Open(const OpenCallback& callback) override; | |
56 void Close(const CloseCallback& callback) override; | |
57 void SetConfiguration(uint8_t value, | |
58 const SetConfigurationCallback& callback) override; | |
59 void ClaimInterface(uint8_t interface_number, | |
60 const ClaimInterfaceCallback& callback) override; | |
61 void ReleaseInterface(uint8_t interface_number, | |
62 const ReleaseInterfaceCallback& callback) override; | |
63 void SetInterfaceAlternateSetting( | |
64 uint8_t interface_number, | |
65 uint8_t alternate_setting, | |
66 const SetInterfaceAlternateSettingCallback& callback) override; | |
67 void Reset(const ResetCallback& callback) override; | |
68 void ClearHalt(uint8_t endpoint, const ClearHaltCallback& callback) override; | |
69 void ControlTransferIn(ControlTransferParamsPtr params, | |
70 uint32_t length, | |
71 uint32_t timeout, | |
72 const ControlTransferInCallback& callback) override; | |
73 void ControlTransferOut(ControlTransferParamsPtr params, | |
74 mojo::Array<uint8_t> data, | |
75 uint32_t timeout, | |
76 const ControlTransferOutCallback& callback) override; | |
77 void GenericTransferIn(uint8_t endpoint_number, | |
78 uint32_t length, | |
79 uint32_t timeout, | |
80 const GenericTransferInCallback& callback) override; | |
81 void GenericTransferOut(uint8_t endpoint_number, | |
82 mojo::Array<uint8_t> data, | |
83 uint32_t timeout, | |
84 const GenericTransferOutCallback& callback) override; | |
85 void IsochronousTransferIn( | |
86 uint8_t endpoint_number, | |
87 mojo::Array<uint32_t> packet_lengths, | |
88 uint32_t timeout, | |
89 const IsochronousTransferInCallback& callback) override; | |
90 void IsochronousTransferOut( | |
91 uint8_t endpoint_number, | |
92 mojo::Array<uint8_t> data, | |
93 mojo::Array<uint32_t> packet_lengths, | |
94 uint32_t timeout, | |
95 const IsochronousTransferOutCallback& callback) override; | |
96 | |
97 mojo::Binding<Device> binding_; | |
98 | |
99 scoped_refptr<UsbDevice> device_; | |
100 // The device handle. Will be null before the device is opened and after it | |
101 // has been closed. | |
102 scoped_refptr<UsbDeviceHandle> device_handle_; | |
103 PermissionProviderPtr permission_provider_; | |
104 | |
105 base::WeakPtrFactory<DeviceImpl> weak_factory_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(DeviceImpl); | |
108 }; | |
109 | |
110 } // namespace usb | |
111 } // namespace device | |
112 | |
113 #endif // DEVICE_DEVICES_APP_USB_DEVICE_IMPL_H_ | |
OLD | NEW |