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