diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 21:54:43 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 21:54:43 +0000 |
commit | 09bd7bc27cf7544bdfb58fe0e21465b6485d599e (patch) | |
tree | ae66b0506d572fe287577288292cb3ae43ae68fd /ppapi/cpp | |
parent | 7ed04df055beabf2300c1163be8e59812ecfb7bf (diff) | |
download | chromium_src-09bd7bc27cf7544bdfb58fe0e21465b6485d599e.zip chromium_src-09bd7bc27cf7544bdfb58fe0e21465b6485d599e.tar.gz chromium_src-09bd7bc27cf7544bdfb58fe0e21465b6485d599e.tar.bz2 |
Remove PPB_Ext_Socket_Dev.
BUG=366304,244653,312916,314899
TEST=None
Review URL: https://codereview.chromium.org/252923005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267348 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/completion_callback.h | 170 | ||||
-rw-r--r-- | ppapi/cpp/extensions/dev/socket_dev.cc | 654 | ||||
-rw-r--r-- | ppapi/cpp/extensions/dev/socket_dev.h | 290 | ||||
-rw-r--r-- | ppapi/cpp/extensions/dict_field.h | 100 | ||||
-rw-r--r-- | ppapi/cpp/extensions/ext_output_traits.h | 142 | ||||
-rw-r--r-- | ppapi/cpp/extensions/from_var_converter.h | 236 | ||||
-rw-r--r-- | ppapi/cpp/extensions/optional.h | 97 | ||||
-rw-r--r-- | ppapi/cpp/extensions/to_var_converter.h | 156 |
8 files changed, 31 insertions, 1814 deletions
diff --git a/ppapi/cpp/completion_callback.h b/ppapi/cpp/completion_callback.h index 14d6784..2062180 100644 --- a/ppapi/cpp/completion_callback.h +++ b/ppapi/cpp/completion_callback.h @@ -7,7 +7,6 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/cpp/extensions/ext_output_traits.h" #include "ppapi/cpp/logging.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/output_traits.h" @@ -168,50 +167,6 @@ class CompletionCallback { PP_CompletionCallback cc_; }; -namespace internal { - -/// The base class of [Ext]CompletionCallbackWithOutput. -/// -/// The template parameter Traits determines the storage type -/// (OutputStorageType), the output parameter type used by the browser -/// (APIArgType), and how to map OutputStorageType to APIArgType. -template <typename T, typename Traits> -class CompletionCallbackWithOutputBase : public CompletionCallback { - public: - typedef typename Traits::StorageType OutputStorageType; - typedef typename Traits::APIArgType APIArgType; - typedef Traits TraitsType; - - explicit CompletionCallbackWithOutputBase(OutputStorageType* output) - : CompletionCallback(), - output_(output) { - } - - CompletionCallbackWithOutputBase(PP_CompletionCallback_Func func, - void* user_data, - OutputStorageType* output) - : CompletionCallback(func, user_data), - output_(output) { - } - - CompletionCallbackWithOutputBase(PP_CompletionCallback_Func func, - void* user_data, - int32_t flags, - OutputStorageType* output) - : CompletionCallback(func, user_data, flags), - output_(output) { - } - - APIArgType output() const { - return Traits::StorageToAPIArg(*output_); - } - - private: - OutputStorageType* output_; -}; - -} // namespace internal - /// A CompletionCallbackWithOutput defines a completion callback that /// additionally stores a pointer to some output data. Some C++ wrappers /// take a CompletionCallbackWithOutput when the browser is returning a @@ -228,37 +183,36 @@ class CompletionCallbackWithOutputBase : public CompletionCallback { /// it just stores a pointer to it. C++ wrapper objects that accept a /// CompletionCallbackWithOutput will retrieve this pointer and pass it to /// the browser as the output parameter. -template <typename T> -class CompletionCallbackWithOutput - : public internal::CompletionCallbackWithOutputBase< - T, internal::CallbackOutputTraits<T> > { +template<typename T> +class CompletionCallbackWithOutput : public CompletionCallback { public: - typedef internal::CompletionCallbackWithOutputBase< - T, internal::CallbackOutputTraits<T> > BaseType; + /// The type that will actually be stored in the completion callback. In the + /// common case, this will be equal to the template parameter (for example, + /// CompletionCallbackWithOutput<int> would obviously take an int*. However, + /// resources are passed as PP_Resource, vars as PP_Var, and arrays as our + /// special ArrayOutputAdapter object. The CallbackOutputTraits defines + /// specializations for all of these cases. + typedef typename internal::CallbackOutputTraits<T>::StorageType + OutputStorageType; + typedef typename internal::CallbackOutputTraits<T>::APIArgType + APIArgType; /// The default constructor will create a blocking - /// <code>CompletionCallbackWithOutput</code> that references the given output + /// <code>CompletionCallback</code> that references the given output /// data. /// /// @param[in] output A pointer to the data associated with the callback. The /// caller must ensure that this pointer outlives the completion callback. - /// In the common case, <code>OutputStorageType</code> will be equal to the - /// template parameter T (for example, - /// <code>CompletionCallbackWithOutput<int></code> would obviously take an - /// int*. However, resources are passed as PP_Resource, vars as PP_Var, and - /// arrays as our special ArrayOutputAdapter object. - /// <code>internal::CallbackOutputTraits</code> defines specializations for - /// all of these cases. /// /// <strong>Note:</strong> Blocking completion callbacks are only allowed from - /// background threads. - explicit CompletionCallbackWithOutput( - typename BaseType::OutputStorageType* output) - : BaseType(output) { + /// from background threads. + CompletionCallbackWithOutput(OutputStorageType* output) + : CompletionCallback(), + output_(output) { } - /// A constructor for creating a <code>CompletionCallbackWithOutput</code> - /// that references the given output data. + /// A constructor for creating a <code>CompletionCallback</code> that + /// references the given output data. /// /// @param[in] func The function to be called on completion. /// @param[in] user_data The user data to be passed to the callback function. @@ -268,12 +222,13 @@ class CompletionCallbackWithOutput /// caller must ensure that this pointer outlives the completion callback. CompletionCallbackWithOutput(PP_CompletionCallback_Func func, void* user_data, - typename BaseType::OutputStorageType* output) - : BaseType(func, user_data, output) { + OutputStorageType* output) + : CompletionCallback(func, user_data), + output_(output) { } - /// A constructor for creating a <code>CompletionCallbackWithOutput</code> - /// that references the given output data. + /// A constructor for creating a <code>CompletionCallback</code> that + /// references the given output data. /// /// @param[in] func The function to be called on completion. /// @@ -290,82 +245,19 @@ class CompletionCallbackWithOutput CompletionCallbackWithOutput(PP_CompletionCallback_Func func, void* user_data, int32_t flags, - typename BaseType::OutputStorageType* output) - : BaseType(func, user_data, flags, output) { - } -}; - -namespace ext { - -/// ExtCompletionCallbackWithOutput is similar to CompletionCallbackWithOutput, -/// but used by APIs within the pp::ext namespace. Usually it is used with the -/// CompletionCallbackFactory's NewExtCallbackWithOutput. -template <typename T> -class ExtCompletionCallbackWithOutput - : public ::pp::internal::CompletionCallbackWithOutputBase< - T, internal::ExtCallbackOutputTraits<T> > { - public: - typedef ::pp::internal::CompletionCallbackWithOutputBase< - T, internal::ExtCallbackOutputTraits<T> > BaseType; - - /// The default constructor will create a blocking - /// <code>ExtCompletionCallbackWithOutput</code> that references the given - /// output data. - /// - /// @param[in] output A pointer to the data associated with the callback. The - /// caller must ensure that this pointer outlives the completion callback. - /// <code>OutputStorageType</code> is either - /// <code>ext::internal::ArrayVarOutputAdapterWithStorage<U></code> (if the - /// template parameter T is of the form std::vector<U>) or - /// <code>ext::internal::VarOutputAdapterWithStorage<T></code> (otherwise). - /// - /// <strong>Note:</strong> Blocking completion callbacks are only allowed from - /// background threads. - explicit ExtCompletionCallbackWithOutput( - typename BaseType::OutputStorageType* output) - : BaseType(output) { + OutputStorageType* output) + : CompletionCallback(func, user_data, flags), + output_(output) { } - /// A constructor for creating an <code>ExtCompletionCallbackWithOutput</code> - /// that references the given output data. - /// - /// @param[in] func The function to be called on completion. - /// @param[in] user_data The user data to be passed to the callback function. - /// This is optional and is typically used to help track state in case of - /// multiple pending callbacks. - /// @param[in] output A pointer to the data associated with the callback. The - /// caller must ensure that this pointer outlives the completion callback. - ExtCompletionCallbackWithOutput(PP_CompletionCallback_Func func, - void* user_data, - typename BaseType::OutputStorageType* output) - : BaseType(func, user_data, output) { + APIArgType output() const { + return internal::CallbackOutputTraits<T>::StorageToAPIArg(*output_); } - /// A constructor for creating an <code>ExtCompletionCallbackWithOutput</code> - /// that references the given output data. - /// - /// @param[in] func The function to be called on completion. - /// - /// @param[in] user_data The user data to be passed to the callback function. - /// This is optional and is typically used to help track state in case of - /// multiple pending callbacks. - /// - /// @param[in] flags Bit field combination of - /// <code>PP_CompletionCallback_Flag</code> flags used to control how - /// non-NULL callbacks are scheduled by asynchronous methods. - /// - /// @param[in] output A pointer to the data associated with the callback. The - /// caller must ensure that this pointer outlives the completion callback. - ExtCompletionCallbackWithOutput(PP_CompletionCallback_Func func, - void* user_data, - int32_t flags, - typename BaseType::OutputStorageType* output) - : BaseType(func, user_data, flags, output) { - } + private: + OutputStorageType* output_; }; -} // namespace ext - /// BlockUntilComplete() is used in place of an actual completion callback /// to request blocking behavior. If specified, the calling thread will block /// until the function completes. Blocking completion callbacks are only diff --git a/ppapi/cpp/extensions/dev/socket_dev.cc b/ppapi/cpp/extensions/dev/socket_dev.cc deleted file mode 100644 index a2c9e7f..0000000 --- a/ppapi/cpp/extensions/dev/socket_dev.cc +++ /dev/null @@ -1,654 +0,0 @@ -// Copyright (c) 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/extensions/dev/socket_dev.h" - -#include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/extensions/optional.h" -#include "ppapi/cpp/extensions/to_var_converter.h" -#include "ppapi/cpp/logging.h" -#include "ppapi/cpp/module_impl.h" - -namespace pp { - -namespace { - -template <> const char* interface_name<PPB_Ext_Socket_Dev_0_2>() { - return PPB_EXT_SOCKET_DEV_INTERFACE_0_2; -} - -} // namespace - -namespace ext { -namespace socket { - -const char* const SocketType_Dev::kTcp = "tcp"; -const char* const SocketType_Dev::kUdp = "udp"; - -SocketType_Dev::SocketType_Dev() : value(NONE) { -} - -SocketType_Dev::SocketType_Dev(ValueType in_value) : value(in_value) { -} - -SocketType_Dev::~SocketType_Dev() { -} - -bool SocketType_Dev::Populate(const PP_Var& var_value) { - if (var_value.type != PP_VARTYPE_STRING) - return false; - - std::string string_value = Var(var_value).AsString(); - if (string_value == kTcp) { - value = TCP; - } else if (string_value == kUdp) { - value = UDP; - } else { - value = NONE; - return false; - } - return true; -} - -Var SocketType_Dev::CreateVar() const { - switch (value) { - case TCP: - return Var(kTcp); - case UDP: - return Var(kUdp); - default: - PP_NOTREACHED(); - return Var(std::string()); - } -} - -const char* const CreateInfo_Dev::kSocketId = "socketId"; - -CreateInfo_Dev::CreateInfo_Dev() - : socket_id(kSocketId) { -} - -CreateInfo_Dev::~CreateInfo_Dev() { -} - -bool CreateInfo_Dev::Populate(const PP_Ext_Socket_CreateInfo_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = socket_id.Populate(dict); - - return result; -} - -Var CreateInfo_Dev::CreateVar() const { - VarDictionary dict; - - bool result = socket_id.AddTo(&dict); - // Suppress unused variable warnings. - static_cast<void>(result); - PP_DCHECK(result); - - return dict; -} - -const char* const AcceptInfo_Dev::kResultCode = "resultCode"; -const char* const AcceptInfo_Dev::kSocketId = "socketId"; - -AcceptInfo_Dev::AcceptInfo_Dev() - : result_code(kResultCode), - socket_id(kSocketId) { -} - -AcceptInfo_Dev::~AcceptInfo_Dev() { -} - -bool AcceptInfo_Dev::Populate(const PP_Ext_Socket_AcceptInfo_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = result_code.Populate(dict); - result = socket_id.Populate(dict) && result; - - return result; -} - -Var AcceptInfo_Dev::CreateVar() const { - VarDictionary dict; - - bool result = result_code.AddTo(&dict); - result = socket_id.MayAddTo(&dict) && result; - PP_DCHECK(result); - - return dict; -} - -const char* const ReadInfo_Dev::kResultCode = "resultCode"; -const char* const ReadInfo_Dev::kData = "data"; - -ReadInfo_Dev::ReadInfo_Dev() - : result_code(kResultCode), - data(kData) { -} - -ReadInfo_Dev::~ReadInfo_Dev() { -} - -bool ReadInfo_Dev::Populate(const PP_Ext_Socket_ReadInfo_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = result_code.Populate(dict); - result = data.Populate(dict) && result; - - return result; -} - -Var ReadInfo_Dev::CreateVar() const { - VarDictionary dict; - - bool result = result_code.AddTo(&dict); - result = data.AddTo(&dict) && result; - PP_DCHECK(result); - - return dict; -} - -const char* const WriteInfo_Dev::kBytesWritten = "bytesWritten"; - -WriteInfo_Dev::WriteInfo_Dev() - : bytes_written(kBytesWritten) { -} - -WriteInfo_Dev::~WriteInfo_Dev() { -} - -bool WriteInfo_Dev::Populate(const PP_Ext_Socket_WriteInfo_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = bytes_written.Populate(dict); - - return result; -} - -Var WriteInfo_Dev::CreateVar() const { - VarDictionary dict; - - bool result = bytes_written.AddTo(&dict); - // Suppress unused variable warnings. - static_cast<void>(result); - PP_DCHECK(result); - - return dict; -} - -const char* const RecvFromInfo_Dev::kResultCode = "resultCode"; -const char* const RecvFromInfo_Dev::kData = "data"; -const char* const RecvFromInfo_Dev::kAddress = "address"; -const char* const RecvFromInfo_Dev::kPort = "port"; - -RecvFromInfo_Dev::RecvFromInfo_Dev() - : result_code(kResultCode), - data(kData), - address(kAddress), - port(kPort) { -} - -RecvFromInfo_Dev::~RecvFromInfo_Dev() { -} - -bool RecvFromInfo_Dev::Populate(const PP_Ext_Socket_RecvFromInfo_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = result_code.Populate(dict); - result = data.Populate(dict) && result; - result = address.Populate(dict) && result; - result = port.Populate(dict) && result; - - return result; -} - -Var RecvFromInfo_Dev::CreateVar() const { - VarDictionary dict; - - bool result = result_code.AddTo(&dict); - result = data.AddTo(&dict) && result; - result = address.AddTo(&dict) && result; - result = port.AddTo(&dict) && result; - PP_DCHECK(result); - - return dict; -} - -const char* const SocketInfo_Dev::kSocketType = "socketType"; -const char* const SocketInfo_Dev::kConnected = "connected"; -const char* const SocketInfo_Dev::kPeerAddress = "peerAddress"; -const char* const SocketInfo_Dev::kPeerPort = "peerPort"; -const char* const SocketInfo_Dev::kLocalAddress = "localAddress"; -const char* const SocketInfo_Dev::kLocalPort = "localPort"; - -SocketInfo_Dev::SocketInfo_Dev() - : socket_type(kSocketType), - connected(kConnected), - peer_address(kPeerAddress), - peer_port(kPeerPort), - local_address(kLocalAddress), - local_port(kLocalPort) { -} - -SocketInfo_Dev::~SocketInfo_Dev() { -} - -bool SocketInfo_Dev::Populate(const PP_Ext_Socket_SocketInfo_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = socket_type.Populate(dict); - result = connected.Populate(dict) && result; - result = peer_address.Populate(dict) && result; - result = peer_port.Populate(dict) && result; - result = local_address.Populate(dict) && result; - result = local_port.Populate(dict) && result; - - return result; -} - -Var SocketInfo_Dev::CreateVar() const { - VarDictionary dict; - - bool result = socket_type.AddTo(&dict); - result = connected.AddTo(&dict) && result; - result = peer_address.MayAddTo(&dict) && result; - result = peer_port.MayAddTo(&dict) && result; - result = local_address.MayAddTo(&dict) && result; - result = local_port.MayAddTo(&dict) && result; - PP_DCHECK(result); - - return dict; -} - -const char* const NetworkInterface_Dev::kName = "name"; -const char* const NetworkInterface_Dev::kAddress = "address"; - -NetworkInterface_Dev::NetworkInterface_Dev() - : name(kName), - address(kAddress) { -} - -NetworkInterface_Dev::~NetworkInterface_Dev() { -} - -bool NetworkInterface_Dev::Populate( - const PP_Ext_Socket_NetworkInterface_Dev& value) { - if (value.type != PP_VARTYPE_DICTIONARY) - return false; - - VarDictionary dict(value); - bool result = name.Populate(dict); - result = address.Populate(dict) && result; - - return result; -} - -Var NetworkInterface_Dev::CreateVar() const { - VarDictionary dict; - - bool result = name.AddTo(&dict); - result = address.AddTo(&dict) && result; - PP_DCHECK(result); - - return dict; -} - -Socket_Dev::Socket_Dev(const InstanceHandle& instance) : instance_(instance) { -} - -Socket_Dev::~Socket_Dev() { -} - -int32_t Socket_Dev::Create(const SocketType_Dev& type, - const Optional<CreateOptions_Dev>& options, - const CreateCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<SocketType_Dev> type_var(type); - internal::ToVarConverter<Optional<CreateOptions_Dev> > options_var(options); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Create( - instance_.pp_instance(), - type_var.pp_var(), - options_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -void Socket_Dev::Destroy(int32_t socket_id) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return; - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Destroy( - instance_.pp_instance(), - socket_id_var.pp_var()); -} - -int32_t Socket_Dev::Connect(int32_t socket_id, - const std::string& hostname, - int32_t port, - const ConnectCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<std::string> hostname_var(hostname); - internal::ToVarConverter<int32_t> port_var(port); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Connect( - instance_.pp_instance(), - socket_id_var.pp_var(), - hostname_var.pp_var(), - port_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::Bind(int32_t socket_id, - const std::string& address, - int32_t port, - const BindCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<std::string> address_var(address); - internal::ToVarConverter<int32_t> port_var(port); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Bind( - instance_.pp_instance(), - socket_id_var.pp_var(), - address_var.pp_var(), - port_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -void Socket_Dev::Disconnect(int32_t socket_id) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return; - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Disconnect( - instance_.pp_instance(), - socket_id_var.pp_var()); -} - -int32_t Socket_Dev::Read(int32_t socket_id, - const Optional<int32_t>& buffer_size, - const ReadCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<Optional<int32_t> > buffer_size_var(buffer_size); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Read( - instance_.pp_instance(), - socket_id_var.pp_var(), - buffer_size_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::Write(int32_t socket_id, - const VarArrayBuffer& data, - const WriteCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<Var> data_var(data); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Write( - instance_.pp_instance(), - socket_id_var.pp_var(), - data_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::RecvFrom(int32_t socket_id, - const Optional<int32_t>& buffer_size, - const RecvFromCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<Optional<int32_t> > buffer_size_var(buffer_size); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->RecvFrom( - instance_.pp_instance(), - socket_id_var.pp_var(), - buffer_size_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::SendTo(int32_t socket_id, - const VarArrayBuffer& data, - const std::string& address, - int32_t port, - const SendToCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<Var> data_var(data); - internal::ToVarConverter<std::string> address_var(address); - internal::ToVarConverter<int32_t> port_var(port); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->SendTo( - instance_.pp_instance(), - socket_id_var.pp_var(), - data_var.pp_var(), - address_var.pp_var(), - port_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::Listen(int32_t socket_id, - const std::string& address, - int32_t port, - const Optional<int32_t>& backlog, - const ListenCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<std::string> address_var(address); - internal::ToVarConverter<int32_t> port_var(port); - internal::ToVarConverter<Optional<int32_t> > backlog_var(backlog); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Listen( - instance_.pp_instance(), - socket_id_var.pp_var(), - address_var.pp_var(), - port_var.pp_var(), - backlog_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::Accept(int32_t socket_id, - const AcceptCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->Accept( - instance_.pp_instance(), - socket_id_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::SetKeepAlive(int32_t socket_id, - bool enable, - const Optional<int32_t>& delay, - const SetKeepAliveCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<bool> enable_var(enable); - internal::ToVarConverter<Optional<int32_t> > delay_var(delay); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetKeepAlive( - instance_.pp_instance(), - socket_id_var.pp_var(), - enable_var.pp_var(), - delay_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::SetNoDelay(int32_t socket_id, - bool no_delay, - const SetNoDelayCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<bool> no_delay_var(no_delay); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetNoDelay( - instance_.pp_instance(), - socket_id_var.pp_var(), - no_delay_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::GetInfo(int32_t socket_id, - const GetInfoCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->GetInfo( - instance_.pp_instance(), - socket_id_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::GetNetworkList(const GetNetworkListCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->GetNetworkList( - instance_.pp_instance(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::JoinGroup(int32_t socket_id, - const std::string& address, - const JoinGroupCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<std::string> address_var(address); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->JoinGroup( - instance_.pp_instance(), - socket_id_var.pp_var(), - address_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::LeaveGroup(int32_t socket_id, - const std::string& address, - const LeaveGroupCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<std::string> address_var(address); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->LeaveGroup( - instance_.pp_instance(), - socket_id_var.pp_var(), - address_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::SetMulticastTimeToLive( - int32_t socket_id, - int32_t ttl, - const SetMulticastTimeToLiveCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<int32_t> ttl_var(ttl); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetMulticastTimeToLive( - instance_.pp_instance(), - socket_id_var.pp_var(), - ttl_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::SetMulticastLoopbackMode( - int32_t socket_id, - bool enabled, - const SetMulticastLoopbackModeCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - internal::ToVarConverter<bool> enabled_var(enabled); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->SetMulticastLoopbackMode( - instance_.pp_instance(), - socket_id_var.pp_var(), - enabled_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -int32_t Socket_Dev::GetJoinedGroups(int32_t socket_id, - const GetJoinedGroupsCallback& callback) { - if (!has_interface<PPB_Ext_Socket_Dev_0_2>()) - return callback.MayForce(PP_ERROR_NOINTERFACE); - - internal::ToVarConverter<int32_t> socket_id_var(socket_id); - - return get_interface<PPB_Ext_Socket_Dev_0_2>()->GetJoinedGroups( - instance_.pp_instance(), - socket_id_var.pp_var(), - callback.output(), - callback.pp_completion_callback()); -} - -} // namespace socket -} // namespace ext -} // namespace pp diff --git a/ppapi/cpp/extensions/dev/socket_dev.h b/ppapi/cpp/extensions/dev/socket_dev.h deleted file mode 100644 index b6ac7b5..0000000 --- a/ppapi/cpp/extensions/dev/socket_dev.h +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright (c) 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_EXTENSIONS_DEV_SOCKET_DEV_H_ -#define PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ - -#include <string> -#include <vector> - -#include "ppapi/c/extensions/dev/ppb_ext_socket_dev.h" -#include "ppapi/cpp/extensions/dict_field.h" -#include "ppapi/cpp/extensions/ext_output_traits.h" -#include "ppapi/cpp/instance_handle.h" -#include "ppapi/cpp/var.h" -#include "ppapi/cpp/var_array_buffer.h" -#include "ppapi/cpp/var_dictionary.h" - -namespace pp { -namespace ext { - -template <class T> -class ExtCompletionCallbackWithOutput; - -template <class T> -class Optional; - -namespace socket { - -// Data types ------------------------------------------------------------------ -class SocketType_Dev { - public: - enum ValueType { - NONE, - TCP, - UDP - }; - - SocketType_Dev(); - SocketType_Dev(ValueType in_value); - ~SocketType_Dev(); - - bool Populate(const PP_Var& var_value); - - Var CreateVar() const; - - ValueType value; - - static const char* const kTcp; - static const char* const kUdp; -}; - -typedef VarDictionary CreateOptions_Dev; - -class CreateInfo_Dev { - public: - CreateInfo_Dev(); - ~CreateInfo_Dev(); - - bool Populate(const PP_Ext_Socket_CreateInfo_Dev& value); - - Var CreateVar() const; - - static const char* const kSocketId; - - DictField<int32_t> socket_id; -}; - -class AcceptInfo_Dev { - public: - AcceptInfo_Dev(); - ~AcceptInfo_Dev(); - - bool Populate(const PP_Ext_Socket_AcceptInfo_Dev& value); - - Var CreateVar() const; - - static const char* const kResultCode; - static const char* const kSocketId; - - DictField<int32_t> result_code; - OptionalDictField<int32_t> socket_id; -}; - -class ReadInfo_Dev { - public: - ReadInfo_Dev(); - ~ReadInfo_Dev(); - - bool Populate(const PP_Ext_Socket_ReadInfo_Dev& value); - - Var CreateVar() const; - - static const char* const kResultCode; - static const char* const kData; - - DictField<int32_t> result_code; - DictField<VarArrayBuffer> data; -}; - -class WriteInfo_Dev { - public: - WriteInfo_Dev(); - ~WriteInfo_Dev(); - - bool Populate(const PP_Ext_Socket_WriteInfo_Dev& value); - - Var CreateVar() const; - - static const char* const kBytesWritten; - - DictField<int32_t> bytes_written; -}; - -class RecvFromInfo_Dev { - public: - RecvFromInfo_Dev(); - ~RecvFromInfo_Dev(); - - bool Populate(const PP_Ext_Socket_RecvFromInfo_Dev& value); - - Var CreateVar() const; - - static const char* const kResultCode; - static const char* const kData; - static const char* const kAddress; - static const char* const kPort; - - DictField<int32_t> result_code; - DictField<VarArrayBuffer> data; - DictField<std::string> address; - DictField<int32_t> port; -}; - -class SocketInfo_Dev { - public: - SocketInfo_Dev(); - ~SocketInfo_Dev(); - - bool Populate(const PP_Ext_Socket_SocketInfo_Dev& value); - - Var CreateVar() const; - - static const char* const kSocketType; - static const char* const kConnected; - static const char* const kPeerAddress; - static const char* const kPeerPort; - static const char* const kLocalAddress; - static const char* const kLocalPort; - - DictField<SocketType_Dev> socket_type; - DictField<bool> connected; - OptionalDictField<std::string> peer_address; - OptionalDictField<int32_t> peer_port; - OptionalDictField<std::string> local_address; - OptionalDictField<int32_t> local_port; -}; - -class NetworkInterface_Dev { - public: - NetworkInterface_Dev(); - ~NetworkInterface_Dev(); - - bool Populate(const PP_Ext_Socket_NetworkInterface_Dev& value); - - Var CreateVar() const; - - static const char* const kName; - static const char* const kAddress; - - DictField<std::string> name; - DictField<std::string> address; -}; - -// Functions ------------------------------------------------------------------- -class Socket_Dev { - public: - explicit Socket_Dev(const InstanceHandle& instance); - ~Socket_Dev(); - - typedef ExtCompletionCallbackWithOutput<CreateInfo_Dev> CreateCallback; - int32_t Create(const SocketType_Dev& type, - const Optional<CreateOptions_Dev>& options, - const CreateCallback& callback); - - void Destroy(int32_t socket_id); - - typedef ExtCompletionCallbackWithOutput<int32_t> ConnectCallback; - int32_t Connect(int32_t socket_id, - const std::string& hostname, - int32_t port, - const ConnectCallback& callback); - - typedef ExtCompletionCallbackWithOutput<int32_t> BindCallback; - int32_t Bind(int32_t socket_id, - const std::string& address, - int32_t port, - const BindCallback& callback); - - void Disconnect(int32_t socket_id); - - typedef ExtCompletionCallbackWithOutput<ReadInfo_Dev> ReadCallback; - int32_t Read(int32_t socket_id, - const Optional<int32_t>& buffer_size, - const ReadCallback& callback); - - typedef ExtCompletionCallbackWithOutput<WriteInfo_Dev> WriteCallback; - int32_t Write(int32_t socket_id, - const VarArrayBuffer& data, - const WriteCallback& callback); - - typedef ExtCompletionCallbackWithOutput<RecvFromInfo_Dev> RecvFromCallback; - int32_t RecvFrom(int32_t socket_id, - const Optional<int32_t>& buffer_size, - const RecvFromCallback& callback); - - typedef ExtCompletionCallbackWithOutput<WriteInfo_Dev> SendToCallback; - int32_t SendTo(int32_t socket_id, - const VarArrayBuffer& data, - const std::string& address, - int32_t port, - const SendToCallback& callback); - - typedef ExtCompletionCallbackWithOutput<int32_t> ListenCallback; - int32_t Listen(int32_t socket_id, - const std::string& address, - int32_t port, - const Optional<int32_t>& backlog, - const ListenCallback& callback); - - typedef ExtCompletionCallbackWithOutput<AcceptInfo_Dev> AcceptCallback; - int32_t Accept(int32_t socket_id, const AcceptCallback& callback); - - typedef ExtCompletionCallbackWithOutput<bool> SetKeepAliveCallback; - int32_t SetKeepAlive(int32_t socket_id, - bool enable, - const Optional<int32_t>& delay, - const SetKeepAliveCallback& callback); - - typedef ExtCompletionCallbackWithOutput<bool> SetNoDelayCallback; - int32_t SetNoDelay(int32_t socket_id, - bool no_delay, - const SetNoDelayCallback& callback); - - typedef ExtCompletionCallbackWithOutput<SocketInfo_Dev> GetInfoCallback; - int32_t GetInfo(int32_t socket_id, - const GetInfoCallback& callback); - - typedef ExtCompletionCallbackWithOutput<std::vector<NetworkInterface_Dev> > - GetNetworkListCallback; - int32_t GetNetworkList(const GetNetworkListCallback& callback); - - typedef ExtCompletionCallbackWithOutput<int32_t> JoinGroupCallback; - int32_t JoinGroup(int32_t socket_id, - const std::string& address, - const JoinGroupCallback& callback); - - typedef ExtCompletionCallbackWithOutput<int32_t> LeaveGroupCallback; - int32_t LeaveGroup(int32_t socket_id, - const std::string& address, - const LeaveGroupCallback& callback); - - typedef ExtCompletionCallbackWithOutput<int32_t> - SetMulticastTimeToLiveCallback; - int32_t SetMulticastTimeToLive( - int32_t socket_id, - int32_t ttl, - const SetMulticastTimeToLiveCallback& callback); - - typedef ExtCompletionCallbackWithOutput<int32_t> - SetMulticastLoopbackModeCallback; - int32_t SetMulticastLoopbackMode( - int32_t socket_id, - bool enabled, - const SetMulticastLoopbackModeCallback& callback); - - typedef ExtCompletionCallbackWithOutput<std::vector<std::string> > - GetJoinedGroupsCallback; - int32_t GetJoinedGroups(int32_t socket_id, - const GetJoinedGroupsCallback& callback); - - private: - InstanceHandle instance_; -}; - -} // namespace socket -} // namespace ext -} // namespace pp - -#endif // PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ diff --git a/ppapi/cpp/extensions/dict_field.h b/ppapi/cpp/extensions/dict_field.h deleted file mode 100644 index f332014..0000000 --- a/ppapi/cpp/extensions/dict_field.h +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 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_EXTENSIONS_DICT_FIELD_H_ -#define PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_ - -#include <string> - -#include "ppapi/c/pp_bool.h" -#include "ppapi/cpp/extensions/from_var_converter.h" -#include "ppapi/cpp/extensions/optional.h" -#include "ppapi/cpp/extensions/to_var_converter.h" -#include "ppapi/cpp/var.h" -#include "ppapi/cpp/var_dictionary.h" - -namespace pp { -namespace ext { - -template <class T> -class DictField { - public: - explicit DictField(const std::string& key) : key_(key), value_() { - } - - ~DictField() { - } - - const std::string& key() const { return key_; } - - // Returns the value. - T& operator()() { return value_; } - const T& operator()() const { return value_; } - - // Adds this field to the dictionary var. - bool AddTo(VarDictionary* dict) const { - if (!dict) - return false; - - internal::ToVarConverter<T> converter(value_); - return dict->Set(Var(key_), converter.var()); - } - - bool Populate(const VarDictionary& dict) { - Var value_var = dict.Get(Var(key_)); - if (value_var.is_undefined()) - return false; - - internal::FromVarConverter<T> converter(value_var.pp_var()); - value_ = converter.value(); - return true; - } - - private: - std::string key_; - T value_; -}; - -template <class T> -class OptionalDictField { - public: - explicit OptionalDictField(const std::string& key) : key_(key) { - } - - ~OptionalDictField() { - } - - const std::string& key() const { return key_; } - - // Returns the value. - Optional<T>& operator()() { return value_; } - const Optional<T>& operator()() const { return value_; } - - // Adds this field to the dictionary var, if |value| has been set. - bool MayAddTo(VarDictionary* dict) const { - if (!dict) - return false; - if (!value_.IsSet()) - return true; - - internal::ToVarConverter<T> converter(*value_); - return dict->Set(Var(key_), converter.var()); - } - - bool Populate(const VarDictionary& dict) { - Var value_var = dict.Get(Var(key_)); - internal::FromVarConverter<Optional<T> > converter(value_var.pp_var()); - value_.Swap(&converter.value()); - return true; - } - - private: - std::string key_; - Optional<T> value_; -}; - -} // namespace ext -} // namespace pp - -#endif // PPAPI_CPP_EXTENSIONS_DICT_FIELD_H_ diff --git a/ppapi/cpp/extensions/ext_output_traits.h b/ppapi/cpp/extensions/ext_output_traits.h deleted file mode 100644 index ed57be1..0000000 --- a/ppapi/cpp/extensions/ext_output_traits.h +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 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_EXTENSIONS_OUTPUT_TRAITS_H_ -#define PPAPI_CPP_EXTENSIONS_OUTPUT_TRAITS_H_ - -#include <vector> - -#include "ppapi/c/pp_var.h" -#include "ppapi/cpp/extensions/from_var_converter.h" -#include "ppapi/cpp/logging.h" -#include "ppapi/cpp/pass_ref.h" -#include "ppapi/cpp/var.h" -#include "ppapi/cpp/var_array.h" - -namespace pp { -namespace ext { -namespace internal { - -template <class T> -class VarOutputAdapterWithStorage { - public: - VarOutputAdapterWithStorage() : pp_var_(PP_MakeUndefined()) { - } - - ~VarOutputAdapterWithStorage() { - PP_DCHECK(pp_var_.type == PP_VARTYPE_UNDEFINED); - } - - PP_Var& pp_var() { return pp_var_; } - - T& output() { - Var auto_release(PASS_REF, pp_var_); - converter_.Set(pp_var_); - pp_var_ = PP_MakeUndefined(); - return converter_.value(); - } - - private: - PP_Var pp_var_; - FromVarConverter<T> converter_; - - // Disallow copying and assignment. - VarOutputAdapterWithStorage(const VarOutputAdapterWithStorage<T>&); - VarOutputAdapterWithStorage<T>& operator=( - const VarOutputAdapterWithStorage<T>&); -}; - -// ExtCallbackOutputTraits is used with ExtCompletionCallbackWithOutput. Unlike -// pp::internal::CallbackOutputTraits, it always uses PP_Var* as output -// parameter type to interact with the browser. -// -// For example, CompletionCallbackWithOutput<double> (using -// pp::internal::CallbackOutputTraits) uses double* as the output parameter -// type; while ExtCompletionCallbackWithOutput<double> uses PP_Var*. -template <class T> -struct ExtCallbackOutputTraits { - typedef PP_Var* APIArgType; - typedef VarOutputAdapterWithStorage<T> StorageType; - - static inline APIArgType StorageToAPIArg(StorageType& t) { - return &t.pp_var(); - } - - // This must be called exactly once to consume the one PP_Var reference - // assigned to us by the browser. - static inline T& StorageToPluginArg(StorageType& t) { - return t.output(); - } - - static inline void Initialize(StorageType* /* t */) {} -}; - -// This class provides storage for a PP_Var and a vector of objects which are -// of type T. The PP_Var is used as an output parameter to receive an array var -// from the browser. Each element in the array var is converted to a T object, -// using FromVarConverter, and stores in the vector. -template <class T> -class ArrayVarOutputAdapterWithStorage { - public: - ArrayVarOutputAdapterWithStorage() : pp_var_(PP_MakeUndefined()) { - } - - ~ArrayVarOutputAdapterWithStorage() { - PP_DCHECK(pp_var_.type == PP_VARTYPE_UNDEFINED); - } - - PP_Var& pp_var() { return pp_var_; } - - std::vector<T>& output() { - PP_DCHECK(output_storage_.empty()); - - Var var(PASS_REF, pp_var_); - pp_var_ = PP_MakeUndefined(); - if (var.is_array()) { - VarArray array(var); - - uint32_t length = array.GetLength(); - output_storage_.reserve(length); - for (uint32_t i = 0; i < length; ++i) { - FromVarConverter<T> converter(array.Get(i).pp_var()); - output_storage_.push_back(converter.value()); - } - } - - return output_storage_; - } - - private: - PP_Var pp_var_; - std::vector<T> output_storage_; - - // Disallow copying and assignment. - ArrayVarOutputAdapterWithStorage(const ArrayVarOutputAdapterWithStorage<T>&); - ArrayVarOutputAdapterWithStorage<T>& operator=( - const ArrayVarOutputAdapterWithStorage<T>&); -}; - -template <class T> -struct ExtCallbackOutputTraits< std::vector<T> > { - typedef PP_Var* APIArgType; - typedef ArrayVarOutputAdapterWithStorage<T> StorageType; - - static inline APIArgType StorageToAPIArg(StorageType& t) { - return &t.pp_var(); - } - - // This must be called exactly once to consume the one PP_Var reference - // assigned to us by the browser. - static inline std::vector<T>& StorageToPluginArg(StorageType& t) { - return t.output(); - } - - static inline void Initialize(StorageType* /* t */) {} -}; - -} // namespace internal -} // namespace ext -} // namespace pp - -#endif // PPAPI_CPP_EXTENSIONS_OUTPUT_TRAITS_H_ diff --git a/ppapi/cpp/extensions/from_var_converter.h b/ppapi/cpp/extensions/from_var_converter.h deleted file mode 100644 index 06ae0df..0000000 --- a/ppapi/cpp/extensions/from_var_converter.h +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (c) 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_EXTENSIONS_FROM_VAR_CONVERTOR_H_ -#define PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_ - -#include <string> - -#include "ppapi/c/pp_var.h" -#include "ppapi/cpp/extensions/optional.h" -#include "ppapi/cpp/logging.h" -#include "ppapi/cpp/var.h" -#include "ppapi/cpp/var_array.h" -#include "ppapi/cpp/var_array_buffer.h" -#include "ppapi/cpp/var_dictionary.h" - -namespace pp { -namespace ext { -namespace internal { - -template <class T> -class FromVarConverterBase { - public: - T& value() { return value_; } - - protected: - FromVarConverterBase() : value_() { - } - - explicit FromVarConverterBase(const T& value) : value_(value) { - } - - ~FromVarConverterBase() { - } - - T value_; -}; - -template <class T> -class FromVarConverter : public FromVarConverterBase<T> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - bool succeeded = FromVarConverterBase<T>::value_.Populate(var); - // Suppress unused variable warnings. - static_cast<void>(succeeded); - PP_DCHECK(succeeded); - } -}; - -template <class T> -class FromVarConverter<Optional<T> > - : public FromVarConverterBase<Optional<T> > { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - if (var.type == PP_VARTYPE_UNDEFINED) { - FromVarConverterBase<Optional<T> >::value_.Reset(); - } else { - FromVarConverter<T> converter(var); - FromVarConverterBase<Optional<T> >::value_ = converter.value(); - } - } -}; - -template <> -class FromVarConverter<bool> : public FromVarConverterBase<bool> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<bool>::value_ = Var(var).AsBool(); - } -}; - -template <> -class FromVarConverter<int32_t> : public FromVarConverterBase<int32_t> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<int32_t>::value_ = Var(var).AsInt(); - } -}; - -template <> -class FromVarConverter<double> : public FromVarConverterBase<double> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<double>::value_ = Var(var).AsDouble(); - } -}; - -template <> -class FromVarConverter<std::string> : public FromVarConverterBase<std::string> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<std::string>::value_ = Var(var).AsString(); - } -}; - -template <> -class FromVarConverter<Var> : public FromVarConverterBase<Var> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<Var>::value_ = Var(var); - } -}; - -template <> -class FromVarConverter<VarArray> - : public FromVarConverterBase<VarArray> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<VarArray>::value_ = Var(var); - } -}; - -template <> -class FromVarConverter<VarDictionary> - : public FromVarConverterBase<VarDictionary> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<VarDictionary>::value_ = Var(var); - } -}; - -template <> -class FromVarConverter<VarArrayBuffer> - : public FromVarConverterBase<VarArrayBuffer> { - public: - FromVarConverter() { - } - - explicit FromVarConverter(const PP_Var& var) { - Set(var); - } - - ~FromVarConverter() { - } - - void Set(const PP_Var& var) { - FromVarConverterBase<VarArrayBuffer>::value_ = Var(var); - } -}; - -} // namespace internal -} // namespace ext -} // namespace pp - -#endif // PPAPI_CPP_EXTENSIONS_FROM_VAR_CONVERTOR_H_ diff --git a/ppapi/cpp/extensions/optional.h b/ppapi/cpp/extensions/optional.h deleted file mode 100644 index fdef839..0000000 --- a/ppapi/cpp/extensions/optional.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) 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_EXTENSIONS_OPTIONAL_H_ -#define PPAPI_CPP_EXTENSIONS_OPTIONAL_H_ - -namespace pp { -namespace ext { - -template <class T> -class Optional { - public: - Optional() : value_(NULL) { - } - // Takes ownership of |value|. - explicit Optional(T* value) : value_(value) { - } - Optional(const T& value) : value_(new T(value)) { - } - Optional(const Optional<T>& other) - : value_(other.value_ ? new T(*other.value_) : NULL) { - } - - ~Optional() { - Reset(); - } - - Optional<T>& operator=(const T& other) { - if (value_ == &other) - return *this; - - Reset(); - value_ = new T(other); - - return *this; - } - - Optional<T>& operator=(const Optional<T>& other) { - if (value_ == other.value_) - return *this; - - Reset(); - if (other.value_) - value_ = new T(*other.value_); - - return *this; - } - - bool IsSet() const { - return !!value_; - } - - T* Get() const { - return value_; - } - - // Should only be used when IsSet() is true. - T& operator*() const { - return *value_; - } - - // Should only be used when IsSet() is true. - T* operator->() const { - PP_DCHECK(value_); - return value_; - } - - // Takes ownership of |value|. - void Set(T* value) { - if (value == value_) - return; - - Reset(); - *value_ = value; - } - - void Reset() { - T* value = value_; - value_ = NULL; - delete value; - } - - void Swap(Optional<T>* other) { - T* temp = value_; - value_ = other->value_; - other->value_ = temp; - } - - private: - T* value_; -}; - -} // namespace ext -} // namespace pp - -#endif // PPAPI_CPP_EXTENSIONS_OPTIONAL_H_ diff --git a/ppapi/cpp/extensions/to_var_converter.h b/ppapi/cpp/extensions/to_var_converter.h deleted file mode 100644 index e384999..0000000 --- a/ppapi/cpp/extensions/to_var_converter.h +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (c) 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_EXTENSIONS_TO_VAR_CONVERTOR_H_ -#define PPAPI_CPP_EXTENSIONS_TO_VAR_CONVERTOR_H_ - -#include <string> - -#include "ppapi/c/pp_var.h" -#include "ppapi/cpp/extensions/optional.h" -#include "ppapi/cpp/var.h" -#include "ppapi/cpp/var_array.h" -#include "ppapi/cpp/var_array_buffer.h" -#include "ppapi/cpp/var_dictionary.h" - -namespace pp { -namespace ext { -namespace internal { - -class ToVarConverterBase { - public: - PP_Var pp_var() const { - return var_.pp_var(); - } - - const Var& var() const { - return var_; - } - - protected: - ToVarConverterBase() { - } - - explicit ToVarConverterBase(const PP_Var& var) : var_(var) { - } - - explicit ToVarConverterBase(const Var& var): var_(var) { - } - - ~ToVarConverterBase() { - } - - Var var_; -}; - -template <class T> -class ToVarConverter : public ToVarConverterBase { - public: - explicit ToVarConverter(const T& object) - : ToVarConverterBase(object.CreateVar()) { - } - - ~ToVarConverter() { - } -}; - -template <class T> -class ToVarConverter<Optional<T> > : public ToVarConverterBase { - public: - explicit ToVarConverter(const Optional<T>& object) - : ToVarConverterBase( - object.IsSet() ? ToVarConverter<T>(*object).pp_var() : - PP_MakeUndefined()) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<bool> : public ToVarConverterBase { - public: - explicit ToVarConverter(bool object) : ToVarConverterBase(Var(object)) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<int32_t> : public ToVarConverterBase { - public: - explicit ToVarConverter(int32_t object) : ToVarConverterBase(Var(object)) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<double> : public ToVarConverterBase { - public: - explicit ToVarConverter(double object) : ToVarConverterBase(Var(object)) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<std::string> : public ToVarConverterBase { - public: - explicit ToVarConverter(const std::string& object) - : ToVarConverterBase(Var(object)) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<Var> : public ToVarConverterBase { - public: - explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<VarArray> : public ToVarConverterBase { - public: - explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<VarDictionary> : public ToVarConverterBase { - public: - explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { - } - - ~ToVarConverter() { - } -}; - -template <> -class ToVarConverter<VarArrayBuffer> : public ToVarConverterBase { - public: - explicit ToVarConverter(const Var& object) : ToVarConverterBase(object) { - } - - ~ToVarConverter() { - } -}; - -} // namespace internal -} // namespace ext -} // namespace pp - -#endif // PPAPI_CPP_EXTENSIONS_TO_VAR_CONVERTOR_H_ |