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_udp_socket_private.h"
8 #include "ppapi/shared_impl/tracked_callback.h"
9 #include "ppapi/thunk/enter.h"
10 #include "ppapi/thunk/ppb_udp_socket_private_api.h"
11 #include "ppapi/thunk/resource_creation_api.h"
12 #include "ppapi/thunk/thunk.h"
19 typedef EnterResource
<PPB_UDPSocket_Private_API
> EnterUDP
;
21 PP_Resource
Create(PP_Instance instance
) {
22 EnterResourceCreation
enter(instance
);
25 return enter
.functions()->CreateUDPSocketPrivate(instance
);
28 PP_Bool
IsUDPSocket(PP_Resource resource
) {
29 EnterUDP
enter(resource
, false);
30 return PP_FromBool(enter
.succeeded());
33 int32_t SetSocketFeature(PP_Resource udp_socket
,
34 PP_UDPSocketFeature_Private name
,
36 EnterUDP
enter(udp_socket
, true);
38 return PP_ERROR_BADRESOURCE
;
39 return enter
.object()->SetSocketFeature(name
, value
);
42 int32_t Bind(PP_Resource udp_socket
,
43 const PP_NetAddress_Private
*addr
,
44 PP_CompletionCallback callback
) {
45 EnterUDP
enter(udp_socket
, callback
, true);
47 return enter
.retval();
48 return enter
.SetResult(enter
.object()->Bind(addr
, enter
.callback()));
51 PP_Bool
GetBoundAddress(PP_Resource udp_socket
,
52 PP_NetAddress_Private
* addr
) {
53 EnterUDP
enter(udp_socket
, true);
56 return enter
.object()->GetBoundAddress(addr
);
59 int32_t RecvFrom(PP_Resource udp_socket
,
62 PP_CompletionCallback callback
) {
64 EnterUDP
enter(udp_socket
, callback
, false);
66 EnterUDP
enter(udp_socket
, callback
, true);
69 return enter
.retval();
70 return enter
.SetResult(enter
.object()->RecvFrom(buffer
, num_bytes
,
74 PP_Bool
GetRecvFromAddress(PP_Resource udp_socket
,
75 PP_NetAddress_Private
* addr
) {
76 EnterUDP
enter(udp_socket
, true);
79 return enter
.object()->GetRecvFromAddress(addr
);
82 int32_t SendTo(PP_Resource udp_socket
,
85 const PP_NetAddress_Private
* addr
,
86 PP_CompletionCallback callback
) {
87 EnterUDP
enter(udp_socket
, callback
, true);
89 return enter
.retval();
90 return enter
.SetResult(enter
.object()->SendTo(buffer
, num_bytes
, addr
,
94 void Close(PP_Resource udp_socket
) {
95 EnterUDP
enter(udp_socket
, true);
96 if (enter
.succeeded())
97 enter
.object()->Close();
100 const PPB_UDPSocket_Private_0_2 g_ppb_udp_socket_thunk_0_2
= {
110 const PPB_UDPSocket_Private_0_3 g_ppb_udp_socket_thunk_0_3
= {
121 const PPB_UDPSocket_Private_0_4 g_ppb_udp_socket_thunk_0_4
= {
135 const PPB_UDPSocket_Private_0_2
* GetPPB_UDPSocket_Private_0_2_Thunk() {
136 return &g_ppb_udp_socket_thunk_0_2
;
139 const PPB_UDPSocket_Private_0_3
* GetPPB_UDPSocket_Private_0_3_Thunk() {
140 return &g_ppb_udp_socket_thunk_0_3
;
143 const PPB_UDPSocket_Private_0_4
* GetPPB_UDPSocket_Private_0_4_Thunk() {
144 return &g_ppb_udp_socket_thunk_0_4
;