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. 4 5 #include "ppapi/c/pp_errors.h" 6 #include "ppapi/c/private/ppb_tcp_server_socket_private.h" 7 #include "ppapi/shared_impl/tracked_callback.h" 8 #include "ppapi/thunk/enter.h" 9 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h" 10 #include "ppapi/thunk/resource_creation_api.h" 11 #include "ppapi/thunk/thunk.h" 12 13 namespace ppapi { 14 namespace thunk { 15 16 namespace { 17 18 typedef EnterResource<PPB_TCPServerSocket_Private_API> EnterTCPServer; 19 20 PP_Resource Create(PP_Instance instance) { 21 EnterResourceCreation enter(instance); 22 if (enter.failed()) 23 return 0; 24 return enter.functions()->CreateTCPServerSocketPrivate(instance); 25 } 26 27 PP_Bool IsTCPServerSocket(PP_Resource resource) { 28 EnterTCPServer enter(resource, false); 29 return PP_FromBool(enter.succeeded()); 30 } 31 32 int32_t Listen(PP_Resource tcp_server_socket, 33 const PP_NetAddress_Private* addr, 34 int32_t backlog, 35 PP_CompletionCallback callback) { 36 EnterTCPServer enter(tcp_server_socket, callback, true); 37 if (enter.failed()) 38 return enter.retval(); 39 return enter.SetResult(enter.object()->Listen(addr, backlog, 40 enter.callback())); 41 } 42 43 int32_t Accept(PP_Resource tcp_server_socket, 44 PP_Resource* tcp_socket, 45 PP_CompletionCallback callback) { 46 EnterTCPServer enter(tcp_server_socket, callback, true); 47 if (enter.failed()) 48 return enter.retval(); 49 return enter.SetResult(enter.object()->Accept(tcp_socket, enter.callback())); 50 } 51 52 int32_t GetLocalAddress(PP_Resource tcp_server_socket, 53 PP_NetAddress_Private* addr) { 54 EnterTCPServer enter(tcp_server_socket, true); 55 if (enter.failed()) 56 return PP_ERROR_BADRESOURCE; 57 return enter.object()->GetLocalAddress(addr); 58 } 59 60 void StopListening(PP_Resource tcp_server_socket) { 61 EnterTCPServer enter(tcp_server_socket, true); 62 if (enter.succeeded()) 63 enter.object()->StopListening(); 64 } 65 66 const PPB_TCPServerSocket_Private_0_1 g_ppb_tcp_server_socket_thunk_0_1 = { 67 Create, 68 IsTCPServerSocket, 69 Listen, 70 Accept, 71 StopListening 72 }; 73 74 const PPB_TCPServerSocket_Private_0_2 g_ppb_tcp_server_socket_thunk_0_2 = { 75 Create, 76 IsTCPServerSocket, 77 Listen, 78 Accept, 79 GetLocalAddress, 80 StopListening, 81 }; 82 83 } // namespace 84 85 const PPB_TCPServerSocket_Private_0_1* 86 GetPPB_TCPServerSocket_Private_0_1_Thunk() { 87 return &g_ppb_tcp_server_socket_thunk_0_1; 88 } 89 90 const PPB_TCPServerSocket_Private_0_2* 91 GetPPB_TCPServerSocket_Private_0_2_Thunk() { 92 return &g_ppb_tcp_server_socket_thunk_0_2; 93 } 94 95 } // namespace thunk 96 } // namespace ppapi 97