diff options
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/private/tcp_socket_private.cc | 105 | ||||
-rw-r--r-- | ppapi/cpp/private/tcp_socket_private.h | 45 | ||||
-rw-r--r-- | ppapi/cpp/private/udp_socket_private.cc | 69 | ||||
-rw-r--r-- | ppapi/cpp/private/udp_socket_private.h | 37 |
4 files changed, 256 insertions, 0 deletions
diff --git a/ppapi/cpp/private/tcp_socket_private.cc b/ppapi/cpp/private/tcp_socket_private.cc new file mode 100644 index 0000000..17938b4 --- /dev/null +++ b/ppapi/cpp/private/tcp_socket_private.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2011 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/private/tcp_socket_private.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_TCPSocket_Private>() { + return PPB_TCPSOCKET_PRIVATE_INTERFACE; +} + +} // namespace + +TCPSocketPrivate::TCPSocketPrivate(Instance* instance) { + if (has_interface<PPB_TCPSocket_Private>() && instance) { + PassRefFromConstructor(get_interface<PPB_TCPSocket_Private>()->Create( + instance->pp_instance())); + } +} + +// static +bool TCPSocketPrivate::IsAvailable() { + return has_interface<PPB_TCPSocket_Private>(); +} + +int32_t TCPSocketPrivate::Connect(const char* host, + uint16_t port, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPSocket_Private>()->Connect( + pp_resource(), host, port, callback.pp_completion_callback()); +} + +int32_t TCPSocketPrivate::ConnectWithNetAddress( + const PP_NetAddress_Private* addr, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPSocket_Private>()->ConnectWithNetAddress( + pp_resource(), addr, callback.pp_completion_callback()); +} + +bool TCPSocketPrivate::GetLocalAddress(PP_NetAddress_Private* local_addr) { + if (!has_interface<PPB_TCPSocket_Private>()) + return false; + + PP_Bool result = get_interface<PPB_TCPSocket_Private>()->GetLocalAddress( + pp_resource(), local_addr); + return PP_ToBool(result); +} + +bool TCPSocketPrivate::GetRemoteAddress(PP_NetAddress_Private* remote_addr) { + if (!has_interface<PPB_TCPSocket_Private>()) + return false; + PP_Bool result = get_interface<PPB_TCPSocket_Private>()->GetRemoteAddress( + pp_resource(), remote_addr); + return PP_ToBool(result); +} + +int32_t TCPSocketPrivate::SSLHandshake(const char* server_name, + uint16_t server_port, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPSocket_Private>()->SSLHandshake( + pp_resource(), server_name, server_port, + callback.pp_completion_callback()); +} + +int32_t TCPSocketPrivate::Read(char* buffer, + int32_t bytes_to_read, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPSocket_Private>()->Read( + pp_resource(), buffer, bytes_to_read, callback.pp_completion_callback()); +} + +int32_t TCPSocketPrivate::Write(const char* buffer, + int32_t bytes_to_write, + const CompletionCallback& callback) { + if (!has_interface<PPB_TCPSocket_Private>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_TCPSocket_Private>()->Write( + pp_resource(), buffer, bytes_to_write, callback.pp_completion_callback()); +} + +void TCPSocketPrivate::Disconnect() { + if (!has_interface<PPB_TCPSocket_Private>()) + return; + return get_interface<PPB_TCPSocket_Private>()->Disconnect(pp_resource()); +} + +} // namespace pp diff --git a/ppapi/cpp/private/tcp_socket_private.h b/ppapi/cpp/private/tcp_socket_private.h new file mode 100644 index 0000000..b8728b4 --- /dev/null +++ b/ppapi/cpp/private/tcp_socket_private.h @@ -0,0 +1,45 @@ +// Copyright (c) 2011 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_PRIVATE_TCP_SOCKET_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_TCP_SOCKET_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_tcp_socket_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class Instance; + +class TCPSocketPrivate : public Resource { + public: + explicit TCPSocketPrivate(Instance* instance); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t Connect(const char* host, + uint16_t port, + const CompletionCallback& callback); + int32_t ConnectWithNetAddress(const PP_NetAddress_Private* addr, + const CompletionCallback& callback); + bool GetLocalAddress(PP_NetAddress_Private* local_addr); + bool GetRemoteAddress(PP_NetAddress_Private* remote_addr); + int32_t SSLHandshake(const char* server_name, + uint16_t server_port, + const CompletionCallback& callback); + int32_t Read(char* buffer, + int32_t bytes_to_read, + const CompletionCallback& callback); + int32_t Write(const char* buffer, + int32_t bytes_to_write, + const CompletionCallback& callback); + void Disconnect(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_TCP_SOCKET_PRIVATE_H_ diff --git a/ppapi/cpp/private/udp_socket_private.cc b/ppapi/cpp/private/udp_socket_private.cc new file mode 100644 index 0000000..8bd49f2 --- /dev/null +++ b/ppapi/cpp/private/udp_socket_private.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2011 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/private/udp_socket_private.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_UDPSocket_Private>() { + return PPB_UDPSOCKET_PRIVATE_INTERFACE; +} + +} // namespace + +UDPSocketPrivate::UDPSocketPrivate(Instance* instance) { + if (has_interface<PPB_UDPSocket_Private>() && instance) { + PassRefFromConstructor(get_interface<PPB_UDPSocket_Private>()->Create( + instance->pp_instance())); + } +} + +int32_t UDPSocketPrivate::Bind(const PP_NetAddress_Private* addr, + const CompletionCallback& callback) { + if (!has_interface<PPB_UDPSocket_Private>()) + return PP_ERROR_NOINTERFACE; + return get_interface<PPB_UDPSocket_Private>()->Bind( + pp_resource(), addr, callback.pp_completion_callback()); +} + +int32_t UDPSocketPrivate::RecvFrom(char* buffer, + int32_t num_bytes, + const CompletionCallback& callback) { + if (!has_interface<PPB_UDPSocket_Private>()) + return PP_ERROR_NOINTERFACE; + return get_interface<PPB_UDPSocket_Private>()->RecvFrom( + pp_resource(), buffer, num_bytes, callback.pp_completion_callback()); +} + +bool UDPSocketPrivate::GetRecvFromAddress(PP_NetAddress_Private* addr) { + if (!has_interface<PPB_UDPSocket_Private>()) + return false; + + PP_Bool result = get_interface<PPB_UDPSocket_Private>()->GetRecvFromAddress( + pp_resource(), addr); + return PP_ToBool(result); +} + +int32_t UDPSocketPrivate::SendTo(const char* buffer, + int32_t num_bytes, + const PP_NetAddress_Private* addr, + const CompletionCallback& callback) { + if (!has_interface<PPB_UDPSocket_Private>()) + return PP_ERROR_NOINTERFACE; + return get_interface<PPB_UDPSocket_Private>()->SendTo( + pp_resource(), buffer, num_bytes, addr, + callback.pp_completion_callback()); +} + +} // namespace pp + diff --git a/ppapi/cpp/private/udp_socket_private.h b/ppapi/cpp/private/udp_socket_private.h new file mode 100644 index 0000000..85bfb53 --- /dev/null +++ b/ppapi/cpp/private/udp_socket_private.h @@ -0,0 +1,37 @@ +// Copyright (c) 2011 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_PRIVATE_UDP_SOCKET_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_UDP_SOCKET_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_udp_socket_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class Instance; + +class UDPSocketPrivate : public Resource { + public: + explicit UDPSocketPrivate(Instance* instance); + + int32_t Bind(const PP_NetAddress_Private* addr, + const CompletionCallback& callback); + int32_t RecvFrom(char* buffer, + int32_t num_bytes, + const CompletionCallback& callback); + bool GetRecvFromAddress(PP_NetAddress_Private* addr); + int32_t SendTo(const char* buffer, + int32_t num_bytes, + const PP_NetAddress_Private* addr, + const CompletionCallback& callback); + void Close(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_UDP_SOCKET_PRIVATE_H_ + |