Pepper_47_C++_interfaces
net_address.cc
Go to the documentation of this file.
1 // Copyright 2013 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_bool.h"
10 
11 namespace pp {
12 
13 namespace {
14 
15 template <> const char* interface_name<PPB_NetAddress_1_0>() {
16  return PPB_NETADDRESS_INTERFACE_1_0;
17 }
18 
19 } // namespace
20 
22 }
23 
25  : Resource(PASS_REF, resource) {
26 }
27 
29  const PP_NetAddress_IPv4& ipv4_addr) {
30  if (has_interface<PPB_NetAddress_1_0>()) {
32  get_interface<PPB_NetAddress_1_0>()->CreateFromIPv4Address(
33  instance.pp_instance(), &ipv4_addr));
34  }
35 }
36 
38  const PP_NetAddress_IPv6& ipv6_addr) {
39  if (has_interface<PPB_NetAddress_1_0>()) {
41  get_interface<PPB_NetAddress_1_0>()->CreateFromIPv6Address(
42  instance.pp_instance(), &ipv6_addr));
43  }
44 }
45 
46 NetAddress::NetAddress(const NetAddress& other) : Resource(other) {
47 }
48 
50 }
51 
53  Resource::operator=(other);
54  return *this;
55 }
56 
57 // static
59  return has_interface<PPB_NetAddress_1_0>();
60 }
61 
62 PP_NetAddress_Family NetAddress::GetFamily() const {
63  if (has_interface<PPB_NetAddress_1_0>())
64  return get_interface<PPB_NetAddress_1_0>()->GetFamily(pp_resource());
65 
66  return PP_NETADDRESS_FAMILY_UNSPECIFIED;
67 }
68 
69 Var NetAddress::DescribeAsString(bool include_port) const {
70  if (has_interface<PPB_NetAddress_1_0>()) {
71  return Var(PASS_REF,
72  get_interface<PPB_NetAddress_1_0>()->DescribeAsString(
73  pp_resource(), PP_FromBool(include_port)));
74  }
75 
76  return Var();
77 }
78 
79 bool NetAddress::DescribeAsIPv4Address(PP_NetAddress_IPv4* ipv4_addr) const {
80  if (has_interface<PPB_NetAddress_1_0>()) {
81  return PP_ToBool(
82  get_interface<PPB_NetAddress_1_0>()->DescribeAsIPv4Address(
83  pp_resource(), ipv4_addr));
84  }
85 
86  return false;
87 }
88 
89 bool NetAddress::DescribeAsIPv6Address(PP_NetAddress_IPv6* ipv6_addr) const {
90  if (has_interface<PPB_NetAddress_1_0>()) {
91  return PP_ToBool(
92  get_interface<PPB_NetAddress_1_0>()->DescribeAsIPv6Address(
93  pp_resource(), ipv6_addr));
94  }
95 
96  return false;
97 }
98 
99 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
static bool IsAvailable()
Definition: net_address.cc:58
virtual ~NetAddress()
The destructor.
Definition: net_address.cc:49
NetAddress & operator=(const NetAddress &other)
Definition: net_address.cc:52
bool DescribeAsIPv4Address(PP_NetAddress_IPv4 *ipv4_addr) const
Definition: net_address.cc:79
The NetAddress class represents a network address.
Definition: net_address.h:18
PassRef
Definition: pass_ref.h:17
PP_NetAddress_Family GetFamily() const
Definition: net_address.cc:62
bool DescribeAsIPv6Address(PP_NetAddress_IPv6 *ipv6_addr) const
Definition: net_address.cc:89
friend class Var
Definition: resource.h:90
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_Instance pp_instance() const
Var DescribeAsString(bool include_port) const
Definition: net_address.cc:69
A reference counted module resource.
Definition: resource.h:20
Resource & operator=(const Resource &other)
Definition: resource.cc:27