Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ppapi/thunk/ppb_flash_udp_socket_thunk.cc

Issue 7745005: Initial work for UDP Pepper API (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: add some error case logic, remove remaining warnings... Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 int32_t Bind(PP_Resource udp_socket,
27 const PP_Flash_NetAddress *addr,
28 PP_CompletionCallback callback) {
29 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
30 if (enter.failed())
31 return PP_FALSE;
32 return enter.object()->Bind(addr, callback);
33 }
34
35 int32_t RecvFrom(PP_Resource udp_socket,
36 char* buffer,
37 int32_t num_bytes,
38 const PP_Flash_NetAddress* addr,
39 PP_CompletionCallback callback) {
40 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
41 if (enter.failed())
42 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
43 int32_t result = enter.object()->RecvFrom(buffer,
44 num_bytes,
45 addr,
46 callback);
47 return MayForceCallback(callback, result);
48 }
49
50 PP_Bool GetRecvFromAddress(PP_Resource udp_socket,
51 PP_Flash_NetAddress* addr) {
52 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
53 if (enter.failed())
54 return PP_FALSE;
55 return enter.object()->GetRecvFromAddress(addr);
56 }
57
58 int32_t SendTo(PP_Resource udp_socket,
59 const char* buffer,
60 int32_t num_bytes,
61 const PP_Flash_NetAddress* addr,
62 PP_CompletionCallback callback) {
63 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
64 if (enter.failed())
65 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
66 int32_t result = enter.object()->SendTo(buffer, num_bytes, addr, callback);
67 return MayForceCallback(callback, result);
68 }
69
70 void Disconnect(PP_Resource udp_socket) {
71 EnterResource<PPB_Flash_UDPSocket_API> enter(udp_socket, true);
72 if (enter.succeeded())
73 enter.object()->Disconnect();
74 }
75
76 const PPB_Flash_UDPSocket g_ppb_flash_udp_socket_thunk = {
77 &Create,
78 &Bind,
79 &RecvFrom,
80 &GetRecvFromAddress,
81 &SendTo,
82 &Disconnect
83 };
84
85 } // namespace
86
87 const PPB_Flash_UDPSocket* GetPPB_Flash_UDPSocket_Thunk() {
88 return &g_ppb_flash_udp_socket_thunk;
89 }
90
91 } // namespace thunk
92 } // namespace ppapi
93
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698