OLD | NEW |
| (Empty) |
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_completion_callback.h" | |
6 #include "ppapi/c/pp_errors.h" | |
7 #include "ppapi/thunk/enter.h" | |
8 #include "ppapi/thunk/thunk.h" | |
9 #include "ppapi/thunk/ppb_transport_api.h" | |
10 #include "ppapi/thunk/resource_creation_api.h" | |
11 | |
12 namespace ppapi { | |
13 namespace thunk { | |
14 | |
15 namespace { | |
16 | |
17 typedef EnterResource<PPB_Transport_API> EnterTransport; | |
18 | |
19 PP_Resource Create(PP_Instance instance, const char* name, | |
20 PP_TransportType type) { | |
21 EnterResourceCreation enter(instance); | |
22 if (enter.failed()) | |
23 return 0; | |
24 return enter.functions()->CreateTransport(instance, name, type); | |
25 } | |
26 | |
27 PP_Bool IsTransport(PP_Resource resource) { | |
28 EnterTransport enter(resource, false); | |
29 return PP_FromBool(enter.succeeded()); | |
30 } | |
31 | |
32 PP_Bool IsWritable(PP_Resource transport) { | |
33 EnterTransport enter(transport, true); | |
34 if (enter.failed()) | |
35 return PP_FALSE; | |
36 return enter.object()->IsWritable(); | |
37 } | |
38 | |
39 int32_t SetProperty(PP_Resource transport, PP_TransportProperty property, | |
40 PP_Var value) { | |
41 EnterTransport enter(transport, true); | |
42 if (enter.failed()) | |
43 return enter.retval(); | |
44 return enter.object()->SetProperty(property, value); | |
45 } | |
46 | |
47 int32_t Connect(PP_Resource transport, PP_CompletionCallback callback) { | |
48 EnterTransport enter(transport, callback, true); | |
49 if (enter.failed()) | |
50 return enter.retval(); | |
51 return enter.SetResult(enter.object()->Connect(callback)); | |
52 } | |
53 | |
54 int32_t GetNextAddress(PP_Resource transport, PP_Var* address, | |
55 PP_CompletionCallback callback) { | |
56 EnterTransport enter(transport, callback, true); | |
57 if (enter.failed()) | |
58 return enter.retval(); | |
59 return enter.SetResult(enter.object()->GetNextAddress(address, callback)); | |
60 } | |
61 | |
62 int32_t ReceiveRemoteAddress(PP_Resource transport, PP_Var address) { | |
63 EnterTransport enter(transport, true); | |
64 if (enter.failed()) | |
65 return enter.retval(); | |
66 return enter.object()->ReceiveRemoteAddress(address); | |
67 } | |
68 | |
69 int32_t Recv(PP_Resource transport, void* data, uint32_t len, | |
70 PP_CompletionCallback callback) { | |
71 EnterTransport enter(transport, callback, true); | |
72 if (enter.failed()) | |
73 return enter.retval(); | |
74 return enter.SetResult(enter.object()->Recv(data, len, callback)); | |
75 } | |
76 | |
77 int32_t Send(PP_Resource transport, const void* data, uint32_t len, | |
78 PP_CompletionCallback callback) { | |
79 EnterTransport enter(transport, callback, true); | |
80 if (enter.failed()) | |
81 return enter.retval(); | |
82 return enter.SetResult(enter.object()->Send(data, len, callback)); | |
83 } | |
84 | |
85 int32_t Close(PP_Resource transport) { | |
86 EnterTransport enter(transport, true); | |
87 if (enter.failed()) | |
88 return enter.retval(); | |
89 return enter.object()->Close(); | |
90 } | |
91 | |
92 const PPB_Transport_Dev g_ppb_transport_thunk = { | |
93 &Create, | |
94 &IsTransport, | |
95 &IsWritable, | |
96 &SetProperty, | |
97 &Connect, | |
98 &GetNextAddress, | |
99 &ReceiveRemoteAddress, | |
100 &Recv, | |
101 &Send, | |
102 &Close, | |
103 }; | |
104 | |
105 } // namespace | |
106 | |
107 const PPB_Transport_Dev_0_7* GetPPB_Transport_Dev_0_7_Thunk() { | |
108 return &g_ppb_transport_thunk; | |
109 } | |
110 | |
111 } // namespace thunk | |
112 } // namespace ppapi | |
OLD | NEW |