Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 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 | |
| 5 | #ifndef PPAPI_CPP_NET_ADDRESS_H_ |
| 6 | #define PPAPI_CPP_NET_ADDRESS_H_ |
| 7 | |
| 8 | #include "ppapi/c/ppb_net_address.h" |
| 9 | #include "ppapi/cpp/pass_ref.h" |
| 10 | #include "ppapi/cpp/resource.h" |
| 11 | #include "ppapi/cpp/var.h" |
| 12 | |
| 13 | namespace pp { |
| 14 | |
| 15 | class InstanceHandle; |
| 16 | |
| 17 | /// The <code>NetAddress</code> class represents a network address. |
| 18 | class NetAddress : public Resource { |
| 19 | public: |
| 20 | /// Default constructor for creating an is_null() <code>NetAddress</code> |
| 21 | /// object. |
| 22 | NetAddress(); |
| 23 | |
| 24 | /// A constructor used when you have received a <code>PP_Resource</code> as a |
| 25 | /// return value that has had 1 ref added for you. |
| 26 | /// |
| 27 | /// @param[in] resource A <code>PPB_NetAddress</code> resource. |
| 28 | NetAddress(PassRef, PP_Resource resource); |
| 29 | |
| 30 | /// A constructor used to create a <code>NetAddress</code> object with the |
| 31 | /// specified IPv4 address. |
| 32 | /// |
| 33 | /// @param[in] instance The instance with which this resource will be |
| 34 | /// associated. |
| 35 | /// @param[in] ipv4_addr An IPv4 address. |
| 36 | NetAddress(const InstanceHandle& instance, |
| 37 | const PP_NetAddress_IPv4& ipv4_addr); |
| 38 | |
| 39 | /// A constructor used to create a <code>NetAddress</code> object with the |
| 40 | /// specified IPv6 address. |
| 41 | /// |
| 42 | /// @param[in] instance The instance with which this resource will be |
| 43 | /// associated. |
| 44 | /// @param[in] ipv6_addr An IPv6 address. |
| 45 | NetAddress(const InstanceHandle& instance, |
| 46 | const PP_NetAddress_IPv6& ipv6_addr); |
| 47 | |
| 48 | /// The copy constructor for <code>NetAddress</code>. |
| 49 | /// |
| 50 | /// @param[in] other A reference to another <code>NetAddress</code>. |
| 51 | NetAddress(const NetAddress& other); |
| 52 | |
| 53 | /// The destructor. |
| 54 | virtual ~NetAddress(); |
| 55 | |
| 56 | /// The assignment operator for <code>NetAddress</code>. |
| 57 | /// |
| 58 | /// @param[in] other A reference to another <code>NetAddress</code>. |
| 59 | /// |
| 60 | /// @return A reference to this <code>NetAddress</code> object. |
| 61 | NetAddress& operator=(const NetAddress& other); |
| 62 | |
| 63 | /// Static function for determining whether the browser supports the |
| 64 | /// <code>PPB_NetAddress</code> interface. |
| 65 | /// |
| 66 | /// @return true if the interface is available, false otherwise. |
| 67 | static bool IsAvailable(); |
| 68 | |
| 69 | /// Gets the address family. |
| 70 | /// |
| 71 | /// @return The address family on success; |
| 72 | /// <code>PP_NETADDRESS_FAMILY_UNSPECIFIED</code> on failure. |
| 73 | PP_NetAddress_Family GetFamily() const; |
| 74 | |
| 75 | /// Returns a human-readable description of the network address. The |
| 76 | /// description is in the form of host [ ":" port ] and conforms to |
| 77 | /// http://tools.ietf.org/html/rfc3986#section-3.2 for IPv4 and IPv6 addresses |
| 78 | /// (e.g., "192.168.0.1", "192.168.0.1:99", or "[::1]:80"). |
| 79 | /// |
| 80 | /// @param[in] include_port Whether to include the port number in the |
| 81 | /// description. |
| 82 | /// |
| 83 | /// @return A string <code>Var</code> on success; an undefined |
| 84 | /// <code>Var</code> on failure. |
| 85 | Var DescribeAsString(bool include_port) const; |
| 86 | |
| 87 | /// Fills a <code>PP_NetAddress_IPv4</code> structure if the network address |
| 88 | /// is of <code>PP_NETADDRESS_FAMILY_IPV4</code> address family. |
| 89 | /// Note that passing a network address of |
| 90 | /// <code>PP_NETADDRESS_FAMILY_IPV6</code> address family will fail even if |
| 91 | /// the address is an IPv4-mapped IPv6 address. |
| 92 | /// |
| 93 | /// @param[out] ipv4_addr A <code>PP_NetAddress_IPv4</code> structure to store |
| 94 | /// the result. |
| 95 | /// |
| 96 | /// @return A boolean value indicating whether the operation succeeded. |
| 97 | bool DescribeAsIPv4Address(PP_NetAddress_IPv4* ipv4_addr) const; |
| 98 | |
| 99 | /// Fills a <code>PP_NetAddress_IPv6</code> structure if the network address |
| 100 | /// is of <code>PP_NETADDRESS_FAMILY_IPV6</code> address family. |
| 101 | /// Note that passing a network address of |
| 102 | /// <code>PP_NETADDRESS_FAMILY_IPV4</code> address family will fail - this |
| 103 | /// method doesn't map it to an IPv6 address. |
| 104 | /// |
| 105 | /// @param[out] ipv6_addr A <code>PP_NetAddress_IPv6</code> structure to store |
| 106 | /// the result. |
| 107 | /// |
| 108 | /// @return A boolean value indicating whether the operation succeeded. |
| 109 | bool DescribeAsIPv6Address(PP_NetAddress_IPv6* ipv6_addr) const; |
| 110 | }; |
| 111 | |
| 112 | } // namespace pp |
| 113 | |
| 114 | #endif // PPAPI_CPP_NET_ADDRESS_H_ |