From d5fc673dda9486c752c098d7306beedcac51dea2 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 27 Feb 2009 16:32:38 -0200 Subject: [PATCH] Improve/complete tipc printing Now all objects have the operator << implemented for std::ostreams. --- src/linux/tipc/print.hpp | 115 ++++++++++++++++++++++++++++++++------- 1 file changed, 95 insertions(+), 20 deletions(-) diff --git a/src/linux/tipc/print.hpp b/src/linux/tipc/print.hpp index 3b3d642..d0f5924 100644 --- a/src/linux/tipc/print.hpp +++ b/src/linux/tipc/print.hpp @@ -4,31 +4,106 @@ #include "../tipc.hpp" // posixx::linux::tipc::sockaddr #include // std::ostream +inline +std::ostream& operator << (std::ostream& os, + const posixx::linux::tipc::addr& a) throw() +{ + return os << a.zone() << "." << a.cluster() << "." << a.node(); +} + +inline +std::ostream& operator << (std::ostream& os, + const posixx::linux::tipc::portid& p) throw() +{ + return os << "portid(" << p.ref << ", " << p.node + << " [" << p.node_addr() << "])"; +} + +inline +std::ostream& operator << (std::ostream& os, + const posixx::linux::tipc::name& n) throw() +{ + return os << "name(" << n.type << ", " << n.instance << ")"; +} + +inline +std::ostream& operator << (std::ostream& os, + const posixx::linux::tipc::nameseq& ns) throw() +{ + return os << "nameseq(" << ns.type << ", " << ns.lower << ", " + << ns.upper << ")"; +} + +inline +std::ostream& operator << (std::ostream& os, + const posixx::linux::tipc::subscr& s) throw() +{ + using namespace posixx::linux::tipc; + + bool has_filter = false; + + os << "subscr(" << s.name_seq() << ", " << s.timeout << ", "; + + os << s.filter; + if (s.filter & SUB_PORTS) { + os << " [PORTS"; + has_filter = true; + } + if (s.filter & SUB_SERVICE) { + if (has_filter) + os << "|"; + else + os << "["; + os << "SERVICE"; + has_filter = true; + } + if (s.filter & SUB_CANCEL) { + if (has_filter) + os << "|"; + else + os << "["; + os << "CANCEL"; + has_filter = true; + } + if (has_filter) + os << "]"; + + os << ", '" << std::string(s.usr_handle, sizeof(s.usr_handle)) << "')"; + + return os; + +} + +inline +std::ostream& operator << (std::ostream& os, + const posixx::linux::tipc::subscr_event& e) throw() +{ + using namespace posixx::linux::tipc; + os << "subscr_event(" << e.event << "["; + if (e.event == PUBLISHED) + os << "PUBLISHED"; + else if (e.event == WITHDRAWN) + os << "WITHDRAWN"; + else if (e.event == TIMEOUT) + os << "TIMEOUT"; + return os << "], " << e.found_lower << ", " << e.found_upper << ", " + << e.port_id() << ", " << e.subscription() << ")"; +} + inline std::ostream& operator << (std::ostream& os, const posixx::linux::tipc::sockaddr& sa) throw() { using posixx::linux::tipc::sockaddr; - os << "tipc::sockaddr(scope=" << unsigned(sa.scope) << ", "; - switch (sa.type()) - { - case sockaddr::ID: - os << "id(ref=" << sa.addr.id.ref - << ", node=" << sa.addr.id.node << ")"; - break; - case sockaddr::NAME: - os << "name(type=" << sa.addr.name.name.type - << ", instance=" << sa.addr.name.name.instance - << ", domain=" << sa.addr.name.domain << ")"; - break; - case sockaddr::NAMESEQ: - os << "nameseq(type=" << sa.addr.nameseq.type - << ", lower=" << sa.addr.nameseq.lower - << ", upper=" << sa.addr.nameseq.upper << ")"; - break; - default: - os << "UNKNOWN!"; - } + os << "sockaddr(" << sa.family << ", " << unsigned(sa.scope) << ", "; + if (sa.type() == sockaddr::ID) + os << sa.port_id(); + else if (sa.type() == sockaddr::NAME) + os << sa.port_name() << ", " << sa.name_domain(); + else if (sa.type() == sockaddr::NAMESEQ) + os << sa.name_seq(); + else + os << "[UNKNOW addrtype=" << sa.addrtype << "]"; return os << ")"; } -- 2.43.0