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 // TODO(yzshen): See the comment in corresponding .h file. |
| 6 |
| 7 #include "ppapi/cpp/private/flash_udp_socket.h" |
| 8 |
| 9 #include "ppapi/c/pp_bool.h" |
| 10 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/cpp/completion_callback.h" |
| 12 #include "ppapi/cpp/instance.h" |
| 13 #include "ppapi/cpp/module.h" |
| 14 #include "ppapi/cpp/module_impl.h" |
| 15 |
| 16 namespace pp { |
| 17 |
| 18 namespace { |
| 19 |
| 20 template <> const char* interface_name<PPB_Flash_UDPSocket>() { |
| 21 return PPB_FLASH_UDPSOCKET_INTERFACE; |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 namespace flash { |
| 27 |
| 28 UDPSocket::UDPSocket(Instance* instance, int32_t family) { |
| 29 if (has_interface<PPB_Flash_UDPSocket>() && instance) { |
| 30 PassRefFromConstructor(get_interface<PPB_Flash_UDPSocket>()->Create( |
| 31 instance->pp_instance(), family)); |
| 32 } |
| 33 } |
| 34 |
| 35 int32_t UDPSocket::Bind(const PP_Flash_NetAddress* addr, |
| 36 const CompletionCallback& callback) { |
| 37 if (!has_interface<PPB_Flash_UDPSocket>()) |
| 38 return PP_ERROR_NOINTERFACE; |
| 39 return get_interface<PPB_Flash_UDPSocket>()->Bind( |
| 40 pp_resource(), addr, callback.pp_completion_callback()); |
| 41 } |
| 42 |
| 43 int32_t UDPSocket::RecvFrom(char *buffer, |
| 44 int32_t num_bytes, |
| 45 const struct PP_Flash_NetAddress* addr, |
| 46 const CompletionCallback& callback){ |
| 47 if (!has_interface<PPB_Flash_UDPSocket>()) |
| 48 return PP_ERROR_NOINTERFACE; |
| 49 return get_interface<PPB_Flash_UDPSocket>()->RecvFrom( |
| 50 pp_resource(), buffer, num_bytes, addr, callback.pp_completion_callback()); |
| 51 } |
| 52 |
| 53 bool UDPSocket::GetRecvFromAddress(PP_Flash_NetAddress* addr) { |
| 54 if (!has_interface<PPB_Flash_UDPSocket>()) |
| 55 return false; |
| 56 |
| 57 PP_Bool result = get_interface<PPB_Flash_UDPSocket>()->GetRecvFromAddress( |
| 58 pp_resource(), addr); |
| 59 return PP_ToBool(result); |
| 60 } |
| 61 |
| 62 int32_t UDPSocket::SendTo(const char* buffer, |
| 63 int32_t num_bytes, |
| 64 const struct PP_Flash_NetAddress* addr, |
| 65 const CompletionCallback& callback){ |
| 66 if (!has_interface<PPB_Flash_UDPSocket>()) |
| 67 return PP_ERROR_NOINTERFACE; |
| 68 return get_interface<PPB_Flash_UDPSocket>()->SendTo( |
| 69 pp_resource(), buffer, num_bytes, addr, callback.pp_completion_callback()); |
| 70 } |
| 71 |
| 72 } // namespace flash |
| 73 } // namespace pp |
OLD | NEW |