Index: ppapi/cpp/private/network_list_private.cc |
diff --git a/ppapi/cpp/private/network_list_private.cc b/ppapi/cpp/private/network_list_private.cc |
index 1297aa3a09c65bc27200022ca2b789c902e08cf2..a42e8f81893ed385e9dccb4f168f9ae9931c6f81 100644 |
--- a/ppapi/cpp/private/network_list_private.cc |
+++ b/ppapi/cpp/private/network_list_private.cc |
@@ -4,7 +4,10 @@ |
#include "ppapi/cpp/private/network_list_private.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 { |
@@ -15,6 +18,25 @@ template <> const char* interface_name<PPB_NetworkList_Private>() { |
return PPB_NETWORKLIST_PRIVATE_INTERFACE; |
yzshen1
2013/09/03 17:47:32
ditto.
Sergey Ulanov
2013/09/03 23:42:54
Done.
|
} |
+// Used in GetIpAddresses(). |
yzshen1
2013/09/03 17:47:32
maybe this could be removed?
Sergey Ulanov
2013/09/03 23:42:54
Yes. I added it before I found ResourceArrayOutput
|
+struct ResourceArray { |
+ PP_Resource* resources; |
+ int count; |
+}; |
+ |
+void* AllocateResourceArray(void* data, uint32_t count, uint32_t size) { |
+ ResourceArray* resource_array = reinterpret_cast<ResourceArray*>(data); |
+ PP_DCHECK(size == sizeof(PP_Resource)); |
+ if (size) { |
+ resource_array->resources = new PP_Resource[count]; |
+ if (resource_array->resources) |
+ resource_array->count = count; |
+ } else { |
+ resource_array->resources = NULL; |
+ } |
+ return resource_array->resources; |
+} |
+ |
} // namespace |
NetworkListPrivate::NetworkListPrivate() { |
@@ -60,35 +82,13 @@ PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { |
void NetworkListPrivate::GetIpAddresses( |
uint32_t index, |
- std::vector<PP_NetAddress_Private>* addresses) const { |
+ std::vector<NetAddress>* addresses) const { |
if (!has_interface<PPB_NetworkList_Private>()) |
return; |
yzshen1
2013/09/03 17:47:32
nit: check NULL for |addresses|?
Sergey Ulanov
2013/09/03 23:42:54
Done.
|
- // Most network interfaces don't have more than 3 network |
- // interfaces. |
- addresses->resize(3); |
- |
- int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( |
- pp_resource(), index, &addresses->front(), addresses->size()); |
- |
- if (result < 0) { |
- addresses->resize(0); |
- return; |
- } |
- |
- if (result <= static_cast<int32_t>(addresses->size())) { |
- addresses->resize(result); |
- return; |
- } |
- |
- addresses->resize(result); |
- result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( |
- pp_resource(), index, &addresses->front(), addresses->size()); |
- if (result < 0) { |
- addresses->resize(0); |
- } else if (result < static_cast<int32_t>(addresses->size())) { |
- addresses->resize(result); |
- } |
+ ResourceArrayOutputAdapter<NetAddress> adapter(addresses); |
+ get_interface<PPB_NetworkList_Private>()->GetIpAddresses( |
+ pp_resource(), index, adapter.pp_array_output()); |
} |
std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { |
@@ -103,8 +103,7 @@ std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { |
uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { |
if (!has_interface<PPB_NetworkList_Private>()) |
return 0; |
- return get_interface<PPB_NetworkList_Private>()->GetMTU( |
- pp_resource(), index); |
+ return get_interface<PPB_NetworkList_Private>()->GetMTU(pp_resource(), index); |
} |
} // namespace pp |