OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO(yzshen): See the comment in corresponding .h file. | |
6 | |
7 #include "ppapi/cpp/private/flash_tcp_socket.h" | 5 #include "ppapi/cpp/private/flash_tcp_socket.h" |
8 | 6 |
9 #include "ppapi/c/pp_bool.h" | 7 #include "ppapi/c/pp_bool.h" |
10 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
12 #include "ppapi/cpp/instance.h" | 10 #include "ppapi/cpp/instance.h" |
13 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
14 #include "ppapi/cpp/module_impl.h" | 12 #include "ppapi/cpp/module_impl.h" |
15 | 13 |
16 namespace pp { | 14 namespace pp { |
17 | 15 |
18 namespace { | 16 namespace { |
19 | 17 |
20 template <> const char* interface_name<PPB_Flash_TCPSocket>() { | 18 template <> const char* interface_name<PPB_Flash_TCPSocket>() { |
21 return PPB_FLASH_TCPSOCKET_INTERFACE; | 19 return PPB_FLASH_TCPSOCKET_INTERFACE; |
22 } | 20 } |
23 | 21 |
24 } // namespace | 22 } // namespace |
25 | 23 |
26 namespace flash { | 24 namespace flash { |
27 | 25 |
28 TCPSocket::TCPSocket(Instance* instance) { | 26 TCPSocket::TCPSocket(Instance* instance) { |
29 if (has_interface<PPB_Flash_TCPSocket>() && instance) { | 27 if (has_interface<PPB_Flash_TCPSocket>() && instance) { |
30 PassRefFromConstructor(get_interface<PPB_Flash_TCPSocket>()->Create( | 28 PassRefFromConstructor(get_interface<PPB_Flash_TCPSocket>()->Create( |
31 instance->pp_instance())); | 29 instance->pp_instance())); |
32 } | 30 } |
33 } | 31 } |
34 | 32 |
| 33 // static |
| 34 bool TCPSocket::IsAvailable() { |
| 35 return has_interface<PPB_Flash_TCPSocket>(); |
| 36 } |
| 37 |
35 int32_t TCPSocket::Connect(const char* host, | 38 int32_t TCPSocket::Connect(const char* host, |
36 uint16_t port, | 39 uint16_t port, |
37 const CompletionCallback& callback) { | 40 const CompletionCallback& callback) { |
38 if (!has_interface<PPB_Flash_TCPSocket>()) | 41 if (!has_interface<PPB_Flash_TCPSocket>()) |
39 return callback.MayForce(PP_ERROR_NOINTERFACE); | 42 return callback.MayForce(PP_ERROR_NOINTERFACE); |
40 return get_interface<PPB_Flash_TCPSocket>()->Connect( | 43 return get_interface<PPB_Flash_TCPSocket>()->Connect( |
41 pp_resource(), host, port, callback.pp_completion_callback()); | 44 pp_resource(), host, port, callback.pp_completion_callback()); |
42 } | 45 } |
43 | 46 |
44 int32_t TCPSocket::ConnectWithNetAddress(const PP_NetAddress_Private* addr, | 47 int32_t TCPSocket::ConnectWithNetAddress(const PP_NetAddress_Private* addr, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 98 } |
96 | 99 |
97 void TCPSocket::Disconnect() { | 100 void TCPSocket::Disconnect() { |
98 if (!has_interface<PPB_Flash_TCPSocket>()) | 101 if (!has_interface<PPB_Flash_TCPSocket>()) |
99 return; | 102 return; |
100 return get_interface<PPB_Flash_TCPSocket>()->Disconnect(pp_resource()); | 103 return get_interface<PPB_Flash_TCPSocket>()->Disconnect(pp_resource()); |
101 } | 104 } |
102 | 105 |
103 } // namespace flash | 106 } // namespace flash |
104 } // namespace pp | 107 } // namespace pp |
OLD | NEW |