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