Pepper_47_C++_interfaces
network_list.cc
Go to the documentation of this file.
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 
6 
7 #include "ppapi/c/pp_errors.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_1_0>() {
19  return PPB_NETWORKLIST_INTERFACE_1_0;
20 }
21 
22 } // namespace
23 
25 }
26 
28  : Resource(PASS_REF, resource) {
29 }
30 
31 // static
33  return has_interface<PPB_NetworkList_1_0>();
34 }
35 
36 uint32_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 
42 std::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 
51 PP_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 
58 PP_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 
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 
78 std::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 
87 uint32_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
PP_NetworkList_Type GetType(uint32_t index) const
Definition: network_list.cc:51
const PP_ArrayOutput & pp_array_output()
Definition: array_output.h:50
int32_t GetIpAddresses(uint32_t index, std::vector< NetAddress > *addresses) const
Definition: network_list.cc:65
std::string AsString() const
Definition: var.cc:250
uint32_t GetMTU(uint32_t index) const
Definition: network_list.cc:87
bool is_string() const
Definition: var.h:123
std::string GetDisplayName(uint32_t index) const
Definition: network_list.cc:78
uint32_t GetCount() const
Definition: network_list.cc:36
static bool IsAvailable()
Returns true if the required interface is available.
Definition: network_list.cc:32
PassRef
Definition: pass_ref.h:17
std::string GetName(uint32_t index) const
Definition: network_list.cc:42
PP_Resource pp_resource() const
Definition: resource.h:47
A generic type used for passing data types between the module and the page.
Definition: var.h:21
PP_NetworkList_State GetState(uint32_t index) const
Definition: network_list.cc:58
A reference counted module resource.
Definition: resource.h:20