Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: ppapi/cpp/private/net_address_private.cc

Issue 9235035: Add getter methods for sockaddr. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Fixing errors found by review system. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/cpp/private/net_address_private.h" 5 #include "ppapi/cpp/private/net_address_private.h"
6 6
7 #include "ppapi/c/pp_bool.h" 7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/cpp/module.h" 8 #include "ppapi/cpp/module.h"
9 #include "ppapi/cpp/module_impl.h" 9 #include "ppapi/cpp/module_impl.h"
10 #include "ppapi/cpp/var.h" 10 #include "ppapi/cpp/var.h"
11 #include "ppapi/c/private/ppb_net_address_private.h" 11 #include "ppapi/c/private/ppb_net_address_private.h"
12 12
13 namespace pp { 13 namespace pp {
14 14
15 namespace { 15 namespace {
16 16
17 template <> const char* interface_name<PPB_NetAddress_Private>() { 17 template <> const char* interface_name<PPB_NetAddress_Private>() {
18 return PPB_NETADDRESS_PRIVATE_INTERFACE; 18 return PPB_NETADDRESS_PRIVATE_INTERFACE;
19 } 19 }
20 20
21 template <> const char* interface_name<PPB_NetAddress_Private_0_1>() {
22 return PPB_NETADDRESS_PRIVATE_INTERFACE_0_1;
23 }
24
21 } // namespace 25 } // namespace
22 26
23 // static 27 // static
24 bool NetAddressPrivate::IsAvailable() { 28 bool NetAddressPrivate::IsAvailable() {
25 return has_interface<PPB_NetAddress_Private>(); 29 return has_interface<PPB_NetAddress_Private>();
26 } 30 }
27 31
28 // static 32 // static
29 bool NetAddressPrivate::AreEqual(const PP_NetAddress_Private& addr1, 33 bool NetAddressPrivate::AreEqual(const PP_NetAddress_Private& addr1,
30 const PP_NetAddress_Private& addr2) { 34 const PP_NetAddress_Private& addr2) {
31 if (!has_interface<PPB_NetAddress_Private>()) 35 if (!has_interface<PPB_NetAddress_Private_0_1>())
32 return false; 36 return false;
33 return !!get_interface<PPB_NetAddress_Private>()->AreEqual(&addr1, &addr2); 37 return !!get_interface<PPB_NetAddress_Private_0_1>()->AreEqual(&addr1,
38 &addr2);
34 } 39 }
35 40
36 // static 41 // static
37 bool NetAddressPrivate::AreHostsEqual(const PP_NetAddress_Private& addr1, 42 bool NetAddressPrivate::AreHostsEqual(const PP_NetAddress_Private& addr1,
38 const PP_NetAddress_Private& addr2) { 43 const PP_NetAddress_Private& addr2) {
39 if (!has_interface<PPB_NetAddress_Private>()) 44 if (!has_interface<PPB_NetAddress_Private_0_1>())
40 return false; 45 return false;
41 return !!get_interface<PPB_NetAddress_Private>()->AreHostsEqual(&addr1, 46 return !!get_interface<PPB_NetAddress_Private_0_1>()->AreHostsEqual(&addr1,
42 &addr2); 47 &addr2);
43 } 48 }
44 49
45 // static 50 // static
46 std::string NetAddressPrivate::Describe(const PP_NetAddress_Private& addr, 51 std::string NetAddressPrivate::Describe(const PP_NetAddress_Private& addr,
47 bool include_port) { 52 bool include_port) {
48 if (!has_interface<PPB_NetAddress_Private>()) 53 if (!has_interface<PPB_NetAddress_Private_0_1>())
49 return std::string(); 54 return std::string();
50 55
51 Module* module = Module::Get(); 56 Module* module = Module::Get();
52 if (!module) 57 if (!module)
53 return std::string(); 58 return std::string();
54 59
55 Var result(Var::PassRef(), 60 Var result(Var::PassRef(),
56 get_interface<PPB_NetAddress_Private>()->Describe( 61 get_interface<PPB_NetAddress_Private_0_1>()->Describe(
57 module->pp_module(), 62 module->pp_module(),
58 &addr, 63 &addr,
59 PP_FromBool(include_port))); 64 PP_FromBool(include_port)));
60 return result.is_string() ? result.AsString() : std::string(); 65 return result.is_string() ? result.AsString() : std::string();
61 } 66 }
62 67
63 // static 68 // static
64 bool NetAddressPrivate::ReplacePort(const PP_NetAddress_Private& addr_in, 69 bool NetAddressPrivate::ReplacePort(const PP_NetAddress_Private& addr_in,
65 uint16_t port, 70 uint16_t port,
66 PP_NetAddress_Private* addr_out) { 71 PP_NetAddress_Private* addr_out) {
67 if (!has_interface<PPB_NetAddress_Private>()) 72 if (!has_interface<PPB_NetAddress_Private_0_1>())
68 return false; 73 return false;
69 return !!get_interface<PPB_NetAddress_Private>()->ReplacePort(&addr_in, 74 return !!get_interface<PPB_NetAddress_Private_0_1>()->ReplacePort(&addr_in,
70 port, 75 port,
71 addr_out); 76 addr_out);
72 } 77 }
73 78
74 // static 79 // static
75 void NetAddressPrivate::GetAnyAddress(bool is_ipv6, 80 void NetAddressPrivate::GetAnyAddress(bool is_ipv6,
76 PP_NetAddress_Private* addr) { 81 PP_NetAddress_Private* addr) {
82 if (!has_interface<PPB_NetAddress_Private_0_1>())
83 return;
84 get_interface<PPB_NetAddress_Private_0_1>()->GetAnyAddress(
85 PP_FromBool(is_ipv6),
86 addr);
87 }
88
89 // static
90 uint16_t NetAddressPrivate::GetFamily(const PP_NetAddress_Private* addr) {
77 if (!has_interface<PPB_NetAddress_Private>()) 91 if (!has_interface<PPB_NetAddress_Private>())
78 return; 92 return 0;
79 get_interface<PPB_NetAddress_Private>()->GetAnyAddress(PP_FromBool(is_ipv6), 93 return get_interface<PPB_NetAddress_Private>()->GetFamily(addr);
80 addr); 94 }
95
96 // static
97 uint16_t NetAddressPrivate::GetPort(const PP_NetAddress_Private* addr) {
98 if (!has_interface<PPB_NetAddress_Private>())
99 return 0;
100 return get_interface<PPB_NetAddress_Private>()->GetPort(addr);
101 }
102
103 bool NetAddressPrivate::GetAddress(const PP_NetAddress_Private* addr,
104 void* address,
105 uint16_t address_size) {
106 if (!has_interface<PPB_NetAddress_Private>())
107 return false;
108 return PP_ToBool(get_interface<PPB_NetAddress_Private>()->GetAddress(
109 addr,
110 address,
111 address_size));
81 } 112 }
82 113
83 } // namespace pp 114 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698