cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / thunk / ppb_tcp_socket_thunk.cc
blobff612fb54dbe7310f586e665102c515e7bace35f
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.
5 // From ppb_tcp_socket.idl modified Thu Jun 20 16:36:53 2013.
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_tcp_socket.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_instance_api.h"
13 #include "ppapi/thunk/ppb_tcp_socket_api.h"
14 #include "ppapi/thunk/resource_creation_api.h"
15 #include "ppapi/thunk/thunk.h"
17 namespace ppapi {
18 namespace thunk {
20 namespace {
22 PP_Resource Create(PP_Instance instance) {
23 VLOG(4) << "PPB_TCPSocket::Create()";
24 EnterResourceCreation enter(instance);
25 if (enter.failed())
26 return 0;
27 return enter.functions()->CreateTCPSocket(instance);
30 PP_Bool IsTCPSocket(PP_Resource resource) {
31 VLOG(4) << "PPB_TCPSocket::IsTCPSocket()";
32 EnterResource<PPB_TCPSocket_API> enter(resource, false);
33 return PP_FromBool(enter.succeeded());
36 int32_t Connect(PP_Resource tcp_socket,
37 PP_Resource addr,
38 struct PP_CompletionCallback callback) {
39 VLOG(4) << "PPB_TCPSocket::Connect()";
40 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, callback, true);
41 if (enter.failed())
42 return enter.retval();
43 return enter.SetResult(enter.object()->Connect(addr, enter.callback()));
46 PP_Resource GetLocalAddress(PP_Resource tcp_socket) {
47 VLOG(4) << "PPB_TCPSocket::GetLocalAddress()";
48 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, true);
49 if (enter.failed())
50 return 0;
51 return enter.object()->GetLocalAddress();
54 PP_Resource GetRemoteAddress(PP_Resource tcp_socket) {
55 VLOG(4) << "PPB_TCPSocket::GetRemoteAddress()";
56 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, true);
57 if (enter.failed())
58 return 0;
59 return enter.object()->GetRemoteAddress();
62 int32_t Read(PP_Resource tcp_socket,
63 char* buffer,
64 int32_t bytes_to_read,
65 struct PP_CompletionCallback callback) {
66 VLOG(4) << "PPB_TCPSocket::Read()";
67 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, callback, true);
68 if (enter.failed())
69 return enter.retval();
70 return enter.SetResult(enter.object()->Read(buffer,
71 bytes_to_read,
72 enter.callback()));
75 int32_t Write(PP_Resource tcp_socket,
76 const char* buffer,
77 int32_t bytes_to_write,
78 struct PP_CompletionCallback callback) {
79 VLOG(4) << "PPB_TCPSocket::Write()";
80 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, callback, true);
81 if (enter.failed())
82 return enter.retval();
83 return enter.SetResult(enter.object()->Write(buffer,
84 bytes_to_write,
85 enter.callback()));
88 void Close(PP_Resource tcp_socket) {
89 VLOG(4) << "PPB_TCPSocket::Close()";
90 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, true);
91 if (enter.failed())
92 return;
93 enter.object()->Close();
96 int32_t SetOption(PP_Resource tcp_socket,
97 PP_TCPSocket_Option name,
98 struct PP_Var value,
99 struct PP_CompletionCallback callback) {
100 VLOG(4) << "PPB_TCPSocket::SetOption()";
101 EnterResource<PPB_TCPSocket_API> enter(tcp_socket, callback, true);
102 if (enter.failed())
103 return enter.retval();
104 return enter.SetResult(enter.object()->SetOption(name,
105 value,
106 enter.callback()));
109 const PPB_TCPSocket_1_0 g_ppb_tcpsocket_thunk_1_0 = {
110 &Create,
111 &IsTCPSocket,
112 &Connect,
113 &GetLocalAddress,
114 &GetRemoteAddress,
115 &Read,
116 &Write,
117 &Close,
118 &SetOption
121 } // namespace
123 const PPB_TCPSocket_1_0* GetPPB_TCPSocket_1_0_Thunk() {
124 return &g_ppb_tcpsocket_thunk_1_0;
127 } // namespace thunk
128 } // namespace ppapi