blob: a4936667d3c38bdccdf83dc520edb18d3600995c [file] [log] [blame]
[email protected]256513872012-01-05 15:41:521// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7813eb02011-09-26 22:12:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/c/pp_completion_callback.h"
6#include "ppapi/c/pp_errors.h"
[email protected]fb575bc2011-11-16 07:06:247#include "ppapi/c/private/ppb_udp_socket_private.h"
[email protected]aed96532012-06-23 14:27:428#include "ppapi/shared_impl/tracked_callback.h"
[email protected]7813eb02011-09-26 22:12:569#include "ppapi/thunk/enter.h"
[email protected]fb575bc2011-11-16 07:06:2410#include "ppapi/thunk/ppb_udp_socket_private_api.h"
[email protected]7813eb02011-09-26 22:12:5611#include "ppapi/thunk/resource_creation_api.h"
12#include "ppapi/thunk/thunk.h"
13
14namespace ppapi {
15namespace thunk {
16
17namespace {
18
[email protected]1bea0d22012-02-05 03:07:2919typedef EnterResource<PPB_UDPSocket_Private_API> EnterUDP;
20
[email protected]7813eb02011-09-26 22:12:5621PP_Resource Create(PP_Instance instance) {
[email protected]4f2006122012-04-30 05:13:1722 EnterResourceCreation enter(instance);
[email protected]7813eb02011-09-26 22:12:5623 if (enter.failed())
24 return 0;
[email protected]fb575bc2011-11-16 07:06:2425 return enter.functions()->CreateUDPSocketPrivate(instance);
[email protected]7813eb02011-09-26 22:12:5626}
27
[email protected]fb575bc2011-11-16 07:06:2428PP_Bool IsUDPSocket(PP_Resource resource) {
[email protected]1bea0d22012-02-05 03:07:2929 EnterUDP enter(resource, false);
[email protected]7813eb02011-09-26 22:12:5630 return PP_FromBool(enter.succeeded());
31}
32
[email protected]386020982013-03-29 19:11:1833int32_t SetSocketFeature(PP_Resource udp_socket,
34 PP_UDPSocketFeature_Private name,
35 PP_Var value) {
[email protected]0addda92012-08-31 08:55:2836 EnterUDP enter(udp_socket, true);
37 if (enter.failed())
38 return PP_ERROR_BADRESOURCE;
39 return enter.object()->SetSocketFeature(name, value);
40}
41
[email protected]7813eb02011-09-26 22:12:5642int32_t Bind(PP_Resource udp_socket,
[email protected]5a2b68f2011-11-10 00:00:4943 const PP_NetAddress_Private *addr,
[email protected]7813eb02011-09-26 22:12:5644 PP_CompletionCallback callback) {
[email protected]1bea0d22012-02-05 03:07:2945 EnterUDP enter(udp_socket, callback, true);
[email protected]7813eb02011-09-26 22:12:5646 if (enter.failed())
[email protected]1bea0d22012-02-05 03:07:2947 return enter.retval();
[email protected]aed96532012-06-23 14:27:4248 return enter.SetResult(enter.object()->Bind(addr, enter.callback()));
[email protected]7813eb02011-09-26 22:12:5649}
50
[email protected]669b2832012-02-21 23:37:1251PP_Bool GetBoundAddress(PP_Resource udp_socket,
52 PP_NetAddress_Private* addr) {
53 EnterUDP enter(udp_socket, true);
54 if (enter.failed())
55 return PP_FALSE;
56 return enter.object()->GetBoundAddress(addr);
57}
58
[email protected]386020982013-03-29 19:11:1859int32_t RecvFrom(PP_Resource udp_socket,
60 char* buffer,
61 int32_t num_bytes,
62 PP_CompletionCallback callback) {
[email protected]98df4beb2012-07-31 17:01:1363#ifdef NDEBUG
64 EnterUDP enter(udp_socket, callback, false);
65#else
[email protected]1bea0d22012-02-05 03:07:2966 EnterUDP enter(udp_socket, callback, true);
[email protected]98df4beb2012-07-31 17:01:1367#endif
[email protected]7813eb02011-09-26 22:12:5668 if (enter.failed())
[email protected]1bea0d22012-02-05 03:07:2969 return enter.retval();
[email protected]386020982013-03-29 19:11:1870 return enter.SetResult(enter.object()->RecvFrom(buffer, num_bytes,
71 enter.callback()));
[email protected]7813eb02011-09-26 22:12:5672}
73
74PP_Bool GetRecvFromAddress(PP_Resource udp_socket,
[email protected]5a2b68f2011-11-10 00:00:4975 PP_NetAddress_Private* addr) {
[email protected]1bea0d22012-02-05 03:07:2976 EnterUDP enter(udp_socket, true);
[email protected]7813eb02011-09-26 22:12:5677 if (enter.failed())
78 return PP_FALSE;
79 return enter.object()->GetRecvFromAddress(addr);
80}
81
82int32_t SendTo(PP_Resource udp_socket,
83 const char* buffer,
84 int32_t num_bytes,
[email protected]5a2b68f2011-11-10 00:00:4985 const PP_NetAddress_Private* addr,
[email protected]7813eb02011-09-26 22:12:5686 PP_CompletionCallback callback) {
[email protected]1bea0d22012-02-05 03:07:2987 EnterUDP enter(udp_socket, callback, true);
[email protected]7813eb02011-09-26 22:12:5688 if (enter.failed())
[email protected]1bea0d22012-02-05 03:07:2989 return enter.retval();
90 return enter.SetResult(enter.object()->SendTo(buffer, num_bytes, addr,
[email protected]aed96532012-06-23 14:27:4291 enter.callback()));
[email protected]7813eb02011-09-26 22:12:5692}
93
94void Close(PP_Resource udp_socket) {
[email protected]1bea0d22012-02-05 03:07:2995 EnterUDP enter(udp_socket, true);
[email protected]7813eb02011-09-26 22:12:5696 if (enter.succeeded())
97 enter.object()->Close();
98}
99
[email protected]669b2832012-02-21 23:37:12100const PPB_UDPSocket_Private_0_2 g_ppb_udp_socket_thunk_0_2 = {
[email protected]7813eb02011-09-26 22:12:56101 &Create,
[email protected]fb575bc2011-11-16 07:06:24102 &IsUDPSocket,
[email protected]7813eb02011-09-26 22:12:56103 &Bind,
[email protected]386020982013-03-29 19:11:18104 &RecvFrom,
[email protected]7813eb02011-09-26 22:12:56105 &GetRecvFromAddress,
106 &SendTo,
107 &Close
108};
109
[email protected]669b2832012-02-21 23:37:12110const PPB_UDPSocket_Private_0_3 g_ppb_udp_socket_thunk_0_3 = {
111 &Create,
112 &IsUDPSocket,
113 &Bind,
114 &GetBoundAddress,
[email protected]386020982013-03-29 19:11:18115 &RecvFrom,
[email protected]669b2832012-02-21 23:37:12116 &GetRecvFromAddress,
117 &SendTo,
118 &Close
119};
120
[email protected]0addda92012-08-31 08:55:28121const PPB_UDPSocket_Private_0_4 g_ppb_udp_socket_thunk_0_4 = {
122 &Create,
123 &IsUDPSocket,
[email protected]386020982013-03-29 19:11:18124 &SetSocketFeature,
[email protected]0addda92012-08-31 08:55:28125 &Bind,
126 &GetBoundAddress,
[email protected]386020982013-03-29 19:11:18127 &RecvFrom,
[email protected]0addda92012-08-31 08:55:28128 &GetRecvFromAddress,
129 &SendTo,
130 &Close
131};
132
[email protected]7813eb02011-09-26 22:12:56133} // namespace
134
[email protected]256513872012-01-05 15:41:52135const PPB_UDPSocket_Private_0_2* GetPPB_UDPSocket_Private_0_2_Thunk() {
[email protected]669b2832012-02-21 23:37:12136 return &g_ppb_udp_socket_thunk_0_2;
137}
138
139const PPB_UDPSocket_Private_0_3* GetPPB_UDPSocket_Private_0_3_Thunk() {
140 return &g_ppb_udp_socket_thunk_0_3;
[email protected]7813eb02011-09-26 22:12:56141}
142
[email protected]0addda92012-08-31 08:55:28143const PPB_UDPSocket_Private_0_4* GetPPB_UDPSocket_Private_0_4_Thunk() {
144 return &g_ppb_udp_socket_thunk_0_4;
145}
146
[email protected]7813eb02011-09-26 22:12:56147} // namespace thunk
148} // namespace ppapi