OLD | NEW |
| (Empty) |
1 // Copyright 2013 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/dev/tcp_socket_dev.h" | |
6 | |
7 #include "ppapi/c/pp_errors.h" | |
8 #include "ppapi/cpp/completion_callback.h" | |
9 #include "ppapi/cpp/instance_handle.h" | |
10 #include "ppapi/cpp/module_impl.h" | |
11 | |
12 namespace pp { | |
13 | |
14 namespace { | |
15 | |
16 template <> const char* interface_name<PPB_TCPSocket_Dev_0_1>() { | |
17 return PPB_TCPSOCKET_DEV_INTERFACE_0_1; | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 TCPSocket_Dev::TCPSocket_Dev() { | |
23 } | |
24 | |
25 TCPSocket_Dev::TCPSocket_Dev(const InstanceHandle& instance) { | |
26 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
27 PassRefFromConstructor(get_interface<PPB_TCPSocket_Dev_0_1>()->Create( | |
28 instance.pp_instance())); | |
29 } | |
30 } | |
31 | |
32 TCPSocket_Dev::TCPSocket_Dev(PassRef, PP_Resource resource) | |
33 : Resource(PASS_REF, resource) { | |
34 } | |
35 | |
36 TCPSocket_Dev::TCPSocket_Dev(const TCPSocket_Dev& other) : Resource(other) { | |
37 } | |
38 | |
39 TCPSocket_Dev::~TCPSocket_Dev() { | |
40 } | |
41 | |
42 TCPSocket_Dev& TCPSocket_Dev::operator=(const TCPSocket_Dev& other) { | |
43 Resource::operator=(other); | |
44 return *this; | |
45 } | |
46 | |
47 // static | |
48 bool TCPSocket_Dev::IsAvailable() { | |
49 return has_interface<PPB_TCPSocket_Dev_0_1>(); | |
50 } | |
51 | |
52 int32_t TCPSocket_Dev::Connect(const NetAddress& addr, | |
53 const CompletionCallback& callback) { | |
54 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
55 return get_interface<PPB_TCPSocket_Dev_0_1>()->Connect( | |
56 pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); | |
57 } | |
58 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
59 } | |
60 | |
61 NetAddress TCPSocket_Dev::GetLocalAddress() const { | |
62 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
63 return NetAddress( | |
64 PASS_REF, | |
65 get_interface<PPB_TCPSocket_Dev_0_1>()->GetLocalAddress(pp_resource())); | |
66 } | |
67 return NetAddress(); | |
68 } | |
69 | |
70 NetAddress TCPSocket_Dev::GetRemoteAddress() const { | |
71 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
72 return NetAddress( | |
73 PASS_REF, | |
74 get_interface<PPB_TCPSocket_Dev_0_1>()->GetRemoteAddress( | |
75 pp_resource())); | |
76 } | |
77 return NetAddress(); | |
78 } | |
79 | |
80 int32_t TCPSocket_Dev::Read(char* buffer, | |
81 int32_t bytes_to_read, | |
82 const CompletionCallback& callback) { | |
83 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
84 return get_interface<PPB_TCPSocket_Dev_0_1>()->Read( | |
85 pp_resource(), buffer, bytes_to_read, | |
86 callback.pp_completion_callback()); | |
87 } | |
88 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
89 } | |
90 | |
91 int32_t TCPSocket_Dev::Write(const char* buffer, | |
92 int32_t bytes_to_write, | |
93 const CompletionCallback& callback) { | |
94 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
95 return get_interface<PPB_TCPSocket_Dev_0_1>()->Write( | |
96 pp_resource(), buffer, bytes_to_write, | |
97 callback.pp_completion_callback()); | |
98 } | |
99 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
100 } | |
101 | |
102 void TCPSocket_Dev::Close() { | |
103 if (has_interface<PPB_TCPSocket_Dev_0_1>()) | |
104 get_interface<PPB_TCPSocket_Dev_0_1>()->Close(pp_resource()); | |
105 } | |
106 | |
107 int32_t TCPSocket_Dev::SetOption(PP_TCPSocket_Option_Dev name, | |
108 const Var& value, | |
109 const CompletionCallback& callback) { | |
110 if (has_interface<PPB_TCPSocket_Dev_0_1>()) { | |
111 return get_interface<PPB_TCPSocket_Dev_0_1>()->SetOption( | |
112 pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); | |
113 } | |
114 return callback.MayForce(PP_ERROR_NOINTERFACE); | |
115 } | |
116 | |
117 } // namespace pp | |
OLD | NEW |