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
112 * @param type Type of the named port.
113 * @param instance Instance of the named port.
115 name(__u32 type, __u32 instance) throw ();
122 * @see tipc_name_seq struct from linux/tipc.h.
124 struct nameseq: tipc_name_seq
130 * @param type Type of the sequence.
131 * @param lower Lower bound.
132 * @param upper Upper bound.
135 nameseq(__u32 type, __u32 lower, __u32 upper) throw ();
139 * @param type Type of the sequence.
140 * @param instance Lower and upper bound.
142 nameseq(__u32 type, __u32 instance) throw ();
147 * Reasons for returned messages when recvmsg() is used.
149 * @see recvmsg(2) of TIPC documentation
153 /// Not a returned message.
155 /// Port name doesn't exist.
156 ERR_NO_NAME = TIPC_ERR_NO_NAME,
157 /// Port ID doesn't exist.
158 ERR_NO_PORT = TIPC_ERR_NO_PORT,
159 /// Node doesn't exist.
160 ERR_NO_NODE = TIPC_ERR_NO_NODE,
161 /// Reception queue is full.
162 ERR_OVERLOAD = TIPC_ERR_OVERLOAD,
163 /// Connection shutted down.
164 CONN_SHUTDOWN = TIPC_CONN_SHUTDOWN
168 * Subscription filter type.
170 * @see TIPC documentation: 1.4.3 Name Subscriptions
176 * Causes the topology service to generate a PUBLISHED event
177 * for each port name or port name sequence it finds that overlaps
178 * the specified port name sequence; a WITHDRAWN event is issued
179 * each time a previously reported name becomes unavailable.
181 * Allows the topology service to inform the application if there
182 * are @b any ports of interest.
184 SUB_PORTS = TIPC_SUB_PORTS,
187 * Causes the topology service to generate a single publish event for
188 * the first port it finds with an overlapping name and a single
189 * withdraw event when the last such port becomes unavailable.
191 * Allows the topology service to inform the application about
192 * @b all ports of interest.
194 SUB_SERVICE = TIPC_SUB_SERVICE,
197 * Instruct the topology service to cancel a previously requested
200 * The application simply resends the original subscription request
201 * with SUB_CANCEL logically OR'd into the event filter.
203 * @note This is implemented in TIPC 1.7+ only (according to TIPC
206 SUB_CANCEL = TIPC_SUB_CANCEL
211 * Subscription request message.
213 * @see TIPC documentation: 1.4.3 Name Subscriptions
215 struct subscr: tipc_subscr
221 * @param seq The port name sequence of interest to the application.
222 * @param timeout A subscription timeout value, in ms
224 * @param filter An event filter specifying which events are of
225 * interest to the application (see subscr_t).
226 * @param usr_handle An 8 byte user handle that is application-defined.
228 subscr(nameseq seq, __u32 timeout, __u32 filter,
229 const char* usr_handle = "") throw ();
237 /// The port has been published.
238 PUBLISHED = TIPC_PUBLISHED,
240 /// The port has been withdrawn.
241 WITHDRAWN = TIPC_WITHDRAWN,
243 /// The event has timed out.
244 TIMEOUT = TIPC_SUBSCR_TIMEOUT
251 * @see TIPC documentation: 1.4.3 Name Subscriptions
253 struct subscr_event: tipc_event
258 * TIPC socket address (name).
260 * @see bind(2), Socket::bind()
261 * @see connect(2), Socket::connect()
262 * @see getsockaddr(2), Socket::getsockaddr()
263 * @see setsockaddr(2), Socket::setsockaddr()
264 * @see accept(2), Socket::accept()
265 * @see sendto(2), Socket::send()
266 * @see recvfrom(2), Socket::recv()
268 struct sockaddr: sockaddr_tipc
271 /// Type of TIPC address
274 ID = TIPC_ADDR_ID, ///< Port ID
275 NAME = TIPC_ADDR_NAME, ///< Port name
276 NAMESEQ = TIPC_ADDR_NAMESEQ ///< Name sequence or multicast
282 * @see TIPC documentation: 2.1.2 bind
286 ZONE = TIPC_ZONE_SCOPE, ///< Zone scope.
287 CLUSTER = TIPC_CLUSTER_SCOPE, ///< Cluster scope.
288 NODE = TIPC_NODE_SCOPE ///< Node scope.
295 * Constructor using a port ID.
297 * @param port Port ID.
298 * @param scope Bind scope.
300 sockaddr(portid port, scope_t scope = ZONE) throw ();
303 * Constructor using a port name.
305 * @param name Port name.
306 * @param scope Bind scope.
307 * @param domain Domain lookup.
309 * @see Documentación de TIPC: 1.4.1 Address Resolution
311 sockaddr(name name, scope_t scope = ZONE,
312 tipc::addr domain = tipc::addr(0u))
316 * Constructor using a port name sequence.
318 * @param nameseq Port name sequence.
319 * @param scope Bind scope.
321 sockaddr(nameseq nameseq, scope_t scope = ZONE) throw ();
323 /// Type of TIPC address
324 type_t type() const throw ();
326 /// Length of this unix socket address
327 socklen_t length() const throw ();
329 /// Compare two TIPC socket addresses
330 bool operator == (const sockaddr& other) const throw ();
334 /// TIPC socket traits.
338 /// Socket address type.
339 typedef tipc::sockaddr sockaddr;
342 enum { PF = PF_TIPC };
347 typedef posixx::socket::basic_socket< traits > socket;
349 } } } // namespace posixx::linux::tipc
353 posixx::linux::tipc::addr::addr() throw (): address(0u)
358 posixx::linux::tipc::addr::addr(__u32 address) throw (): address(address)
363 posixx::linux::tipc::addr::addr(unsigned int zone, unsigned int cluster,
364 unsigned int node) throw ():
365 address(tipc_addr(zone, cluster, node))
370 void posixx::linux::tipc::addr::zone(unsigned int zone) throw ()
372 address = tipc_addr(zone, cluster(), node());
376 unsigned int posixx::linux::tipc::addr::zone() const throw ()
378 return tipc_zone(address);
382 void posixx::linux::tipc::addr::cluster(unsigned int cluster) throw ()
384 address = tipc_addr(zone(), cluster, node());
388 unsigned int posixx::linux::tipc::addr::cluster() const throw ()
390 return tipc_cluster(address);
394 void posixx::linux::tipc::addr::node(unsigned int node) throw ()
396 address = tipc_addr(zone(), cluster(), node);
400 unsigned int posixx::linux::tipc::addr::node() const throw ()
402 return tipc_node(address);
406 posixx::linux::tipc::addr::operator __u32 () const throw ()
412 posixx::linux::tipc::portid::portid(__u32 r, addr n) throw ()
419 posixx::linux::tipc::name::name(__u32 t, __u32 i) throw ()
426 posixx::linux::tipc::nameseq::nameseq(__u32 t, __u32 low, __u32 up) throw ()
434 posixx::linux::tipc::nameseq::nameseq(__u32 t, __u32 instance) throw ()
442 posixx::linux::tipc::subscr::subscr(nameseq s, __u32 t, __u32 f,
443 const char* uh) throw ()
448 std::memcpy(usr_handle, uh, sizeof(usr_handle));
452 posixx::linux::tipc::sockaddr::sockaddr() throw ()
457 posixx::linux::tipc::sockaddr::sockaddr(portid port, scope_t s) throw ()
460 addrtype = TIPC_ADDR_ID;
466 posixx::linux::tipc::sockaddr::sockaddr(name name, scope_t s, tipc::addr d)
470 addrtype = TIPC_ADDR_NAME;
472 addr.name.name = name;
473 addr.name.domain = d;
477 posixx::linux::tipc::sockaddr::sockaddr(nameseq nameseq, scope_t s) throw ()
480 addrtype = TIPC_ADDR_NAMESEQ;
482 addr.nameseq = nameseq;
486 posixx::linux::tipc::sockaddr::type_t posixx::linux::tipc::sockaddr::type()
489 return static_cast< type_t >(addrtype);
493 socklen_t posixx::linux::tipc::sockaddr::length() const throw ()
495 return sizeof(sockaddr_tipc);
499 bool posixx::linux::tipc::sockaddr::operator == (const sockaddr& other) const
502 return !memcmp(this, &other, sizeof(*this));
505 #endif // POSIXX_LINUX_TIPC_HPP_