diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 22:43:39 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-13 22:43:39 +0000 |
commit | 31cb147366bde602adf20717c478ff54c09cb4c2 (patch) | |
tree | 94f7243da6e7ec64fa2594fb5c5a97863de406da /ppapi/cpp | |
parent | dcab1bf3aa1029789765b5a74727ba0653460efc (diff) | |
download | chromium_src-31cb147366bde602adf20717c478ff54c09cb4c2.zip chromium_src-31cb147366bde602adf20717c478ff54c09cb4c2.tar.gz chromium_src-31cb147366bde602adf20717c478ff54c09cb4c2.tar.bz2 |
Introduce PPB_UDPSocket_Dev.
This change exposes the PPB_UDPSocket_Dev interface and makes it to share the same backend as PPB_UDPSocket_Private.
It doesn't include:
- apps permission check;
- UDP socket options that PPB_UDPSocket_Private doesn't support.
These will be implemented in separate CLs.
BUG=247225
TEST=newly added test_udp_socket.{h,cc}.
Review URL: https://chromiumcodereview.appspot.com/16282005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206183 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/dev/udp_socket_dev.cc | 111 | ||||
-rw-r--r-- | ppapi/cpp/dev/udp_socket_dev.h | 57 |
2 files changed, 168 insertions, 0 deletions
diff --git a/ppapi/cpp/dev/udp_socket_dev.cc b/ppapi/cpp/dev/udp_socket_dev.cc new file mode 100644 index 0000000..dd8ffd0 --- /dev/null +++ b/ppapi/cpp/dev/udp_socket_dev.cc @@ -0,0 +1,111 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/dev/udp_socket_dev.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_UDPSocket_Dev_0_1>() { + return PPB_UDPSOCKET_DEV_INTERFACE_0_1; +} + +} // namespace + +UDPSocket_Dev::UDPSocket_Dev() { +} + +UDPSocket_Dev::UDPSocket_Dev(const InstanceHandle& instance) { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) { + PassRefFromConstructor(get_interface<PPB_UDPSocket_Dev_0_1>()->Create( + instance.pp_instance())); + } +} + +UDPSocket_Dev::UDPSocket_Dev(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +UDPSocket_Dev::UDPSocket_Dev(const UDPSocket_Dev& other) : Resource(other) { +} + +UDPSocket_Dev::~UDPSocket_Dev() { +} + +UDPSocket_Dev& UDPSocket_Dev::operator=(const UDPSocket_Dev& other) { + Resource::operator=(other); + return *this; +} + +// static +bool UDPSocket_Dev::IsAvailable() { + return has_interface<PPB_UDPSocket_Dev_0_1>(); +} + +int32_t UDPSocket_Dev::Bind(const NetAddress_Dev& addr, + const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) { + return get_interface<PPB_UDPSocket_Dev_0_1>()->Bind( + pp_resource(), addr.pp_resource(), callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +NetAddress_Dev UDPSocket_Dev::GetBoundAddress() { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) { + return NetAddress_Dev( + PASS_REF, + get_interface<PPB_UDPSocket_Dev_0_1>()->GetBoundAddress(pp_resource())); + } + return NetAddress_Dev(); +} + +int32_t UDPSocket_Dev::RecvFrom( + char* buffer, + int32_t num_bytes, + const CompletionCallbackWithOutput<NetAddress_Dev>& callback) { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) { + return get_interface<PPB_UDPSocket_Dev_0_1>()->RecvFrom( + pp_resource(), buffer, num_bytes, callback.output(), + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t UDPSocket_Dev::SendTo(const char* buffer, + int32_t num_bytes, + const NetAddress_Dev& addr, + const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) { + return get_interface<PPB_UDPSocket_Dev_0_1>()->SendTo( + pp_resource(), buffer, num_bytes, addr.pp_resource(), + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +void UDPSocket_Dev::Close() { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) + return get_interface<PPB_UDPSocket_Dev_0_1>()->Close(pp_resource()); +} + +int32_t UDPSocket_Dev::SetOption(PP_UDPSocket_Option_Dev name, + const Var& value, + const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_Dev_0_1>()) { + return get_interface<PPB_UDPSocket_Dev_0_1>()->SetOption( + pp_resource(), name, value.pp_var(), + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/udp_socket_dev.h b/ppapi/cpp/dev/udp_socket_dev.h new file mode 100644 index 0000000..9f46f0a --- /dev/null +++ b/ppapi/cpp/dev/udp_socket_dev.h @@ -0,0 +1,57 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ +#define PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ + +#include "ppapi/c/dev/ppb_udp_socket_dev.h" +#include "ppapi/cpp/dev/net_address_dev.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class InstanceHandle; +class Var; + +template <typename T> class CompletionCallbackWithOutput; + +class UDPSocket_Dev: public Resource { + public: + UDPSocket_Dev(); + + explicit UDPSocket_Dev(const InstanceHandle& instance); + + UDPSocket_Dev(PassRef, PP_Resource resource); + + UDPSocket_Dev(const UDPSocket_Dev& other); + + virtual ~UDPSocket_Dev(); + + UDPSocket_Dev& operator=(const UDPSocket_Dev& other); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t Bind(const NetAddress_Dev& addr, + const CompletionCallback& callback); + NetAddress_Dev GetBoundAddress(); + int32_t RecvFrom( + char* buffer, + int32_t num_bytes, + const CompletionCallbackWithOutput<NetAddress_Dev>& callback); + int32_t SendTo(const char* buffer, + int32_t num_bytes, + const NetAddress_Dev& addr, + const CompletionCallback& callback); + void Close(); + int32_t SetOption(PP_UDPSocket_Option_Dev name, + const Var& value, + const CompletionCallback& callback); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_UDP_SOCKET_DEV_H_ |