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 // From ppb_udp_socket.idl modified Tue Aug 20 08:13:36 2013.
6
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"
14
15 namespace ppapi {
16 namespace thunk {
17
18 namespace {
19
Create(PP_Instance instance)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);
26 }
27
IsUDPSocket(PP_Resource resource)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());
32 }
33
Bind(PP_Resource udp_socket,PP_Resource addr,struct PP_CompletionCallback callback)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()));
42 }
43
GetBoundAddress(PP_Resource udp_socket)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();
50 }
51
RecvFrom(PP_Resource udp_socket,char * buffer,int32_t num_bytes,PP_Resource * addr,struct PP_CompletionCallback callback)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(enter.object()->RecvFrom(buffer,
62 num_bytes,
63 addr,
64 enter.callback()));
65 }
66
SendTo(PP_Resource udp_socket,const char * buffer,int32_t num_bytes,PP_Resource addr,struct PP_CompletionCallback callback)67 int32_t SendTo(PP_Resource udp_socket,
68 const char* buffer,
69 int32_t num_bytes,
70 PP_Resource addr,
71 struct PP_CompletionCallback callback) {
72 VLOG(4) << "PPB_UDPSocket::SendTo()";
73 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
74 if (enter.failed())
75 return enter.retval();
76 return enter.SetResult(enter.object()->SendTo(buffer,
77 num_bytes,
78 addr,
79 enter.callback()));
80 }
81
Close(PP_Resource udp_socket)82 void Close(PP_Resource udp_socket) {
83 VLOG(4) << "PPB_UDPSocket::Close()";
84 EnterResource<PPB_UDPSocket_API> enter(udp_socket, true);
85 if (enter.failed())
86 return;
87 enter.object()->Close();
88 }
89
SetOption(PP_Resource udp_socket,PP_UDPSocket_Option name,struct PP_Var value,struct PP_CompletionCallback callback)90 int32_t SetOption(PP_Resource udp_socket,
91 PP_UDPSocket_Option name,
92 struct PP_Var value,
93 struct PP_CompletionCallback callback) {
94 VLOG(4) << "PPB_UDPSocket::SetOption()";
95 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
96 if (enter.failed())
97 return enter.retval();
98 return enter.SetResult(enter.object()->SetOption(name,
99 value,
100 enter.callback()));
101 }
102
103 const PPB_UDPSocket_1_0 g_ppb_udpsocket_thunk_1_0 = {
104 &Create,
105 &IsUDPSocket,
106 &Bind,
107 &GetBoundAddress,
108 &RecvFrom,
109 &SendTo,
110 &Close,
111 &SetOption
112 };
113
114 } // namespace
115
GetPPB_UDPSocket_1_0_Thunk()116 PPAPI_THUNK_EXPORT const PPB_UDPSocket_1_0* GetPPB_UDPSocket_1_0_Thunk() {
117 return &g_ppb_udpsocket_thunk_1_0;
118 }
119
120 } // namespace thunk
121 } // namespace ppapi
122