1
/* vim:ts=8:sts=4:sw=4:noai:noexpandtab
5
* Copyright (c) 2010 Miru Limited.
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#ifndef __PGM_IP_PGM_ENDPOINT_HH__
23
#define __PGM_IP_PGM_ENDPOINT_HH__
25
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
27
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
36
template <typename InternetProtocol>
40
/// The protocol type associated with the endpoint.
41
typedef InternetProtocol protocol_type;
43
typedef struct cpgm::pgm_sockaddr_t data_type;
45
/// Default constructor.
50
cpgm::pgm_tsi_t tmp_addr = PGM_TSI_INIT;
51
data_.sa_addr = tmp_addr;
54
/// Construct an endpoint using a port number, specified in host byte
55
/// order. The GSI will be generated from the node name.
58
* To initialise a PGM endpoint for port 7500, use:
60
* ip::pgm::endpoint ep (7500);
63
pgm_endpoint (unsigned short port_num)
66
data_.sa_port = port_num;
67
data_.sa_addr.sport = 0;
68
pgm_gsi_create_from_hostname (&data_.sa_addr.gsi, NULL);
71
/// Construct an endpoint using a port number and a TSI.
72
pgm_endpoint (const cpgm::pgm_tsi_t& tsi, unsigned short port_num)
75
data_.sa_port = port_num;
79
/// Construct an endpoint using a port number and a memory area.
80
pgm_endpoint (const void* src, std::size_t len, unsigned short port_num)
83
data_.sa_port = port_num;
84
data_.sa_addr.sport = 0;
85
pgm_gsi_create_from_data (&data_.sa_addr.gsi, static_cast<const uint8_t*>(src), len);
89
pgm_endpoint (const pgm_endpoint& other)
94
/// Assign from another endpoint.
95
pgm_endpoint& operator= (const pgm_endpoint& other)
101
/// Get the underlying endpoint in the native type.
102
const data_type* data() const
107
/// Get the underlying size of the endpoint in the native type.
108
std::size_t size() const
110
return sizeof(data_type);
113
/// Get the port associated with the endpoint. The port number is always in
114
/// the host's byte order.
115
unsigned short port() const
117
return data_.sa_port;
120
/// Set the port associated with the endpoint. The port number is always in
121
/// the host's byte order.
122
void port (unsigned short port_num)
124
data_.sa_port = port_num;
127
/// Get the TSI associated with the endpoint.
128
const cpgm::pgm_tsi_t* address() const
130
return &data_.sa_addr;
133
/// Set the TSI associated with the endpoint.
134
void address (cpgm::pgm_tsi_t& addr)
136
data_.sa_addr = addr;
139
/// Compare two endpoints for equality.
140
friend bool operator== (const pgm_endpoint<InternetProtocol>& e1,
141
const pgm_endpoint<InternetProtocol>& e2)
143
return e1.address() == e2.address() && e1.port() == e2.port();
146
/// Compare two endpoints for inequality.
147
friend bool operator!= (const pgm_endpoint<InternetProtocol>& e1,
148
const pgm_endpoint<InternetProtocol>& e2)
150
return e1.address() != e2.address() || e1.port() != e2.port();
153
/// Compare endpoints for ordering.
154
friend bool operator<(const pgm_endpoint<InternetProtocol>& e1,
155
const pgm_endpoint<InternetProtocol>& e2)
157
if (e1.address() < e2.address())
159
if (e1.address() != e2.address())
161
return e1.port() < e2.port();
165
// The underlying PGM socket address.
171
#endif /* __PGM_IP_PGM_ENDPOINT_HH__ */