OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/c/private/ppb_flash_net_connector.h" | 5 #include "ppapi/c/private/ppb_flash_net_connector.h" |
6 #include "ppapi/c/pp_completion_callback.h" | 6 #include "ppapi/c/pp_completion_callback.h" |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/thunk/common.h" | |
9 #include "ppapi/thunk/enter.h" | 8 #include "ppapi/thunk/enter.h" |
10 #include "ppapi/thunk/thunk.h" | 9 #include "ppapi/thunk/thunk.h" |
11 #include "ppapi/thunk/ppb_flash_net_connector_api.h" | 10 #include "ppapi/thunk/ppb_flash_net_connector_api.h" |
12 #include "ppapi/thunk/resource_creation_api.h" | 11 #include "ppapi/thunk/resource_creation_api.h" |
13 | 12 |
14 namespace ppapi { | 13 namespace ppapi { |
15 namespace thunk { | 14 namespace thunk { |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
| 18 typedef EnterResource<PPB_Flash_NetConnector_API> EnterNetConnector; |
| 19 |
19 PP_Resource Create(PP_Instance instance) { | 20 PP_Resource Create(PP_Instance instance) { |
20 EnterFunction<ResourceCreationAPI> enter(instance, true); | 21 EnterResourceCreation enter(instance); |
21 if (enter.failed()) | 22 if (enter.failed()) |
22 return 0; | 23 return 0; |
23 return enter.functions()->CreateFlashNetConnector(instance); | 24 return enter.functions()->CreateFlashNetConnector(instance); |
24 } | 25 } |
25 | 26 |
26 PP_Bool IsFlashNetConnector(PP_Resource resource) { | 27 PP_Bool IsFlashNetConnector(PP_Resource resource) { |
27 EnterResource<PPB_Flash_NetConnector_API> enter(resource, false); | 28 EnterNetConnector enter(resource, false); |
28 return PP_FromBool(enter.succeeded()); | 29 return PP_FromBool(enter.succeeded()); |
29 } | 30 } |
30 | 31 |
31 int32_t ConnectTcp(PP_Resource resource, | 32 int32_t ConnectTcp(PP_Resource resource, |
32 const char* host, | 33 const char* host, |
33 uint16_t port, | 34 uint16_t port, |
34 PP_FileHandle* socket_out, | 35 PP_FileHandle* socket_out, |
35 PP_NetAddress_Private* local_addr_out, | 36 PP_NetAddress_Private* local_addr_out, |
36 PP_NetAddress_Private* remote_addr_out, | 37 PP_NetAddress_Private* remote_addr_out, |
37 PP_CompletionCallback callback) { | 38 PP_CompletionCallback callback) { |
38 EnterResource<PPB_Flash_NetConnector_API> enter(resource, true); | 39 EnterNetConnector enter(resource, callback, true); |
39 if (enter.failed()) | 40 if (enter.failed()) |
40 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | 41 return enter.retval(); |
41 int32_t result = | 42 return enter.SetResult(enter.object()->ConnectTcp( |
42 enter.object()->ConnectTcp(host, port, socket_out, local_addr_out, | 43 host, port, socket_out, local_addr_out, remote_addr_out, callback)); |
43 remote_addr_out, callback); | |
44 return MayForceCallback(callback, result); | |
45 } | 44 } |
46 | 45 |
47 int32_t ConnectTcpAddress(PP_Resource resource, | 46 int32_t ConnectTcpAddress(PP_Resource resource, |
48 const PP_NetAddress_Private* addr, | 47 const PP_NetAddress_Private* addr, |
49 PP_FileHandle* socket_out, | 48 PP_FileHandle* socket_out, |
50 PP_NetAddress_Private* local_addr_out, | 49 PP_NetAddress_Private* local_addr_out, |
51 PP_NetAddress_Private* remote_addr_out, | 50 PP_NetAddress_Private* remote_addr_out, |
52 PP_CompletionCallback callback) { | 51 PP_CompletionCallback callback) { |
53 EnterResource<PPB_Flash_NetConnector_API> enter(resource, true); | 52 EnterNetConnector enter(resource, callback, true); |
54 if (enter.failed()) | 53 if (enter.failed()) |
55 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | 54 return enter.retval(); |
56 int32_t result = | 55 return enter.SetResult(enter.object()->ConnectTcpAddress( |
57 enter.object()->ConnectTcpAddress(addr, socket_out, local_addr_out, | 56 addr, socket_out, local_addr_out, remote_addr_out, callback)); |
58 remote_addr_out, callback); | |
59 return MayForceCallback(callback, result); | |
60 } | 57 } |
61 | 58 |
62 const PPB_Flash_NetConnector g_ppb_flash_net_connector_thunk = { | 59 const PPB_Flash_NetConnector g_ppb_flash_net_connector_thunk = { |
63 &Create, | 60 &Create, |
64 &IsFlashNetConnector, | 61 &IsFlashNetConnector, |
65 &ConnectTcp, | 62 &ConnectTcp, |
66 &ConnectTcpAddress | 63 &ConnectTcpAddress |
67 }; | 64 }; |
68 | 65 |
69 } // namespace | 66 } // namespace |
70 | 67 |
71 const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_0_2_Thunk() { | 68 const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_0_2_Thunk() { |
72 return &g_ppb_flash_net_connector_thunk; | 69 return &g_ppb_flash_net_connector_thunk; |
73 } | 70 } |
74 | 71 |
75 } // namespace thunk | 72 } // namespace thunk |
76 } // namespace ppapi | 73 } // namespace ppapi |
OLD | NEW |