OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
rpaquay
2014/04/22 15:47:55
nit: Copyright 2014
keybuk
2014/04/24 11:46:45
Done.
| |
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 { | |
not at google - send to devlin
2014/04/22 17:27:05
is there an API proposal that encompasses this API
keybuk
2014/04/24 11:46:45
I wrote this to outline the changes:
https://docs.
| |
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 // Result of the <code>send</code> method. | |
65 dictionary SendInfo { | |
66 // The result code returned from the underlying network call. | |
67 // A negative value indicates an error. | |
68 long resultCode; | |
rpaquay
2014/04/22 15:47:55
Maybe we should use a custom enum for the bluetoot
keybuk
2014/04/24 11:46:45
Oops, yes!
I was copying from both the existing i
| |
69 | |
70 // The number of bytes sent (if result == 0) | |
71 long? bytesSent; | |
72 }; | |
73 | |
74 // Callback from the <code>send</code> method. | |
75 // |sendInfo| : Result of the <code>send</code> method. | |
76 callback SendCallback = void (SendInfo sendInfo); | |
77 | |
78 // Result of the <code>getInfo</code> method. | |
79 dictionary SocketInfo { | |
80 // The socket identifier. | |
81 long socketId; | |
82 | |
83 // Flag indicating if the socket remains open when the event page of the | |
84 // application is unloaded (see <code>SocketProperties.persistent</code>). | |
85 // The default value is "false". | |
86 boolean persistent; | |
87 | |
88 // Application-defined string associated with the socket. | |
89 DOMString? name; | |
90 | |
91 // The size of the buffer used to receive data. If no buffer size has been | |
92 // specified explictly, the value is not provided. | |
93 long? bufferSize; | |
94 | |
95 // Flag indicating whether a connected socket blocks its peer from sending | |
96 // mode data, or whether connection requests on a listening socket are | |
armansito
2014/04/22 20:13:04
nit: s/mode/more ?
keybuk
2014/04/24 11:46:45
Done.
| |
97 // dispatched through the <code>onAccept</code> event or queued up in the | |
98 // listen queue backlog. | |
99 // See <code>setPaused</code>. The default value is "false". | |
100 boolean paused; | |
101 | |
102 // Flag indicating whether the socket is connected to a remote peer. | |
103 boolean connected; | |
104 | |
105 // If the underlying socket is connected, contains information about the | |
106 // device it is connected to. | |
107 bluetooth.Device? device; | |
108 | |
109 // If the underlying socket is connected, contains information about the | |
110 // service UUID it is connected to, otherwise if the underlying socket is | |
111 // listening, contains information about the service UUID it is listening | |
112 // on. | |
113 DOMString? uuid; | |
114 }; | |
115 | |
116 // Callback from the <code>getInfo</code> method. | |
117 // |socketInfo| : Object containing the socket information. | |
118 callback GetInfoCallback = void (SocketInfo socketInfo); | |
119 | |
120 // Callback from the <code>getSockets</code> method. | |
121 // |socketInfos| : Array of object containing socket information. | |
122 callback GetSocketsCallback = void (SocketInfo[] sockets); | |
123 | |
124 // Data from an <code>onAccept</code> event. | |
125 dictionary AcceptInfo { | |
126 // The server socket identifier. | |
127 long socketId; | |
128 | |
129 // The client socket identifier, i.e. the socket identifier of the newly | |
130 // established connection. This socket identifier should be used only with | |
131 // functions from the <code>chrome.sockets.tcp</code> namespace. Note the | |
rpaquay
2014/04/22 15:47:55
chrome.bluetoothSocket
keybuk
2014/04/24 11:46:45
Done.
| |
132 // client socket is initially paused and must be explictly un-paused by the | |
133 // application to start receiving data. | |
134 long clientSocketId; | |
135 }; | |
136 | |
137 // Data from an <code>onAcceptError</code> event. | |
138 dictionary AcceptErrorInfo { | |
139 // The server socket identifier. | |
140 long socketId; | |
141 | |
142 // The result code returned from the underlying network call. | |
143 long resultCode; | |
144 }; | |
145 | |
146 // Data from an <code>onReceive</code> event. | |
147 dictionary ReceiveInfo { | |
148 // The socket identifier. | |
149 long socketId; | |
150 | |
151 // The data received, with a maxium size of <code>bufferSize</code>. | |
152 ArrayBuffer data; | |
153 }; | |
154 | |
155 // Data from an <code>onReceiveError</code> event. | |
156 dictionary ReceiveErrorInfo { | |
157 // The socket identifier. | |
158 long socketId; | |
159 | |
160 // The result code returned from the underlying network call. | |
161 long resultCode; | |
162 }; | |
163 | |
164 // These functions all report failures via chrome.runtime.lastError. | |
165 interface Functions { | |
166 // Creates a Bluetooth socket. | |
167 // |properties| : The socket properties (optional). | |
168 // |callback| : Called when the socket has been created. | |
169 static void create(optional SocketProperties properties, | |
170 CreateCallback callback); | |
171 | |
172 // Updates the socket properties. | |
173 // |socketId| : The socket identifier. | |
174 // |properties| : The properties to update. | |
175 // |callback| : Called when the properties are updated. | |
176 static void update(long socketId, | |
177 SocketProperties properties, | |
178 optional UpdateCallback callback); | |
179 | |
180 // Enables or disables a connected socket from receiving messages from its | |
181 // peer, or a listening socket from accepting new connections. The default | |
182 // value is "false". Pausing a connected socket is typically used by an | |
183 // application to throttle data sent by its peer. When a connected socket | |
184 // is paused, no <code>onReceive</code>event is raised. When a socket is | |
185 // connected and un-paused, <code>onReceive</code> events are raised again | |
186 // when messages are received. When a listening socket is paused, new | |
187 // connections are accepted until its backlog is full then additional | |
188 // connection requests are refused. <code>onAccept</code> events are raised | |
189 // only when the socket is un-paused. | |
190 static void setPaused(long socketId, | |
191 boolean paused, | |
192 optional SetPausedCallback callback); | |
193 | |
194 // Listen for connections using the RFCOMM protocol. | |
195 // |socketId| : The socket identifier. | |
196 // |uuid| : Service UUID to listen on. | |
197 // |channel| : RFCOMM channel id to listen on. Zero may be specified to | |
198 // allocate an unused channel. | |
199 // |backlog| : Length of the socket's listen queue. The default value | |
200 // depends on the Operating System Host Subsystem. | |
201 // |callback| : Called when listen operation completes. | |
202 static void listenUsingRfcomm(long socketId, | |
203 DOMString uuid, | |
204 long channel, | |
205 optional long backlog, | |
206 ListenCallback callback); | |
207 | |
208 // Listens for connections from Bluetooth 1.0 and 2.0 devices using the | |
209 // RFCOMM protocol without requiring encryption or authentication on the | |
210 // socket. | |
211 // |socketId| : The socket identifier. | |
212 // |uuid| : Service UUID to listen on. | |
213 // |channel| : RFCOMM channel id to listen on. Zero may be specified to | |
214 // allocate an unused channel. | |
215 // |backlog| : Length of the socket's listen queue. The default value | |
216 // depends on the Operating System Host Subsystem. | |
217 // |callback| : Called when listen operation completes. | |
218 static void listenUsingInsecureRfcomm(long socketId, | |
219 DOMString uuid, | |
220 long channel, | |
221 optional long backlog, | |
222 ListenCallback callback); | |
223 | |
224 // Listen for connections using the L2CAP protocol. | |
225 // |socketId| : The socket identifier. | |
226 // |uuid| : Service UUID to listen on. | |
227 // |psm| : L2CAP PSM to listen on. Zero may be specified to allocate an | |
228 // unused PSM. | |
229 // |backlog| : Length of the socket's listen queue. The default value | |
230 // depends on the Operating System Host Subsystem. | |
miket_OOO
2014/04/22 20:18:17
Unless "Operating System Host Subsystem" is a term
keybuk
2014/04/24 11:46:45
Done.
| |
231 // |callback| : Called when listen operation completes. | |
232 static void listenUsingL2cap(long socketId, | |
233 DOMString uuid, | |
234 long psm, | |
235 optional long backlog, | |
236 ListenCallback callback); | |
237 | |
238 // Connects the socket to a remote Bluetooth device. When the | |
239 // <code>connect</code> operation completes successfully, | |
240 // <code>onReceive</code> events are raised when data is received from the | |
241 // peer. If a network error occur while the runtime is receiving packets, | |
242 // a <code>onReceiveError</code> event is raised, at which point no more | |
243 // <code>onReceive</code> event will be raised for this socket until the | |
244 // <code>resume</code> method is called. | |
rpaquay
2014/04/22 15:47:55
<code>setPaused(false)</code>
keybuk
2014/04/24 11:46:45
Done.
| |
245 // |socketId| : The socket identifier. | |
246 // |address| : The address of the Bluetooth device. | |
247 // |uuid| : The UUID of the service to connect to. | |
248 // |callback| : Called when the connect attempt is complete. | |
249 static void connect(long socketId, | |
250 DOMString address, | |
251 DOMString uuid, | |
252 ConnectCallback callback); | |
253 | |
254 // Disconnects the socket. The socket identifier remains valid. | |
255 // |socketId| : The socket identifier. | |
256 // |callback| : Called when the disconnect attempt is complete. | |
257 static void disconnect(long socketId, | |
258 optional DisconnectCallback callback); | |
259 | |
260 // Disconnects and destroys the socket. Each socket created should be | |
261 // closed after use. The socket id is no longer valid as soon at the | |
262 // function is called. However, the socket is guaranteed to be closed only | |
263 // when the callback is invoked. | |
264 // |socketId| : The socket identifier. | |
265 // |callback| : Called when the <code>close</code> operation completes. | |
266 static void close(long socketId, | |
267 optional CloseCallback callback); | |
268 | |
269 // Sends data on the given Bluetooth socket. | |
270 // |socketId| : The socket identifier. | |
271 // |data| : The data to send. | |
272 // |callback| : Called with the number of bytes sent. | |
273 static void send(long socketId, | |
274 ArrayBuffer data, | |
275 optional SendCallback callback); | |
276 | |
277 // Retrieves the state of the given socket. | |
278 // |socketId| : The socket identifier. | |
279 // |callback| : Called when the socket state is available. | |
280 static void getInfo(long socketId, | |
281 GetInfoCallback callback); | |
282 | |
283 // Retrieves the list of currently opened sockets owned by the application. | |
284 // |callback| : Called when the list of sockets is available. | |
285 static void getSockets(GetSocketsCallback callback); | |
286 }; | |
287 | |
288 interface Events { | |
289 // Event raised when a connection has been established for a given socket. | |
290 // |info| : The event data. | |
291 static void onAccept(AcceptInfo info); | |
292 | |
293 // Event raised when a network error occurred while the runtime was waiting | |
294 // for new connections on the given socket. Once this event is raised, the | |
295 // socket is set to <code>paused</code> and no more <code>onAccept</code> | |
296 // events are raised for this socket. | |
297 // |info| : The event data. | |
298 static void onAcceptError(AcceptErrorInfo info); | |
299 | |
300 // Event raised when data has been received for a given socket. | |
301 // |info| : The event data. | |
302 static void onReceive(ReceiveInfo info); | |
303 | |
304 // Event raised when a network error occured while the runtime was waiting | |
305 // for data on the socket. Once this event is raised, the socket is set to | |
306 // <code>paused</code> and no more <code>onReceive</code> events are raised | |
307 // for this socket. | |
308 // |info| : The event data. | |
309 static void onReceiveError(ReceiveErrorInfo info); | |
310 }; | |
311 }; | |
OLD | NEW |