OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cpp/dev/transport_dev.h" | 5 #include "ppapi/cpp/dev/transport_dev.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | |
8 #include "ppapi/cpp/instance.h" | 7 #include "ppapi/cpp/instance.h" |
9 #include "ppapi/cpp/resource.h" | 8 #include "ppapi/cpp/resource.h" |
10 #include "ppapi/cpp/module.h" | 9 #include "ppapi/cpp/module.h" |
11 #include "ppapi/cpp/module_impl.h" | 10 #include "ppapi/cpp/module_impl.h" |
12 #include "ppapi/cpp/var.h" | |
13 | 11 |
14 namespace pp { | 12 namespace pp { |
15 | 13 |
16 namespace { | 14 namespace { |
17 | 15 |
18 template <> const char* interface_name<PPB_Transport_Dev>() { | 16 template <> const char* interface_name<PPB_Transport_Dev>() { |
19 return PPB_TRANSPORT_DEV_INTERFACE; | 17 return PPB_TRANSPORT_DEV_INTERFACE; |
20 } | 18 } |
21 | 19 |
22 } // namespace | 20 } // namespace |
23 | 21 |
24 Transport_Dev::Transport_Dev(Instance* instance, | 22 Transport_Dev::Transport_Dev(Instance* instance, |
25 const char* name, | 23 const char* name, |
26 const char* proto) { | 24 const char* proto) { |
27 if (has_interface<PPB_Transport_Dev>()) | 25 if (has_interface<PPB_Transport_Dev>()) |
28 PassRefFromConstructor(get_interface<PPB_Transport_Dev>()->CreateTransport( | 26 PassRefFromConstructor(get_interface<PPB_Transport_Dev>()->CreateTransport( |
29 instance->pp_instance(), name, proto)); | 27 instance->pp_instance(), name, proto)); |
30 } | 28 } |
31 | 29 |
32 bool Transport_Dev::IsWritable() { | 30 } // namespace pp |
33 if (!has_interface<PPB_Transport_Dev>()) | |
34 return false; | |
35 return PPBoolToBool( | |
36 get_interface<PPB_Transport_Dev>()->IsWritable(pp_resource())); | |
37 } | |
38 | 31 |
39 int32_t Transport_Dev::Connect(const CompletionCallback& cc) { | |
40 if (!has_interface<PPB_Transport_Dev>()) | |
41 return PP_ERROR_NOINTERFACE; | |
42 return get_interface<PPB_Transport_Dev>()->Connect( | |
43 pp_resource(), cc.pp_completion_callback()); | |
44 } | |
45 | |
46 int32_t Transport_Dev::GetNextAddress(Var* address, | |
47 const CompletionCallback& cc) { | |
48 if (!has_interface<PPB_Transport_Dev>()) | |
49 return PP_ERROR_NOINTERFACE; | |
50 PP_Var temp_address = PP_MakeUndefined(); | |
51 int32_t ret_val = get_interface<PPB_Transport_Dev>()->GetNextAddress( | |
52 pp_resource(), &temp_address, cc.pp_completion_callback()); | |
53 *address = Var(Var::PassRef(), temp_address); | |
54 return ret_val; | |
55 } | |
56 | |
57 int32_t Transport_Dev::ReceiveRemoteAddress(const pp::Var& address) { | |
58 if (!has_interface<PPB_Transport_Dev>()) | |
59 return PP_ERROR_NOINTERFACE; | |
60 return get_interface<PPB_Transport_Dev>()->ReceiveRemoteAddress( | |
61 pp_resource(), address.pp_var()); | |
62 } | |
63 | |
64 int32_t Transport_Dev::Recv(void* data, uint32_t len, | |
65 const CompletionCallback& cc) { | |
66 if (!has_interface<PPB_Transport_Dev>()) | |
67 return PP_ERROR_NOINTERFACE; | |
68 return get_interface<PPB_Transport_Dev>()->Recv( | |
69 pp_resource(), data, len, cc.pp_completion_callback()); | |
70 } | |
71 | |
72 int32_t Transport_Dev::Send(const void* data, uint32_t len, | |
73 const CompletionCallback& cc) { | |
74 if (!has_interface<PPB_Transport_Dev>()) | |
75 return PP_ERROR_NOINTERFACE; | |
76 return get_interface<PPB_Transport_Dev>()->Send( | |
77 pp_resource(), data, len, cc.pp_completion_callback()); | |
78 } | |
79 | |
80 int32_t Transport_Dev::Close() { | |
81 if (!has_interface<PPB_Transport_Dev>()) | |
82 return PP_ERROR_NOINTERFACE; | |
83 return get_interface<PPB_Transport_Dev>()->Close(pp_resource()); | |
84 } | |
85 | |
86 } // namespace pp | |
OLD | NEW |