[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 2 | // 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] | fb575bc | 2011-11-16 07:06:24 | [diff] [blame] | 7 | #include "ppapi/c/private/ppb_udp_socket_private.h" |
[email protected] | aed9653 | 2012-06-23 14:27:42 | [diff] [blame] | 8 | #include "ppapi/shared_impl/tracked_callback.h" |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 9 | #include "ppapi/thunk/enter.h" |
[email protected] | fb575bc | 2011-11-16 07:06:24 | [diff] [blame] | 10 | #include "ppapi/thunk/ppb_udp_socket_private_api.h" |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 11 | #include "ppapi/thunk/resource_creation_api.h" |
| 12 | #include "ppapi/thunk/thunk.h" |
| 13 | |
| 14 | namespace ppapi { |
| 15 | namespace thunk { |
| 16 | |
| 17 | namespace { |
| 18 | |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 19 | typedef EnterResource<PPB_UDPSocket_Private_API> EnterUDP; |
| 20 | |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 21 | PP_Resource Create(PP_Instance instance) { |
[email protected] | 4f200612 | 2012-04-30 05:13:17 | [diff] [blame] | 22 | EnterResourceCreation enter(instance); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 23 | if (enter.failed()) |
| 24 | return 0; |
[email protected] | fb575bc | 2011-11-16 07:06:24 | [diff] [blame] | 25 | return enter.functions()->CreateUDPSocketPrivate(instance); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | fb575bc | 2011-11-16 07:06:24 | [diff] [blame] | 28 | PP_Bool IsUDPSocket(PP_Resource resource) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 29 | EnterUDP enter(resource, false); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 30 | return PP_FromBool(enter.succeeded()); |
| 31 | } |
| 32 | |
[email protected] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 33 | int32_t SetSocketFeature(PP_Resource udp_socket, |
| 34 | PP_UDPSocketFeature_Private name, |
| 35 | PP_Var value) { |
[email protected] | 0addda9 | 2012-08-31 08:55:28 | [diff] [blame] | 36 | 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] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 42 | int32_t Bind(PP_Resource udp_socket, |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 43 | const PP_NetAddress_Private *addr, |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 44 | PP_CompletionCallback callback) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 45 | EnterUDP enter(udp_socket, callback, true); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 46 | if (enter.failed()) |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 47 | return enter.retval(); |
[email protected] | aed9653 | 2012-06-23 14:27:42 | [diff] [blame] | 48 | return enter.SetResult(enter.object()->Bind(addr, enter.callback())); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 49 | } |
| 50 | |
[email protected] | 669b283 | 2012-02-21 23:37:12 | [diff] [blame] | 51 | PP_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] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 59 | int32_t RecvFrom(PP_Resource udp_socket, |
| 60 | char* buffer, |
| 61 | int32_t num_bytes, |
| 62 | PP_CompletionCallback callback) { |
[email protected] | 98df4beb | 2012-07-31 17:01:13 | [diff] [blame] | 63 | #ifdef NDEBUG |
| 64 | EnterUDP enter(udp_socket, callback, false); |
| 65 | #else |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 66 | EnterUDP enter(udp_socket, callback, true); |
[email protected] | 98df4beb | 2012-07-31 17:01:13 | [diff] [blame] | 67 | #endif |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 68 | if (enter.failed()) |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 69 | return enter.retval(); |
[email protected] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 70 | return enter.SetResult(enter.object()->RecvFrom(buffer, num_bytes, |
| 71 | enter.callback())); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | PP_Bool GetRecvFromAddress(PP_Resource udp_socket, |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 75 | PP_NetAddress_Private* addr) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 76 | EnterUDP enter(udp_socket, true); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 77 | if (enter.failed()) |
| 78 | return PP_FALSE; |
| 79 | return enter.object()->GetRecvFromAddress(addr); |
| 80 | } |
| 81 | |
| 82 | int32_t SendTo(PP_Resource udp_socket, |
| 83 | const char* buffer, |
| 84 | int32_t num_bytes, |
[email protected] | 5a2b68f | 2011-11-10 00:00:49 | [diff] [blame] | 85 | const PP_NetAddress_Private* addr, |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 86 | PP_CompletionCallback callback) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 87 | EnterUDP enter(udp_socket, callback, true); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 88 | if (enter.failed()) |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 89 | return enter.retval(); |
| 90 | return enter.SetResult(enter.object()->SendTo(buffer, num_bytes, addr, |
[email protected] | aed9653 | 2012-06-23 14:27:42 | [diff] [blame] | 91 | enter.callback())); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void Close(PP_Resource udp_socket) { |
[email protected] | 1bea0d2 | 2012-02-05 03:07:29 | [diff] [blame] | 95 | EnterUDP enter(udp_socket, true); |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 96 | if (enter.succeeded()) |
| 97 | enter.object()->Close(); |
| 98 | } |
| 99 | |
[email protected] | 669b283 | 2012-02-21 23:37:12 | [diff] [blame] | 100 | const PPB_UDPSocket_Private_0_2 g_ppb_udp_socket_thunk_0_2 = { |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 101 | &Create, |
[email protected] | fb575bc | 2011-11-16 07:06:24 | [diff] [blame] | 102 | &IsUDPSocket, |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 103 | &Bind, |
[email protected] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 104 | &RecvFrom, |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 105 | &GetRecvFromAddress, |
| 106 | &SendTo, |
| 107 | &Close |
| 108 | }; |
| 109 | |
[email protected] | 669b283 | 2012-02-21 23:37:12 | [diff] [blame] | 110 | const PPB_UDPSocket_Private_0_3 g_ppb_udp_socket_thunk_0_3 = { |
| 111 | &Create, |
| 112 | &IsUDPSocket, |
| 113 | &Bind, |
| 114 | &GetBoundAddress, |
[email protected] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 115 | &RecvFrom, |
[email protected] | 669b283 | 2012-02-21 23:37:12 | [diff] [blame] | 116 | &GetRecvFromAddress, |
| 117 | &SendTo, |
| 118 | &Close |
| 119 | }; |
| 120 | |
[email protected] | 0addda9 | 2012-08-31 08:55:28 | [diff] [blame] | 121 | const PPB_UDPSocket_Private_0_4 g_ppb_udp_socket_thunk_0_4 = { |
| 122 | &Create, |
| 123 | &IsUDPSocket, |
[email protected] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 124 | &SetSocketFeature, |
[email protected] | 0addda9 | 2012-08-31 08:55:28 | [diff] [blame] | 125 | &Bind, |
| 126 | &GetBoundAddress, |
[email protected] | 38602098 | 2013-03-29 19:11:18 | [diff] [blame] | 127 | &RecvFrom, |
[email protected] | 0addda9 | 2012-08-31 08:55:28 | [diff] [blame] | 128 | &GetRecvFromAddress, |
| 129 | &SendTo, |
| 130 | &Close |
| 131 | }; |
| 132 | |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 133 | } // namespace |
| 134 | |
[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 135 | const PPB_UDPSocket_Private_0_2* GetPPB_UDPSocket_Private_0_2_Thunk() { |
[email protected] | 669b283 | 2012-02-21 23:37:12 | [diff] [blame] | 136 | return &g_ppb_udp_socket_thunk_0_2; |
| 137 | } |
| 138 | |
| 139 | const PPB_UDPSocket_Private_0_3* GetPPB_UDPSocket_Private_0_3_Thunk() { |
| 140 | return &g_ppb_udp_socket_thunk_0_3; |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 0addda9 | 2012-08-31 08:55:28 | [diff] [blame] | 143 | const PPB_UDPSocket_Private_0_4* GetPPB_UDPSocket_Private_0_4_Thunk() { |
| 144 | return &g_ppb_udp_socket_thunk_0_4; |
| 145 | } |
| 146 | |
[email protected] | 7813eb0 | 2011-09-26 22:12:56 | [diff] [blame] | 147 | } // namespace thunk |
| 148 | } // namespace ppapi |