| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/cpp/private/network_list_private.h" | 5 #include "ppapi/cpp/private/network_list_private.h" |
| 6 | 6 |
| 7 #include "ppapi/cpp/module_impl.h" | 7 #include "ppapi/cpp/module_impl.h" |
| 8 #include "ppapi/cpp/var.h" | 8 #include "ppapi/cpp/var.h" |
| 9 | 9 |
| 10 namespace pp { | 10 namespace pp { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 template <> const char* interface_name<PPB_NetworkList_Private>() { | 14 template <> const char* interface_name<PPB_NetworkList_Private>() { |
| 15 return PPB_NETWORKLIST_PRIVATE_INTERFACE; | 15 return PPB_NETWORKLIST_PRIVATE_INTERFACE; |
| 16 } | 16 } |
| 17 | 17 |
| 18 } // namespace | 18 } // namespace |
| 19 | 19 |
| 20 NetworkListPrivate::NetworkListPrivate() { |
| 21 } |
| 22 |
| 20 NetworkListPrivate::NetworkListPrivate(PP_Resource resource) | 23 NetworkListPrivate::NetworkListPrivate(PP_Resource resource) |
| 21 : Resource(resource) { | 24 : Resource(resource) { |
| 22 } | 25 } |
| 23 | 26 |
| 24 // static | 27 // static |
| 25 bool NetworkListPrivate::IsAvailable() { | 28 bool NetworkListPrivate::IsAvailable() { |
| 26 return has_interface<PPB_NetworkList_Private>(); | 29 return has_interface<PPB_NetworkList_Private>(); |
| 27 } | 30 } |
| 28 | 31 |
| 29 uint32_t NetworkListPrivate::GetCount() { | 32 uint32_t NetworkListPrivate::GetCount() const { |
| 30 if (!has_interface<PPB_NetworkList_Private>()) | 33 if (!has_interface<PPB_NetworkList_Private>()) |
| 31 return 0; | 34 return 0; |
| 32 return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource()); | 35 return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource()); |
| 33 } | 36 } |
| 34 | 37 |
| 35 std::string NetworkListPrivate::GetName(uint32_t index) { | 38 std::string NetworkListPrivate::GetName(uint32_t index) const { |
| 36 if (!has_interface<PPB_NetworkList_Private>()) | 39 if (!has_interface<PPB_NetworkList_Private>()) |
| 37 return std::string(); | 40 return std::string(); |
| 38 Var result(PASS_REF, | 41 Var result(PASS_REF, |
| 39 get_interface<PPB_NetworkList_Private>()->GetName( | 42 get_interface<PPB_NetworkList_Private>()->GetName( |
| 40 pp_resource(), index)); | 43 pp_resource(), index)); |
| 41 return result.is_string() ? result.AsString() : std::string(); | 44 return result.is_string() ? result.AsString() : std::string(); |
| 42 } | 45 } |
| 43 | 46 |
| 44 PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) { | 47 PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { |
| 45 if (!has_interface<PPB_NetworkList_Private>()) | 48 if (!has_interface<PPB_NetworkList_Private>()) |
| 46 return PP_NETWORKLIST_ETHERNET; | 49 return PP_NETWORKLIST_ETHERNET; |
| 47 return get_interface<PPB_NetworkList_Private>()->GetType( | 50 return get_interface<PPB_NetworkList_Private>()->GetType( |
| 48 pp_resource(), index); | 51 pp_resource(), index); |
| 49 } | 52 } |
| 50 | 53 |
| 51 PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) { | 54 PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { |
| 52 if (!has_interface<PPB_NetworkList_Private>()) | 55 if (!has_interface<PPB_NetworkList_Private>()) |
| 53 return PP_NETWORKLIST_DOWN; | 56 return PP_NETWORKLIST_DOWN; |
| 54 return get_interface<PPB_NetworkList_Private>()->GetState( | 57 return get_interface<PPB_NetworkList_Private>()->GetState( |
| 55 pp_resource(), index); | 58 pp_resource(), index); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void NetworkListPrivate::GetIpAddresses( | 61 void NetworkListPrivate::GetIpAddresses( |
| 59 uint32_t index, | 62 uint32_t index, |
| 60 std::vector<PP_NetAddress_Private>* addresses) { | 63 std::vector<PP_NetAddress_Private>* addresses) const { |
| 61 if (!has_interface<PPB_NetworkList_Private>()) | 64 if (!has_interface<PPB_NetworkList_Private>()) |
| 62 return; | 65 return; |
| 63 | 66 |
| 64 // Most netword interfaces don't have more than 3 network | 67 // Most netword interfaces don't have more than 3 network |
| 65 // interfaces. | 68 // interfaces. |
| 66 addresses->resize(3); | 69 addresses->resize(3); |
| 67 | 70 |
| 68 int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( | 71 int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( |
| 69 pp_resource(), index, &addresses->front(), addresses->size()); | 72 pp_resource(), index, &addresses->front(), addresses->size()); |
| 70 | 73 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 addresses->resize(result); | 84 addresses->resize(result); |
| 82 result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( | 85 result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( |
| 83 pp_resource(), index, &addresses->front(), addresses->size()); | 86 pp_resource(), index, &addresses->front(), addresses->size()); |
| 84 if (result < 0) { | 87 if (result < 0) { |
| 85 addresses->resize(0); | 88 addresses->resize(0); |
| 86 } else if (result < static_cast<int32_t>(addresses->size())) { | 89 } else if (result < static_cast<int32_t>(addresses->size())) { |
| 87 addresses->resize(result); | 90 addresses->resize(result); |
| 88 } | 91 } |
| 89 } | 92 } |
| 90 | 93 |
| 91 std::string NetworkListPrivate::GetDisplayName(uint32_t index) { | 94 std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { |
| 92 if (!has_interface<PPB_NetworkList_Private>()) | 95 if (!has_interface<PPB_NetworkList_Private>()) |
| 93 return std::string(); | 96 return std::string(); |
| 94 Var result(PASS_REF, | 97 Var result(PASS_REF, |
| 95 get_interface<PPB_NetworkList_Private>()->GetDisplayName( | 98 get_interface<PPB_NetworkList_Private>()->GetDisplayName( |
| 96 pp_resource(), index)); | 99 pp_resource(), index)); |
| 97 return result.is_string() ? result.AsString() : std::string(); | 100 return result.is_string() ? result.AsString() : std::string(); |
| 98 } | 101 } |
| 99 | 102 |
| 100 uint32_t NetworkListPrivate::GetMTU(uint32_t index) { | 103 uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { |
| 101 if (!has_interface<PPB_NetworkList_Private>()) | 104 if (!has_interface<PPB_NetworkList_Private>()) |
| 102 return 0; | 105 return 0; |
| 103 return get_interface<PPB_NetworkList_Private>()->GetMTU( | 106 return get_interface<PPB_NetworkList_Private>()->GetMTU( |
| 104 pp_resource(), index); | 107 pp_resource(), index); |
| 105 } | 108 } |
| 106 | 109 |
| 107 } // namespace pp | 110 } // namespace pp |
| OLD | NEW |