From 67c511b36d56c5042cef47d84a5f91e24f3fcbe5 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 27 Feb 2009 17:04:49 -0200 Subject: [PATCH] Move type_t and scope_t out from tipc::sockaddr Having nested constant definitions makes their use a little annoying. --- src/linux/tipc.hpp | 42 ++++++++++++++++++------------------ src/linux/tipc/print.hpp | 8 +++---- test/linux/tipc/sockaddr.cpp | 30 +++++++++++++------------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/linux/tipc.hpp b/src/linux/tipc.hpp index cb56413..0fc49fb 100644 --- a/src/linux/tipc.hpp +++ b/src/linux/tipc.hpp @@ -315,6 +315,26 @@ struct subscr_event: tipc_event }; +/// 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. +}; + /** * TIPC socket address (name). * @@ -329,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 (); @@ -675,7 +675,7 @@ posixx::linux::tipc::sockaddr::sockaddr(nameseq nameseq, scope_t s) throw () } 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); diff --git a/src/linux/tipc/print.hpp b/src/linux/tipc/print.hpp index d0f5924..ae067df 100644 --- a/src/linux/tipc/print.hpp +++ b/src/linux/tipc/print.hpp @@ -94,13 +94,13 @@ inline std::ostream& operator << (std::ostream& os, const posixx::linux::tipc::sockaddr& sa) throw() { - using posixx::linux::tipc::sockaddr; + using namespace posixx::linux::tipc; os << "sockaddr(" << sa.family << ", " << unsigned(sa.scope) << ", "; - if (sa.type() == sockaddr::ID) + if (sa.type() == ID) os << sa.port_id(); - else if (sa.type() == sockaddr::NAME) + else if (sa.type() == NAME) os << sa.port_name() << ", " << sa.name_domain(); - else if (sa.type() == sockaddr::NAMESEQ) + else if (sa.type() == NAMESEQ) os << sa.name_seq(); else os << "[UNKNOW addrtype=" << sa.addrtype << "]"; diff --git a/test/linux/tipc/sockaddr.cpp b/test/linux/tipc/sockaddr.cpp index 45ef3c4..f304ce2 100644 --- a/test/linux/tipc/sockaddr.cpp +++ b/test/linux/tipc/sockaddr.cpp @@ -408,9 +408,9 @@ BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_id_ctor_test ) portid id(12313, addr(1, 1, 77)); tipc::sockaddr sp(id); BOOST_CHECK_EQUAL( sp.family, AF_TIPC ); - BOOST_CHECK_EQUAL( sp.addrtype, tipc::sockaddr::ID ); - BOOST_CHECK_EQUAL( sp.type(), tipc::sockaddr::ID ); - BOOST_CHECK_EQUAL( sp.scope, tipc::sockaddr::ZONE ); + BOOST_CHECK_EQUAL( sp.addrtype, ID ); + BOOST_CHECK_EQUAL( sp.type(), ID ); + BOOST_CHECK_EQUAL( sp.scope, ZONE ); BOOST_CHECK_EQUAL( sp.port_id(), id ); BOOST_CHECK_EQUAL( sp.addr.id.ref, id.ref ); BOOST_CHECK_EQUAL( sp.addr.id.node, id.node ); @@ -420,11 +420,11 @@ BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_id_ctor_test ) BOOST_CHECK_EQUAL( sp, tipc::sockaddr(portid(12313, addr(2, 1, 77))) ); - tipc::sockaddr sp2(id, tipc::sockaddr::NODE); + tipc::sockaddr sp2(id, NODE); BOOST_CHECK_EQUAL( sp2.family, AF_TIPC ); - BOOST_CHECK_EQUAL( sp2.addrtype, tipc::sockaddr::ID ); - BOOST_CHECK_EQUAL( sp2.type(), tipc::sockaddr::ID ); - BOOST_CHECK_EQUAL( sp2.scope, tipc::sockaddr::NODE ); + BOOST_CHECK_EQUAL( sp2.addrtype, ID ); + BOOST_CHECK_EQUAL( sp2.type(), ID ); + BOOST_CHECK_EQUAL( sp2.scope, NODE ); BOOST_CHECK_EQUAL( sp2.port_id(), id ); BOOST_CHECK_EQUAL( sp2.addr.id.ref, id.ref ); BOOST_CHECK_EQUAL( sp2.addr.id.node, id.node ); @@ -437,9 +437,9 @@ BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_name_ctor_test ) name n(12313, 77); tipc::sockaddr sn(n); BOOST_CHECK_EQUAL( sn.family, AF_TIPC ); - BOOST_CHECK_EQUAL( sn.addrtype, tipc::sockaddr::NAME ); - BOOST_CHECK_EQUAL( sn.type(), tipc::sockaddr::NAME ); - BOOST_CHECK_EQUAL( sn.scope, tipc::sockaddr::ZONE ); + BOOST_CHECK_EQUAL( sn.addrtype, NAME ); + BOOST_CHECK_EQUAL( sn.type(), NAME ); + BOOST_CHECK_EQUAL( sn.scope, ZONE ); BOOST_CHECK_EQUAL( sn.port_name(), n ); BOOST_CHECK_EQUAL( sn.addr.name.name.type, n.type ); BOOST_CHECK_EQUAL( sn.addr.name.name.instance, n.instance ); @@ -452,8 +452,8 @@ BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_name_ctor_test ) sn.name_domain().node(999); BOOST_CHECK_EQUAL( sn.name_domain(), addr(0, 0, 999) ); - BOOST_CHECK_EQUAL( sn, tipc::sockaddr(name(999, 77), - tipc::sockaddr::ZONE, addr(0, 0, 999)) ); + BOOST_CHECK_EQUAL( sn, tipc::sockaddr(name(999, 77), ZONE, + addr(0, 0, 999)) ); } @@ -463,9 +463,9 @@ BOOST_AUTO_TEST_CASE( linux_tipc_sockaddr_nameseq_ctor_test ) nameseq ns(12313, 77); tipc::sockaddr sns(ns); BOOST_CHECK_EQUAL( sns.family, AF_TIPC ); - BOOST_CHECK_EQUAL( sns.addrtype, tipc::sockaddr::NAMESEQ ); - BOOST_CHECK_EQUAL( sns.type(), tipc::sockaddr::NAMESEQ ); - BOOST_CHECK_EQUAL( sns.scope, tipc::sockaddr::ZONE ); + BOOST_CHECK_EQUAL( sns.addrtype, NAMESEQ ); + BOOST_CHECK_EQUAL( sns.type(), NAMESEQ ); + BOOST_CHECK_EQUAL( sns.scope, ZONE ); BOOST_CHECK_EQUAL( sns.name_seq(), ns ); BOOST_CHECK_EQUAL( sns.addr.nameseq.type, ns.type ); BOOST_CHECK_EQUAL( sns.addr.nameseq.lower, ns.lower ); -- 2.43.0