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 #ifndef PPAPI_CPP_HELPER_DEV_WEBSOCKET_API_DEV_H_ | |
6 #define PPAPI_CPP_HELPER_DEV_WEBSOCKET_API_DEV_H_ | |
7 | |
8 #include "ppapi/c/dev/ppb_websocket_dev.h" | |
9 | |
10 /// @file | |
11 /// This file defines the helper::WebSocketAPI_Dev interface. | |
12 | |
13 namespace pp { | |
14 | |
15 class CompletionCallback; | |
16 class Instance; | |
17 class Var; | |
18 | |
19 namespace helper { | |
20 | |
21 /// The <code>WebSocketAPI_Dev</code> class | |
22 class WebSocketAPI_Dev { | |
23 public: | |
24 /// Constructs a WebSocketAPI_Dev object. | |
25 WebSocketAPI_Dev(Instance* instance); | |
26 | |
27 /// Destructs a WebSocketAPI_Dev object. | |
28 virtual ~WebSocketAPI_Dev(); | |
29 | |
30 /// Connect() connects to the specified WebSocket server. Caller can call | |
31 /// this method at most once. | |
32 /// | |
33 /// @param[in] url A <code>Var</code> of string type representing a WebSocket | |
34 /// server URL. | |
35 /// @param[in] protocols A pointer to an array of string type | |
36 /// <code>Var</code> specifying sub-protocols. Each <code>Var</code> | |
37 /// represents one sub-protocol and its <code>PP_VarType</code> must be | |
38 /// <code>PP_VARTYPE_STRING</code>. This argument can be null only if | |
39 /// <code>protocol_count</code> is 0. | |
40 /// @param[in] protocol_count The number of sub-protocols in | |
41 /// <code>protocols</code>. | |
42 /// | |
43 /// @return An int32_t containing an error code from | |
44 /// <code>pp_errors.h</code>. | |
45 /// See also <code>pp::WebSocket_Dev::Connect</code>. | |
46 int32_t Connect(const Var& url, const Var protocols[], | |
47 uint32_t protocol_count); | |
48 | |
49 /// Close() closes the specified WebSocket connection by specifying | |
50 /// <code>code</code> and <code>reason</code>. | |
51 /// | |
52 /// @param[in] code The WebSocket close code. Ignored if it is 0. | |
53 /// @param[in] reason A <code>Var</code> of string type which represents the | |
54 /// WebSocket close reason. Ignored if it is undefined type. | |
55 /// | |
56 /// @return An int32_t containing an error code from | |
57 /// <code>pp_errors.h</code>. | |
58 /// See also <code>pp::WebSocket_Dev::Close</code>. | |
59 int32_t Close(uint16_t code, const Var& reason); | |
60 | |
61 /// Send() sends a message to the WebSocket server. | |
62 /// | |
63 /// @param[in] data A message to send. The message is copied to internal | |
64 /// buffer. So caller can free <code>data</code> safely after returning | |
65 /// from the function. | |
66 /// | |
67 /// @return An int32_t containing an error code from | |
68 /// <code>pp_errors.h</code>. | |
69 /// See also <code>pp::WebSocket_Dev::SendMessage</code>. | |
70 int32_t Send(const Var& data); | |
71 | |
72 /// GetBufferedAmount() returns the number of bytes of text and binary | |
73 /// messages that have been queued for the WebSocket connection to send but | |
74 /// have not been transmitted to the network yet. | |
75 /// | |
76 /// @return Returns the number of bytes. | |
77 uint64_t GetBufferedAmount(); | |
78 | |
79 /// GetExtensions() returns the extensions selected by the server for the | |
80 /// specified WebSocket connection. | |
81 /// | |
82 /// @return Returns a <code>Var</code> of string type. If called before the | |
83 /// connection is established, its data is empty string. | |
84 /// Currently its data is always an empty string. | |
85 Var GetExtensions(); | |
86 | |
87 /// GetProtocol() returns the sub-protocol chosen by the server for the | |
88 /// specified WebSocket connection. | |
89 /// | |
90 /// @return Returns a <code>Var</code> of string type. If called before the | |
91 /// connection is established, it contains the empty string. | |
92 Var GetProtocol(); | |
93 | |
94 /// GetReadyState() returns the ready state of the specified WebSocket | |
95 /// connection. | |
96 /// | |
97 /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID_DEV</code> if called | |
98 /// before connect() is called. | |
99 PP_WebSocketReadyState_Dev GetReadyState(); | |
100 | |
101 /// GetURL() returns the URL associated with specified WebSocket connection. | |
102 /// | |
103 /// @return Returns a <code>Var</code> of string type. If called before the | |
104 /// connection is established, it contains the empty string. | |
105 Var GetURL(); | |
106 | |
107 /// OnOpen() is invoked when the connection is established by Connect(). | |
108 virtual void OnOpen() = 0; | |
109 | |
110 /// OnMessage() is invoked when a message is received. | |
111 virtual void OnMessage(const Var& message) = 0; | |
112 | |
113 /// OnError() is invoked if the user agent was required to fail the WebSocket | |
114 /// connection or the WebSocket connection is closed with prejudice. | |
115 /// OnClose() always follows OnError(). | |
116 virtual void OnError() = 0; | |
117 | |
118 /// OnClose() is invoked when the connection is closed by errors or Close(). | |
119 virtual void OnClose(bool wasClean, uint16_t code, const Var& reason) = 0; | |
120 | |
121 private: | |
122 class Implement; | |
123 Implement* impl_; | |
124 }; | |
125 | |
126 } // namespace helper | |
127 | |
128 } // namespace pp | |
129 | |
130 #endif // PPAPI_CPP_HELPER_DEV_WEBSOCKET_API_DEV_H_ | |
OLD | NEW |