cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / thunk / ppb_tcp_socket_private_thunk.cc
blob928f07381c8f7d491b37ebbf8e808dfcae1651ef
1 // Copyright (c) 2012 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.
5 #include "ppapi/c/pp_completion_callback.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "ppapi/c/private/ppb_tcp_socket_private.h"
8 #include "ppapi/shared_impl/tracked_callback.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/thunk.h"
11 #include "ppapi/thunk/ppb_tcp_socket_private_api.h"
12 #include "ppapi/thunk/resource_creation_api.h"
14 namespace ppapi {
15 namespace thunk {
17 namespace {
19 typedef EnterResource<PPB_TCPSocket_Private_API> EnterTCP;
21 PP_Resource Create(PP_Instance instance) {
22 EnterResourceCreation enter(instance);
23 if (enter.failed())
24 return 0;
25 return enter.functions()->CreateTCPSocketPrivate(instance);
28 PP_Bool IsTCPSocket(PP_Resource resource) {
29 EnterTCP enter(resource, false);
30 return PP_FromBool(enter.succeeded());
33 int32_t Connect(PP_Resource tcp_socket,
34 const char* host,
35 uint16_t port,
36 PP_CompletionCallback callback) {
37 EnterTCP enter(tcp_socket, callback, true);
38 if (enter.failed())
39 return enter.retval();
40 return enter.SetResult(enter.object()->Connect(host, port, enter.callback()));
43 int32_t ConnectWithNetAddress(PP_Resource tcp_socket,
44 const PP_NetAddress_Private* addr,
45 PP_CompletionCallback callback) {
46 EnterTCP enter(tcp_socket, callback, true);
47 if (enter.failed())
48 return enter.retval();
49 return enter.SetResult(
50 enter.object()->ConnectWithNetAddress(addr, enter.callback()));
53 PP_Bool GetLocalAddress(PP_Resource tcp_socket,
54 PP_NetAddress_Private* local_addr) {
55 EnterTCP enter(tcp_socket, true);
56 if (enter.failed())
57 return PP_FALSE;
58 return enter.object()->GetLocalAddress(local_addr);
61 PP_Bool GetRemoteAddress(PP_Resource tcp_socket,
62 PP_NetAddress_Private* remote_addr) {
63 EnterTCP enter(tcp_socket, true);
64 if (enter.failed())
65 return PP_FALSE;
66 return enter.object()->GetRemoteAddress(remote_addr);
69 int32_t SSLHandshake(PP_Resource tcp_socket,
70 const char* server_name,
71 uint16_t server_port,
72 PP_CompletionCallback callback) {
73 EnterTCP enter(tcp_socket, callback, true);
74 if (enter.failed())
75 return enter.retval();
76 return enter.SetResult(enter.object()->SSLHandshake(server_name, server_port,
77 enter.callback()));
80 PP_Resource GetServerCertificate(PP_Resource tcp_socket) {
81 EnterTCP enter(tcp_socket, true);
82 if (enter.failed())
83 return 0;
84 return enter.object()->GetServerCertificate();
87 PP_Bool AddChainBuildingCertificate(PP_Resource tcp_socket,
88 PP_Resource certificate,
89 PP_Bool trusted) {
90 EnterTCP enter(tcp_socket, true);
91 if (enter.failed())
92 return PP_FALSE;
93 return enter.object()->AddChainBuildingCertificate(certificate, trusted);
96 int32_t Read(PP_Resource tcp_socket,
97 char* buffer,
98 int32_t bytes_to_read,
99 PP_CompletionCallback callback) {
100 EnterTCP enter(tcp_socket, callback, true);
101 if (enter.failed())
102 return enter.retval();
103 return enter.SetResult(enter.object()->Read(buffer, bytes_to_read,
104 enter.callback()));
107 int32_t Write(PP_Resource tcp_socket,
108 const char* buffer,
109 int32_t bytes_to_write,
110 PP_CompletionCallback callback) {
111 EnterTCP enter(tcp_socket, callback, true);
112 if (enter.failed())
113 return enter.retval();
114 return enter.SetResult(enter.object()->Write(buffer, bytes_to_write,
115 enter.callback()));
118 void Disconnect(PP_Resource tcp_socket) {
119 EnterTCP enter(tcp_socket, true);
120 if (enter.succeeded())
121 enter.object()->Disconnect();
124 int32_t SetOption(PP_Resource tcp_socket,
125 PP_TCPSocketOption_Private name,
126 PP_Var value,
127 PP_CompletionCallback callback) {
128 EnterTCP enter(tcp_socket, callback, true);
129 if (enter.failed())
130 return enter.retval();
131 return enter.SetResult(
132 enter.object()->SetOption(name, value, enter.callback()));
135 const PPB_TCPSocket_Private_0_3 g_ppb_tcp_socket_thunk_0_3 = {
136 &Create,
137 &IsTCPSocket,
138 &Connect,
139 &ConnectWithNetAddress,
140 &GetLocalAddress,
141 &GetRemoteAddress,
142 &SSLHandshake,
143 &Read,
144 &Write,
145 &Disconnect
148 const PPB_TCPSocket_Private_0_4 g_ppb_tcp_socket_thunk_0_4 = {
149 &Create,
150 &IsTCPSocket,
151 &Connect,
152 &ConnectWithNetAddress,
153 &GetLocalAddress,
154 &GetRemoteAddress,
155 &SSLHandshake,
156 &GetServerCertificate,
157 &AddChainBuildingCertificate,
158 &Read,
159 &Write,
160 &Disconnect
163 const PPB_TCPSocket_Private_0_5 g_ppb_tcp_socket_thunk_0_5 = {
164 &Create,
165 &IsTCPSocket,
166 &Connect,
167 &ConnectWithNetAddress,
168 &GetLocalAddress,
169 &GetRemoteAddress,
170 &SSLHandshake,
171 &GetServerCertificate,
172 &AddChainBuildingCertificate,
173 &Read,
174 &Write,
175 &Disconnect,
176 &SetOption
179 } // namespace
181 const PPB_TCPSocket_Private_0_3* GetPPB_TCPSocket_Private_0_3_Thunk() {
182 return &g_ppb_tcp_socket_thunk_0_3;
185 const PPB_TCPSocket_Private_0_4* GetPPB_TCPSocket_Private_0_4_Thunk() {
186 return &g_ppb_tcp_socket_thunk_0_4;
189 const PPB_TCPSocket_Private_0_5* GetPPB_TCPSocket_Private_0_5_Thunk() {
190 return &g_ppb_tcp_socket_thunk_0_5;
193 } // namespace thunk
194 } // namespace ppapi