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_DEV_WEBSOCKET_DEV_H_ | |
6 #define PPAPI_CPP_DEV_WEBSOCKET_DEV_H_ | |
7 | |
8 #include "ppapi/c/dev/ppb_websocket_dev.h" | |
9 | |
10 /// @file | |
11 /// This file defines the WebSocket_Dev interface. | |
12 | |
13 namespace pp { | |
14 | |
15 class Var; | |
16 | |
17 /// The <code>WebSocket_Dev</code> class | |
18 /// A version that use virtual functions | |
19 class WebSocket_Dev : public Resource { | |
20 public: | |
21 WebSocket_Dev(); | |
22 virtual ~WebSocket_Dev(); | |
23 | |
24 int32_t Connect(const Var& url, const Var& protocols[], | |
25 uint32_t protocol_count); | |
26 int32_t Close(uint16_t code, const Var& reason); | |
27 int32_t Send(const Var& data); | |
28 | |
29 PP_WebSocketReadyState_Dev GetReadyState(); | |
30 uint64_t GetBufferedAmount(); | |
31 Var GetExtensions(); | |
32 Var GetProtocol(); | |
33 Var GetURL(); | |
34 | |
35 virtual void OnOpen() = 0; | |
36 virtual void OnMessage(Var message) = 0; | |
37 virtual void OnError() = 0; | |
38 virtual void OnClose(bool wasClean, uint16_t code, const Var& reason) = 0; | |
39 }; | |
40 | |
41 /// The <code>WebSocket_Dev</code> class | |
42 /// A version that use delegate. | |
43 class WebSocket_Dev : public Resource { | |
44 public: | |
45 class Delegate { | |
46 virtual void OnOpen(WebSocket_Dev* instance) = 0; | |
47 virtual void OnMessage(WebSocket_Dev* instance, Var message) = 0; | |
48 virtual void OnError(WebSocket_Dev* instance) = 0; | |
49 virtual void OnClose(WebSocket_Dev* instance, bool wasClean, uint16_t code, | |
50 const Var& reason) = 0; | |
51 }; | |
52 WebSocket_Dev(Delegate* delegate); | |
53 virtual ~WebSocket_Dev(); | |
54 | |
55 int32_t Connect(const Var& url, const Var& protocols[], | |
56 uint32_t protocol_count); | |
57 int32_t Close(uint16_t code, const Var& reason); | |
58 int32_t Send(const Var& data); | |
59 | |
60 PP_WebSocketReadyState_Dev GetReadyState(); | |
61 uint64_t GetBufferedAmount(); | |
62 Var GetExtensions(); | |
63 Var GetProtocol(); | |
64 Var GetURL(); | |
dmichael (off chromium)
2011/11/04 15:26:18
The delegate pattern does seem nice here. If there
Takashi Toyoshima
2011/11/07 08:35:57
OK, I see.
Actually, it seems to be difficult that
| |
65 }; | |
66 | |
67 } // namespace pp | |
68 | |
69 #endif // PPAPI_CPP_DEV_WEBSOCKET_DEV_H_ | |
OLD | NEW |