OLD | NEW |
---|---|
(Empty) | |
1 /* Copyright (c) 2011 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 | |
6 /* From dev/ppb_websocket_dev.idl modified Thu Oct 27 22:42:42 2011. */ | |
7 | |
8 #ifndef PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ | |
9 #define PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ | |
10 | |
11 #include "ppapi/c/pp_bool.h" | |
12 #include "ppapi/c/pp_completion_callback.h" | |
13 #include "ppapi/c/pp_instance.h" | |
14 #include "ppapi/c/pp_macros.h" | |
15 #include "ppapi/c/pp_resource.h" | |
16 #include "ppapi/c/pp_stdint.h" | |
17 #include "ppapi/c/pp_var.h" | |
18 | |
19 #define PPB_WEBSOCKET_DEV_INTERFACE_0_1 "PPB_WebSocket(Dev);0.1" | |
20 #define PPB_WEBSOCKET_DEV_INTERFACE PPB_WEBSOCKET_DEV_INTERFACE_0_1 | |
21 | |
22 /** | |
23 * @file | |
24 * This file defines the <code>PPB_WebSocket_Dev</code> interface. | |
25 */ | |
26 | |
27 | |
28 /** | |
29 * @addtogroup Enums | |
30 * @{ | |
31 */ | |
32 /** | |
33 * This enumeration contains the types representing the WebSocket ready state | |
34 * and these states are based on the JavaScript WebSocket API specification. | |
35 * GetReadyState() returns one of these states. | |
36 */ | |
37 typedef enum { | |
38 /** | |
39 * Ready state that the connection has not yet been established. | |
40 */ | |
41 PP_WEBSOCKETREADYSTATE_CONNECTING = 0, | |
42 /** | |
43 * Ready state that the WebSocket connection is established and communication | |
44 * is possible. | |
45 */ | |
46 PP_WEBSOCKETREADYSTATE_OPEN = 1, | |
47 /** | |
48 * Ready state that the connection is going through the closing handshake. | |
49 */ | |
50 PP_WEBSOCKETREADYSTATE_CLOSING = 2, | |
51 /** | |
52 * Ready state that the connection has been closed or could not be opened. | |
53 */ | |
54 PP_WEBSOCKETREADYSTATE_CLOSED = 3 | |
55 } PP_WebSocketReadyState_Dev; | |
56 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketReadyState_Dev, 4); | |
57 | |
58 /** | |
59 * This enumeration contains the types representing the WebSocket message type | |
60 * and these types are based on the JavaScript WebSocket API specification. | |
61 * ReceiveMessage() and SendMessage() use them as a parameter to represent | |
62 * handling message types. | |
63 */ | |
64 typedef enum { | |
65 /** | |
66 * Message type that represents a text message type. | |
67 */ | |
68 PP_WEBSOCKET_MESSAGE_TYPE_TEXT = 0, | |
69 /** | |
70 * Message type that represents a binary message type. | |
71 */ | |
72 PP_WEBSOCKET_MESSAGE_TYPE_BINARY = 1 | |
73 } PP_WebSocketMessageType_Dev; | |
74 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_WebSocketMessageType_Dev, 4); | |
75 /** | |
76 * @} | |
77 */ | |
78 | |
79 /** | |
80 * @addtogroup Interfaces | |
81 * @{ | |
82 */ | |
83 struct PPB_WebSocket_Dev { | |
84 /** | |
85 * Create() creates a WebSocket instance. | |
86 * | |
87 * @param[in] instance A <code>PP_Instance</code> identifying the instance | |
88 * with the WebSocket. | |
89 * | |
90 * @return A <code>PP_Resource</code> corresponding to a WebSocket if | |
91 * successful. | |
92 */ | |
93 PP_Resource (*Create)(PP_Instance instance); | |
94 /** | |
95 * IsWebSocket() determines if the provided <code>resource</code> is a | |
96 * WebSocket instance. | |
97 * | |
98 * @param[in] resource A <code>PP_Resource</code> corresponding to a | |
99 * WebSocket. | |
100 * | |
101 * @return Returns <code>PP_TRUE</code> if <code>resource</code> is a | |
102 * <code>PPB_WebSocket_Dev</code>, <code>PP_FALSE</code> if the | |
103 * <code>resource</code> is invalid or some type other than | |
104 * <code>PPB_WebSocket_Dev</code>. | |
105 */ | |
106 PP_Bool (*IsWebSocket)(PP_Resource resource); | |
107 /** | |
108 * SetOpenCallback() sets the callback which is called when the WebSocket | |
109 * connection is opened. This callback corresponds to onopen event of | |
110 * JavaScript API. | |
111 * Caller can call this method safely only before calling Connect(). | |
112 * | |
113 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
114 * WebSocket. | |
115 * | |
116 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
117 * when the connection is opened. | |
118 * | |
119 * @return Returns <code>PP_OK</code>. | |
120 */ | |
121 int32_t (*SetOpenCallback)(PP_Resource web_socket, | |
122 struct PP_CompletionCallback callback); | |
123 /** | |
124 * SetMessageCallback() sets the callback which is called when the WebSocket | |
125 * connection receives a frame. This callback corresponds to onmessage event | |
126 * of JavaScript API. | |
127 * Callback is invoked when the next frame can be read via ReceiveMessage(). | |
128 * Caller can call this method safely only before calling Connect(). | |
129 * | |
130 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
131 * WebSocket. | |
132 * | |
133 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
134 * when the connection receives a frame. | |
135 * | |
136 * @return Returns <code>PP_OK</code>. | |
137 */ | |
138 int32_t (*SetMessageCallback)(PP_Resource web_socket, | |
139 struct PP_CompletionCallback callback); | |
140 /** | |
141 * SetErrorCallback() sets the callback which is called when the WebSocket | |
142 * connection is closed with prejudice. This callback corresponds to onclose | |
143 * event of JavaScript API. | |
144 * Caller can call this method safely only before calling Connect(). | |
145 * | |
146 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
147 * WebSocket. | |
148 * | |
149 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
150 * when the connection receives a frame. | |
151 * | |
152 * @return Returns <code>PP_OK</code>. | |
153 */ | |
154 int32_t (*SetErrorCallback)(PP_Resource web_socket, | |
155 struct PP_CompletionCallback callback); | |
156 /** | |
157 * SetCloseCallback() sets the callback which is called when the WebSocket | |
158 * connection is closed. This callback corresponds to onclose event of | |
159 * JavaScript API. | |
160 * Close code and reason should be queried via each interface. | |
161 * Caller can call this method safely only before calling Connect(). | |
162 * | |
163 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
164 * WebSocket. | |
165 * | |
166 * @param[in] callback A <code>PP_CompletionCallback</code> which is called | |
167 * when the connection is closed. | |
168 * | |
169 * @return Returns <code>PP_OK</code>. | |
170 */ | |
171 int32_t (*SetCloseCallback)(PP_Resource web_socket, | |
172 struct PP_CompletionCallback callback); | |
173 /** | |
174 * Connect() connects to the specified WebSocket server. Caller can call this | |
175 * method at most once for a <code>web_socket</code>. | |
176 * | |
177 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
178 * WebSocket. | |
179 * | |
180 * @param[in] url A <code>PP_Var</code> representing a WebSocket server URL. | |
181 * The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>. | |
182 * | |
183 * @param[in] protocols A pointer to an array of <code>PP_Var</code> | |
184 * specifying sub-protocols. Each <code>PP_Var</code> represents one | |
185 * sub-protocol and its <code>PP_VarType</code> must be | |
186 * <code>PP_VARTYPE_STRING</code>. This argument can be null only if | |
187 * <code>protocol_count</code> is 0. | |
188 * | |
189 * @param[in] protocol_count The number of sub-protocols in | |
190 * <code>protocols</code>. | |
191 * | |
192 * @return In case of immediate failure, returns an error code as follows. | |
193 * Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript | |
194 * SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to JavaScript | |
195 * SecurityError. Otherwise, returns <code>PP_OK</code>. | |
196 */ | |
197 int32_t (*Connect)(PP_Resource web_socket, | |
198 struct PP_Var url, | |
199 const struct PP_Var protocols[], | |
200 uint32_t protocol_count); | |
201 /** | |
202 * Close() closes the specified WebSocket connection by specifying | |
203 * <code>code</code> and <code>reason</code>. | |
204 * | |
205 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
206 * WebSocket. | |
207 * | |
208 * @param[in] code The WebSocket close code. Ignored if it is 0. | |
209 * | |
210 * @param[in] reason A <code>PP_Var</code> which represents the WebSocket | |
211 * close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>. | |
212 * Otherwise, its <code>PP_VarType</code> must be | |
213 * <code>PP_VARTYPE_STRING</code>. | |
214 * | |
215 * @return In case of immediate failure, returns an error code as follows. | |
216 * Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript | |
217 * SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to JavaScript | |
218 * InvalidAccessError. Otherwise, returns | |
219 * <code>PP_OK</code>. | |
220 */ | |
221 int32_t (*Close)(PP_Resource web_socket, uint16_t code, struct PP_Var reason); | |
222 /** | |
223 * ReceiveMessage() receives a message from the WebSocket server. | |
224 * This interface only returns bytes of a single message. That is, this | |
225 * interface must be called at least N times to receive N messages, no matter | |
226 * how small each message is. | |
227 * | |
228 * Note: This interface might be changed as follows. | |
229 * int32_t ReceiveMessage([in] PP_Resource web_socket, | |
230 * [out] PP_Var message, | |
231 * [out] int32_t remaining_message_byte_count); | |
232 * | |
233 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
234 * WebSocket. | |
235 * | |
236 * @param[out] message_bytes The message is copied to provided | |
237 * <code>message_bytes</code> up to <code>message_byte_count</code> bytes. | |
238 * <code>message_bytes</code> can be null only if | |
239 * <code>message_byte_count</code> is 0. | |
cstefansen
2011/11/01 17:58:15
What would be the purpose of calling ReceiveMessag
Takashi Toyoshima
2011/11/02 09:23:42
This header file is generated from IDL automatical
| |
240 * In copying message to <code>message_bytes</code>, UTF-8 byte sequence | |
241 * boundaries are not considered. Hence if the message is larger than | |
242 * <code>message_bytes</code>, the last byte sequence may end prematurely. | |
243 * Likewise, the first sequence of the bytes returned for the subsequent call | |
cstefansen
2011/11/01 17:58:15
This sounds a bit inconvenient for the API user. I
Takashi Toyoshima
2011/11/02 09:23:42
Now, I think we must define minimum C API which is
| |
244 * may start in the middle. | |
245 * | |
246 * @param[in] message_bytes_count The maximum receiving size in bytes. | |
247 * | |
248 * @param[out] remaining_byte_count The number of remaining bytes, if any, is | |
249 * set to <code>remaining_message_byte_count</code> if | |
250 * <code>remaining_message_byte_count</code> is not null. The remaining bytes | |
251 * of the message are returned for subsequent call(s) to this method. | |
252 * | |
253 * @param[out] message_type A <code>PP_WebSocketMessageType_Dev</code> | |
254 * representing the message type is set to <code>message_type</code> if | |
255 * <code>message_type</code> is not null. If the message is text, it is | |
256 * encoded in UTF-8. | |
257 * | |
258 * @return If a message is currently available, returns the number of bytes | |
259 * copied to <code>message_bytes</code>. Otherwise, returns 0. | |
260 * Frame boundaries must be detected by <code>remaining_byte_count</code>. | |
261 * If the next message is available as a result, registerd callback by | |
262 * SetMessageCallback() will be invoked. | |
263 * Messages are queued internally. Hence this method can be called either | |
264 * before or after a message is received by the browser. If the queue grows | |
265 * beyond the browser-dependent limit, <code>web_socket</code> is closed and | |
266 * messages are discarded. | |
267 */ | |
268 int32_t (*ReceiveMessage)(PP_Resource web_socket, | |
269 void* message_bytes, | |
270 int32_t message_byte_count, | |
271 int32_t* remaining_message_byte_count, | |
272 PP_WebSocketMessageType_Dev* message_type); | |
cstefansen
2011/11/01 17:58:15
To receive a message one would have to (a) receive
Takashi Toyoshima
2011/11/02 09:23:42
OK.
I'll take care on it for next revision.
| |
273 /** | |
274 * SendMessage() sends a message to the WebSocket server. | |
275 * | |
276 * Note: This interface might be changed as follows. | |
277 * int32_t SendMessage([in] PP_Resource web_socket, | |
278 * [in] PP_Var message); | |
279 * | |
280 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
281 * WebSocket. | |
282 * | |
283 * @param[in] message_bytes A message to send. The message is copied to | |
284 * internal buffer. So caller can free <code>message_bytes</code> safely | |
285 * after returning from the function. | |
286 * | |
287 * @param[in] message_byte_count The length of the message in bytes. | |
288 * | |
289 * @param[in] message_type A <code>PP_WebSocketMessageType_Dev</code> | |
290 * representing the message type of the <code>message</code>. | |
291 * | |
292 * @return In case of immediate failure, returns an error code as follows. | |
293 * Returns <code>PP_ERROR_FAILED</code> corresponding JavaScript | |
cstefansen
2011/11/01 17:58:15
Nit: corresponding -> corresponding to
Takashi Toyoshima
2011/11/02 09:23:42
Done.
| |
294 * InvalidStateError and <code>PP_ERROR_BADARGUMENT</code> corresponding | |
cstefansen
2011/11/01 17:58:15
Same here.
Takashi Toyoshima
2011/11/02 09:23:42
Done.
| |
295 * JavaScript SyntaxError. Otherwise, return <code>PP_OK</code>. | |
296 * <code>PP_OK</code> doesn't necessarily mean that the server received the | |
297 * message. | |
298 */ | |
299 int32_t (*SendMessage)(PP_Resource web_socket, | |
300 const void message_bytes[], | |
301 int32_t message_byte_count, | |
302 PP_WebSocketMessageType_Dev message_type); | |
303 /** | |
304 * GetBufferedAmount() returns the number of bytes of text and binary | |
305 * messages that have been queued for the WebSocket connection to send but | |
306 * have not been transmitted to the network yet. | |
307 * | |
308 * Note: This interface might not be able to return exact bytes in the first | |
309 * release. | |
cstefansen
2011/11/01 17:58:15
Could you elaborate?
Takashi Toyoshima
2011/11/02 09:23:42
Done.
| |
310 * | |
311 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
312 * WebSocket. | |
313 * | |
314 * @return Returns the number of bytes. | |
315 */ | |
316 uint64_t (*GetBufferedAmount)(PP_Resource web_socket); | |
317 /** | |
318 * GetCloseCode() returns the connection close code for the WebSocket | |
319 * connection. | |
320 * | |
321 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
322 * WebSocket. | |
323 * | |
324 * @return Returns 0 if called before the close code is set. | |
325 */ | |
326 uint16_t (*GetCloseCode)(PP_Resource web_socket); | |
327 /** | |
328 * GetCloseReason() returns the connection close reason for the WebSocket | |
329 * connection. | |
330 * | |
331 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
332 * WebSocket. | |
333 * | |
334 * @return Returns a <code>PP_VARTYPE_NULL</code> var if called before the | |
335 * close reason is set, or <code>PP_VARTYPE_UNDEFINED</code> if called on an | |
336 * invalid resource. | |
337 */ | |
338 struct PP_Var (*GetCloseReason)(PP_Resource web_socket); | |
339 /** | |
340 * GetCloseWasClean() returns if the connection was closed cleanly for the | |
341 * specified WebSocket connection. | |
342 * | |
343 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
344 * WebSocket. | |
345 * | |
346 * @return Returns <code>PP_FALSE</code> if called before the connection is | |
347 * closed. Otherwise, returns <code>PP_TRUE</code> if the connection was | |
348 * closed cleanly and returns <code>PP_FALSE</code> if the connection was | |
349 * closed by abnormal reasons. | |
350 */ | |
351 PP_Bool (*GetCloseWasClean)(PP_Resource web_socket); | |
352 /** | |
353 * GetExtensions() returns the extensions selected by the server for the | |
354 * specified WebSocket connection. | |
355 * | |
356 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
357 * WebSocket. | |
358 * | |
359 * @return Returns a <code>PP_VARTYPE_NULL</code> var if called before the | |
360 * connection is established, or <code>PP_VARTYPE_UNDEFINED</code> if called | |
361 * on an invalid resource. | |
362 */ | |
363 struct PP_Var (*GetExtensions)(PP_Resource web_socket); | |
364 /** | |
365 * GetProtocol() returns the sub-protocol chosen by the server for the | |
366 * specified WebSocket connection. | |
367 * | |
368 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
369 * WebSocket. | |
370 * | |
371 * @return Returns a <code>PP_VARTYPE_NULL</code> var if called before the | |
372 * connection is established, or <code>PP_VARTYPE_UNDEFINED</code> if called | |
373 * on an invalid resource. | |
374 */ | |
375 struct PP_Var (*GetProtocol)(PP_Resource web_socket); | |
376 /** | |
377 * GetReadyState() returns the ready state of the specified WebSocket | |
378 * connection. | |
379 * | |
380 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
381 * WebSocket. | |
382 * | |
383 * @return Returns <code>PP_WEBSOCKETREADYSTATE_CONNECTING</code> if called | |
384 * before the connection is established. | |
385 */ | |
386 PP_WebSocketReadyState_Dev (*GetReadyState)(PP_Resource web_socket); | |
387 /** | |
388 * GetUrl() returns the URL associated with specified WebSocket connection. | |
389 * | |
390 * @param[in] web_socket A <code>PP_Resource</code> corresponding to a | |
391 * WebSocket. | |
392 * | |
393 * @return Returns a <code>PP_VARTYPE_NULL</code> var if called before the | |
394 * connection is established, or <code>PP_VARTYPE_UNDEFINED</code> if called | |
395 * on an invalid resource. | |
396 */ | |
397 struct PP_Var (*GetUrl)(PP_Resource web_socket); | |
398 }; | |
399 /** | |
400 * @} | |
401 */ | |
402 | |
403 #endif /* PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_ */ | |
404 | |
OLD | NEW |