da1ee4ed73f7008614f32b997387ef7ca0dd58f6
[senf.git] / Utils / Logger / Target.cci
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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
30 #define prefix_ inline
31 ///////////////////////////////cci.p///////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::log::Target
35
36 prefix_ senf::log::Target::iterator senf::log::Target::begin()
37     const
38 {
39     return rib_.begin();
40 }
41
42 prefix_ senf::log::Target::iterator senf::log::Target::end()
43     const
44 {
45     return rib_.end();
46 }
47
48 ///////////////////////////////////////////////////////////////////////////
49 // senf::log::Target::RoutingEntry
50
51 prefix_ senf::log::Target::RoutingEntry::RoutingEntry(detail::StreamBase const * stream,
52                                                       detail::AreaBase const * area,
53                                                       unsigned level, action_t action)
54     : stream_(stream), area_(area), level_(level), action_(action) 
55 {}
56
57 prefix_ senf::log::Target::RoutingEntry::RoutingEntry()
58     : stream_(0), area_(0), level_(0), action_(ACCEPT) 
59 {}
60
61 prefix_ bool senf::log::Target::RoutingEntry::operator==(RoutingEntry const & other)
62
63     return 
64         stream_ == other.stream_ && 
65         area_ == other.area_ && 
66         level_ == other.level_ &&
67         action_ == other.action_; 
68 }
69
70 prefix_ std::string senf::log::Target::RoutingEntry::stream()
71     const
72 {
73     return stream_ ? stream_->v_name() : "";
74 }
75
76 prefix_ std::string senf::log::Target::RoutingEntry::area()
77     const
78 {
79     return area_ ? area_->v_name() : "";
80 }
81
82 prefix_ unsigned senf::log::Target::RoutingEntry::level()
83     const
84 {
85     return level_;
86 }
87
88 prefix_ senf::log::Target::action_t senf::log::Target::RoutingEntry::action()
89     const
90 {
91     return action_;
92 }
93
94 ///////////////////////////////////////////////////////////////////////////
95 // senf::log::detail::TargetRegistry
96
97 prefix_ void senf::log::detail::TargetRegistry::write(StreamBase const & stream,
98                                                       AreaBase const & area, unsigned level,
99                                                       std::string msg)
100 {
101     area.write((*timeSource_)(), stream, level, msg);
102 }
103
104 prefix_ void senf::log::detail::TargetRegistry::timeSource(std::auto_ptr<TimeSource> source)
105 {
106     timeSource_.reset(source.release());
107 }
108
109 ////////////////////////////////////////
110 // private members
111
112 prefix_ senf::log::detail::TargetRegistry::TargetRegistry()
113     : timeSource_(new SystemTimeSource())
114 {}
115
116 prefix_ void senf::log::detail::TargetRegistry::registerTarget(Target * target)
117 {
118     targets_.insert(target);
119 }
120
121 prefix_ void senf::log::detail::TargetRegistry::unregisterTarget(Target * target)
122 {
123     targets_.erase(target);
124 }
125
126 ///////////////////////////////////////////////////////////////////////////
127 // namespace senf::log members
128
129 prefix_ void senf::log::timeSource(std::auto_ptr<TimeSource> source)
130 {
131     detail::TargetRegistry::instance().timeSource(source);
132 }
133
134 /////////////////////////////cci.e///////////////////////////////////////
135 #undef prefix_
136
137 \f
138 // Local Variables:
139 // mode: c++
140 // fill-column: 100
141 // comment-column: 40
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // End: