OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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/cpp/dev/udp_socket_dev.h" |
| 6 |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/cpp/completion_callback.h" |
| 9 #include "ppapi/cpp/instance_handle.h" |
| 10 #include "ppapi/cpp/module_impl.h" |
| 11 #include "ppapi/cpp/var.h" |
| 12 |
| 13 namespace pp { |
| 14 |
| 15 namespace { |
| 16 |
| 17 template <> const char* interface_name<PPB_UDPSocket_Dev_0_1>() { |
| 18 return PPB_UDPSOCKET_DEV_INTERFACE_0_1; |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 UDPSocket_Dev::UDPSocket_Dev() { |
| 24 } |
| 25 |
| 26 UDPSocket_Dev::UDPSocket_Dev(const InstanceHandle& instance) { |
| 27 if (has_interface<PPB_UDPSocket_Dev_0_1>()) { |
| 28 PassRefFromConstructor(get_interface<PPB_UDPSocket_Dev_0_1>()->Create( |
| 29 instance.pp_instance())); |
| 30 } |
| 31 } |
| 32 |
| 33 UDPSocket_Dev::UDPSocket_Dev(PassRef, PP_Resource resource) |
| 34 : Resource(PASS_REF, resource) { |
| 35 } |
| 36 |
| 37 UDPSocket_Dev::UDPSocket_Dev(const UDPSocket_Dev& other) : Resource(other) { |
| 38 } |
| 39 |
| 40 UDPSocket_Dev::~UDPSocket_Dev() { |
| 41 } |
| 42 |
| 43 UDPSocket_Dev& UDPSocket_Dev::operator=(const UDPSocket_Dev& other) { |
| 44 Resource::operator=(other); |
| 45 return *this; |
| 46 } |
| 47 |
| 48 // static |
| 49 bool UDPSocket_Dev::IsAvailable() { |
| 50 return has_interface<PPB_UDPSocket_Dev_0_1>(); |
| 51 } |
| 52 |
| 53 int32_t UDPSocket_Dev::Bind(const NetAddress_Dev& addr, |
| 54 const CompletionCallback& callback) { |
| 55 if (has_interface<PPB_UDPSocket_Dev_0_1>()) { |
| 56 return get_interface<PPB_UDPSocket_Dev_0_1>()->Bind( |
| 57 pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); |
| 58 } |
| 59 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 60 } |
| 61 |
| 62 NetAddress_Dev UDPSocket_Dev::GetBoundAddress() { |
| 63 if (has_interface<PPB_UDPSocket_Dev_0_1>()) { |
| 64 return NetAddress_Dev( |
| 65 PASS_REF, |
| 66 get_interface<PPB_UDPSocket_Dev_0_1>()->GetBoundAddress(pp_resource())); |
| 67 } |
| 68 return NetAddress_Dev(); |
| 69 } |
| 70 |
| 71 int32_t UDPSocket_Dev::RecvFrom( |
| 72 char* buffer, |
| 73 int32_t num_bytes, |
| 74 const CompletionCallbackWithOutput<NetAddress_Dev>& callback) { |
| 75 if (has_interface<PPB_UDPSocket_Dev_0_1>()) { |
| 76 return get_interface<PPB_UDPSocket_Dev_0_1>()->RecvFrom( |
| 77 pp_resource(), buffer, num_bytes, callback.output(), |
| 78 callback.pp_completion_callback()); |
| 79 } |
| 80 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 81 } |
| 82 |
| 83 int32_t UDPSocket_Dev::SendTo(const char* buffer, |
| 84 int32_t num_bytes, |
| 85 const NetAddress_Dev& addr, |
| 86 const CompletionCallback& callback) { |
| 87 if (has_interface<PPB_UDPSocket_Dev_0_1>()) { |
| 88 return get_interface<PPB_UDPSocket_Dev_0_1>()->SendTo( |
| 89 pp_resource(), buffer, num_bytes, addr.pp_resource(), |
| 90 callback.pp_completion_callback()); |
| 91 } |
| 92 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 93 } |
| 94 |
| 95 void UDPSocket_Dev::Close() { |
| 96 if (has_interface<PPB_UDPSocket_Dev_0_1>()) |
| 97 return get_interface<PPB_UDPSocket_Dev_0_1>()->Close(pp_resource()); |
| 98 } |
| 99 |
| 100 int32_t UDPSocket_Dev::SetOption(PP_UDPSocket_Option_Dev name, |
| 101 const Var& value, |
| 102 const CompletionCallback& callback) { |
| 103 if (has_interface<PPB_UDPSocket_Dev_0_1>()) { |
| 104 return get_interface<PPB_UDPSocket_Dev_0_1>()->SetOption( |
| 105 pp_resource(), name, value.pp_var(), |
| 106 callback.pp_completion_callback()); |
| 107 } |
| 108 return callback.MayForce(PP_ERROR_NOINTERFACE); |
| 109 } |
| 110 |
| 111 } // namespace pp |
OLD | NEW |