Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / common / extensions / api / bluetooth_socket.idl
blob71472ad0471a37c50b37a5b8789d2624834f9ab0
1 // Copyright 2014 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.
5 // Use the <code>chrome.bluetoothSocket</code> API to send and receive data
6 // to Bluetooth devices using RFCOMM and L2CAP connections.
7 namespace bluetoothSocket {
8 // The socket properties specified in the $ref:create or $ref:update
9 // function. Each property is optional. If a property value is not specified,
10 // a default value is used when calling $ref:create, or the existing value is
11 // preserved when calling $ref:update.
12 dictionary SocketProperties {
13 // Flag indicating whether the socket is left open when the event page of
14 // the application is unloaded (see <a
15 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
16 // Lifecycle</a>). The default value is <code>false.</code> When the
17 // application is loaded, any sockets previously opened with persistent=true
18 // can be fetched with $ref:getSockets.
19 boolean? persistent;
21 // An application-defined string associated with the socket.
22 DOMString? name;
24 // The size of the buffer used to receive data. The default value is 4096.
25 long? bufferSize;
28 // Result of <code>create</code> call.
29 dictionary CreateInfo {
30 // The ID of the newly created socket. Note that socket IDs created
31 // from this API are not compatible with socket IDs created from other APIs,
32 // such as the <code>$(ref:sockets.tcp)</code> API.
33 long socketId;
36 // Callback from the <code>create</code> method.
37 // |createInfo| : The result of the socket creation.
38 callback CreateCallback = void (CreateInfo createInfo);
40 // Callback from the <code>update</code> method.
41 callback UpdateCallback = void ();
43 // Callback from the <code>setPaused</code> method.
44 callback SetPausedCallback = void ();
46 // Callback from the <code>listenUsingRfcomm</code>,
47 // <code>listenUsingInsecureRfcomm</code> and
48 // <code>listenUsingL2cap</code> methods.
49 callback ListenCallback = void ();
51 // Callback from the <code>connect</code> method.
52 callback ConnectCallback = void ();
54 // Callback from the <code>disconnect</code> method.
55 callback DisconnectCallback = void ();
57 // Callback from the <code>close</code> method.
58 callback CloseCallback = void ();
60 // Callback from the <code>send</code> method.
61 // |bytesSent| : The number of bytes sent.
62 callback SendCallback = void (long bytesSent);
64 // Result of the <code>getInfo</code> method.
65 dictionary SocketInfo {
66 // The socket identifier.
67 long socketId;
69 // Flag indicating if the socket remains open when the event page of the
70 // application is unloaded (see <code>SocketProperties.persistent</code>).
71 // The default value is "false".
72 boolean persistent;
74 // Application-defined string associated with the socket.
75 DOMString? name;
77 // The size of the buffer used to receive data. If no buffer size has been
78 // specified explictly, the value is not provided.
79 long? bufferSize;
81 // Flag indicating whether a connected socket blocks its peer from sending
82 // more data, or whether connection requests on a listening socket are
83 // dispatched through the <code>onAccept</code> event or queued up in the
84 // listen queue backlog.
85 // See <code>setPaused</code>. The default value is "false".
86 boolean paused;
88 // Flag indicating whether the socket is connected to a remote peer.
89 boolean connected;
91 // If the underlying socket is connected, contains the Bluetooth address of
92 // the device it is connected to.
93 DOMString? address;
95 // If the underlying socket is connected, contains information about the
96 // service UUID it is connected to, otherwise if the underlying socket is
97 // listening, contains information about the service UUID it is listening
98 // on.
99 DOMString? uuid;
102 // Callback from the <code>getInfo</code> method.
103 // |socketInfo| : Object containing the socket information.
104 callback GetInfoCallback = void (SocketInfo socketInfo);
106 // Callback from the <code>getSockets</code> method.
107 // |socketInfos| : Array of object containing socket information.
108 callback GetSocketsCallback = void (SocketInfo[] sockets);
110 // Data from an <code>onAccept</code> event.
111 dictionary AcceptInfo {
112 // The server socket identifier.
113 long socketId;
115 // The client socket identifier, i.e. the socket identifier of the newly
116 // established connection. This socket identifier should be used only with
117 // functions from the <code>chrome.bluetoothSocket</code> namespace. Note
118 // the client socket is initially paused and must be explictly un-paused by
119 // the application to start receiving data.
120 long clientSocketId;
123 enum AcceptError {
124 // A system error occurred and the connection may be unrecoverable.
125 system_error,
127 // The socket is not listening.
128 not_listening
131 // Data from an <code>onAcceptError</code> event.
132 dictionary AcceptErrorInfo {
133 // The server socket identifier.
134 long socketId;
136 // The error message.
137 DOMString errorMessage;
139 // An error code indicating what went wrong.
140 AcceptError error;
143 // Data from an <code>onReceive</code> event.
144 dictionary ReceiveInfo {
145 // The socket identifier.
146 long socketId;
148 // The data received, with a maxium size of <code>bufferSize</code>.
149 ArrayBuffer data;
152 enum ReceiveError {
153 // The connection was disconnected.
154 disconnected,
156 // A system error occurred and the connection may be unrecoverable.
157 system_error,
159 // The socket has not been connected.
160 not_connected
163 // Data from an <code>onReceiveError</code> event.
164 dictionary ReceiveErrorInfo {
165 // The socket identifier.
166 long socketId;
168 // The error message.
169 DOMString errorMessage;
171 // An error code indicating what went wrong.
172 ReceiveError error;
175 // These functions all report failures via chrome.runtime.lastError.
176 interface Functions {
177 // Creates a Bluetooth socket.
178 // |properties| : The socket properties (optional).
179 // |callback| : Called when the socket has been created.
180 static void create(optional SocketProperties properties,
181 CreateCallback callback);
183 // Updates the socket properties.
184 // |socketId| : The socket identifier.
185 // |properties| : The properties to update.
186 // |callback| : Called when the properties are updated.
187 static void update(long socketId,
188 SocketProperties properties,
189 optional UpdateCallback callback);
191 // Enables or disables a connected socket from receiving messages from its
192 // peer, or a listening socket from accepting new connections. The default
193 // value is "false". Pausing a connected socket is typically used by an
194 // application to throttle data sent by its peer. When a connected socket
195 // is paused, no <code>onReceive</code>event is raised. When a socket is
196 // connected and un-paused, <code>onReceive</code> events are raised again
197 // when messages are received. When a listening socket is paused, new
198 // connections are accepted until its backlog is full then additional
199 // connection requests are refused. <code>onAccept</code> events are raised
200 // only when the socket is un-paused.
201 static void setPaused(long socketId,
202 boolean paused,
203 optional SetPausedCallback callback);
205 // Listen for connections using the RFCOMM protocol.
206 // |socketId| : The socket identifier.
207 // |uuid| : Service UUID to listen on.
208 // |channel| : RFCOMM channel id to listen on. Zero may be specified to
209 // allocate an unused channel.
210 // |backlog| : Length of the socket's listen queue. The default value
211 // depends on the operating system's host subsystem.
212 // |callback| : Called when listen operation completes.
213 static void listenUsingRfcomm(long socketId,
214 DOMString uuid,
215 long channel,
216 optional long backlog,
217 ListenCallback callback);
219 // Listens for connections from Bluetooth 1.0 and 2.0 devices using the
220 // RFCOMM protocol without requiring encryption or authentication on the
221 // socket.
222 // |socketId| : The socket identifier.
223 // |uuid| : Service UUID to listen on.
224 // |channel| : RFCOMM channel id to listen on. Zero may be specified to
225 // allocate an unused channel.
226 // |backlog| : Length of the socket's listen queue. The default value
227 // depends on the operating system's host subsystem.
228 // |callback| : Called when listen operation completes.
229 static void listenUsingInsecureRfcomm(long socketId,
230 DOMString uuid,
231 long channel,
232 optional long backlog,
233 ListenCallback callback);
235 // Listen for connections using the L2CAP protocol.
236 // |socketId| : The socket identifier.
237 // |uuid| : Service UUID to listen on.
238 // |psm| : L2CAP PSM to listen on. Zero may be specified to allocate an
239 // unused PSM.
240 // |backlog| : Length of the socket's listen queue. The default value
241 // depends on the operating system's host subsystem.
242 // |callback| : Called when listen operation completes.
243 static void listenUsingL2cap(long socketId,
244 DOMString uuid,
245 long psm,
246 optional long backlog,
247 ListenCallback callback);
249 // Connects the socket to a remote Bluetooth device. When the
250 // <code>connect</code> operation completes successfully,
251 // <code>onReceive</code> events are raised when data is received from the
252 // peer. If a network error occur while the runtime is receiving packets,
253 // a <code>onReceiveError</code> event is raised, at which point no more
254 // <code>onReceive</code> event will be raised for this socket until the
255 // <code>setPaused(false)</code> method is called.
256 // |socketId| : The socket identifier.
257 // |address| : The address of the Bluetooth device.
258 // |uuid| : The UUID of the service to connect to.
259 // |callback| : Called when the connect attempt is complete.
260 static void connect(long socketId,
261 DOMString address,
262 DOMString uuid,
263 ConnectCallback callback);
265 // Disconnects the socket. The socket identifier remains valid.
266 // |socketId| : The socket identifier.
267 // |callback| : Called when the disconnect attempt is complete.
268 static void disconnect(long socketId,
269 optional DisconnectCallback callback);
271 // Disconnects and destroys the socket. Each socket created should be
272 // closed after use. The socket id is no longer valid as soon at the
273 // function is called. However, the socket is guaranteed to be closed only
274 // when the callback is invoked.
275 // |socketId| : The socket identifier.
276 // |callback| : Called when the <code>close</code> operation completes.
277 static void close(long socketId,
278 optional CloseCallback callback);
280 // Sends data on the given Bluetooth socket.
281 // |socketId| : The socket identifier.
282 // |data| : The data to send.
283 // |callback| : Called with the number of bytes sent.
284 static void send(long socketId,
285 ArrayBuffer data,
286 optional SendCallback callback);
288 // Retrieves the state of the given socket.
289 // |socketId| : The socket identifier.
290 // |callback| : Called when the socket state is available.
291 static void getInfo(long socketId,
292 GetInfoCallback callback);
294 // Retrieves the list of currently opened sockets owned by the application.
295 // |callback| : Called when the list of sockets is available.
296 static void getSockets(GetSocketsCallback callback);
299 interface Events {
300 // Event raised when a connection has been established for a given socket.
301 // |info| : The event data.
302 static void onAccept(AcceptInfo info);
304 // Event raised when a network error occurred while the runtime was waiting
305 // for new connections on the given socket. Once this event is raised, the
306 // socket is set to <code>paused</code> and no more <code>onAccept</code>
307 // events are raised for this socket.
308 // |info| : The event data.
309 static void onAcceptError(AcceptErrorInfo info);
311 // Event raised when data has been received for a given socket.
312 // |info| : The event data.
313 static void onReceive(ReceiveInfo info);
315 // Event raised when a network error occured while the runtime was waiting
316 // for data on the socket. Once this event is raised, the socket is set to
317 // <code>paused</code> and no more <code>onReceive</code> events are raised
318 // for this socket.
319 // |info| : The event data.
320 static void onReceiveError(ReceiveErrorInfo info);