NaCl docs: update release notes for 42 branch
[chromium-blink-merge.git] / ppapi / thunk / ppb_net_address_thunk.cc
blobf8916fe9716c86adaa56b4a425b3bac33ae46e4f
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.
5 #include "ppapi/c/pp_errors.h"
6 #include "ppapi/c/ppb_net_address.h"
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_instance_api.h"
10 #include "ppapi/thunk/ppb_net_address_api.h"
11 #include "ppapi/thunk/resource_creation_api.h"
12 #include "ppapi/thunk/thunk.h"
14 namespace ppapi {
15 namespace thunk {
17 namespace {
19 PP_Resource CreateFromIPv4Address(
20 PP_Instance instance,
21 const struct PP_NetAddress_IPv4* ipv4_addr) {
22 VLOG(4) << "PPB_NetAddress::CreateFromIPv4Address()";
23 EnterResourceCreation enter(instance);
24 if (enter.failed())
25 return 0;
26 return enter.functions()->CreateNetAddressFromIPv4Address(instance,
27 ipv4_addr);
30 PP_Resource CreateFromIPv6Address(
31 PP_Instance instance,
32 const struct PP_NetAddress_IPv6* ipv6_addr) {
33 VLOG(4) << "PPB_NetAddress::CreateFromIPv6Address()";
34 EnterResourceCreation enter(instance);
35 if (enter.failed())
36 return 0;
37 return enter.functions()->CreateNetAddressFromIPv6Address(instance,
38 ipv6_addr);
41 PP_Bool IsNetAddress(PP_Resource resource) {
42 VLOG(4) << "PPB_NetAddress::IsNetAddress()";
43 EnterResource<PPB_NetAddress_API> enter(resource, false);
44 return PP_FromBool(enter.succeeded());
47 PP_NetAddress_Family GetFamily(PP_Resource addr) {
48 VLOG(4) << "PPB_NetAddress::GetFamily()";
49 EnterResource<PPB_NetAddress_API> enter(addr, true);
50 if (enter.failed())
51 return PP_NETADDRESS_FAMILY_UNSPECIFIED;
52 return enter.object()->GetFamily();
55 struct PP_Var DescribeAsString(PP_Resource addr, PP_Bool include_port) {
56 VLOG(4) << "PPB_NetAddress::DescribeAsString()";
57 EnterResource<PPB_NetAddress_API> enter(addr, true);
58 if (enter.failed())
59 return PP_MakeUndefined();
60 return enter.object()->DescribeAsString(include_port);
63 PP_Bool DescribeAsIPv4Address(PP_Resource addr,
64 struct PP_NetAddress_IPv4* ipv4_addr) {
65 VLOG(4) << "PPB_NetAddress::DescribeAsIPv4Address()";
66 EnterResource<PPB_NetAddress_API> enter(addr, true);
67 if (enter.failed())
68 return PP_FALSE;
69 return enter.object()->DescribeAsIPv4Address(ipv4_addr);
72 PP_Bool DescribeAsIPv6Address(PP_Resource addr,
73 struct PP_NetAddress_IPv6* ipv6_addr) {
74 VLOG(4) << "PPB_NetAddress::DescribeAsIPv6Address()";
75 EnterResource<PPB_NetAddress_API> enter(addr, true);
76 if (enter.failed())
77 return PP_FALSE;
78 return enter.object()->DescribeAsIPv6Address(ipv6_addr);
81 const PPB_NetAddress_1_0 g_ppb_netaddress_thunk_1_0 = {
82 &CreateFromIPv4Address,
83 &CreateFromIPv6Address,
84 &IsNetAddress,
85 &GetFamily,
86 &DescribeAsString,
87 &DescribeAsIPv4Address,
88 &DescribeAsIPv6Address
91 } // namespace
93 const PPB_NetAddress_1_0* GetPPB_NetAddress_1_0_Thunk() {
94 return &g_ppb_netaddress_thunk_1_0;
97 } // namespace thunk
98 } // namespace ppapi