Update V8 to version 4.7.47.
[chromium-blink-merge.git] / ppapi / thunk / ppb_udp_socket_thunk.cc
blobf0d3ceeb5faa8fca157b8bd65d9711b23a1bacff
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_udp_socket.idl modified Fri Mar 13 17:49:57 2015.
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_udp_socket.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppapi_thunk_export.h"
13 #include "ppapi/thunk/ppb_udp_socket_api.h"
15 namespace ppapi {
16 namespace thunk {
18 namespace {
20 PP_Resource Create(PP_Instance instance) {
21 VLOG(4) << "PPB_UDPSocket::Create()";
22 EnterResourceCreation enter(instance);
23 if (enter.failed())
24 return 0;
25 return enter.functions()->CreateUDPSocket(instance);
28 PP_Bool IsUDPSocket(PP_Resource resource) {
29 VLOG(4) << "PPB_UDPSocket::IsUDPSocket()";
30 EnterResource<PPB_UDPSocket_API> enter(resource, false);
31 return PP_FromBool(enter.succeeded());
34 int32_t Bind(PP_Resource udp_socket,
35 PP_Resource addr,
36 struct PP_CompletionCallback callback) {
37 VLOG(4) << "PPB_UDPSocket::Bind()";
38 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
39 if (enter.failed())
40 return enter.retval();
41 return enter.SetResult(enter.object()->Bind(addr, enter.callback()));
44 PP_Resource GetBoundAddress(PP_Resource udp_socket) {
45 VLOG(4) << "PPB_UDPSocket::GetBoundAddress()";
46 EnterResource<PPB_UDPSocket_API> enter(udp_socket, true);
47 if (enter.failed())
48 return 0;
49 return enter.object()->GetBoundAddress();
52 int32_t RecvFrom(PP_Resource udp_socket,
53 char* buffer,
54 int32_t num_bytes,
55 PP_Resource* addr,
56 struct PP_CompletionCallback callback) {
57 VLOG(4) << "PPB_UDPSocket::RecvFrom()";
58 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
59 if (enter.failed())
60 return enter.retval();
61 return enter.SetResult(
62 enter.object()->RecvFrom(buffer, num_bytes, addr, enter.callback()));
65 int32_t SendTo(PP_Resource udp_socket,
66 const char* buffer,
67 int32_t num_bytes,
68 PP_Resource addr,
69 struct PP_CompletionCallback callback) {
70 VLOG(4) << "PPB_UDPSocket::SendTo()";
71 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
72 if (enter.failed())
73 return enter.retval();
74 return enter.SetResult(
75 enter.object()->SendTo(buffer, num_bytes, addr, enter.callback()));
78 void Close(PP_Resource udp_socket) {
79 VLOG(4) << "PPB_UDPSocket::Close()";
80 EnterResource<PPB_UDPSocket_API> enter(udp_socket, true);
81 if (enter.failed())
82 return;
83 enter.object()->Close();
86 int32_t SetOption_1_0(PP_Resource udp_socket,
87 PP_UDPSocket_Option name,
88 struct PP_Var value,
89 struct PP_CompletionCallback callback) {
90 VLOG(4) << "PPB_UDPSocket::SetOption_1_0()";
91 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
92 if (enter.failed())
93 return enter.retval();
94 return enter.SetResult(
95 enter.object()->SetOption1_0(name, value, enter.callback()));
98 int32_t SetOption_1_1(PP_Resource udp_socket,
99 PP_UDPSocket_Option name,
100 struct PP_Var value,
101 struct PP_CompletionCallback callback) {
102 VLOG(4) << "PPB_UDPSocket::SetOption_1_1()";
103 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
104 if (enter.failed())
105 return enter.retval();
106 return enter.SetResult(
107 enter.object()->SetOption1_1(name, value, enter.callback()));
110 int32_t SetOption(PP_Resource udp_socket,
111 PP_UDPSocket_Option name,
112 struct PP_Var value,
113 struct PP_CompletionCallback callback) {
114 VLOG(4) << "PPB_UDPSocket::SetOption()";
115 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
116 if (enter.failed())
117 return enter.retval();
118 return enter.SetResult(
119 enter.object()->SetOption(name, value, enter.callback()));
122 int32_t JoinGroup(PP_Resource udp_socket,
123 PP_Resource group,
124 struct PP_CompletionCallback callback) {
125 VLOG(4) << "PPB_UDPSocket::JoinGroup()";
126 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
127 if (enter.failed())
128 return enter.retval();
129 return enter.SetResult(enter.object()->JoinGroup(group, enter.callback()));
132 int32_t LeaveGroup(PP_Resource udp_socket,
133 PP_Resource group,
134 struct PP_CompletionCallback callback) {
135 VLOG(4) << "PPB_UDPSocket::LeaveGroup()";
136 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
137 if (enter.failed())
138 return enter.retval();
139 return enter.SetResult(enter.object()->LeaveGroup(group, enter.callback()));
142 const PPB_UDPSocket_1_0 g_ppb_udpsocket_thunk_1_0 = {&Create,
143 &IsUDPSocket,
144 &Bind,
145 &GetBoundAddress,
146 &RecvFrom,
147 &SendTo,
148 &Close,
149 &SetOption_1_0};
151 const PPB_UDPSocket_1_1 g_ppb_udpsocket_thunk_1_1 = {&Create,
152 &IsUDPSocket,
153 &Bind,
154 &GetBoundAddress,
155 &RecvFrom,
156 &SendTo,
157 &Close,
158 &SetOption_1_1};
160 const PPB_UDPSocket_1_2 g_ppb_udpsocket_thunk_1_2 = {&Create,
161 &IsUDPSocket,
162 &Bind,
163 &GetBoundAddress,
164 &RecvFrom,
165 &SendTo,
166 &Close,
167 &SetOption,
168 &JoinGroup,
169 &LeaveGroup};
171 } // namespace
173 PPAPI_THUNK_EXPORT const PPB_UDPSocket_1_0* GetPPB_UDPSocket_1_0_Thunk() {
174 return &g_ppb_udpsocket_thunk_1_0;
177 PPAPI_THUNK_EXPORT const PPB_UDPSocket_1_1* GetPPB_UDPSocket_1_1_Thunk() {
178 return &g_ppb_udpsocket_thunk_1_1;
181 PPAPI_THUNK_EXPORT const PPB_UDPSocket_1_2* GetPPB_UDPSocket_1_2_Thunk() {
182 return &g_ppb_udpsocket_thunk_1_2;
185 } // namespace thunk
186 } // namespace ppapi