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