Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / common / extensions / api / bluetooth_socket.idl
blob3b03879d9a9c6fdd918c6f9572a6e7a938fa58df
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 // |result| : The result code returned from the underlying network call.
50 // A negative value indicates an error.
51 callback ListenCallback = void (long result);
53 // Callback from the <code>connect</code> method.
54 callback ConnectCallback = void ();
56 // Callback from the <code>disconnect</code> method.
57 callback DisconnectCallback = void ();
59 // Callback from the <code>close</code> method.
60 callback CloseCallback = void ();
62 // Callback from the <code>send</code> method.
63 // |bytesSent| : The number of bytes sent.
64 callback SendCallback = void (long bytesSent);
66 // Result of the <code>getInfo</code> method.
67 dictionary SocketInfo {
68 // The socket identifier.
69 long socketId;
71 // Flag indicating if the socket remains open when the event page of the
72 // application is unloaded (see <code>SocketProperties.persistent</code>).
73 // The default value is "false".
74 boolean persistent;
76 // Application-defined string associated with the socket.
77 DOMString? name;
79 // The size of the buffer used to receive data. If no buffer size has been
80 // specified explictly, the value is not provided.
81 long? bufferSize;
83 // Flag indicating whether a connected socket blocks its peer from sending
84 // more data, or whether connection requests on a listening socket are
85 // dispatched through the <code>onAccept</code> event or queued up in the
86 // listen queue backlog.
87 // See <code>setPaused</code>. The default value is "false".
88 boolean paused;
90 // Flag indicating whether the socket is connected to a remote peer.
91 boolean connected;
93 // If the underlying socket is connected, contains the Bluetooth address of
94 // the device it is connected to.
95 DOMString? address;
97 // If the underlying socket is connected, contains information about the
98 // service UUID it is connected to, otherwise if the underlying socket is
99 // listening, contains information about the service UUID it is listening
100 // on.
101 DOMString? uuid;
104 // Callback from the <code>getInfo</code> method.
105 // |socketInfo| : Object containing the socket information.
106 callback GetInfoCallback = void (SocketInfo socketInfo);
108 // Callback from the <code>getSockets</code> method.
109 // |socketInfos| : Array of object containing socket information.
110 callback GetSocketsCallback = void (SocketInfo[] sockets);
112 // Data from an <code>onAccept</code> event.
113 dictionary AcceptInfo {
114 // The server socket identifier.
115 long socketId;
117 // The client socket identifier, i.e. the socket identifier of the newly
118 // established connection. This socket identifier should be used only with
119 // functions from the <code>chrome.bluetoothSocket</code> namespace. Note
120 // the client socket is initially paused and must be explictly un-paused by
121 // the application to start receiving data.
122 long clientSocketId;
125 enum AcceptError {
126 // A system error occurred and the connection may be unrecoverable.
127 system_error,
129 // The socket is not listening.
130 not_listening
133 // Data from an <code>onAcceptError</code> event.
134 dictionary AcceptErrorInfo {
135 // The server socket identifier.
136 long socketId;
138 // The error message.
139 DOMString errorMessage;
141 // An error code indicating what went wrong.
142 AcceptError error;
145 // Data from an <code>onReceive</code> event.
146 dictionary ReceiveInfo {
147 // The socket identifier.
148 long socketId;
150 // The data received, with a maxium size of <code>bufferSize</code>.
151 ArrayBuffer data;
154 enum ReceiveError {
155 // The connection was disconnected.
156 disconnected,
158 // A system error occurred and the connection may be unrecoverable.
159 system_error,
161 // The socket has not been connected.
162 not_connected
165 // Data from an <code>onReceiveError</code> event.
166 dictionary ReceiveErrorInfo {
167 // The socket identifier.
168 long socketId;
170 // The error message.
171 DOMString errorMessage;
173 // An error code indicating what went wrong.
174 ReceiveError error;
177 // These functions all report failures via chrome.runtime.lastError.
178 interface Functions {
179 // Creates a Bluetooth socket.
180 // |properties| : The socket properties (optional).
181 // |callback| : Called when the socket has been created.
182 static void create(optional SocketProperties properties,
183 CreateCallback callback);
185 // Updates the socket properties.
186 // |socketId| : The socket identifier.
187 // |properties| : The properties to update.
188 // |callback| : Called when the properties are updated.
189 static void update(long socketId,
190 SocketProperties properties,
191 optional UpdateCallback callback);
193 // Enables or disables a connected socket from receiving messages from its
194 // peer, or a listening socket from accepting new connections. The default
195 // value is "false". Pausing a connected socket is typically used by an
196 // application to throttle data sent by its peer. When a connected socket
197 // is paused, no <code>onReceive</code>event is raised. When a socket is
198 // connected and un-paused, <code>onReceive</code> events are raised again
199 // when messages are received. When a listening socket is paused, new
200 // connections are accepted until its backlog is full then additional
201 // connection requests are refused. <code>onAccept</code> events are raised
202 // only when the socket is un-paused.
203 static void setPaused(long socketId,
204 boolean paused,
205 optional SetPausedCallback callback);
207 // Listen for connections using the RFCOMM protocol.
208 // |socketId| : The socket identifier.
209 // |uuid| : Service UUID to listen on.
210 // |channel| : RFCOMM channel id to listen on. Zero may be specified to
211 // allocate an unused channel.
212 // |backlog| : Length of the socket's listen queue. The default value
213 // depends on the operating system's host subsystem.
214 // |callback| : Called when listen operation completes.
215 static void listenUsingRfcomm(long socketId,
216 DOMString uuid,
217 long channel,
218 optional long backlog,
219 ListenCallback callback);
221 // Listens for connections from Bluetooth 1.0 and 2.0 devices using the
222 // RFCOMM protocol without requiring encryption or authentication on the
223 // socket.
224 // |socketId| : The socket identifier.
225 // |uuid| : Service UUID to listen on.
226 // |channel| : RFCOMM channel id to listen on. Zero may be specified to
227 // allocate an unused channel.
228 // |backlog| : Length of the socket's listen queue. The default value
229 // depends on the operating system's host subsystem.
230 // |callback| : Called when listen operation completes.
231 static void listenUsingInsecureRfcomm(long socketId,
232 DOMString uuid,
233 long channel,
234 optional long backlog,
235 ListenCallback callback);
237 // Listen for connections using the L2CAP protocol.
238 // |socketId| : The socket identifier.
239 // |uuid| : Service UUID to listen on.
240 // |psm| : L2CAP PSM to listen on. Zero may be specified to allocate an
241 // unused PSM.
242 // |backlog| : Length of the socket's listen queue. The default value
243 // depends on the operating system's host subsystem.
244 // |callback| : Called when listen operation completes.
245 static void listenUsingL2cap(long socketId,
246 DOMString uuid,
247 long psm,
248 optional long backlog,
249 ListenCallback callback);
251 // Connects the socket to a remote Bluetooth device. When the
252 // <code>connect</code> operation completes successfully,
253 // <code>onReceive</code> events are raised when data is received from the
254 // peer. If a network error occur while the runtime is receiving packets,
255 // a <code>onReceiveError</code> event is raised, at which point no more
256 // <code>onReceive</code> event will be raised for this socket until the
257 // <code>setPaused(false)</code> method is called.
258 // |socketId| : The socket identifier.
259 // |address| : The address of the Bluetooth device.
260 // |uuid| : The UUID of the service to connect to.
261 // |callback| : Called when the connect attempt is complete.
262 static void connect(long socketId,
263 DOMString address,
264 DOMString uuid,
265 ConnectCallback callback);
267 // Disconnects the socket. The socket identifier remains valid.
268 // |socketId| : The socket identifier.
269 // |callback| : Called when the disconnect attempt is complete.
270 static void disconnect(long socketId,
271 optional DisconnectCallback callback);
273 // Disconnects and destroys the socket. Each socket created should be
274 // closed after use. The socket id is no longer valid as soon at the
275 // function is called. However, the socket is guaranteed to be closed only
276 // when the callback is invoked.
277 // |socketId| : The socket identifier.
278 // |callback| : Called when the <code>close</code> operation completes.
279 static void close(long socketId,
280 optional CloseCallback callback);
282 // Sends data on the given Bluetooth socket.
283 // |socketId| : The socket identifier.
284 // |data| : The data to send.
285 // |callback| : Called with the number of bytes sent.
286 static void send(long socketId,
287 ArrayBuffer data,
288 optional SendCallback callback);
290 // Retrieves the state of the given socket.
291 // |socketId| : The socket identifier.
292 // |callback| : Called when the socket state is available.
293 static void getInfo(long socketId,
294 GetInfoCallback callback);
296 // Retrieves the list of currently opened sockets owned by the application.
297 // |callback| : Called when the list of sockets is available.
298 static void getSockets(GetSocketsCallback callback);
301 interface Events {
302 // Event raised when a connection has been established for a given socket.
303 // |info| : The event data.
304 static void onAccept(AcceptInfo info);
306 // Event raised when a network error occurred while the runtime was waiting
307 // for new connections on the given socket. Once this event is raised, the
308 // socket is set to <code>paused</code> and no more <code>onAccept</code>
309 // events are raised for this socket.
310 // |info| : The event data.
311 static void onAcceptError(AcceptErrorInfo info);
313 // Event raised when data has been received for a given socket.
314 // |info| : The event data.
315 static void onReceive(ReceiveInfo info);
317 // Event raised when a network error occured while the runtime was waiting
318 // for data on the socket. Once this event is raised, the socket is set to
319 // <code>paused</code> and no more <code>onReceive</code> events are raised
320 // for this socket.
321 // |info| : The event data.
322 static void onReceiveError(ReceiveErrorInfo info);