OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // TODO(gdk): The string-style enumerations are temporary, and will be removed | |
6 // once full enumeration support is added. Also, the array-of-longs are | |
7 // temporary and will be removed once there is full ArrayBuffer support. | |
8 | |
9 [nodoc] namespace experimental.usb { | |
10 | |
11 // A Device encapsulates everything that is needed to communicate with a USB | |
12 // device. They are returned by findDevice calls and have all of their | |
13 // fields populated before being returned. | |
14 dictionary Device { | |
15 long handle; | |
16 long vendorId; | |
17 long productId; | |
18 }; | |
19 | |
20 // ControlTransferInfo represents that parameters to a single USB control | |
21 // transfer. | |
22 dictionary ControlTransferInfo { | |
23 // The direction of this transfer. Must be one of either in or out. | |
24 DOMString direction; | |
25 | |
26 // The intended recipient for this transfer. Must be one of device, | |
27 // interface, endpoint, or other. | |
28 DOMString recipient; | |
29 | |
30 // The type of this request. Must be one of standard, class, vendor, | |
31 // or reserved. | |
32 DOMString requestType; | |
33 | |
34 long request; | |
35 long value; | |
36 long index; | |
37 | |
38 // If this transfer is an input transfer, then this field must be set to | |
39 // indicate the expected data length. If this is an output transfer, then | |
40 // this field is ignored. | |
41 long? length; | |
42 | |
43 // The data payload carried by this transfer. If this is an output tranfer | |
44 // then this field must be set. | |
45 long[]? data; | |
46 }; | |
47 | |
48 // GenericTransferInfo is used by both bulk and interrupt transfers to | |
49 // specify the parameters of the transfer. | |
50 dictionary GenericTransferInfo { | |
51 // The direction of this transfer. Must be one of in or out. | |
52 DOMString direction; | |
53 | |
54 long endpoint; | |
55 | |
56 // If this is an input transfer then this field indicates the size of the | |
57 // input buffer. If this is an output transfer then this field is ignored. | |
58 long? length; | |
59 | |
60 // If this is an output transfer then this field must be populated. | |
61 // Otherwise, it will be ignored. | |
62 long[]? data; | |
63 }; | |
64 | |
65 // When a USB event occurs the event handler specified by the DeviceOptions | |
66 // provided to findDevice will have a UsbEvent delivered to it which will | |
67 // contain the result of a transfer, including returned data. | |
68 dictionary UsbEvent { | |
69 // A string indicating the type of the event. Currently will only contain | |
70 // the value 'transferResult'. | |
71 DOMString type; | |
72 | |
73 // A value of 0 indicates that the transfer was a success. Other values | |
74 // indicate failure. | |
75 long? resultCode; | |
76 | |
77 // If the transfer was an input transfer then this field will contain all | |
78 // of the input data requested. | |
79 long[]? data; | |
80 | |
81 // The following fields are used for internal event routing and can be | |
82 // ignored. | |
83 [nodoc] boolean isFinalEvent; | |
84 [nodoc] long srcId; | |
85 }; | |
86 | |
87 callback OnEventCallback = void (UsbEvent event); | |
88 | |
89 dictionary DeviceOptions { | |
90 // The schema generator does not support dictionaries with only events. | |
91 // Ignore this field. | |
92 [nodoc] long? dummyValue; | |
93 | |
94 // Invoked by the extension API whenever an event occurs for the device(s) | |
95 // that this DeviceOptions is associated with. | |
96 OnEventCallback? onEvent; | |
97 }; | |
98 | |
99 callback FindDeviceCallback = void (optional Device device); | |
100 callback TransferCallback = void (); | |
101 | |
102 interface Functions { | |
103 // Finds the first instance of the USB device specified by the vendorId/ | |
104 // productId pair and, if permissions allow, opens it for use. | |
105 // Upon successfully opening a device the callback is invoked with a | |
106 // populated Device object. On failure, the callback is invoked with null. | |
107 // |vendorId|: The vendor ID of the USB device to find. | |
108 // |productId|: The product ID of the USB device to find. | |
109 // |callback|: Invoked with the opened Device on success. | |
110 static void findDevice(long vendorId, long productId, | |
111 DeviceOptions options, FindDeviceCallback callback); | |
112 | |
113 // Closes an open device instance. Invoking operations on a device after it | |
114 // has been closed is a safe operation, but causes no action to be taken. | |
115 // |device|: The device to close. | |
116 static void closeDevice(Device device); | |
117 | |
118 // Performs a control transfer on the specified device. See the | |
119 // ControlTransferInfo structure for the parameters required to make a | |
120 // transfer. | |
121 // |device|: An open device to make the transfer on. | |
122 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. | |
123 // |callback|: Invoked once the transfer has completed. | |
124 static void controlTransfer(Device device, | |
125 ControlTransferInfo transferInfo, optional TransferCallback callback); | |
126 | |
127 // Performs a bulk transfer on the specified device. | |
128 // |device|: An open device to make the transfer on. | |
129 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. | |
130 // |callback|: Invoked once the transfer has completed. | |
131 static void bulkTransfer(Device device, GenericTransferInfo transferInfo, | |
132 optional TransferCallback callback); | |
133 | |
134 // Performs an interrupt transfer on the specified device. | |
135 // |device|: An open device to make the transfer on. | |
136 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. | |
137 // |callback|: Invoked once the transfer has completed. | |
138 static void interruptTransfer(Device device, | |
139 GenericTransferInfo transferInfo, optional TransferCallback callback); | |
140 }; | |
141 | |
142 interface Events { | |
143 static void onEvent(UsbEvent event); | |
144 }; | |
145 | |
146 }; | |
OLD | NEW |