// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef PPAPI_CPP_NET_ADDRESS_H_ #define PPAPI_CPP_NET_ADDRESS_H_ #include "ppapi/c/ppb_net_address.h" #include "ppapi/cpp/pass_ref.h" #include "ppapi/cpp/resource.h" #include "ppapi/cpp/var.h" namespace pp { class InstanceHandle; /// The NetAddress class represents a network address. class NetAddress : public Resource { public: /// Default constructor for creating an is_null() NetAddress /// object. NetAddress(); /// A constructor used when you have received a PP_Resource as a /// return value that has had 1 ref added for you. /// /// @param[in] resource A PPB_NetAddress resource. NetAddress(PassRef, PP_Resource resource); /// A constructor used to create a NetAddress object with the /// specified IPv4 address. /// /// @param[in] instance The instance with which this resource will be /// associated. /// @param[in] ipv4_addr An IPv4 address. NetAddress(const InstanceHandle& instance, const PP_NetAddress_IPv4& ipv4_addr); /// A constructor used to create a NetAddress object with the /// specified IPv6 address. /// /// @param[in] instance The instance with which this resource will be /// associated. /// @param[in] ipv6_addr An IPv6 address. NetAddress(const InstanceHandle& instance, const PP_NetAddress_IPv6& ipv6_addr); /// The copy constructor for NetAddress. /// /// @param[in] other A reference to another NetAddress. NetAddress(const NetAddress& other); /// The destructor. virtual ~NetAddress(); /// The assignment operator for NetAddress. /// /// @param[in] other A reference to another NetAddress. /// /// @return A reference to this NetAddress object. NetAddress& operator=(const NetAddress& other); /// Static function for determining whether the browser supports the /// PPB_NetAddress interface. /// /// @return true if the interface is available, false otherwise. static bool IsAvailable(); /// Gets the address family. /// /// @return The address family on success; /// PP_NETADDRESS_FAMILY_UNSPECIFIED on failure. PP_NetAddress_Family GetFamily() const; /// Returns a human-readable description of the network address. The /// description is in the form of host [ ":" port ] and conforms to /// http://tools.ietf.org/html/rfc3986#section-3.2 for IPv4 and IPv6 addresses /// (e.g., "192.168.0.1", "192.168.0.1:99", or "[::1]:80"). /// /// @param[in] include_port Whether to include the port number in the /// description. /// /// @return A string Var on success; an undefined /// Var on failure. Var DescribeAsString(bool include_port) const; /// Fills a PP_NetAddress_IPv4 structure if the network address /// is of PP_NETADDRESS_FAMILY_IPV4 address family. /// Note that passing a network address of /// PP_NETADDRESS_FAMILY_IPV6 address family will fail even if /// the address is an IPv4-mapped IPv6 address. /// /// @param[out] ipv4_addr A PP_NetAddress_IPv4 structure to store /// the result. /// /// @return A boolean value indicating whether the operation succeeded. bool DescribeAsIPv4Address(PP_NetAddress_IPv4* ipv4_addr) const; /// Fills a PP_NetAddress_IPv6 structure if the network address /// is of PP_NETADDRESS_FAMILY_IPV6 address family. /// Note that passing a network address of /// PP_NETADDRESS_FAMILY_IPV4 address family will fail - this /// method doesn't map it to an IPv6 address. /// /// @param[out] ipv6_addr A PP_NetAddress_IPv6 structure to store /// the result. /// /// @return A boolean value indicating whether the operation succeeded. bool DescribeAsIPv6Address(PP_NetAddress_IPv6* ipv6_addr) const; }; } // namespace pp #endif // PPAPI_CPP_NET_ADDRESS_H_