| 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/c/pp_errors.h" |
| 8 #include "ppapi/cpp/array_output.h" |
| 9 #include "ppapi/cpp/logging.h" |
| 7 #include "ppapi/cpp/module_impl.h" | 10 #include "ppapi/cpp/module_impl.h" |
| 11 #include "ppapi/cpp/net_address.h" |
| 8 #include "ppapi/cpp/var.h" | 12 #include "ppapi/cpp/var.h" |
| 9 | 13 |
| 10 namespace pp { | 14 namespace pp { |
| 11 | 15 |
| 12 namespace { | 16 namespace { |
| 13 | 17 |
| 14 template <> const char* interface_name<PPB_NetworkList_Private>() { | 18 template <> const char* interface_name<PPB_NetworkList_Private_0_3>() { |
| 15 return PPB_NETWORKLIST_PRIVATE_INTERFACE; | 19 return PPB_NETWORKLIST_PRIVATE_INTERFACE_0_3; |
| 16 } | 20 } |
| 17 | 21 |
| 18 } // namespace | 22 } // namespace |
| 19 | 23 |
| 20 NetworkListPrivate::NetworkListPrivate() { | 24 NetworkListPrivate::NetworkListPrivate() { |
| 21 } | 25 } |
| 22 | 26 |
| 23 NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) | 27 NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) |
| 24 : Resource(PASS_REF, resource) { | 28 : Resource(PASS_REF, resource) { |
| 25 } | 29 } |
| 26 | 30 |
| 27 // static | 31 // static |
| 28 bool NetworkListPrivate::IsAvailable() { | 32 bool NetworkListPrivate::IsAvailable() { |
| 29 return has_interface<PPB_NetworkList_Private>(); | 33 return has_interface<PPB_NetworkList_Private_0_3>(); |
| 30 } | 34 } |
| 31 | 35 |
| 32 uint32_t NetworkListPrivate::GetCount() const { | 36 uint32_t NetworkListPrivate::GetCount() const { |
| 33 if (!has_interface<PPB_NetworkList_Private>()) | 37 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 34 return 0; | 38 return 0; |
| 35 return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource()); | 39 return get_interface<PPB_NetworkList_Private_0_3>()->GetCount(pp_resource()); |
| 36 } | 40 } |
| 37 | 41 |
| 38 std::string NetworkListPrivate::GetName(uint32_t index) const { | 42 std::string NetworkListPrivate::GetName(uint32_t index) const { |
| 39 if (!has_interface<PPB_NetworkList_Private>()) | 43 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 40 return std::string(); | 44 return std::string(); |
| 41 Var result(PASS_REF, | 45 Var result(PASS_REF, |
| 42 get_interface<PPB_NetworkList_Private>()->GetName( | 46 get_interface<PPB_NetworkList_Private_0_3>()->GetName( |
| 43 pp_resource(), index)); | 47 pp_resource(), index)); |
| 44 return result.is_string() ? result.AsString() : std::string(); | 48 return result.is_string() ? result.AsString() : std::string(); |
| 45 } | 49 } |
| 46 | 50 |
| 47 PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { | 51 PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { |
| 48 if (!has_interface<PPB_NetworkList_Private>()) | 52 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 49 return PP_NETWORKLIST_ETHERNET; | 53 return PP_NETWORKLIST_ETHERNET; |
| 50 return get_interface<PPB_NetworkList_Private>()->GetType( | 54 return get_interface<PPB_NetworkList_Private_0_3>()->GetType( |
| 51 pp_resource(), index); | 55 pp_resource(), index); |
| 52 } | 56 } |
| 53 | 57 |
| 54 PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { | 58 PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { |
| 55 if (!has_interface<PPB_NetworkList_Private>()) | 59 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 56 return PP_NETWORKLIST_DOWN; | 60 return PP_NETWORKLIST_DOWN; |
| 57 return get_interface<PPB_NetworkList_Private>()->GetState( | 61 return get_interface<PPB_NetworkList_Private_0_3>()->GetState( |
| 58 pp_resource(), index); | 62 pp_resource(), index); |
| 59 } | 63 } |
| 60 | 64 |
| 61 void NetworkListPrivate::GetIpAddresses( | 65 int32_t NetworkListPrivate::GetIpAddresses( |
| 62 uint32_t index, | 66 uint32_t index, |
| 63 std::vector<PP_NetAddress_Private>* addresses) const { | 67 std::vector<NetAddress>* addresses) const { |
| 64 if (!has_interface<PPB_NetworkList_Private>()) | 68 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 65 return; | 69 return PP_ERROR_NOINTERFACE; |
| 70 if (!addresses) |
| 71 return PP_ERROR_BADARGUMENT; |
| 66 | 72 |
| 67 // Most network interfaces don't have more than 3 network | 73 ResourceArrayOutputAdapter<NetAddress> adapter(addresses); |
| 68 // interfaces. | 74 return get_interface<PPB_NetworkList_Private_0_3>()->GetIpAddresses( |
| 69 addresses->resize(3); | 75 pp_resource(), index, adapter.pp_array_output()); |
| 70 | |
| 71 int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( | |
| 72 pp_resource(), index, &addresses->front(), addresses->size()); | |
| 73 | |
| 74 if (result < 0) { | |
| 75 addresses->resize(0); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 if (result <= static_cast<int32_t>(addresses->size())) { | |
| 80 addresses->resize(result); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 addresses->resize(result); | |
| 85 result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( | |
| 86 pp_resource(), index, &addresses->front(), addresses->size()); | |
| 87 if (result < 0) { | |
| 88 addresses->resize(0); | |
| 89 } else if (result < static_cast<int32_t>(addresses->size())) { | |
| 90 addresses->resize(result); | |
| 91 } | |
| 92 } | 76 } |
| 93 | 77 |
| 94 std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { | 78 std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { |
| 95 if (!has_interface<PPB_NetworkList_Private>()) | 79 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 96 return std::string(); | 80 return std::string(); |
| 97 Var result(PASS_REF, | 81 Var result(PASS_REF, |
| 98 get_interface<PPB_NetworkList_Private>()->GetDisplayName( | 82 get_interface<PPB_NetworkList_Private_0_3>()->GetDisplayName( |
| 99 pp_resource(), index)); | 83 pp_resource(), index)); |
| 100 return result.is_string() ? result.AsString() : std::string(); | 84 return result.is_string() ? result.AsString() : std::string(); |
| 101 } | 85 } |
| 102 | 86 |
| 103 uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { | 87 uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { |
| 104 if (!has_interface<PPB_NetworkList_Private>()) | 88 if (!has_interface<PPB_NetworkList_Private_0_3>()) |
| 105 return 0; | 89 return 0; |
| 106 return get_interface<PPB_NetworkList_Private>()->GetMTU( | 90 return get_interface<PPB_NetworkList_Private_0_3>()->GetMTU(pp_resource(), ind
ex); |
| 107 pp_resource(), index); | |
| 108 } | 91 } |
| 109 | 92 |
| 110 } // namespace pp | 93 } // namespace pp |
| OLD | NEW |