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 Thu Jun 20 14:03:55 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/ppb_instance_api.h"
13 #include "ppapi/thunk/ppb_udp_socket_api.h"
14 #include "ppapi/thunk/resource_creation_api.h"
15 #include "ppapi/thunk/thunk.h"
16
17 namespace ppapi {
18 namespace thunk {
19
20 namespace {
21
Create(PP_Instance instance)22 PP_Resource Create(PP_Instance instance) {
23 VLOG(4) << "PPB_UDPSocket::Create()";
24 EnterResourceCreation enter(instance);
25 if (enter.failed())
26 return 0;
27 return enter.functions()->CreateUDPSocket(instance);
28 }
29
IsUDPSocket(PP_Resource resource)30 PP_Bool IsUDPSocket(PP_Resource resource) {
31 VLOG(4) << "PPB_UDPSocket::IsUDPSocket()";
32 EnterResource<PPB_UDPSocket_API> enter(resource, false);
33 return PP_FromBool(enter.succeeded());
34 }
35
Bind(PP_Resource udp_socket,PP_Resource addr,struct PP_CompletionCallback callback)36 int32_t Bind(PP_Resource udp_socket,
37 PP_Resource addr,
38 struct PP_CompletionCallback callback) {
39 VLOG(4) << "PPB_UDPSocket::Bind()";
40 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
41 if (enter.failed())
42 return enter.retval();
43 return enter.SetResult(enter.object()->Bind(addr, enter.callback()));
44 }
45
GetBoundAddress(PP_Resource udp_socket)46 PP_Resource GetBoundAddress(PP_Resource udp_socket) {
47 VLOG(4) << "PPB_UDPSocket::GetBoundAddress()";
48 EnterResource<PPB_UDPSocket_API> enter(udp_socket, true);
49 if (enter.failed())
50 return 0;
51 return enter.object()->GetBoundAddress();
52 }
53
RecvFrom(PP_Resource udp_socket,char * buffer,int32_t num_bytes,PP_Resource * addr,struct PP_CompletionCallback callback)54 int32_t RecvFrom(PP_Resource udp_socket,
55 char* buffer,
56 int32_t num_bytes,
57 PP_Resource* addr,
58 struct PP_CompletionCallback callback) {
59 VLOG(4) << "PPB_UDPSocket::RecvFrom()";
60 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
61 if (enter.failed())
62 return enter.retval();
63 return enter.SetResult(enter.object()->RecvFrom(buffer,
64 num_bytes,
65 addr,
66 enter.callback()));
67 }
68
SendTo(PP_Resource udp_socket,const char * buffer,int32_t num_bytes,PP_Resource addr,struct PP_CompletionCallback callback)69 int32_t SendTo(PP_Resource udp_socket,
70 const char* buffer,
71 int32_t num_bytes,
72 PP_Resource addr,
73 struct PP_CompletionCallback callback) {
74 VLOG(4) << "PPB_UDPSocket::SendTo()";
75 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
76 if (enter.failed())
77 return enter.retval();
78 return enter.SetResult(enter.object()->SendTo(buffer,
79 num_bytes,
80 addr,
81 enter.callback()));
82 }
83
Close(PP_Resource udp_socket)84 void Close(PP_Resource udp_socket) {
85 VLOG(4) << "PPB_UDPSocket::Close()";
86 EnterResource<PPB_UDPSocket_API> enter(udp_socket, true);
87 if (enter.failed())
88 return;
89 enter.object()->Close();
90 }
91
SetOption(PP_Resource udp_socket,PP_UDPSocket_Option name,struct PP_Var value,struct PP_CompletionCallback callback)92 int32_t SetOption(PP_Resource udp_socket,
93 PP_UDPSocket_Option name,
94 struct PP_Var value,
95 struct PP_CompletionCallback callback) {
96 VLOG(4) << "PPB_UDPSocket::SetOption()";
97 EnterResource<PPB_UDPSocket_API> enter(udp_socket, callback, true);
98 if (enter.failed())
99 return enter.retval();
100 return enter.SetResult(enter.object()->SetOption(name,
101 value,
102 enter.callback()));
103 }
104
105 const PPB_UDPSocket_1_0 g_ppb_udpsocket_thunk_1_0 = {
106 &Create,
107 &IsUDPSocket,
108 &Bind,
109 &GetBoundAddress,
110 &RecvFrom,
111 &SendTo,
112 &Close,
113 &SetOption
114 };
115
116 } // namespace
117
GetPPB_UDPSocket_1_0_Thunk()118 const PPB_UDPSocket_1_0* GetPPB_UDPSocket_1_0_Thunk() {
119 return &g_ppb_udpsocket_thunk_1_0;
120 }
121
122 } // namespace thunk
123 } // namespace ppapi
124