From 86fbad285cb3697e662e2f0b34f82dd2fba2f71e Mon Sep 17 00:00:00 2001 From: "sergeyu@chromium.org" Date: Sun, 22 Sep 2013 06:34:03 +0000 Subject: Make NetworkList and NetworkMonitor APIs public BUG=281781 R=nfullagar@chromium.org, thakis@chromium.org, yzshen@chromium.org TBR=cevans@chromium.org Review URL: https://codereview.chromium.org/23450012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224626 0039d316-1c4b-4281-b951-d872f2087c98 --- ppapi/cpp/network_list.cc | 94 ++++++++++++++++++++++++++++ ppapi/cpp/network_list.h | 60 ++++++++++++++++++ ppapi/cpp/network_monitor.cc | 44 +++++++++++++ ppapi/cpp/network_monitor.h | 31 +++++++++ ppapi/cpp/private/network_list_private.cc | 94 ---------------------------- ppapi/cpp/private/network_list_private.h | 60 ------------------ ppapi/cpp/private/network_monitor_private.cc | 44 ------------- ppapi/cpp/private/network_monitor_private.h | 31 --------- 8 files changed, 229 insertions(+), 229 deletions(-) create mode 100644 ppapi/cpp/network_list.cc create mode 100644 ppapi/cpp/network_list.h create mode 100644 ppapi/cpp/network_monitor.cc create mode 100644 ppapi/cpp/network_monitor.h delete mode 100644 ppapi/cpp/private/network_list_private.cc delete mode 100644 ppapi/cpp/private/network_list_private.h delete mode 100644 ppapi/cpp/private/network_monitor_private.cc delete mode 100644 ppapi/cpp/private/network_monitor_private.h (limited to 'ppapi/cpp') diff --git a/ppapi/cpp/network_list.cc b/ppapi/cpp/network_list.cc new file mode 100644 index 0000000..12c3bf4 --- /dev/null +++ b/ppapi/cpp/network_list.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2012 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/network_list.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/array_output.h" +#include "ppapi/cpp/logging.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/net_address.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name() { + return PPB_NETWORKLIST_INTERFACE_1_0; +} + +} // namespace + +NetworkList::NetworkList() { +} + +NetworkList::NetworkList(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +// static +bool NetworkList::IsAvailable() { + return has_interface(); +} + +uint32_t NetworkList::GetCount() const { + if (!has_interface()) + return 0; + return get_interface()->GetCount(pp_resource()); +} + +std::string NetworkList::GetName(uint32_t index) const { + if (!has_interface()) + return std::string(); + Var result(PASS_REF, + get_interface()->GetName( + pp_resource(), index)); + return result.is_string() ? result.AsString() : std::string(); +} + +PP_NetworkList_Type NetworkList::GetType(uint32_t index) const { + if (!has_interface()) + return PP_NETWORKLIST_TYPE_ETHERNET; + return get_interface()->GetType( + pp_resource(), index); +} + +PP_NetworkList_State NetworkList::GetState(uint32_t index) const { + if (!has_interface()) + return PP_NETWORKLIST_STATE_DOWN; + return get_interface()->GetState( + pp_resource(), index); +} + +int32_t NetworkList::GetIpAddresses( + uint32_t index, + std::vector* addresses) const { + if (!has_interface()) + return PP_ERROR_NOINTERFACE; + if (!addresses) + return PP_ERROR_BADARGUMENT; + + ResourceArrayOutputAdapter adapter(addresses); + return get_interface()->GetIpAddresses( + pp_resource(), index, adapter.pp_array_output()); +} + +std::string NetworkList::GetDisplayName(uint32_t index) const { + if (!has_interface()) + return std::string(); + Var result(PASS_REF, + get_interface()->GetDisplayName( + pp_resource(), index)); + return result.is_string() ? result.AsString() : std::string(); +} + +uint32_t NetworkList::GetMTU(uint32_t index) const { + if (!has_interface()) + return 0; + return get_interface()->GetMTU( + pp_resource(), index); +} + +} // namespace pp diff --git a/ppapi/cpp/network_list.h b/ppapi/cpp/network_list.h new file mode 100644 index 0000000..d479129 --- /dev/null +++ b/ppapi/cpp/network_list.h @@ -0,0 +1,60 @@ +// Copyright (c) 2012 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_NETWORK_LIST_H_ +#define PPAPI_CPP_NETWORK_LIST_H_ + +#include +#include + +#include "ppapi/c/ppb_network_list.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class NetAddress; + +class NetworkList : public Resource { + public: + NetworkList(); + NetworkList(PassRef, PP_Resource resource); + + /// Returns true if the required interface is available. + static bool IsAvailable(); + + /// @return Returns the number of available network interfaces or 0 + /// if the list has never been updated. + uint32_t GetCount() const; + + /// @return Returns the name for the network interface with the + /// specified index. + std::string GetName(uint32_t index) const; + + /// @return Returns the type of the network interface with the + /// specified index. + PP_NetworkList_Type GetType(uint32_t index) const; + + /// @return Returns the current state of the network interface with + /// the specified index. + PP_NetworkList_State GetState(uint32_t index) const; + + /// Gets the list of IP addresses for the network interface with the + /// specified index and stores them in + /// addresses. + int32_t GetIpAddresses(uint32_t index, + std::vector* addresses) const; + + /// @return Returns the display name for the network interface with + /// the specified index. + std::string GetDisplayName(uint32_t index) const; + + /// @return Returns the MTU for the network interface with the + /// specified index. + uint32_t GetMTU(uint32_t index) const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_NETWORK_LIST_H_ diff --git a/ppapi/cpp/network_monitor.cc b/ppapi/cpp/network_monitor.cc new file mode 100644 index 0000000..b721e96 --- /dev/null +++ b/ppapi/cpp/network_monitor.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2012 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/network_monitor.h" + +#include "ppapi/c/ppb_network_monitor.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/network_list.h" + +namespace pp { + +namespace { + +template <> const char* interface_name() { + return PPB_NETWORKMONITOR_INTERFACE_1_0; +} + +} // namespace + +NetworkMonitor::NetworkMonitor(const InstanceHandle& instance) { + if (has_interface()) { + PassRefFromConstructor(get_interface()->Create( + instance.pp_instance())); + } +} + +int32_t NetworkMonitor::UpdateNetworkList( + const CompletionCallbackWithOutput& callback) { + if (has_interface()) { + return get_interface()->UpdateNetworkList( + pp_resource(), callback.output(), callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +// static +bool NetworkMonitor::IsAvailable() { + return has_interface(); +} + +} // namespace pp diff --git a/ppapi/cpp/network_monitor.h b/ppapi/cpp/network_monitor.h new file mode 100644 index 0000000..bce731d9 --- /dev/null +++ b/ppapi/cpp/network_monitor.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 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_NETWORK_MONITOR_H_ +#define PPAPI_CPP_NETWORK_MONITOR_H_ + +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Instance; +class NetworkList; + +template class CompletionCallbackWithOutput; + +class NetworkMonitor : public Resource { + public: + explicit NetworkMonitor(const InstanceHandle& instance); + + int32_t UpdateNetworkList( + const CompletionCallbackWithOutput& callback); + + // Returns true if the required interface is available. + static bool IsAvailable(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_NETWORK_MONITOR_H_ diff --git a/ppapi/cpp/private/network_list_private.cc b/ppapi/cpp/private/network_list_private.cc deleted file mode 100644 index 5a3a5be..0000000 --- a/ppapi/cpp/private/network_list_private.cc +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2012 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/network_list_private.h" - -#include "ppapi/c/pp_errors.h" -#include "ppapi/cpp/array_output.h" -#include "ppapi/cpp/logging.h" -#include "ppapi/cpp/module_impl.h" -#include "ppapi/cpp/net_address.h" -#include "ppapi/cpp/var.h" - -namespace pp { - -namespace { - -template <> const char* interface_name() { - return PPB_NETWORKLIST_PRIVATE_INTERFACE_0_3; -} - -} // namespace - -NetworkListPrivate::NetworkListPrivate() { -} - -NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) - : Resource(PASS_REF, resource) { -} - -// static -bool NetworkListPrivate::IsAvailable() { - return has_interface(); -} - -uint32_t NetworkListPrivate::GetCount() const { - if (!has_interface()) - return 0; - return get_interface()->GetCount(pp_resource()); -} - -std::string NetworkListPrivate::GetName(uint32_t index) const { - if (!has_interface()) - return std::string(); - Var result(PASS_REF, - get_interface()->GetName( - pp_resource(), index)); - return result.is_string() ? result.AsString() : std::string(); -} - -PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { - if (!has_interface()) - return PP_NETWORKLIST_ETHERNET; - return get_interface()->GetType( - pp_resource(), index); -} - -PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { - if (!has_interface()) - return PP_NETWORKLIST_DOWN; - return get_interface()->GetState( - pp_resource(), index); -} - -int32_t NetworkListPrivate::GetIpAddresses( - uint32_t index, - std::vector* addresses) const { - if (!has_interface()) - return PP_ERROR_NOINTERFACE; - if (!addresses) - return PP_ERROR_BADARGUMENT; - - ResourceArrayOutputAdapter adapter(addresses); - return get_interface()->GetIpAddresses( - pp_resource(), index, adapter.pp_array_output()); -} - -std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { - if (!has_interface()) - return std::string(); - Var result(PASS_REF, - get_interface()->GetDisplayName( - pp_resource(), index)); - return result.is_string() ? result.AsString() : std::string(); -} - -uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { - if (!has_interface()) - return 0; - return get_interface()->GetMTU( - pp_resource(), index); -} - -} // namespace pp diff --git a/ppapi/cpp/private/network_list_private.h b/ppapi/cpp/private/network_list_private.h deleted file mode 100644 index c338aa6..0000000 --- a/ppapi/cpp/private/network_list_private.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2012 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_NETWORK_LIST_PRIVATE_H_ -#define PPAPI_CPP_PRIVATE_NETWORK_LIST_PRIVATE_H_ - -#include -#include - -#include "ppapi/c/private/ppb_network_list_private.h" -#include "ppapi/cpp/pass_ref.h" -#include "ppapi/cpp/resource.h" - -namespace pp { - -class NetAddress; - -class NetworkListPrivate : public Resource { - public: - NetworkListPrivate(); - NetworkListPrivate(PassRef, PP_Resource resource); - - /// Returns true if the required interface is available. - static bool IsAvailable(); - - /// @return Returns the number of available network interfaces or 0 - /// if the list has never been updated. - uint32_t GetCount() const; - - /// @return Returns the name for the network interface with the - /// specified index. - std::string GetName(uint32_t index) const; - - /// @return Returns the type of the network interface with the - /// specified index. - PP_NetworkListType_Private GetType(uint32_t index) const; - - /// @return Returns the current state of the network interface with - /// the specified index. - PP_NetworkListState_Private GetState(uint32_t index) const; - - /// Gets the list of IP addresses for the network interface with the - /// specified index and stores them in - /// addresses. - int32_t GetIpAddresses(uint32_t index, - std::vector* addresses) const; - - /// @return Returns the display name for the network interface with - /// the specified index. - std::string GetDisplayName(uint32_t index) const; - - /// @return Returns the MTU for the network interface with the - /// specified index. - uint32_t GetMTU(uint32_t index) const; -}; - -} // namespace pp - -#endif // PPAPI_CPP_PRIVATE_NETWORK_LIST_PRIVATE_H_ diff --git a/ppapi/cpp/private/network_monitor_private.cc b/ppapi/cpp/private/network_monitor_private.cc deleted file mode 100644 index 7cef97f..0000000 --- a/ppapi/cpp/private/network_monitor_private.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2012 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/network_monitor_private.h" - -#include "ppapi/c/private/ppb_network_monitor_private.h" -#include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" -#include "ppapi/cpp/module_impl.h" -#include "ppapi/cpp/private/network_list_private.h" - -namespace pp { - -namespace { - -template <> const char* interface_name() { - return PPB_NETWORKMONITOR_PRIVATE_INTERFACE_0_3; -} - -} // namespace - -NetworkMonitorPrivate::NetworkMonitorPrivate(const InstanceHandle& instance) { - if (has_interface()) { - PassRefFromConstructor(get_interface()-> - Create(instance.pp_instance())); - } -} - -int32_t NetworkMonitorPrivate::UpdateNetworkList( - const CompletionCallbackWithOutput& callback) { - if (has_interface()) { - return get_interface()->UpdateNetworkList( - pp_resource(), callback.output(), callback.pp_completion_callback()); - } - return callback.MayForce(PP_ERROR_NOINTERFACE); -} - -// static -bool NetworkMonitorPrivate::IsAvailable() { - return has_interface(); -} - -} // namespace pp diff --git a/ppapi/cpp/private/network_monitor_private.h b/ppapi/cpp/private/network_monitor_private.h deleted file mode 100644 index b8fbe0f..0000000 --- a/ppapi/cpp/private/network_monitor_private.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012 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_NETWORK_MONITOR_PRIVATE_H_ -#define PPAPI_CPP_PRIVATE_NETWORK_MONITOR_PRIVATE_H_ - -#include "ppapi/cpp/resource.h" -#include "ppapi/cpp/instance_handle.h" - -namespace pp { - -class Instance; -class NetworkListPrivate; - -template class CompletionCallbackWithOutput; - -class NetworkMonitorPrivate : public Resource { - public: - explicit NetworkMonitorPrivate(const InstanceHandle& instance); - - int32_t UpdateNetworkList( - const CompletionCallbackWithOutput& callback); - - // Returns true if the required interface is available. - static bool IsAvailable(); -}; - -} // namespace pp - -#endif // PPAPI_CPP_PRIVATE_NETWORK_MONITOR_PRIVATE_H_ -- cgit v1.1