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 WebUSBDevice_h | |
6 #define WebUSBDevice_h | |
7 | |
8 #include "public/platform/WebCallbacks.h" | |
9 #include "public/platform/WebVector.h" | |
10 | |
11 #include <memory> | |
12 | |
13 namespace blink { | |
14 | |
15 struct WebUSBDeviceInfo; | |
16 struct WebUSBError; | |
17 struct WebUSBTransferInfo; | |
18 | |
19 using WebUSBDeviceOpenCallbacks = WebCallbacks<void, const WebUSBError&>; | |
20 using WebUSBDeviceCloseCallbacks = WebCallbacks<void, const WebUSBError&>; | |
21 using WebUSBDeviceSetConfigurationCallbacks = WebCallbacks<void, const WebUSBErr
or&>; | |
22 using WebUSBDeviceClaimInterfaceCallbacks = WebCallbacks<void, const WebUSBError
&>; | |
23 using WebUSBDeviceReleaseInterfaceCallbacks = WebCallbacks<void, const WebUSBErr
or&>; | |
24 using WebUSBDeviceResetCallbacks = WebCallbacks<void, const WebUSBError&>; | |
25 using WebUSBDeviceSetInterfaceAlternateSettingCallbacks = WebCallbacks<void, con
st WebUSBError&>; | |
26 using WebUSBDeviceClearHaltCallbacks = WebCallbacks<void, const WebUSBError&>; | |
27 using WebUSBDeviceTransferCallbacks = WebCallbacks<std::unique_ptr<WebUSBTransfe
rInfo>, const WebUSBError&>; | |
28 | |
29 class WebUSBDevice { | |
30 public: | |
31 enum class TransferDirection { | |
32 In, | |
33 Out, | |
34 }; | |
35 | |
36 enum class RequestType { | |
37 Standard, | |
38 Class, | |
39 Vendor, | |
40 }; | |
41 | |
42 enum class RequestRecipient { | |
43 Device, | |
44 Interface, | |
45 Endpoint, | |
46 Other, | |
47 }; | |
48 | |
49 struct ControlTransferParameters { | |
50 TransferDirection direction; | |
51 RequestType type; | |
52 RequestRecipient recipient; | |
53 uint8_t request; | |
54 uint16_t value; | |
55 uint16_t index; | |
56 }; | |
57 | |
58 virtual ~WebUSBDevice() { } | |
59 | |
60 virtual const WebUSBDeviceInfo& info() const = 0; | |
61 | |
62 // Opens the device. | |
63 // Ownership of the WebUSBDeviceOpenCallbacks is transferred to the client. | |
64 virtual void open(WebUSBDeviceOpenCallbacks*) = 0; | |
65 | |
66 // Closes the device. | |
67 // Ownership of the WebUSBDeviceCloseCallbacks is transferred to the client. | |
68 virtual void close(WebUSBDeviceCloseCallbacks*) = 0; | |
69 | |
70 // Sets the active configuration for the device. | |
71 // Ownership of the WebUSBDeviceSetConfigurationCallbacks is transferred to
the client. | |
72 virtual void setConfiguration(uint8_t configurationValue, WebUSBDeviceSetCon
figurationCallbacks*) = 0; | |
73 | |
74 // Claims an interface in the active configuration. | |
75 // Ownership of the WebUSBDeviceClaimInterfaceCallbacks is transferred to th
e client. | |
76 virtual void claimInterface(uint8_t interfaceNumber, WebUSBDeviceClaimInterf
aceCallbacks*) = 0; | |
77 | |
78 // Releases a claimed interface. | |
79 // Ownership of the WebUSBDeviceReleaseInterfaceCallbacks is transferred to
the client. | |
80 virtual void releaseInterface(uint8_t interfaceNumber, WebUSBDeviceReleaseIn
terfaceCallbacks*) = 0; | |
81 | |
82 // Sets the alternate setting of an interface. | |
83 // Ownership of the WebUSBDeviceSetInterfaceAlternateSettingCallbacks is tra
nsferred to the client. | |
84 virtual void setInterface(uint8_t interfaceNumber, uint8_t alternateSetting,
WebUSBDeviceSetInterfaceAlternateSettingCallbacks*) = 0; | |
85 | |
86 // Clears the halt condition on a specific endpoint. | |
87 // Ownership of the WebUSBDeviceClearHaltCallbacks is transferred to the cli
ent. | |
88 virtual void clearHalt(uint8_t endpointNumber, WebUSBDeviceClearHaltCallback
s*) = 0; | |
89 | |
90 // Initiates a control transfer. | |
91 // Ownership of the WebUSBDeviceTransferCallbacks is transferred to the clie
nt. | |
92 virtual void controlTransfer(const ControlTransferParameters&, uint8_t* data
, size_t dataSize, unsigned timeout, WebUSBDeviceTransferCallbacks*) = 0; | |
93 | |
94 // Initiates a bulk or interrupt transfer. | |
95 // Ownership of the WebUSBDeviceTransferCallbacks is transferred to the clie
nt. | |
96 virtual void transfer(TransferDirection, uint8_t endpointNumber, uint8_t* da
ta, size_t dataSize, unsigned timeout, WebUSBDeviceTransferCallbacks*) = 0; | |
97 | |
98 // Initiates an isochronous transfer. | |
99 // Ownership of the WebUSBDeviceTransferCallbacks is transferred to the clie
nt. | |
100 virtual void isochronousTransfer(TransferDirection, uint8_t endpointNumber,
uint8_t* data, size_t dataSize, WebVector<unsigned> packetLengths, unsigned time
out, WebUSBDeviceTransferCallbacks*) = 0; | |
101 | |
102 // Resets the device. | |
103 // Ownership of the WebUSBDeviceResetCallbacks is transferred to the client. | |
104 virtual void reset(WebUSBDeviceResetCallbacks*) = 0; | |
105 }; | |
106 | |
107 } // namespace blink | |
108 | |
109 #endif // WebUSBDevice_h | |
OLD | NEW |