Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/common/extensions/api/usb.idl

Issue 22914023: Introducing chrome.usb.getDevices/openDevice API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-interface
Patch Set: Fix IDL Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Use the <code>chrome.usb</code> API to interact with connected USB 5 // Use the <code>chrome.usb</code> API to interact with connected USB
6 // devices. This API provides access to USB operations from within the context 6 // devices. This API provides access to USB operations from within the context
7 // of an app. Using this API, apps can function as drivers for hardware devices. 7 // of an app. Using this API, apps can function as drivers for hardware devices.
8 namespace usb { 8 namespace usb {
9 9
10 // Direction, Recipient, RequestType, and TransferType all map to their 10 // Direction, Recipient, RequestType, and TransferType all map to their
11 // namesakes within the USB specification. 11 // namesakes within the USB specification.
12 enum Direction {in, out}; 12 enum Direction {in, out};
13 enum Recipient {device, _interface, endpoint, other}; 13 enum Recipient {device, _interface, endpoint, other};
14 enum RequestType {standard, class, vendor, reserved}; 14 enum RequestType {standard, class, vendor, reserved};
15 enum TransferType {control, interrupt, isochronous, bulk}; 15 enum TransferType {control, interrupt, isochronous, bulk};
16 16
17 // For isochronous mode, SynchronizationType and UsageType map to their 17 // For isochronous mode, SynchronizationType and UsageType map to their
18 // namesakes within the USB specification. 18 // namesakes within the USB specification.
19 enum SynchronizationType {asynchronous, adaptive, synchronous}; 19 enum SynchronizationType {asynchronous, adaptive, synchronous};
20 enum UsageType {data, feedback, explicitFeedback}; 20 enum UsageType {data, feedback, explicitFeedback};
21 21
22 // A Device encapsulates everything that is needed to communicate with a USB 22 // Returned by |getDevices| to identify a connected USB device.
23 // device. They are returned by findDevice calls and have all of their
24 // fields populated before being returned.
25 dictionary Device { 23 dictionary Device {
24 // The id of the USB device. It remains unchanged until the device is
25 // unplugged.
26 long device;
asargent_no_longer_on_chrome 2013/08/28 20:52:42 For a given device, I assume the |device| value I
Bei Zhang 2013/08/29 20:26:06 Done.
27 long vendorId;
28 long productId;
29 };
30
31 // Returned by |openDevice| to be used for USB communication. Every time a
32 // device is opened, a new device handle is created. All device handles can
33 // work together if the device allows it. The device handle will be closed
34 // when the app is reloaded or suspended.
35 //
36 // When a device handle is closed by calling |closeDevice| or unplugging the
37 // device physically, all the interfaces it claimed will be released and all
38 // the transfers in progress will be canceled immediately.
39 dictionary DeviceHandle {
scheib 2013/08/28 23:23:48 This is really a connection handle, not a device h
Bei Zhang 2013/08/29 20:26:06 "Device handle" is a well-known term in libusb to
40 // The id of the device handle.
26 long handle; 41 long handle;
27 long vendorId; 42 long vendorId;
28 long productId; 43 long productId;
29 }; 44 };
30 45
31 dictionary EndpointDescriptor { 46 dictionary EndpointDescriptor {
32 long address; 47 long address;
33 TransferType type; 48 TransferType type;
34 Direction direction; 49 Direction direction;
35 long maximumPacketSize; 50 long maximumPacketSize;
(...skipping 30 matching lines...) Expand all
66 81
67 long request; 82 long request;
68 long value; 83 long value;
69 long index; 84 long index;
70 85
71 // If this transfer is an input transfer, then this field must be set to 86 // If this transfer is an input transfer, then this field must be set to
72 // indicate the expected data length. If this is an output transfer, then 87 // indicate the expected data length. If this is an output transfer, then
73 // this field is ignored. 88 // this field is ignored.
74 long? length; 89 long? length;
75 90
76 // The data payload carried by this transfer. If this is an output tranfer 91 // The data payload carried by this transfer. If this is an output transfer
77 // then this field must be set. 92 // then this field must be set.
78 ArrayBuffer? data; 93 ArrayBuffer? data;
79 }; 94 };
80 95
81 // GenericTransferInfo is used by both bulk and interrupt transfers to 96 // GenericTransferInfo is used by both bulk and interrupt transfers to
82 // specify the parameters of the transfer. 97 // specify the parameters of the transfer.
83 dictionary GenericTransferInfo { 98 dictionary GenericTransferInfo {
84 // The direction of this transfer. 99 // The direction of this transfer.
85 Direction direction; 100 Direction direction;
86 101
(...skipping 27 matching lines...) Expand all
114 dictionary TransferResultInfo { 129 dictionary TransferResultInfo {
115 // A value of 0 indicates that the transfer was a success. Other values 130 // A value of 0 indicates that the transfer was a success. Other values
116 // indicate failure. 131 // indicate failure.
117 long? resultCode; 132 long? resultCode;
118 133
119 // If the transfer was an input transfer then this field will contain all 134 // If the transfer was an input transfer then this field will contain all
120 // of the input data requested. 135 // of the input data requested.
121 ArrayBuffer? data; 136 ArrayBuffer? data;
122 }; 137 };
123 138
124 // FindDevicesOptions describes the properties of devices which are found and 139 // Describes the properties of devices which are found via |getDevices| and
125 // opened via findDevices. 140 // |findDevices|.
126 dictionary FindDevicesOptions { 141 dictionary EnumerateDevicesOptions {
127 long vendorId; 142 long vendorId;
128 long productId; 143 long productId;
129 long? interfaceId; 144 long? interfaceId;
130 }; 145 };
131 146
132 callback VoidCallback = void (); 147 callback VoidCallback = void ();
133 callback FindDevicesCallback = void (Device[] device); 148 callback GetDevicesCallback = void (Device[] devices);
149 callback OpenDeviceCallback = void (DeviceHandle handle);
150 callback FindDevicesCallback = void (DeviceHandle[] handles);
134 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors); 151 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors);
135 callback CloseDeviceCallback = void (); 152 callback CloseDeviceCallback = void ();
136 callback TransferCallback = void (TransferResultInfo info); 153 callback TransferCallback = void (TransferResultInfo info);
137 callback ResetDeviceCallback = void(boolean result); 154 callback ResetDeviceCallback = void(boolean result);
138 155
139 interface Functions { 156 interface Functions {
140 // Finds the first instance of the USB device specified by the vendorId/ 157 // Lists USB devices specified by vendorId/productId pair.
scheib 2013/08/28 23:23:48 Will the optional |interfaceId| be used? (same for
Bei Zhang 2013/08/29 20:26:06 Done.
141 // productId pair and, if permissions allow, opens it for use.
142 // Upon successfully opening a device the callback is invoked with a
143 // populated Device object. On failure, the callback is invoked with null.
144 // |options|: The properties to search for on target devices. 158 // |options|: The properties to search for on target devices.
145 // |callback|: Invoked with the opened Device on success. 159 // |callback|: Invoked with a list of |Device|s on complete.
146 static void findDevices(FindDevicesOptions options, 160 static void getDevices(EnumerateDevicesOptions options,
147 FindDevicesCallback callback); 161 GetDevicesCallback callback);
148 162
149 // Closes an open device instance. Invoking operations on a device after it 163 // Opens a USB device returned by |getDevices|.
164 // |device|: The device to open.
165 // |callback|: Invoked with the created DeviceHandle on complete.
166 static void openDevice(Device device, OpenDeviceCallback callback);
167
168 // Finds USB devices specified by the vendorId/productId pair and,
169 // if permissions allow, opens them for use.
170 //
171 // If a device is failed to be opened, its handles will not be returned.
172 //
173 // Calling this method is equivalent to a |getDevices| followed by
174 // a series of |openDevice| calls, and returning all the successfully opened
175 // device handles.
176 // |options|: The properties to search for on target devices.
177 // |callback|: Invoked with the opened DeviceHandle on complete.
178 static void findDevices(EnumerateDevicesOptions options,
179 FindDevicesCallback callback);
180
181 // Closes a device handle. Invoking operations on a device after it
150 // has been closed is a safe operation, but causes no action to be taken. 182 // has been closed is a safe operation, but causes no action to be taken.
151 // |device|: The device to close. 183 // |handle|: The device handle to close.
152 // |callback|: The callback to invoke once the device is closed. 184 // |callback|: The callback to invoke once the device is closed.
153 static void closeDevice(Device device, 185 static void closeDevice(DeviceHandle handle,
154 optional CloseDeviceCallback callback); 186 optional CloseDeviceCallback callback);
155 187
156 // Lists all the interfaces on the USB device. 188 // Lists all the interfaces on the USB device.
157 // |device|: The device from which the interfaces should be listed. 189 // |handle|: The device from which the interfaces should be listed.
158 // |callback|: The callback to invoke when the interfaces are enumerated. 190 // |callback|: The callback to invoke when the interfaces are enumerated.
159 static void listInterfaces(Device device, 191 static void listInterfaces(DeviceHandle handle,
160 ListInterfacesCallback callback); 192 ListInterfacesCallback callback);
161 193
162 // Claims an interface on the specified USB device. 194 // Claims an interface on the specified USB device.
163 // |device|: The device on which the interface is to be claimed. 195 // Before you can transfer data with endpoints, you must claim their parent
196 // interfaces. Only one device handle on the same host can claim each
197 // interface. If the interface is already claimed, this call will fail.
198 //
199 // You shall call releaseInterface when the interface is not needed anymore.
200 //
201 // |handle|: The device on which the interface is to be claimed.
164 // |interface|: The interface number to be claimed. 202 // |interface|: The interface number to be claimed.
165 // |callback|: The callback to invoke once the interface is claimed. 203 // |callback|: The callback to invoke once the interface is claimed.
166 static void claimInterface(Device device, long interfaceNumber, 204 static void claimInterface(DeviceHandle handle, long interfaceNumber,
167 VoidCallback callback); 205 VoidCallback callback);
168 206
169 // Releases a claim to an interface on the provided device. 207 // Releases a claim to an interface on the provided device.
170 // |device|: The device on which the interface is to be released. 208 // |handle|: The device on which the interface is to be released.
171 // |interface|: The interface number to be released. 209 // |interface|: The interface number to be released.
172 // |callback|: The callback to invoke once the interface is released. 210 // |callback|: The callback to invoke once the interface is released.
173 static void releaseInterface(Device device, long interfaceNumber, 211 static void releaseInterface(DeviceHandle handle, long interfaceNumber,
174 VoidCallback callback); 212 VoidCallback callback);
175 213
176 // Selects an alternate setting on a previously claimed interface on a 214 // Selects an alternate setting on a previously claimed interface on a
177 // device. 215 // device.
178 // |device|: The device on which the interface settings are to be set. 216 // |handle|: The device on which the interface settings are to be set.
179 // |interface|: The interface number to be set. 217 // |interface|: The interface number to be set.
180 // |alternateSetting|: The alternate setting to set. 218 // |alternateSetting|: The alternate setting to set.
181 // |callback|: The callback to invoke once the interface setting is set. 219 // |callback|: The callback to invoke once the interface setting is set.
182 static void setInterfaceAlternateSetting(Device device, 220 static void setInterfaceAlternateSetting(DeviceHandle handle,
183 long interfaceNumber, long alternateSetting, VoidCallback callback); 221 long interfaceNumber,
222 long alternateSetting,
223 VoidCallback callback);
184 224
185 // Performs a control transfer on the specified device. See the 225 // Performs a control transfer on the specified device. See the
186 // ControlTransferInfo structure for the parameters required to make a 226 // ControlTransferInfo structure for the parameters required to make a
187 // transfer. 227 // transfer.
188 // |device|: An open device to make the transfer on. 228 //
229 // Conceptually control transfer talks to the device itself. You do not need
230 // to claim interface 0 to perform a control transfer.
231 //
232 // |handle|: A device handle to make the transfer on.
189 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. 233 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo.
190 // |callback|: Invoked once the transfer has completed. 234 // |callback|: Invoked once the transfer has completed.
191 static void controlTransfer(Device device, 235 static void controlTransfer(DeviceHandle handle,
192 ControlTransferInfo transferInfo, TransferCallback callback); 236 ControlTransferInfo transferInfo,
237 TransferCallback callback);
193 238
194 // Performs a bulk transfer on the specified device. 239 // Performs a bulk transfer on the specified device.
195 // |device|: An open device to make the transfer on. 240 // |handle|: A device handle to make the transfer on.
196 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. 241 // |transferInfo|: The parameters to the transfer. See GenericTransferInfo.
197 // |callback|: Invoked once the transfer has completed. 242 // |callback|: Invoked once the transfer has completed.
198 static void bulkTransfer(Device device, GenericTransferInfo transferInfo, 243 static void bulkTransfer(DeviceHandle handle,
199 TransferCallback callback); 244 GenericTransferInfo transferInfo,
245 TransferCallback callback);
200 246
201 // Performs an interrupt transfer on the specified device. 247 // Performs an interrupt transfer on the specified device.
202 // |device|: An open device to make the transfer on. 248 // |handle|: A device handle to make the transfer on.
203 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. 249 // |transferInfo|: The parameters to the transfer. See GenericTransferInfo.
204 // |callback|: Invoked once the transfer has completed. 250 // |callback|: Invoked once the transfer has completed.
205 static void interruptTransfer(Device device, 251 static void interruptTransfer(DeviceHandle handle,
206 GenericTransferInfo transferInfo, TransferCallback callback); 252 GenericTransferInfo transferInfo,
253 TransferCallback callback);
207 254
208 // Performs an isochronous transfer on the specific device. 255 // Performs an isochronous transfer on the specific device.
209 // |device|: An open device to make the transfer on. 256 // |handle|: A device handle to make the transfer on.
210 // |transferInfo|: The parameters to the transfer. See 257 // |transferInfo|: The parameters to the transfer. See
211 // IsochronousTransferInfo. 258 // IsochronousTransferInfo.
212 // |callback|: Invoked once the transfer has been completed. 259 // |callback|: Invoked once the transfer has been completed.
213 static void isochronousTransfer(Device device, 260 static void isochronousTransfer(DeviceHandle handle,
214 IsochronousTransferInfo transferInfo, 261 IsochronousTransferInfo transferInfo,
215 TransferCallback callback); 262 TransferCallback callback);
216 263
217 // Try to reset the USB device and restore the previous status. 264 // Tries to reset the USB device and restores it to the previous status.
265 // If the reset fails, the given device handle will be closed and the USB
266 // device will appear to be disconnected then reconnected. In that case you
267 // must call |getDevices| or |findDevices| again to acquire the device.
218 // 268 //
219 // If the reset fails, the given device will be closed and the USB device 269 // |handle|: A device handle to reset.
220 // will appear to be disconected and reconnected.
221 // You must call <code>findDevice</code> again to acquire the device.
222 //
223 // |device|: An opened device to reset.
224 // |callback|: Invoked once the device is reset with a boolean indicating 270 // |callback|: Invoked once the device is reset with a boolean indicating
225 // whether the reset is completed successfully. 271 // whether the reset is completed successfully.
226 static void resetDevice(Device device, 272 static void resetDevice(DeviceHandle handle,
227 ResetDeviceCallback callback); 273 ResetDeviceCallback callback);
228 }; 274 };
229 }; 275 };
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_service.cc ('k') | chrome/test/data/extensions/api_test/usb/device_handling/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698