]> git.llucax.com Git - software/posixx.git/blob - src/linux/tipc/print.hpp
Add Boost License
[software/posixx.git] / src / linux / tipc / print.hpp
1 // Copyright Leandro Lucarella 2008 - 2010.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file COPYING or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6
7 #ifndef POSIXX_LINUX_TIPC_PRINT_HPP_
8 #define POSIXX_LINUX_TIPC_PRINT_HPP_
9
10 #include "../tipc.hpp" // posixx::linux::tipc::sockaddr
11 #include <ostream> // std::ostream
12
13 inline
14 std::ostream& operator << (std::ostream& os,
15                 const posixx::linux::tipc::addr& a) throw()
16 {
17         return os << a.zone() << "." << a.cluster() << "." << a.node();
18 }
19
20 inline
21 std::ostream& operator << (std::ostream& os,
22                 const posixx::linux::tipc::portid& p) throw()
23 {
24         return os << "portid(" << p.ref << ", " << p.node
25                         << " [" << p.node_addr() << "])";
26 }
27
28 inline
29 std::ostream& operator << (std::ostream& os,
30                 const posixx::linux::tipc::name& n) throw()
31 {
32         return os << "name(" << n.type << ", " << n.instance << ")";
33 }
34
35 inline
36 std::ostream& operator << (std::ostream& os,
37                 const posixx::linux::tipc::nameseq& ns) throw()
38 {
39         return os << "nameseq(" << ns.type << ", " << ns.lower << ", "
40                         << ns.upper << ")";
41 }
42
43 inline
44 std::ostream& operator << (std::ostream& os,
45                 const posixx::linux::tipc::subscr& s) throw()
46 {
47         using namespace posixx::linux::tipc;
48
49         bool has_filter = false;
50
51         os << "subscr(" << s.name_seq() << ", " << s.timeout << ", ";
52
53         os << s.filter;
54         if (s.filter & SUB_PORTS) {
55                 os << " [PORTS";
56                 has_filter = true;
57         }
58         if (s.filter & SUB_SERVICE) {
59                 if (has_filter)
60                         os << "|";
61                 else
62                         os << "[";
63                 os << "SERVICE";
64                 has_filter = true;
65         }
66         if (s.filter & SUB_CANCEL) {
67                 if (has_filter)
68                         os << "|";
69                 else
70                         os << "[";
71                 os << "CANCEL";
72                 has_filter = true;
73         }
74         if (has_filter)
75                 os << "]";
76
77         os << ", '" << std::string(s.usr_handle, sizeof(s.usr_handle)) << "')";
78
79         return os;
80
81 }
82
83 inline
84 std::ostream& operator << (std::ostream& os,
85                 const posixx::linux::tipc::subscr_event& e) throw()
86 {
87         using namespace posixx::linux::tipc;
88         os << "subscr_event(" << e.event << "[";
89         if (e.event == PUBLISHED)
90                 os << "PUBLISHED";
91         else if (e.event == WITHDRAWN)
92                 os << "WITHDRAWN";
93         else if (e.event == TIMEOUT)
94                 os << "TIMEOUT";
95         return os << "], " << e.found_lower << ", " << e.found_upper << ", "
96                         << e.port_id() << ", " << e.subscription() << ")";
97 }
98
99 inline
100 std::ostream& operator << (std::ostream& os,
101                 const posixx::linux::tipc::sockaddr& sa) throw()
102 {
103         using namespace posixx::linux::tipc;
104         os << "sockaddr(" << sa.family << ", " << unsigned(sa.scope) << ", ";
105         if (sa.type() == ID)
106                 os << sa.port_id();
107         else if (sa.type() == NAME)
108                 os << sa.port_name() << ", " << sa.name_domain();
109         else if (sa.type() == NAMESEQ)
110                 os << sa.name_seq();
111         else
112                 os << "[UNKNOW addrtype=" << sa.addrtype << "]";
113         return os << ")";
114 }
115
116 #endif // POSIXX_LINUX_TIPC_PRINT_HPP_