Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ppapi / thunk / ppb_tcp_server_socket_private_thunk.cc
bloba9fcb1412e0882dc817947d2335b2cd31e5accc5
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.
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"
13 namespace ppapi {
14 namespace thunk {
16 namespace {
18 typedef EnterResource<PPB_TCPServerSocket_Private_API> EnterTCPServer;
20 PP_Resource Create(PP_Instance instance) {
21 EnterResourceCreation enter(instance);
22 if (enter.failed())
23 return 0;
24 return enter.functions()->CreateTCPServerSocketPrivate(instance);
27 PP_Bool IsTCPServerSocket(PP_Resource resource) {
28 EnterTCPServer enter(resource, false);
29 return PP_FromBool(enter.succeeded());
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()));
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()));
52 void StopListening(PP_Resource tcp_server_socket) {
53 EnterTCPServer enter(tcp_server_socket, true);
54 if (enter.succeeded())
55 enter.object()->StopListening();
58 const PPB_TCPServerSocket_Private g_ppb_tcp_server_socket_thunk = {
59 Create,
60 IsTCPServerSocket,
61 Listen,
62 Accept,
63 StopListening
66 } // namespace
68 const PPB_TCPServerSocket_Private* GetPPB_TCPServerSocket_Private_0_1_Thunk() {
69 return &g_ppb_tcp_server_socket_thunk;
72 } // namespace thunk
73 } // namespace ppapi