X-Git-Url: https://git.llucax.com/software/posixx.git/blobdiff_plain/6f13e47380788948b958309c89df400fea6b32fb..d22d22101e7dda5da951a76408ec32708072849e:/src/linux/tipc.hpp?ds=sidebyside diff --git a/src/linux/tipc.hpp b/src/linux/tipc.hpp index 26bae1d..0fc49fb 100644 --- a/src/linux/tipc.hpp +++ b/src/linux/tipc.hpp @@ -96,6 +96,12 @@ 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 (); @@ -255,6 +261,12 @@ struct subscr: tipc_subscr 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 (); @@ -288,6 +300,39 @@ enum event_t */ 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. }; /** @@ -304,26 +349,6 @@ struct subscr_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 (); @@ -365,6 +390,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. @@ -451,6 +500,19 @@ 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 () @@ -515,6 +577,19 @@ posixx::linux::tipc::subscr::subscr(nameseq s, __u32 t, __u32 f, 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 () { @@ -535,16 +610,46 @@ bool posixx::linux::tipc::subscr::operator == (const subscr& other) const 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; } @@ -554,7 +659,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; @@ -564,13 +669,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::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); @@ -586,7 +691,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_