4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Target non-inline non-template implementation */
27 //#include "Target.ih"
32 //#include "Target.mpp"
34 ///////////////////////////////cc.p////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////
39 prefix_ senf::log::Target::Target()
41 TargetRegistry::instance().registerTarget(this);
44 prefix_ senf::log::Target::~Target()
46 while( ! rib_.empty()) {
47 // This is terribly slow but simplifies the area cache handling and removing a target should
49 RIB::reverse_iterator i (rib_.rbegin());
50 unroute(i->stream_, i->area_, i->level_, i->action_);
52 TargetRegistry::instance().unregisterTarget(this);
55 prefix_ void senf::log::Target::route(std::string const & stream, std::string const & area,
56 unsigned level, action_t action, int index)
58 detail::StreamBase const * s (StreamRegistry::instance().lookup(stream));
60 throw InvalidStreamException();
61 detail::AreaBase const * a (0);
63 a = AreaRegistry::instance().lookup(area);
65 throw InvalidAreaException();
67 route(s, a, level, action, index);
70 prefix_ void senf::log::Target::unroute(std::string const & stream, std::string const & area,
71 unsigned level, action_t action)
73 detail::StreamBase const * s (StreamRegistry::instance().lookup(stream));
75 throw InvalidStreamException();
76 detail::AreaBase const * a (0);
78 a = AreaRegistry::instance().lookup(area);
80 throw InvalidAreaException();
82 unroute(s, a, level, action);
85 prefix_ void senf::log::Target::unroute(int index)
89 if (RIB::size_type(-index) >= rib_.size())
93 std::advance(i, -index);
96 if (RIB::size_type(index+1) >= rib_.size()) {
101 std::advance(i, index);
104 RoutingEntry entry (*i);
106 if (entry.action_ == ACCEPT)
107 updateRoutingCache(entry.stream_, entry.area_);
110 ////////////////////////////////////////
113 prefix_ void senf::log::Target::route(detail::StreamBase const * stream,
114 detail::AreaBase const * area, unsigned level,
115 action_t action, int index)
119 if (RIB::size_type(-index-1) >= rib_.size())
123 std::advance(i, index + 1 );
126 if (RIB::size_type(index) >= rib_.size())
130 std::advance(i, index);
133 rib_.insert(i, RoutingEntry(stream, area, level, action));
134 if (action == ACCEPT)
135 updateRoutingCache(stream, area);
138 prefix_ void senf::log::Target::unroute(detail::StreamBase const * stream,
139 detail::AreaBase const * area, unsigned level,
142 RIB::iterator i = std::find(rib_.begin(), rib_.end(),
143 RoutingEntry(stream, area, level, action));
145 unroute(std::distance(rib_.begin(), i));
148 prefix_ void senf::log::Target::updateRoutingCache(detail::StreamBase const * stream,
149 detail::AreaBase const * area)
152 StreamRegistry::Registry::iterator i (StreamRegistry::instance().registry_.begin());
153 StreamRegistry::Registry::iterator const i_end (StreamRegistry::instance().registry_.end());
154 for (; i != i_end ; ++i)
155 updateRoutingCache(i->second, area);
159 AreaRegistry::Registry::iterator i (AreaRegistry::instance().registry_.begin());
160 AreaRegistry::Registry::iterator const i_end (AreaRegistry::instance().registry_.end());
161 for (; i != i_end ; ++i)
162 updateRoutingCache(stream, i->second);
165 unsigned limit (DISABLED::value);
166 RIB::iterator i (rib_.begin());
167 RIB::iterator const i_end (rib_.end());
168 for(; i != i_end; ++i)
169 if ( (! i->stream_ || i->stream_ == stream) &&
170 (! i->area_ || i->area_ == area) &&
171 i->action_ == ACCEPT ) {
172 unsigned l (i->level_ == NONE::value ? i->stream_->defaultRuntimeLimit() : i->level_);
176 if (limit == DISABLED::value)
177 area->removeRoutingCache(*this, *stream);
179 area->updateRoutingCache(*this, *stream, limit);
182 prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp,
183 detail::StreamBase const & stream,
184 detail::AreaBase const & area, unsigned level,
185 std::string const & message)
187 RIB::iterator i (rib_.begin());
188 RIB::iterator const i_end (rib_.end());
189 for (; i != i_end; ++i)
190 if ( (! i->stream_ || i->stream_ == &stream) &&
191 (! i->area_ || i->area_ == &area) &&
192 (i->level_ == NONE::value ? i->stream_->defaultRuntimeLimit() : i->level_) <= level ) {
193 if (i->action_ == ACCEPT)
194 v_write(timestamp, stream.v_name(), area.v_name(), level, message);
199 ///////////////////////////////////////////////////////////////////////////
200 // senf::log::TargetRegistry
202 prefix_ void senf::log::TargetRegistry::write(detail::StreamBase const & stream,
203 detail::AreaBase const & area, unsigned level,
206 boost::posix_time::ptime timestamp (boost::posix_time::microsec_clock::universal_time());
207 area.write(timestamp, stream, level, msg);
210 ///////////////////////////////cc.e////////////////////////////////////////
212 //#include "Target.mpp"
218 // comment-column: 40
219 // c-file-style: "senf"
220 // indent-tabs-mode: nil
221 // ispell-local-dictionary: "american"
222 // compile-command: "scons -u test"