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 #include "ppapi/cpp/private/flash_tcp_socket.h" | |
6 | |
7 #include "ppapi/c/pp_bool.h" | |
8 #include "ppapi/c/pp_errors.h" | |
9 #include "ppapi/cpp/completion_callback.h" | |
10 #include "ppapi/cpp/instance.h" | |
11 #include "ppapi/cpp/module.h" | |
12 #include "ppapi/cpp/module_impl.h" | |
13 | |
14 namespace pp { | |
15 | |
16 namespace { | |
17 | |
18 template <> const char* interface_name<PPB_Flash_TCPSocket>() { | |
19 return PPB_FLASH_TCPSOCKET_INTERFACE; | |
20 } | |
21 | |
22 } // namespace | |
23 | |
24 namespace flash { | |
25 | |
26 TCPSocket::TCPSocket(Instance* instance) { | |
27 if (has_interface<PPB_Flash_TCPSocket>() && instance) { | |
28 PassRefFromConstructor(get_interface<PPB_Flash_TCPSocket>()->Create( | |
29 instance->pp_instance())); | |
30 } | |
31 } | |
32 | |
33 // static | |
34 bool TCPSocket::IsAvailable() { | |
35 return has_interface<PPB_Flash_TCPSocket>(); | |
36 } | |
37 | |
38 int32_t TCPSocket::Connect(const char* host, | |
39 uint16_t port, | |
40 const CompletionCallback& callback) { | |
41 if (!has_interface<PPB_Flash_TCPSocket>()) | |
42 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
43 return get_interface<PPB_Flash_TCPSocket>()->Connect( | |
44 pp_resource(), host, port, callback.pp_completion_callback()); | |
45 } | |
46 | |
47 int32_t TCPSocket::ConnectWithNetAddress(const PP_NetAddress_Private* addr, | |
48 const CompletionCallback& callback) { | |
49 if (!has_interface<PPB_Flash_TCPSocket>()) | |
50 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
51 return get_interface<PPB_Flash_TCPSocket>()->ConnectWithNetAddress( | |
52 pp_resource(), addr, callback.pp_completion_callback()); | |
53 } | |
54 | |
55 bool TCPSocket::GetLocalAddress(PP_NetAddress_Private* local_addr) { | |
56 if (!has_interface<PPB_Flash_TCPSocket>()) | |
57 return false; | |
58 | |
59 PP_Bool result = get_interface<PPB_Flash_TCPSocket>()->GetLocalAddress( | |
60 pp_resource(), local_addr); | |
61 return PP_ToBool(result); | |
62 } | |
63 | |
64 bool TCPSocket::GetRemoteAddress(PP_NetAddress_Private* remote_addr) { | |
65 if (!has_interface<PPB_Flash_TCPSocket>()) | |
66 return false; | |
67 PP_Bool result = get_interface<PPB_Flash_TCPSocket>()->GetRemoteAddress( | |
68 pp_resource(), remote_addr); | |
69 return PP_ToBool(result); | |
70 } | |
71 | |
72 int32_t TCPSocket::SSLHandshake(const char* server_name, | |
73 uint16_t server_port, | |
74 const CompletionCallback& callback) { | |
75 if (!has_interface<PPB_Flash_TCPSocket>()) | |
76 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
77 return get_interface<PPB_Flash_TCPSocket>()->SSLHandshake( | |
78 pp_resource(), server_name, server_port, | |
79 callback.pp_completion_callback()); | |
80 } | |
81 | |
82 int32_t TCPSocket::Read(char* buffer, | |
83 int32_t bytes_to_read, | |
84 const CompletionCallback& callback) { | |
85 if (!has_interface<PPB_Flash_TCPSocket>()) | |
86 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
87 return get_interface<PPB_Flash_TCPSocket>()->Read( | |
88 pp_resource(), buffer, bytes_to_read, callback.pp_completion_callback()); | |
89 } | |
90 | |
91 int32_t TCPSocket::Write(const char* buffer, | |
92 int32_t bytes_to_write, | |
93 const CompletionCallback& callback) { | |
94 if (!has_interface<PPB_Flash_TCPSocket>()) | |
95 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
96 return get_interface<PPB_Flash_TCPSocket>()->Write( | |
97 pp_resource(), buffer, bytes_to_write, callback.pp_completion_callback()); | |
98 } | |
99 | |
100 void TCPSocket::Disconnect() { | |
101 if (!has_interface<PPB_Flash_TCPSocket>()) | |
102 return; | |
103 return get_interface<PPB_Flash_TCPSocket>()->Disconnect(pp_resource()); | |
104 } | |
105 | |
106 } // namespace flash | |
107 } // namespace pp | |
OLD | NEW |