1 #ifndef POSIXX_LINUX_TIPC_HPP_
2 #define POSIXX_LINUX_TIPC_HPP_
4 #include "../socket/basic_socket.hpp" // posixx::socket
6 #include <linux/tipc.h> // all tipc stuff
7 #include <cstring> // memcpy
13 /// Linux specific functionality
16 /// TIPC socket domain.
21 /// Configuration port name.
22 CFG_SRV = TIPC_CFG_SRV,
23 /// Topology discovery port name.
24 TOP_SRV = TIPC_TOP_SRV,
25 /// Name of the last reserved port.
26 RESERVED_TYPES = TIPC_RESERVED_TYPES,
27 /// Maximum message size.
28 MAX_USER_MSG_SIZE = TIPC_MAX_USER_MSG_SIZE,
29 /// Wait forever (for subscriptions).
30 WAIT_FOREVER = TIPC_WAIT_FOREVER
44 * Constructor from a raw 32-bit address.
46 * @param addr Raw 32-bit address.
48 explicit addr(__u32 addr) throw ();
51 * Constructor from a zone, cluster and node information.
54 * @param cluster Cluster.
57 addr(unsigned int zone, unsigned int cluster, unsigned int node)
61 void zone(unsigned int zone) throw ();
64 unsigned int zone() const throw ();
67 void cluster(unsigned int cluster) throw ();
70 unsigned int cluster() const throw ();
73 void node(unsigned int node) throw ();
76 unsigned int node() const throw ();
78 /// Cast to a raw 32-bit address.
79 operator __u32 () const throw ();
86 * @see tipc_portid struct from linux/tipc.h.
88 struct portid: tipc_portid
94 * @param ref Unique ID fo the port in the address.
95 * @param node Node address.
97 portid(__u32 ref, addr node) throw ();
104 * @see tipc_name struct from linux/tipc.h.
106 struct name: tipc_name
111 * @param type Type of the named port.
112 * @param instance Instance of the named port.
114 name(__u32 type, __u32 instance) throw ();
120 * @see tipc_name_seq struct from linux/tipc.h.
122 struct nameseq: tipc_name_seq
127 * @param type Type of the sequence.
128 * @param lower Lower bound.
129 * @param upper Upper bound.
131 nameseq(__u32 type, __u32 lower, __u32 upper) throw ();
135 * @param type Type of the sequence.
136 * @param instance Lower and upper bound.
138 nameseq(__u32 type, __u32 instance) throw ();
143 * Reasons for returned messages when recvmsg() is used.
145 * @see recvmsg(2) of TIPC documentation
149 /// Not a returned message.
151 /// Port name doesn't exist.
152 ERR_NO_NAME = TIPC_ERR_NO_NAME,
153 /// Port ID doesn't exist.
154 ERR_NO_PORT = TIPC_ERR_NO_PORT,
155 /// Node doesn't exist.
156 ERR_NO_NODE = TIPC_ERR_NO_NODE,
157 /// Reception queue is full.
158 ERR_OVERLOAD = TIPC_ERR_OVERLOAD,
159 /// Connection shutted down.
160 CONN_SHUTDOWN = TIPC_CONN_SHUTDOWN
164 * Subscription filter type.
166 * @see TIPC documentation: 1.4.3 Name Subscriptions
171 * Causes the topology service to generate a PUBLISHED event
172 * for each port name or port name sequence it finds that overlaps
173 * the specified port name sequence; a WITHDRAWN event is issued
174 * each time a previously reported name becomes unavailable.
176 * Allows the topology service to inform the application if there
177 * are @b any ports of interest.
179 SUB_PORTS = TIPC_SUB_PORTS,
181 * Causes the topology service to generate a single publish event for
182 * the first port it finds with an overlapping name and a single
183 * withdraw event when the last such port becomes unavailable.
185 * Allows the topology service to inform the application about
186 * @b all ports of interest.
188 SUB_SERVICE = TIPC_SUB_SERVICE
192 * Subscription request message.
194 * @see TIPC documentation: 1.4.3 Name Subscriptions
196 struct subscr: tipc_subscr
201 * @param seq The port name sequence of interest to the application.
202 * @param timeout A subscription timeout value, in ms
204 * @param filter An event filter specifying which events are of
205 * interest to the application (see subscr_t).
206 * @param usr_handle An 8 byte user handle that is application-defined.
208 subscr(nameseq seq, __u32 timeout, __u32 filter,
209 const char* usr_handle = "") throw ();
215 /// The port has been published.
216 PUBLISHED = TIPC_PUBLISHED,
217 /// The port has been withdrawn.
218 WITHDRAWN = TIPC_WITHDRAWN,
219 /// The event has timed out.
220 TIMEOUT = TIPC_SUBSCR_TIMEOUT
226 * @see TIPC documentation: 1.4.3 Name Subscriptions
228 struct subscr_event: tipc_event
233 * TIPC socket address (name).
235 * @see bind(2), Socket::bind()
236 * @see connect(2), Socket::connect()
237 * @see getsockaddr(2), Socket::getsockaddr()
238 * @see setsockaddr(2), Socket::setsockaddr()
239 * @see accept(2), Socket::accept()
240 * @see sendto(2), Socket::send()
241 * @see recvfrom(2), Socket::recv()
243 struct sockaddr: sockaddr_tipc
246 /// Type of TIPC address
249 ID = TIPC_ADDR_ID, ///< Port ID
250 NAME = TIPC_ADDR_NAME, ///< Port name
251 NAMESEQ = TIPC_ADDR_NAMESEQ ///< Name sequence or multicast
257 * @see TIPC documentation: 2.1.2 bind
261 ZONE = TIPC_ZONE_SCOPE, ///< Zone scope.
262 CLUSTER = TIPC_CLUSTER_SCOPE, ///< Cluster scope.
263 NODE = TIPC_NODE_SCOPE ///< Node scope.
270 * Constructor using a port ID.
272 * @param port Port ID.
273 * @param scope Bind scope.
275 sockaddr(portid port, scope_t scope = ZONE) throw ();
278 * Constructor using a port name.
280 * @param name Port name.
281 * @param scope Bind scope.
282 * @param domain Domain lookup.
284 * @see Documentación de TIPC: 1.4.1 Address Resolution
286 sockaddr(name name, scope_t scope = ZONE,
287 tipc::addr domain = tipc::addr(0u))
291 * Constructor using a port name sequence.
293 * @param nameseq Port name sequence.
294 * @param scope Bind scope.
296 sockaddr(nameseq nameseq, scope_t scope = ZONE) throw ();
298 /// Type of TIPC address
299 type_t type() const throw ();
301 /// Length of this unix socket address
302 socklen_t length() const throw ();
304 /// Compare two TIPC socket addresses
305 bool operator == (const sockaddr& other) const throw ();
309 /// TIPC socket traits.
313 /// Socket address type.
314 typedef tipc::sockaddr sockaddr;
317 enum { PF = PF_TIPC };
322 typedef posixx::socket::basic_socket< traits > socket;
324 } } } // namespace posixx::linux::tipc
328 posixx::linux::tipc::addr::addr() throw (): address(0u)
333 posixx::linux::tipc::addr::addr(__u32 address) throw (): address(address)
338 posixx::linux::tipc::addr::addr(unsigned int zone, unsigned int cluster,
339 unsigned int node) throw ():
340 address(tipc_addr(zone, cluster, node))
345 void posixx::linux::tipc::addr::zone(unsigned int zone) throw ()
347 address = tipc_addr(zone, cluster(), node());
351 unsigned int posixx::linux::tipc::addr::zone() const throw ()
353 return tipc_zone(address);
357 void posixx::linux::tipc::addr::cluster(unsigned int cluster) throw ()
359 address = tipc_addr(zone(), cluster, node());
363 unsigned int posixx::linux::tipc::addr::cluster() const throw ()
365 return tipc_cluster(address);
369 void posixx::linux::tipc::addr::node(unsigned int node) throw ()
371 address = tipc_addr(zone(), cluster(), node);
375 unsigned int posixx::linux::tipc::addr::node() const throw ()
377 return tipc_node(address);
381 posixx::linux::tipc::addr::operator __u32 () const throw ()
387 posixx::linux::tipc::portid::portid(__u32 r, addr n) throw ()
394 posixx::linux::tipc::name::name(__u32 t, __u32 i) throw ()
401 posixx::linux::tipc::nameseq::nameseq(__u32 t, __u32 low, __u32 up) throw ()
409 posixx::linux::tipc::nameseq::nameseq(__u32 t, __u32 instance) throw ()
417 posixx::linux::tipc::subscr::subscr(nameseq s, __u32 t, __u32 f,
418 const char* uh) throw ()
423 std::memcpy(usr_handle, uh, sizeof(usr_handle));
427 posixx::linux::tipc::sockaddr::sockaddr() throw ()
432 posixx::linux::tipc::sockaddr::sockaddr(portid port, scope_t s) throw ()
435 addrtype = TIPC_ADDR_ID;
441 posixx::linux::tipc::sockaddr::sockaddr(name name, scope_t s, tipc::addr d)
445 addrtype = TIPC_ADDR_NAME;
447 addr.name.name = name;
448 addr.name.domain = d;
452 posixx::linux::tipc::sockaddr::sockaddr(nameseq nameseq, scope_t s) throw ()
455 addrtype = TIPC_ADDR_NAMESEQ;
457 addr.nameseq = nameseq;
461 posixx::linux::tipc::sockaddr::type_t posixx::linux::tipc::sockaddr::type()
464 return static_cast< type_t >(addrtype);
468 socklen_t posixx::linux::tipc::sockaddr::length() const throw ()
470 return sizeof(sockaddr_tipc);
474 bool posixx::linux::tipc::sockaddr::operator == (const sockaddr& other) const
477 return !memcmp(this, &other, sizeof(*this));
480 #endif // POSIXX_LINUX_TIPC_HPP_