OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/c/pp_completion_callback.h" | |
6 #include "ppapi/c/pp_errors.h" | |
7 #include "ppapi/c/private/ppb_flash_udp_socket.h" | |
8 #include "ppapi/thunk/common.h" | |
9 #include "ppapi/thunk/enter.h" | |
10 #include "ppapi/thunk/ppb_flash_udp_socket_api.h" | |
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 | |
19 PP_Resource Create(PP_Instance instance, int32_t family) { | |
20 EnterFunction<ResourceCreationAPI> enter(instance, true); | |
21 if (enter.failed()) | |
22 return 0; | |
23 return enter.functions()->CreateFlashUDPSocket(instance, family); | |
24 } | |
25 | |
26 PP_Bool IsFlashUDPSocket(PP_Resource resource) { | |
27 EnterResource<PPB_Flash_UDPSocket_API> enter(resource, false); | |
28 return PP_FromBool(enter.succeeded()); | |
29 } | |
30 | |
31 int32_t Bind(PP_Resource udp_socket, | |
32 const PP_Flash_NetAddress *addr, | |
33 PP_CompletionCallback callback) { | |
34 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true); | |
brettw
2011/09/16 17:50:17
Check you're using 2-space indents consistently in
mtilburg
2011/09/21 01:46:43
Done.
| |
35 if (enter.failed()) | |
36 return PP_FALSE; | |
yzshen1
2011/09/17 02:10:07
MayForceCallback
and you need to return PP_ERROR_B
mtilburg
2011/09/21 01:46:43
Done.
| |
37 return enter.object()->Bind(addr, callback); | |
yzshen1
2011/09/17 02:10:07
MayForceCallback
mtilburg
2011/09/21 01:46:43
Done.
| |
38 } | |
39 | |
40 int32_t RecvFrom(PP_Resource udp_socket, | |
41 char* buffer, | |
42 int32_t num_bytes, | |
43 PP_CompletionCallback callback) { | |
44 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true); | |
45 if (enter.failed()) | |
46 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | |
47 int32_t result = enter.object()->RecvFrom(buffer, | |
48 num_bytes, | |
49 callback); | |
50 return MayForceCallback(callback, result); | |
51 } | |
52 | |
53 PP_Bool GetRecvFromAddress(PP_Resource udp_socket, | |
54 PP_Flash_NetAddress* addr) { | |
55 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true); | |
56 if (enter.failed()) | |
57 return PP_FALSE; | |
58 return enter.object()->GetRecvFromAddress(addr); | |
59 } | |
60 | |
61 int32_t SendTo(PP_Resource udp_socket, | |
62 const char* buffer, | |
63 int32_t num_bytes, | |
64 const PP_Flash_NetAddress* addr, | |
65 PP_CompletionCallback callback) { | |
66 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true); | |
67 if (enter.failed()) | |
68 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | |
69 int32_t result = enter.object()->SendTo(buffer, num_bytes, addr, callback); | |
70 return MayForceCallback(callback, result); | |
71 } | |
72 | |
73 void Disconnect(PP_Resource udp_socket) { | |
74 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true); | |
75 if (enter.succeeded()) | |
76 enter.object()->Disconnect(); | |
77 } | |
78 | |
79 const PPB_Flash_UDPSocket g_ppb_flash_udp_socket_thunk = { | |
80 &Create, | |
81 &IsFlashUDPSocket, | |
82 &Bind, | |
83 &RecvFrom, | |
84 &GetRecvFromAddress, | |
85 &SendTo, | |
86 &Disconnect | |
87 }; | |
88 | |
89 } // namespace | |
90 | |
91 const PPB_Flash_UDPSocket* GetPPB_Flash_UDPSocket_Thunk() { | |
92 return &g_ppb_flash_udp_socket_thunk; | |
93 } | |
94 | |
95 } // namespace thunk | |
96 } // namespace ppapi | |
97 | |
OLD | NEW |