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

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

Issue 246883003: Introduce chrome.bluetoothSocket API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
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;
20
21 // An application-defined string associated with the socket.
22 DOMString? name;
23
24 // The size of the buffer used to receive data. The default value is 4096.
25 long? bufferSize;
26 };
27
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;
34 };
35
36 // Callback from the <code>create</code> method.
37 // |createInfo| : The result of the socket creation.
38 callback CreateCallback = void (CreateInfo createInfo);
39
40 // Callback from the <code>update</code> method.
41 callback UpdateCallback = void ();
42
43 // Callback from the <code>setPaused</code> method.
44 callback SetPausedCallback = void ();
45
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);
52
53 // Callback from the <code>connect</code> method.
54 // |result| : The result code returned from the underlying network call.
55 // A negative value indicates an error.
56 callback ConnectCallback = void (long result);
57
58 // Callback from the <code>disconnect</code> method.
59 callback DisconnectCallback = void ();
60
61 // Callback from the <code>close</code> method.
62 callback CloseCallback = void ();
63
64 enum SendError {
65 // No error occurred.
66 success,
67
68 // The connection was disconnected.
69 disconnected,
70
71 // A system error occurred and the connection may be unrecoverable.
72 system_error
73 };
74
75 // Result of the <code>send</code> method.
76 dictionary SendInfo {
77 // The error message.
78 DOMString errorMessage;
79
80 // An error code indicating what went wrong.
81 SendError error;
82
83 // The number of bytes sent (if result == 0)
84 long? bytesSent;
85 };
86
87 // Callback from the <code>send</code> method.
88 // |sendInfo| : Result of the <code>send</code> method.
89 callback SendCallback = void (SendInfo sendInfo);
90
91 // Result of the <code>getInfo</code> method.
92 dictionary SocketInfo {
93 // The socket identifier.
94 long socketId;
95
96 // Flag indicating if the socket remains open when the event page of the
97 // application is unloaded (see <code>SocketProperties.persistent</code>).
98 // The default value is "false".
99 boolean persistent;
100
101 // Application-defined string associated with the socket.
102 DOMString? name;
103
104 // The size of the buffer used to receive data. If no buffer size has been
105 // specified explictly, the value is not provided.
106 long? bufferSize;
107
108 // Flag indicating whether a connected socket blocks its peer from sending
109 // more data, or whether connection requests on a listening socket are
110 // dispatched through the <code>onAccept</code> event or queued up in the
111 // listen queue backlog.
112 // See <code>setPaused</code>. The default value is "false".
113 boolean paused;
114
115 // Flag indicating whether the socket is connected to a remote peer.
116 boolean connected;
117
118 // If the underlying socket is connected, contains the Bluetooth address of
119 // the device it is connected to.
120 DOMString? address;
121
122 // If the underlying socket is connected, contains information about the
123 // service UUID it is connected to, otherwise if the underlying socket is
124 // listening, contains information about the service UUID it is listening
125 // on.
126 DOMString? uuid;
127 };
128
129 // Callback from the <code>getInfo</code> method.
130 // |socketInfo| : Object containing the socket information.
131 callback GetInfoCallback = void (SocketInfo socketInfo);
132
133 // Callback from the <code>getSockets</code> method.
134 // |socketInfos| : Array of object containing socket information.
135 callback GetSocketsCallback = void (SocketInfo[] sockets);
136
137 // Data from an <code>onAccept</code> event.
138 dictionary AcceptInfo {
139 // The server socket identifier.
140 long socketId;
141
142 // The client socket identifier, i.e. the socket identifier of the newly
143 // established connection. This socket identifier should be used only with
144 // functions from the <code>chrome.bluetoothSocket</code> namespace. Note
145 // the client socket is initially paused and must be explictly un-paused by
146 // the application to start receiving data.
147 long clientSocketId;
148 };
149
150 enum AcceptError {
151 // A system error occurred and the connection may be unrecoverable.
152 system_error
153 };
154
155 // Data from an <code>onAcceptError</code> event.
156 dictionary AcceptErrorInfo {
157 // The server socket identifier.
158 long socketId;
159
160 // The error message.
161 DOMString errorMessage;
162
163 // An error code indicating what went wrong.
164 AcceptError error;
165 };
166
167 // Data from an <code>onReceive</code> event.
168 dictionary ReceiveInfo {
169 // The socket identifier.
170 long socketId;
171
172 // The data received, with a maxium size of <code>bufferSize</code>.
173 ArrayBuffer data;
174 };
175
176 enum ReceiveError {
177 // The connection was disconnected.
178 disconnected,
179
180 // A system error occurred and the connection may be unrecoverable.
181 system_error
182 };
183
184 // Data from an <code>onReceiveError</code> event.
185 dictionary ReceiveErrorInfo {
186 // The socket identifier.
187 long socketId;
188
189 // The error message.
190 DOMString errorMessage;
191
192 // An error code indicating what went wrong.
193 ReceiveError error;
194 };
195
196 // These functions all report failures via chrome.runtime.lastError.
197 interface Functions {
198 // Creates a Bluetooth socket.
199 // |properties| : The socket properties (optional).
200 // |callback| : Called when the socket has been created.
201 static void create(optional SocketProperties properties,
202 CreateCallback callback);
203
204 // Updates the socket properties.
205 // |socketId| : The socket identifier.
206 // |properties| : The properties to update.
207 // |callback| : Called when the properties are updated.
208 static void update(long socketId,
209 SocketProperties properties,
210 optional UpdateCallback callback);
211
212 // Enables or disables a connected socket from receiving messages from its
213 // peer, or a listening socket from accepting new connections. The default
214 // value is "false". Pausing a connected socket is typically used by an
215 // application to throttle data sent by its peer. When a connected socket
216 // is paused, no <code>onReceive</code>event is raised. When a socket is
217 // connected and un-paused, <code>onReceive</code> events are raised again
218 // when messages are received. When a listening socket is paused, new
219 // connections are accepted until its backlog is full then additional
220 // connection requests are refused. <code>onAccept</code> events are raised
221 // only when the socket is un-paused.
222 static void setPaused(long socketId,
223 boolean paused,
224 optional SetPausedCallback callback);
225
226 // Listen for connections using the RFCOMM protocol.
227 // |socketId| : The socket identifier.
228 // |uuid| : Service UUID to listen on.
229 // |channel| : RFCOMM channel id to listen on. Zero may be specified to
230 // allocate an unused channel.
231 // |backlog| : Length of the socket's listen queue. The default value
232 // depends on the operating system's host subsystem.
233 // |callback| : Called when listen operation completes.
234 static void listenUsingRfcomm(long socketId,
235 DOMString uuid,
236 long channel,
237 optional long backlog,
238 ListenCallback callback);
239
240 // Listens for connections from Bluetooth 1.0 and 2.0 devices using the
241 // RFCOMM protocol without requiring encryption or authentication on the
242 // socket.
243 // |socketId| : The socket identifier.
244 // |uuid| : Service UUID to listen on.
245 // |channel| : RFCOMM channel id to listen on. Zero may be specified to
246 // allocate an unused channel.
247 // |backlog| : Length of the socket's listen queue. The default value
248 // depends on the operating system's host subsystem.
249 // |callback| : Called when listen operation completes.
250 static void listenUsingInsecureRfcomm(long socketId,
251 DOMString uuid,
252 long channel,
253 optional long backlog,
254 ListenCallback callback);
255
256 // Listen for connections using the L2CAP protocol.
257 // |socketId| : The socket identifier.
258 // |uuid| : Service UUID to listen on.
259 // |psm| : L2CAP PSM to listen on. Zero may be specified to allocate an
260 // unused PSM.
261 // |backlog| : Length of the socket's listen queue. The default value
262 // depends on the operating system's host subsystem.
263 // |callback| : Called when listen operation completes.
264 static void listenUsingL2cap(long socketId,
265 DOMString uuid,
266 long psm,
267 optional long backlog,
268 ListenCallback callback);
269
270 // Connects the socket to a remote Bluetooth device. When the
271 // <code>connect</code> operation completes successfully,
272 // <code>onReceive</code> events are raised when data is received from the
273 // peer. If a network error occur while the runtime is receiving packets,
274 // a <code>onReceiveError</code> event is raised, at which point no more
275 // <code>onReceive</code> event will be raised for this socket until the
276 // <code>setPaused(false)</code> method is called.
277 // |socketId| : The socket identifier.
278 // |address| : The address of the Bluetooth device.
279 // |uuid| : The UUID of the service to connect to.
280 // |callback| : Called when the connect attempt is complete.
281 static void connect(long socketId,
282 DOMString address,
283 DOMString uuid,
284 ConnectCallback callback);
285
286 // Disconnects the socket. The socket identifier remains valid.
287 // |socketId| : The socket identifier.
288 // |callback| : Called when the disconnect attempt is complete.
289 static void disconnect(long socketId,
290 optional DisconnectCallback callback);
291
292 // Disconnects and destroys the socket. Each socket created should be
293 // closed after use. The socket id is no longer valid as soon at the
294 // function is called. However, the socket is guaranteed to be closed only
295 // when the callback is invoked.
296 // |socketId| : The socket identifier.
297 // |callback| : Called when the <code>close</code> operation completes.
298 static void close(long socketId,
299 optional CloseCallback callback);
300
301 // Sends data on the given Bluetooth socket.
302 // |socketId| : The socket identifier.
303 // |data| : The data to send.
304 // |callback| : Called with the number of bytes sent.
305 static void send(long socketId,
306 ArrayBuffer data,
307 optional SendCallback callback);
308
309 // Retrieves the state of the given socket.
310 // |socketId| : The socket identifier.
311 // |callback| : Called when the socket state is available.
312 static void getInfo(long socketId,
313 GetInfoCallback callback);
314
315 // Retrieves the list of currently opened sockets owned by the application.
316 // |callback| : Called when the list of sockets is available.
317 static void getSockets(GetSocketsCallback callback);
318 };
319
320 interface Events {
321 // Event raised when a connection has been established for a given socket.
322 // |info| : The event data.
323 static void onAccept(AcceptInfo info);
324
325 // Event raised when a network error occurred while the runtime was waiting
326 // for new connections on the given socket. Once this event is raised, the
327 // socket is set to <code>paused</code> and no more <code>onAccept</code>
328 // events are raised for this socket.
329 // |info| : The event data.
330 static void onAcceptError(AcceptErrorInfo info);
331
332 // Event raised when data has been received for a given socket.
333 // |info| : The event data.
334 static void onReceive(ReceiveInfo info);
335
336 // Event raised when a network error occured while the runtime was waiting
337 // for data on the socket. Once this event is raised, the socket is set to
338 // <code>paused</code> and no more <code>onReceive</code> events are raised
339 // for this socket.
340 // |info| : The event data.
341 static void onReceiveError(ReceiveErrorInfo info);
342 };
343 };
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/api.gyp ('k') | chrome/common/extensions/docs/templates/public/apps/bluetoothSocket.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698