X-Git-Url: https://git.llucax.com/software/posixx.git/blobdiff_plain/7b35c34eaa3ee421eb5effc63801aeff69a9ffe8..HEAD:/src/linux/tipc.hpp diff --git a/src/linux/tipc.hpp b/src/linux/tipc.hpp index 15292e8..bd985e5 100644 --- a/src/linux/tipc.hpp +++ b/src/linux/tipc.hpp @@ -1,7 +1,13 @@ +// Copyright Leandro Lucarella 2008 - 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file COPYING or copy at +// http://www.boost.org/LICENSE_1_0.txt) + + #ifndef POSIXX_LINUX_TIPC_HPP_ #define POSIXX_LINUX_TIPC_HPP_ -#include "../basic_socket.hpp" // posixx::socket +#include "../socket/basic_socket.hpp" // posixx::socket #include // all tipc stuff #include // memcpy @@ -96,6 +102,15 @@ struct portid: tipc_portid */ portid(__u32 ref, addr node) throw (); + /// Access to the node addr. + addr& node_addr() throw (); + + /// Access to the node addr. + const addr& node_addr() const throw (); + + /// Compares 2 port ids. + bool operator == (const portid& other) const throw (); + }; /** @@ -105,6 +120,7 @@ struct portid: tipc_portid */ struct name: tipc_name { + /** * Constructor. * @@ -112,16 +128,20 @@ struct name: tipc_name * @param instance Instance of the named port. */ name(__u32 type, __u32 instance) throw (); + + /// Compares 2 port names. + bool operator == (const name& other) const throw (); + }; /** * Port sequence. * - * @see Multicast * @see tipc_name_seq struct from linux/tipc.h. */ struct nameseq: tipc_name_seq { + /** * Constructor. * @@ -129,6 +149,7 @@ struct nameseq: tipc_name_seq * @param lower Lower bound. * @param upper Upper bound. */ + nameseq(__u32 type, __u32 lower, __u32 upper) throw (); /** * Constructor. @@ -137,34 +158,10 @@ struct nameseq: tipc_name_seq * @param instance Lower and upper bound. */ nameseq(__u32 type, __u32 instance) throw (); -}; -/** - * Multicast port sequence. - * - * It's a port sequence just like nameseq used to simplify the use of the - * sockaddr. - * - * @see nameseq - * @see Estructura tipc_name_seq de linux/tipc.h - */ -struct multicast: tipc_name_seq -{ - /** - * Constructor. - * - * @param type Type of the multicast sequence. - * @param lower Lower bound. - * @param upper Upper bound. - */ - multicast(__u32 type, __u32 lower, __u32 upper) throw (); - /** - * Constructor. - * - * @param type Type of the multicast sequence. - * @param instance Lower and upper bound. - */ - multicast(__u32 type, __u32 instance) throw (); + /// Compares 2 port name sequences. + bool operator == (const nameseq& other) const throw (); + }; /** @@ -193,18 +190,20 @@ enum reason_t * * @see TIPC documentation: 1.4.3 Name Subscriptions */ -enum subcription_t +enum subscr_t { + /** - * Causes the topology service to generate a event::PUBLISHED event + * Causes the topology service to generate a PUBLISHED event * for each port name or port name sequence it finds that overlaps - * the specified port name sequence; a TIPC_WITHDRAWN event is issued + * the specified port name sequence; a WITHDRAWN event is issued * each time a previously reported name becomes unavailable. * * Allows the topology service to inform the application if there * are @b any ports of interest. */ SUB_PORTS = TIPC_SUB_PORTS, + /** * Causes the topology service to generate a single publish event for * the first port it finds with an overlapping name and a single @@ -213,7 +212,20 @@ enum subcription_t * Allows the topology service to inform the application about * @b all ports of interest. */ - SUB_SERVICE = TIPC_SUB_SERVICE + SUB_SERVICE = TIPC_SUB_SERVICE, + + /** + * Instruct the topology service to cancel a previously requested + * subscription. + * + * The application simply resends the original subscription request + * with SUB_CANCEL logically OR'd into the event filter. + * + * @note This is implemented in TIPC 1.7+ only (according to TIPC + * documentation). + */ + SUB_CANCEL = TIPC_SUB_CANCEL + }; /** @@ -221,8 +233,9 @@ enum subcription_t * * @see TIPC documentation: 1.4.3 Name Subscriptions */ -struct subscription: tipc_subscr +struct subscr: tipc_subscr { + /** * Constructor. * @@ -230,11 +243,60 @@ struct subscription: tipc_subscr * @param timeout A subscription timeout value, in ms * (or WAIT_FOREVER). * @param filter An event filter specifying which events are of - * interest to the application (see subscription_t). - * @param usr_handle An 8 byte user handle that is application-defined. + * interest to the application (see subscr_t). + * @param usr_handle An 8 byte user handle that is application-defined, + * (treated as a string). */ - subscription(nameseq seq, __u32 timeout, __u32 filter, + subscr(nameseq seq, __u32 timeout, __u32 filter, const char* usr_handle = "") throw (); + + /** + * Constructor. + * + * @param seq The port name sequence of interest to the application. + * @param timeout A subscription timeout value, in ms + * (or WAIT_FOREVER). + * @param filter An event filter specifying which events are of + * interest to the application (see subscr_t). + * @param usr_handle An 8 byte user handle that is application-defined. + * (treated as binary data). + * @param handle_size Size of the usr_handle buffer (it should be at + * most 8) + */ + subscr(nameseq seq, __u32 timeout, __u32 filter, + const char* usr_handle, size_t handle_size) + throw (); + + /// Access to the subscribed name sequence. + nameseq& name_seq() throw (); + + /// Access to the subscribed name sequence. + const nameseq& name_seq() const throw (); + + /// Set the user handle as a string. + void handle(const char* usr_handle) throw (); + + /// Set the user handle as binary data. + void handle(const char* usr_handle, size_t handle_size) throw (); + + /// Compares 2 subscription request messages. + bool operator == (const subscr& other) const throw (); + +}; + +/// Type of events. +enum event_t +{ + + /// The port has been published. + PUBLISHED = TIPC_PUBLISHED, + + /// The port has been withdrawn. + WITHDRAWN = TIPC_WITHDRAWN, + + /// The event has timed out. + TIMEOUT = TIPC_SUBSCR_TIMEOUT + }; /** @@ -242,18 +304,41 @@ struct subscription: tipc_subscr * * @see TIPC documentation: 1.4.3 Name Subscriptions */ -struct event: tipc_event -{ - /// Type of events. - enum type_t - { - /// The port has been published. - PUBLISHED = TIPC_PUBLISHED, - /// The port has been withdrawn. - WITHDRAWN = TIPC_WITHDRAWN, - /// The event has timed out. - TIMEOUT = TIPC_SUBSCR_TIMEOUT - }; +struct subscr_event: tipc_event +{ + + /// Access to the subscribed name sequence. + portid& port_id() throw (); + + /// Access to the subscribed name sequence. + const portid& port_id() const throw (); + + /// Access to the subscribed name sequence. + subscr& subscription() throw (); + + /// Access to the subscribed name sequence. + const subscr& subscription() const throw (); + +}; + +/// Type of TIPC address +enum type_t +{ + ID = TIPC_ADDR_ID, ///< Port ID + NAME = TIPC_ADDR_NAME, ///< Port name + NAMESEQ = TIPC_ADDR_NAMESEQ ///< Name sequence or multicast +}; + +/** + * Bind scope. + * + * @see TIPC documentation: 2.1.2 bind + */ +enum scope_t +{ + ZONE = TIPC_ZONE_SCOPE, ///< Zone scope. + CLUSTER = TIPC_CLUSTER_SCOPE, ///< Cluster scope. + NODE = TIPC_NODE_SCOPE ///< Node scope. }; /** @@ -270,26 +355,6 @@ struct event: tipc_event struct sockaddr: sockaddr_tipc { - /// Type of TIPC address - enum type_t - { - ID = TIPC_ADDR_ID, ///< Port ID - NAME = TIPC_ADDR_NAME, ///< Port name - NAMESEQ = TIPC_ADDR_NAMESEQ, ///< Name sequence or multicast - }; - - /** - * Bind scope. - * - * @see TIPC documentation: 2.1.2 bind - */ - enum scope_t - { - ZONE = TIPC_ZONE_SCOPE, ///< Zone scope. - CLUSTER = TIPC_CLUSTER_SCOPE, ///< Cluster scope. - NODE = TIPC_NODE_SCOPE ///< Node scope. - }; - /// Constructor. sockaddr() throw (); @@ -322,14 +387,6 @@ struct sockaddr: sockaddr_tipc */ sockaddr(nameseq nameseq, scope_t scope = ZONE) throw (); - /** - * Constructor using a multicast port name sequence. - * - * @param mcast Multicast port name sequence. - * @param scope Bind scope. - */ - sockaddr(multicast mcast, scope_t scope = ZONE) throw (); - /// Type of TIPC address type_t type() const throw (); @@ -339,6 +396,30 @@ struct sockaddr: sockaddr_tipc /// Compare two TIPC socket addresses bool operator == (const sockaddr& other) const throw (); + /// Access to the port ID (only valid if addrtype == ID) + portid& port_id() throw (); + + /// Access to the port ID (only valid if addrtype == ID) + const portid& port_id() const throw (); + + /// Access to the port name (only valid if addrtype == NAME) + name& port_name() throw (); + + /// Access to the port name (only valid if addrtype == NAME) + const name& port_name() const throw (); + + /// Access to the port name domain (only valid if addrtype == NAME) + tipc::addr& name_domain() throw (); + + /// Access to the port name domain (only valid if addrtype == NAME) + const tipc::addr& name_domain() const throw (); + + /// Access to the port name sequence (only valid if addrtype == NAMESEQ) + nameseq& name_seq() throw (); + + /// Access to the port name sequence (only valid if addrtype == NAMESEQ) + const nameseq& name_seq() const throw (); + }; /// TIPC socket traits. @@ -425,6 +506,26 @@ posixx::linux::tipc::portid::portid(__u32 r, addr n) throw () node = n; } +inline +posixx::linux::tipc::addr& posixx::linux::tipc::portid::node_addr() throw () +{ + return *reinterpret_cast(&node); +} + +inline +const posixx::linux::tipc::addr& posixx::linux::tipc::portid::node_addr() const + throw () +{ + return *reinterpret_cast(&node); +} + +inline +bool posixx::linux::tipc::portid::operator == ( + const posixx::linux::tipc::portid& other) const throw () +{ + return memcmp(this, &other, sizeof(*this)) == 0; +} + inline posixx::linux::tipc::name::name(__u32 t, __u32 i) throw () { @@ -432,6 +533,13 @@ posixx::linux::tipc::name::name(__u32 t, __u32 i) throw () instance = i; } +inline +bool posixx::linux::tipc::name::operator == ( + const posixx::linux::tipc::name& other) const throw () +{ + return memcmp(this, &other, sizeof(*this)) == 0; +} + inline posixx::linux::tipc::nameseq::nameseq(__u32 t, __u32 low, __u32 up) throw () { @@ -449,42 +557,105 @@ posixx::linux::tipc::nameseq::nameseq(__u32 t, __u32 instance) throw () } inline -posixx::linux::tipc::multicast::multicast(__u32 t, __u32 low, __u32 up) - throw () +bool posixx::linux::tipc::nameseq::operator == ( + const posixx::linux::tipc::nameseq& other) const throw () { - type = t; - lower = low; - upper = up; + return memcmp(this, &other, sizeof(*this)) == 0; } inline -posixx::linux::tipc::multicast::multicast(__u32 t, __u32 instance) throw () +posixx::linux::tipc::subscr::subscr(nameseq s, __u32 t, __u32 f, + const char* uh) throw () { - type = t; - lower = instance; - upper = instance; + seq = s; + timeout = t; + filter = f; + handle(uh); } inline -posixx::linux::tipc::subscription::subscription(nameseq s, __u32 t, __u32 f, - const char* uh) throw () +posixx::linux::tipc::subscr::subscr(nameseq s, __u32 t, __u32 f, + const char* uh, size_t uh_size) throw () { seq = s; timeout = t; filter = f; - std::memcpy(usr_handle, uh, sizeof(usr_handle)); + handle(uh, uh_size); +} + +inline +posixx::linux::tipc::nameseq& posixx::linux::tipc::subscr::name_seq() throw () +{ + return *reinterpret_cast(&seq); +} + +inline +const posixx::linux::tipc::nameseq& +posixx::linux::tipc::subscr::name_seq() const throw () +{ + return *reinterpret_cast(&seq); +} + +inline +void posixx::linux::tipc::subscr::handle(const char* uh) throw () +{ + std::strncpy(usr_handle, uh, sizeof(usr_handle)); +} + +inline +void posixx::linux::tipc::subscr::handle(const char* uh, size_t uh_size) + throw () +{ + std::memcpy(usr_handle, uh, uh_size); +} + +inline +bool posixx::linux::tipc::subscr::operator == (const subscr& other) const + throw () +{ + return memcmp(this, &other, sizeof(*this)) == 0; +} + +inline +posixx::linux::tipc::portid& posixx::linux::tipc::subscr_event::port_id() + throw () +{ + return *reinterpret_cast(&port); +} + +inline +const posixx::linux::tipc::portid& posixx::linux::tipc::subscr_event::port_id() + const throw () +{ + return *reinterpret_cast(&port); +} + +inline +posixx::linux::tipc::subscr& posixx::linux::tipc::subscr_event::subscription() + throw () +{ + return *reinterpret_cast(&s); +} + +inline +const posixx::linux::tipc::subscr& +posixx::linux::tipc::subscr_event::subscription() const throw () +{ + return *reinterpret_cast(&s); } inline posixx::linux::tipc::sockaddr::sockaddr() throw () { + memset(this, 0, sizeof(*this)); + family = AF_TIPC; } inline posixx::linux::tipc::sockaddr::sockaddr(portid port, scope_t s) throw () { family = AF_TIPC; - addrtype = TIPC_ADDR_ID; + addrtype = ID; scope = s; addr.id = port; } @@ -494,7 +665,7 @@ posixx::linux::tipc::sockaddr::sockaddr(name name, scope_t s, tipc::addr d) throw () { family = AF_TIPC; - addrtype = TIPC_ADDR_NAME; + addrtype = NAME; scope = s; addr.name.name = name; addr.name.domain = d; @@ -504,22 +675,13 @@ inline posixx::linux::tipc::sockaddr::sockaddr(nameseq nameseq, scope_t s) throw () { family = AF_TIPC; - addrtype = TIPC_ADDR_NAMESEQ; + addrtype = NAMESEQ; scope = s; addr.nameseq = nameseq; } inline -posixx::linux::tipc::sockaddr::sockaddr(multicast mcast, scope_t s) throw () -{ - family = AF_TIPC; - addrtype = TIPC_ADDR_MCAST; - scope = s; - addr.nameseq = mcast; -} - -inline -posixx::linux::tipc::sockaddr::type_t posixx::linux::tipc::sockaddr::type() +posixx::linux::tipc::type_t posixx::linux::tipc::sockaddr::type() const throw () { return static_cast< type_t >(addrtype); @@ -535,7 +697,74 @@ inline bool posixx::linux::tipc::sockaddr::operator == (const sockaddr& other) const throw () { - return !memcmp(this, &other, sizeof(*this)); + if (family != other.family) + return false; + if (addrtype != other.addrtype) + return false; + if (scope != other.scope) + return false; + if (addrtype == ID) + return port_id() == other.port_id(); + if (addrtype == NAME) + return name_domain() == other.name_domain() + && port_name() == other.port_name(); + if (addrtype == NAMESEQ) + return name_seq() == other.name_seq(); + return memcmp(this, &other, sizeof(*this)) == 0; +} + +inline +posixx::linux::tipc::portid& posixx::linux::tipc::sockaddr::port_id() throw () +{ + return *reinterpret_cast(&addr.id); +} + +inline +const posixx::linux::tipc::portid& posixx::linux::tipc::sockaddr::port_id() + const throw () +{ + return *reinterpret_cast(&addr.id); +} + +inline +posixx::linux::tipc::name& posixx::linux::tipc::sockaddr::port_name() throw () +{ + return *reinterpret_cast(&addr.name.name); +} + +inline +const posixx::linux::tipc::name& posixx::linux::tipc::sockaddr::port_name() + const throw () +{ + return *reinterpret_cast(&addr.name.name); +} + +inline +posixx::linux::tipc::addr& posixx::linux::tipc::sockaddr::name_domain() + throw () +{ + return *reinterpret_cast(&addr.name.domain); +} + +inline +const posixx::linux::tipc::addr& posixx::linux::tipc::sockaddr::name_domain() + const throw () +{ + return *reinterpret_cast(&addr.name.domain); +} + +inline +posixx::linux::tipc::nameseq& posixx::linux::tipc::sockaddr::name_seq() + throw () +{ + return *reinterpret_cast(&addr.nameseq); +} + +inline +const posixx::linux::tipc::nameseq& posixx::linux::tipc::sockaddr::name_seq() + const throw () +{ + return *reinterpret_cast(&addr.nameseq); } #endif // POSIXX_LINUX_TIPC_HPP_