1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/private/network_list_private.h"
7 #include "ppapi/cpp/module_impl.h"
8 #include "ppapi/cpp/var.h"
14 template <> const char* interface_name
<PPB_NetworkList_Private
>() {
15 return PPB_NETWORKLIST_PRIVATE_INTERFACE
;
20 NetworkListPrivate::NetworkListPrivate() {
23 NetworkListPrivate::NetworkListPrivate(PassRef
, PP_Resource resource
)
24 : Resource(PASS_REF
, resource
) {
28 bool NetworkListPrivate::IsAvailable() {
29 return has_interface
<PPB_NetworkList_Private
>();
32 uint32_t NetworkListPrivate::GetCount() const {
33 if (!has_interface
<PPB_NetworkList_Private
>())
35 return get_interface
<PPB_NetworkList_Private
>()->GetCount(pp_resource());
38 std::string
NetworkListPrivate::GetName(uint32_t index
) const {
39 if (!has_interface
<PPB_NetworkList_Private
>())
42 get_interface
<PPB_NetworkList_Private
>()->GetName(
43 pp_resource(), index
));
44 return result
.is_string() ? result
.AsString() : std::string();
47 PP_NetworkListType_Private
NetworkListPrivate::GetType(uint32_t index
) const {
48 if (!has_interface
<PPB_NetworkList_Private
>())
49 return PP_NETWORKLIST_ETHERNET
;
50 return get_interface
<PPB_NetworkList_Private
>()->GetType(
51 pp_resource(), index
);
54 PP_NetworkListState_Private
NetworkListPrivate::GetState(uint32_t index
) const {
55 if (!has_interface
<PPB_NetworkList_Private
>())
56 return PP_NETWORKLIST_DOWN
;
57 return get_interface
<PPB_NetworkList_Private
>()->GetState(
58 pp_resource(), index
);
61 void NetworkListPrivate::GetIpAddresses(
63 std::vector
<PP_NetAddress_Private
>* addresses
) const {
64 if (!has_interface
<PPB_NetworkList_Private
>())
67 // Most network interfaces don't have more than 3 network
71 int32_t result
= get_interface
<PPB_NetworkList_Private
>()->GetIpAddresses(
72 pp_resource(), index
, &addresses
->front(), addresses
->size());
79 if (result
<= static_cast<int32_t>(addresses
->size())) {
80 addresses
->resize(result
);
84 addresses
->resize(result
);
85 result
= get_interface
<PPB_NetworkList_Private
>()->GetIpAddresses(
86 pp_resource(), index
, &addresses
->front(), addresses
->size());
89 } else if (result
< static_cast<int32_t>(addresses
->size())) {
90 addresses
->resize(result
);
94 std::string
NetworkListPrivate::GetDisplayName(uint32_t index
) const {
95 if (!has_interface
<PPB_NetworkList_Private
>())
98 get_interface
<PPB_NetworkList_Private
>()->GetDisplayName(
99 pp_resource(), index
));
100 return result
.is_string() ? result
.AsString() : std::string();
103 uint32_t NetworkListPrivate::GetMTU(uint32_t index
) const {
104 if (!has_interface
<PPB_NetworkList_Private
>())
106 return get_interface
<PPB_NetworkList_Private
>()->GetMTU(
107 pp_resource(), index
);