OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 namespace usb { | 5 namespace usb { |
6 | 6 |
7 // Direction, Recipient and RequestType all map to their namesakes within the | |
8 // USB specification with the exception of the "iface" value which, for | |
9 // technical reasons, maps to "interface". | |
Matt Perry
2012/12/14 18:50:16
That's... odd. We control this API, why can't we j
Garret Kelly
2012/12/14 18:56:21
"interface" is a reserved word in IDL.
Matt Perry
2012/12/14 19:05:31
Oh, lame :(. I wonder if we can fix our IDL parser
| |
10 enum Direction {in, out}; | |
11 enum Recipient {device, iface, endpoint, other}; | |
12 enum RequestType {standard, class, vendor, reserved}; | |
13 | |
7 // A Device encapsulates everything that is needed to communicate with a USB | 14 // A Device encapsulates everything that is needed to communicate with a USB |
8 // device. They are returned by findDevice calls and have all of their | 15 // device. They are returned by findDevice calls and have all of their |
9 // fields populated before being returned. | 16 // fields populated before being returned. |
10 dictionary Device { | 17 dictionary Device { |
11 long handle; | 18 long handle; |
12 long vendorId; | 19 long vendorId; |
13 long productId; | 20 long productId; |
14 }; | 21 }; |
15 | 22 |
16 // ControlTransferInfo represents that parameters to a single USB control | 23 // ControlTransferInfo represents that parameters to a single USB control |
17 // transfer. | 24 // transfer. |
18 dictionary ControlTransferInfo { | 25 dictionary ControlTransferInfo { |
19 // The direction of this transfer. Must be one of either in or out. | 26 // The direction of this transfer. |
20 DOMString direction; | 27 Direction direction; |
21 | 28 |
22 // The intended recipient for this transfer. Must be one of device, | 29 // The intended recipient for this transfer. |
23 // interface, endpoint, or other. | 30 Recipient recipient; |
24 DOMString recipient; | |
25 | 31 |
26 // The type of this request. Must be one of standard, class, vendor, | 32 // The type of this request. |
27 // or reserved. | 33 RequestType requestType; |
28 DOMString requestType; | |
29 | 34 |
30 long request; | 35 long request; |
31 long value; | 36 long value; |
32 long index; | 37 long index; |
33 | 38 |
34 // If this transfer is an input transfer, then this field must be set to | 39 // If this transfer is an input transfer, then this field must be set to |
35 // indicate the expected data length. If this is an output transfer, then | 40 // indicate the expected data length. If this is an output transfer, then |
36 // this field is ignored. | 41 // this field is ignored. |
37 long? length; | 42 long? length; |
38 | 43 |
39 // The data payload carried by this transfer. If this is an output tranfer | 44 // The data payload carried by this transfer. If this is an output tranfer |
40 // then this field must be set. | 45 // then this field must be set. |
41 ArrayBuffer? data; | 46 ArrayBuffer? data; |
42 }; | 47 }; |
43 | 48 |
44 // GenericTransferInfo is used by both bulk and interrupt transfers to | 49 // GenericTransferInfo is used by both bulk and interrupt transfers to |
45 // specify the parameters of the transfer. | 50 // specify the parameters of the transfer. |
46 dictionary GenericTransferInfo { | 51 dictionary GenericTransferInfo { |
47 // The direction of this transfer. Must be one of in or out. | 52 // The direction of this transfer. |
48 DOMString direction; | 53 Direction direction; |
49 | 54 |
50 long endpoint; | 55 long endpoint; |
51 | 56 |
52 // If this is an input transfer then this field indicates the size of the | 57 // If this is an input transfer then this field indicates the size of the |
53 // input buffer. If this is an output transfer then this field is ignored. | 58 // input buffer. If this is an output transfer then this field is ignored. |
54 long? length; | 59 long? length; |
55 | 60 |
56 // If this is an output transfer then this field must be populated. | 61 // If this is an output transfer then this field must be populated. |
57 // Otherwise, it will be ignored. | 62 // Otherwise, it will be ignored. |
58 ArrayBuffer? data; | 63 ArrayBuffer? data; |
(...skipping 18 matching lines...) Expand all Loading... | |
77 dictionary TransferResultInfo { | 82 dictionary TransferResultInfo { |
78 // A value of 0 indicates that the transfer was a success. Other values | 83 // A value of 0 indicates that the transfer was a success. Other values |
79 // indicate failure. | 84 // indicate failure. |
80 long? resultCode; | 85 long? resultCode; |
81 | 86 |
82 // If the transfer was an input transfer then this field will contain all | 87 // If the transfer was an input transfer then this field will contain all |
83 // of the input data requested. | 88 // of the input data requested. |
84 ArrayBuffer? data; | 89 ArrayBuffer? data; |
85 }; | 90 }; |
86 | 91 |
87 dictionary FindDevicesOptions {}; | 92 // FindDevicesOptions describes the properties of devices which are found and |
93 // opened via findDevices. | |
94 dictionary FindDevicesOptions { | |
95 long vendorId; | |
96 long productId; | |
97 }; | |
88 | 98 |
89 callback VoidCallback = void (); | 99 callback VoidCallback = void (); |
90 | |
91 callback FindDevicesCallback = void (Device[] device); | 100 callback FindDevicesCallback = void (Device[] device); |
92 callback CloseDeviceCallback = void (); | 101 callback CloseDeviceCallback = void (); |
93 callback TransferCallback = void (TransferResultInfo info); | 102 callback TransferCallback = void (TransferResultInfo info); |
94 | 103 |
95 interface Functions { | 104 interface Functions { |
96 // Finds the first instance of the USB device specified by the vendorId/ | 105 // Finds the first instance of the USB device specified by the vendorId/ |
97 // productId pair and, if permissions allow, opens it for use. | 106 // productId pair and, if permissions allow, opens it for use. |
98 // Upon successfully opening a device the callback is invoked with a | 107 // Upon successfully opening a device the callback is invoked with a |
99 // populated Device object. On failure, the callback is invoked with null. | 108 // populated Device object. On failure, the callback is invoked with null. |
100 // |vendorId|: The vendor ID of the USB device to find. | 109 // |options|: The properties to search for on target devices. |
101 // |productId|: The product ID of the USB device to find. | |
102 // |callback|: Invoked with the opened Device on success. | 110 // |callback|: Invoked with the opened Device on success. |
103 static void findDevices(long vendorId, long productId, | 111 static void findDevices(FindDevicesOptions options, |
104 FindDevicesOptions options, FindDevicesCallback callback); | 112 FindDevicesCallback callback); |
105 | 113 |
106 // Closes an open device instance. Invoking operations on a device after it | 114 // Closes an open device instance. Invoking operations on a device after it |
107 // has been closed is a safe operation, but causes no action to be taken. | 115 // has been closed is a safe operation, but causes no action to be taken. |
108 // |device|: The device to close. | 116 // |device|: The device to close. |
109 // |callback|: The callback to invoke once the device is closed. | 117 // |callback|: The callback to invoke once the device is closed. |
110 static void closeDevice(Device device, | 118 static void closeDevice(Device device, |
111 optional CloseDeviceCallback callback); | 119 optional CloseDeviceCallback callback); |
112 | 120 |
113 // Claims an interface on the specified USB device. | 121 // Claims an interface on the specified USB device. |
114 // |device|: The device on which the interface is to be claimed. | 122 // |device|: The device on which the interface is to be claimed. |
115 // |interface|: The interface number to be claimed. | 123 // |interface|: The interface number to be claimed. |
116 // |callback|: The callback to invoke once the interface is claimed. | 124 // |callback|: The callback to invoke once the interface is claimed. |
117 static long claimInterface(Device device, long interfaceNumber, | 125 static void claimInterface(Device device, long interfaceNumber, |
118 VoidCallback callback); | 126 VoidCallback callback); |
Matt Perry
2012/12/14 18:50:16
Are you planning on passing the error value to the
Garret Kelly
2012/12/14 18:56:21
Since these operations can't ever fail I'm incline
| |
119 | 127 |
120 // Releases a claim to an interface on the provided device. | 128 // Releases a claim to an interface on the provided device. |
121 // |device|: The device on which the interface is to be released. | 129 // |device|: The device on which the interface is to be released. |
122 // |interface|: The interface number to be released. | 130 // |interface|: The interface number to be released. |
123 // |callback|: The callback to invoke once the interface is released. | 131 // |callback|: The callback to invoke once the interface is released. |
124 static long releaseInterface(Device device, long interfaceNumber, | 132 static void releaseInterface(Device device, long interfaceNumber, |
125 VoidCallback callback); | 133 VoidCallback callback); |
126 | 134 |
127 // Selects an alternate setting on a previously claimed interface on a | 135 // Selects an alternate setting on a previously claimed interface on a |
128 // device. | 136 // device. |
129 // |device|: The device on which the interface settings are to be set. | 137 // |device|: The device on which the interface settings are to be set. |
130 // |interface|: The interface number to be set. | 138 // |interface|: The interface number to be set. |
131 // |alternateSetting|: The alternate setting to set. | 139 // |alternateSetting|: The alternate setting to set. |
132 // |callback|: The callback to invoke once the interface setting is set. | 140 // |callback|: The callback to invoke once the interface setting is set. |
133 static long setInterfaceAlternateSetting(Device device, | 141 static void setInterfaceAlternateSetting(Device device, |
134 long interfaceNumber, long alternateSetting, VoidCallback callback); | 142 long interfaceNumber, long alternateSetting, VoidCallback callback); |
135 | 143 |
136 // Performs a control transfer on the specified device. See the | 144 // Performs a control transfer on the specified device. See the |
137 // ControlTransferInfo structure for the parameters required to make a | 145 // ControlTransferInfo structure for the parameters required to make a |
138 // transfer. | 146 // transfer. |
139 // |device|: An open device to make the transfer on. | 147 // |device|: An open device to make the transfer on. |
140 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. | 148 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. |
141 // |callback|: Invoked once the transfer has completed. | 149 // |callback|: Invoked once the transfer has completed. |
142 static void controlTransfer(Device device, | 150 static void controlTransfer(Device device, |
143 ControlTransferInfo transferInfo, TransferCallback callback); | 151 ControlTransferInfo transferInfo, TransferCallback callback); |
(...skipping 15 matching lines...) Expand all Loading... | |
159 // Performs an isochronous transfer on the specific device. | 167 // Performs an isochronous transfer on the specific device. |
160 // |device|: An open device to make the transfer on. | 168 // |device|: An open device to make the transfer on. |
161 // |transferInfo|: The parameters to the transfer. See | 169 // |transferInfo|: The parameters to the transfer. See |
162 // IsochronousTransferInfo. | 170 // IsochronousTransferInfo. |
163 // |callback|: Invoked once the transfer has been completed. | 171 // |callback|: Invoked once the transfer has been completed. |
164 static void isochronousTransfer(Device device, | 172 static void isochronousTransfer(Device device, |
165 IsochronousTransferInfo transferInfo, | 173 IsochronousTransferInfo transferInfo, |
166 TransferCallback callback); | 174 TransferCallback callback); |
167 }; | 175 }; |
168 }; | 176 }; |
OLD | NEW |