Utils/Logger: Extend Target routing API
[senf.git] / Utils / Logger / Target.cci
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Target inline non-template implementation */
25
26 #include "Target.ih"
27
28 // Custom includes
29 #include "AreaRegistry.hh"
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::log::Target
36
37 prefix_ void senf::log::Target::route(action_t action, int index)
38 {
39     route(0, 0, NONE::value, action, index);
40 }
41
42 prefix_ void senf::log::Target::unroute(action_t action)
43 {
44     unroute(0, 0, NONE::value, action);
45 }
46
47 prefix_ senf::log::Target::iterator senf::log::Target::begin()
48     const
49 {
50     return rib_.begin();
51 }
52
53 prefix_ senf::log::Target::iterator senf::log::Target::end()
54     const
55 {
56     return rib_.end();
57 }
58
59 prefix_ RoutingEntry const & senf::log::Target::operator[](size_type i)
60     size_type size() const
61 {
62     return rib_[i];
63 }
64
65 prefix_ RoutingEntry const & senf::log::Target::operator[](size_type i)
66     size_type size() const
67 {
68     return rib_.size();
69 }
70
71 prefix_ bool senf::log::Target::empty()
72     const
73 {
74     return rib_.empty();
75 }
76
77 ///////////////////////////////////////////////////////////////////////////
78 // senf::log::Target::RoutingEntry
79
80 prefix_ senf::log::Target::RoutingEntry::RoutingEntry(detail::StreamBase const * stream,
81                                                       detail::AreaBase const * area,
82                                                       unsigned level, action_t action)
83     : stream_(stream), area_(area), level_(level), action_(action) 
84 {}
85
86 prefix_ senf::log::Target::RoutingEntry::RoutingEntry()
87     : stream_(0), area_(0), level_(0), action_(ACCEPT) 
88 {}
89
90 prefix_ bool senf::log::Target::RoutingEntry::operator==(RoutingEntry const & other)
91
92     return 
93         stream_ == other.stream_ && 
94         area_ == other.area_ && 
95         level_ == other.level_ &&
96         action_ == other.action_; 
97 }
98
99 prefix_ std::string senf::log::Target::RoutingEntry::stream()
100     const
101 {
102     return stream_ ? stream_->v_name() : "";
103 }
104
105 prefix_ std::string senf::log::Target::RoutingEntry::area()
106     const
107 {
108     return area_ ? area_->v_name() : "";
109 }
110
111 prefix_ unsigned senf::log::Target::RoutingEntry::level()
112     const
113 {
114     return level_;
115 }
116
117 prefix_ senf::log::Target::action_t senf::log::Target::RoutingEntry::action()
118     const
119 {
120     return action_;
121 }
122
123 ///////////////////////////////////////////////////////////////////////////
124 // senf::log::detail::TargetRegistry
125
126 prefix_ void senf::log::detail::TargetRegistry::routed()
127 {
128     fallbackRouting_ = false;
129 }
130
131 prefix_ bool senf::log::detail::TargetRegistry::fallbackRouting()
132 {
133     return fallbackRouting_;
134 }
135
136 ////////////////////////////////////////
137 // private members
138
139 prefix_ senf::log::detail::TargetRegistry::TargetRegistry()
140     : fallbackRouting_(true)
141 {}
142
143 prefix_ void senf::log::detail::TargetRegistry::registerTarget(Target * target)
144 {
145     targets_.insert(target);
146 }
147
148 prefix_ void senf::log::detail::TargetRegistry::unregisterTarget(Target * target)
149 {
150     targets_.erase(target);
151 }
152
153 /////////////////////////////cci.e///////////////////////////////////////
154 #undef prefix_
155
156 \f
157 // Local Variables:
158 // mode: c++
159 // fill-column: 100
160 // comment-column: 40
161 // c-file-style: "senf"
162 // indent-tabs-mode: nil
163 // ispell-local-dictionary: "american"
164 // compile-command: "scons -u test"
165 // End: