Pepper_47_C++_interfaces
host_resolver.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_errors.h"
10 #include "ppapi/cpp/module_impl.h"
11 
12 namespace pp {
13 
14 namespace {
15 
16 template <> const char* interface_name<PPB_HostResolver_1_0>() {
17  return PPB_HOSTRESOLVER_INTERFACE_1_0;
18 }
19 
20 } // namespace
21 
23 }
24 
26  if (has_interface<PPB_HostResolver_1_0>()) {
27  PassRefFromConstructor(get_interface<PPB_HostResolver_1_0>()->Create(
28  instance.pp_instance()));
29  }
30 }
31 
33  : Resource(PASS_REF, resource) {
34 }
35 
37 }
38 
40 }
41 
43  Resource::operator=(other);
44  return *this;
45 }
46 
47 // static
49  return has_interface<PPB_HostResolver_1_0>();
50 }
51 
52 int32_t HostResolver::Resolve(const char* host,
53  uint16_t port,
54  const PP_HostResolver_Hint& hint,
55  const CompletionCallback& callback) {
56  if (has_interface<PPB_HostResolver_1_0>()) {
57  return get_interface<PPB_HostResolver_1_0>()->Resolve(
58  pp_resource(), host, port, &hint, callback.pp_completion_callback());
59  }
60 
61  return callback.MayForce(PP_ERROR_NOINTERFACE);
62 }
63 
65  if (has_interface<PPB_HostResolver_1_0>()) {
66  return Var(PASS_REF,
67  get_interface<PPB_HostResolver_1_0>()->GetCanonicalName(
68  pp_resource()));
69  }
70 
71  return Var();
72 }
73 
75  if (has_interface<PPB_HostResolver_1_0>()) {
76  return get_interface<PPB_HostResolver_1_0>()->GetNetAddressCount(
77  pp_resource());
78  }
79 
80  return 0;
81 }
82 
83 NetAddress HostResolver::GetNetAddress(uint32_t index) const {
84  if (has_interface<PPB_HostResolver_1_0>()) {
85  return NetAddress(PASS_REF,
86  get_interface<PPB_HostResolver_1_0>()->GetNetAddress(
87  pp_resource(), index));
88  }
89 
90  return NetAddress();
91 }
92 
93 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
virtual ~HostResolver()
The destructor.
int32_t MayForce(int32_t result) const
const PP_CompletionCallback & pp_completion_callback() const
static bool IsAvailable()
The NetAddress class represents a network address.
Definition: net_address.h:18
uint32_t GetNetAddressCount() const
Var GetCanonicalName() const
PassRef
Definition: pass_ref.h:17
friend class Var
Definition: resource.h:90
int32_t Resolve(const char *host, uint16_t port, const PP_HostResolver_Hint &hint, const CompletionCallback &callback)
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
A reference counted module resource.
Definition: resource.h:20
HostResolver & operator=(const HostResolver &other)
Resource & operator=(const Resource &other)
Definition: resource.cc:27
NetAddress GetNetAddress(uint32_t index) const