cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / cpp / private / network_list_private.cc
blob1297aa3a09c65bc27200022ca2b789c902e08cf2
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.
5 #include "ppapi/cpp/private/network_list_private.h"
7 #include "ppapi/cpp/module_impl.h"
8 #include "ppapi/cpp/var.h"
10 namespace pp {
12 namespace {
14 template <> const char* interface_name<PPB_NetworkList_Private>() {
15 return PPB_NETWORKLIST_PRIVATE_INTERFACE;
18 } // namespace
20 NetworkListPrivate::NetworkListPrivate() {
23 NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource)
24 : Resource(PASS_REF, resource) {
27 // static
28 bool NetworkListPrivate::IsAvailable() {
29 return has_interface<PPB_NetworkList_Private>();
32 uint32_t NetworkListPrivate::GetCount() const {
33 if (!has_interface<PPB_NetworkList_Private>())
34 return 0;
35 return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource());
38 std::string NetworkListPrivate::GetName(uint32_t index) const {
39 if (!has_interface<PPB_NetworkList_Private>())
40 return std::string();
41 Var result(PASS_REF,
42 get_interface<PPB_NetworkList_Private>()->GetName(
43 pp_resource(), index));
44 return result.is_string() ? result.AsString() : std::string();
47 PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const {
48 if (!has_interface<PPB_NetworkList_Private>())
49 return PP_NETWORKLIST_ETHERNET;
50 return get_interface<PPB_NetworkList_Private>()->GetType(
51 pp_resource(), index);
54 PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const {
55 if (!has_interface<PPB_NetworkList_Private>())
56 return PP_NETWORKLIST_DOWN;
57 return get_interface<PPB_NetworkList_Private>()->GetState(
58 pp_resource(), index);
61 void NetworkListPrivate::GetIpAddresses(
62 uint32_t index,
63 std::vector<PP_NetAddress_Private>* addresses) const {
64 if (!has_interface<PPB_NetworkList_Private>())
65 return;
67 // Most network interfaces don't have more than 3 network
68 // interfaces.
69 addresses->resize(3);
71 int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses(
72 pp_resource(), index, &addresses->front(), addresses->size());
74 if (result < 0) {
75 addresses->resize(0);
76 return;
79 if (result <= static_cast<int32_t>(addresses->size())) {
80 addresses->resize(result);
81 return;
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);
94 std::string NetworkListPrivate::GetDisplayName(uint32_t index) const {
95 if (!has_interface<PPB_NetworkList_Private>())
96 return std::string();
97 Var result(PASS_REF,
98 get_interface<PPB_NetworkList_Private>()->GetDisplayName(
99 pp_resource(), index));
100 return result.is_string() ? result.AsString() : std::string();
103 uint32_t NetworkListPrivate::GetMTU(uint32_t index) const {
104 if (!has_interface<PPB_NetworkList_Private>())
105 return 0;
106 return get_interface<PPB_NetworkList_Private>()->GetMTU(
107 pp_resource(), index);
110 } // namespace pp