blob: 12c3bf4c96ce91f45070b3a0b3d4854a36698aba [file] [log] [blame]
Torne (Richard Coles)68043e12013-09-26 13:24:57 +01001// 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/network_list.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
14namespace pp {
15
16namespace {
17
18template <> const char* interface_name<PPB_NetworkList_1_0>() {
19 return PPB_NETWORKLIST_INTERFACE_1_0;
20}
21
22} // namespace
23
24NetworkList::NetworkList() {
25}
26
27NetworkList::NetworkList(PassRef, PP_Resource resource)
28 : Resource(PASS_REF, resource) {
29}
30
31// static
32bool NetworkList::IsAvailable() {
33 return has_interface<PPB_NetworkList_1_0>();
34}
35
36uint32_t NetworkList::GetCount() const {
37 if (!has_interface<PPB_NetworkList_1_0>())
38 return 0;
39 return get_interface<PPB_NetworkList_1_0>()->GetCount(pp_resource());
40}
41
42std::string NetworkList::GetName(uint32_t index) const {
43 if (!has_interface<PPB_NetworkList_1_0>())
44 return std::string();
45 Var result(PASS_REF,
46 get_interface<PPB_NetworkList_1_0>()->GetName(
47 pp_resource(), index));
48 return result.is_string() ? result.AsString() : std::string();
49}
50
51PP_NetworkList_Type NetworkList::GetType(uint32_t index) const {
52 if (!has_interface<PPB_NetworkList_1_0>())
53 return PP_NETWORKLIST_TYPE_ETHERNET;
54 return get_interface<PPB_NetworkList_1_0>()->GetType(
55 pp_resource(), index);
56}
57
58PP_NetworkList_State NetworkList::GetState(uint32_t index) const {
59 if (!has_interface<PPB_NetworkList_1_0>())
60 return PP_NETWORKLIST_STATE_DOWN;
61 return get_interface<PPB_NetworkList_1_0>()->GetState(
62 pp_resource(), index);
63}
64
65int32_t NetworkList::GetIpAddresses(
66 uint32_t index,
67 std::vector<NetAddress>* addresses) const {
68 if (!has_interface<PPB_NetworkList_1_0>())
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_1_0>()->GetIpAddresses(
75 pp_resource(), index, adapter.pp_array_output());
76}
77
78std::string NetworkList::GetDisplayName(uint32_t index) const {
79 if (!has_interface<PPB_NetworkList_1_0>())
80 return std::string();
81 Var result(PASS_REF,
82 get_interface<PPB_NetworkList_1_0>()->GetDisplayName(
83 pp_resource(), index));
84 return result.is_string() ? result.AsString() : std::string();
85}
86
87uint32_t NetworkList::GetMTU(uint32_t index) const {
88 if (!has_interface<PPB_NetworkList_1_0>())
89 return 0;
90 return get_interface<PPB_NetworkList_1_0>()->GetMTU(
91 pp_resource(), index);
92}
93
94} // namespace pp