// 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_HOST_RESOLVER_H_ #define PPAPI_CPP_HOST_RESOLVER_H_ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/ppb_host_resolver.h" #include "ppapi/cpp/net_address.h" #include "ppapi/cpp/pass_ref.h" #include "ppapi/cpp/resource.h" #include "ppapi/cpp/var.h" namespace pp { class CompletionCallback; class InstanceHandle; /// The HostResolver class supports host name resolution. /// /// Permissions: In order to run Resolve(), apps permission /// socket with subrule resolve-host is required. /// For more details about network communication permissions, please see: /// http://developer.chrome.com/apps/app_network.html class HostResolver : public Resource { public: /// Default constructor for creating an is_null() HostResolver /// object. HostResolver(); /// A constructor used to create a HostResolver object. /// /// @param[in] instance The instance with which this resource will be /// associated. explicit HostResolver(const InstanceHandle& instance); /// 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_HostResolver resource. HostResolver(PassRef, PP_Resource resource); /// The copy constructor for HostResolver. /// /// @param[in] other A reference to another HostResolver. HostResolver(const HostResolver& other); /// The destructor. virtual ~HostResolver(); /// The assignment operator for HostResolver. /// /// @param[in] other A reference to another HostResolver. /// /// @return A reference to this HostResolver object. HostResolver& operator=(const HostResolver& other); /// Static function for determining whether the browser supports the /// PPB_HostResolver interface. /// /// @return true if the interface is available, false otherwise. static bool IsAvailable(); /// Requests resolution of a host name. If the call completes successully, the /// results can be retrieved by GetCanonicalName(), /// GetNetAddressCount() and GetNetAddress(). /// /// @param[in] host The host name (or IP address literal) to resolve. /// @param[in] port The port number to be set in the resulting network /// addresses. /// @param[in] hint A PP_HostResolver_Hint structure /// providing hints for host resolution. /// @param[in] callback A CompletionCallback to be called upon /// completion. /// /// @return An int32_t containing an error code from pp_errors.h. /// PP_ERROR_NOACCESS will be returned if the caller doesn't have /// required permissions. PP_ERROR_NAME_NOT_RESOLVED will be /// returned if the host name couldn't be resolved. int32_t Resolve(const char* host, uint16_t port, const PP_HostResolver_Hint& hint, const CompletionCallback& callback); /// Gets the canonical name of the host. /// /// @return A string Var on success, which is an empty string /// if PP_HOSTRESOLVER_FLAG_CANONNAME is not set in the hint /// flags when calling Resolve(); an undefined Var /// if there is a pending Resolve() call or the previous /// Resolve() call failed. Var GetCanonicalName() const; /// Gets the number of network addresses. /// /// @return The number of available network addresses on success; 0 if there /// is a pending Resolve() call or the previous /// Resolve() call failed. uint32_t GetNetAddressCount() const; /// Gets a network address. /// /// @param[in] index An index indicating which address to return. /// /// @return A NetAddress object. The object will be null /// (i.e., is_null() returns true) if there is a pending /// Resolve() call or the previous Resolve() call /// failed, or the specified index is out of range. NetAddress GetNetAddress(uint32_t index) const; }; } // namespace pp #endif // PPAPI_CPP_HOST_RESOLVER_H_