Pepper_47_C++_interfaces
host_resolver_private.cc
Go to the documentation of this file.
1 // Copyright (c) 2012 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"
8 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/module_impl.h"
13 #include "ppapi/cpp/pass_ref.h"
14 
15 namespace pp {
16 
17 namespace {
18 
19 template <> const char* interface_name<PPB_HostResolver_Private_0_1>() {
20  return PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1;
21 }
22 
23 } // namespace
24 
26  if (has_interface<PPB_HostResolver_Private_0_1>()) {
28  get_interface<PPB_HostResolver_Private_0_1>()->Create(
29  instance.pp_instance()));
30  }
31 }
32 
33 // static
35  return has_interface<PPB_HostResolver_Private_0_1>();
36 }
37 
38 int32_t HostResolverPrivate::Resolve(const std::string& host,
39  uint16_t port,
40  const PP_HostResolver_Private_Hint& hint,
41  const CompletionCallback& callback) {
42  if (!has_interface<PPB_HostResolver_Private_0_1>())
43  return callback.MayForce(PP_ERROR_NOINTERFACE);
44  return get_interface<PPB_HostResolver_Private_0_1>()->Resolve(
45  pp_resource(),
46  host.c_str(),
47  port,
48  &hint,
49  callback.pp_completion_callback());
50 }
51 
53  if (!has_interface<PPB_HostResolver_Private_0_1>())
54  return Var(Var::Null());
55 
56  PP_Var pp_canonical_name =
57  get_interface<PPB_HostResolver_Private_0_1>()->GetCanonicalName(
58  pp_resource());
59  return Var(PASS_REF, pp_canonical_name);
60 }
61 
63  if (!has_interface<PPB_HostResolver_Private_0_1>())
64  return 0;
65  return get_interface<PPB_HostResolver_Private_0_1>()->GetSize(pp_resource());
66 }
67 
69  PP_NetAddress_Private* address) {
70  if (!has_interface<PPB_HostResolver_Private_0_1>())
71  return false;
72  PP_Bool result = get_interface<PPB_HostResolver_Private_0_1>()->GetNetAddress(
73  pp_resource(), index, address);
74  return PP_ToBool(result);
75 }
76 
77 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
Special value passed to constructor to make NULL.
Definition: var.h:24
int32_t MayForce(int32_t result) const
const PP_CompletionCallback & pp_completion_callback() const
HostResolverPrivate(const InstanceHandle &instance)
bool GetNetAddress(uint32_t index, PP_NetAddress_Private *address)
friend class Var
Definition: resource.h:90
int32_t Resolve(const std::string &host, uint16_t port, const PP_HostResolver_Private_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