// $Id$
//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
\brief Target non-inline non-template implementation */
#include "Target.hh"
-//#include "Target.ih"
+#include "Target.ih"
// Custom includes
#include <algorithm>
+#include "ConsoleTarget.hh"
//#include "Target.mpp"
#define prefix_
prefix_ senf::log::Target::Target()
{
- TargetRegistry::instance().registerTarget(this);
+ detail::TargetRegistry::instance().registerTarget(this);
}
prefix_ senf::log::Target::~Target()
{
while( ! rib_.empty()) {
- // This is terribly slow but simplifies the area cache handling and removing a target should
- // be quite seldom
+ // This is slow but simplifies the area cache handling and removing a target should be
+ // relatively seldom
RIB::reverse_iterator i (rib_.rbegin());
unroute(i->stream_, i->area_, i->level_, i->action_);
}
- TargetRegistry::instance().unregisterTarget(this);
+ detail::TargetRegistry::instance().unregisterTarget(this);
}
prefix_ void senf::log::Target::route(std::string const & stream, std::string const & area,
i = rib_.begin();
else {
i = rib_.end();
- std::advance(i, -index);
+ std::advance(i, index);
}
} else {
if (RIB::size_type(index+1) >= rib_.size()) {
std::advance(i, index);
}
}
+ if (i == rib_.end())
+ return;
RoutingEntry entry (*i);
rib_.erase(i);
if (entry.action_ == ACCEPT)
rib_.insert(i, RoutingEntry(stream, area, level, action));
if (action == ACCEPT)
updateRoutingCache(stream, area);
+ // This disables the initial fallback routing
+ detail::TargetRegistry::instance().routed();
}
prefix_ void senf::log::Target::unroute(detail::StreamBase const * stream,
- detail::AreaBase const * area, unsigned level,
+ detail::AreaBase const * area, unsigned level,
action_t action)
{
- RIB::iterator i = std::find(rib_.begin(), rib_.end(),
+ RIB::iterator i = std::find(rib_.begin(), rib_.end(),
RoutingEntry(stream, area, level, action));
if (i != rib_.end())
unroute(std::distance(rib_.begin(), i));
if ( (! i->stream_ || i->stream_ == stream) &&
(! i->area_ || i->area_ == area) &&
i->action_ == ACCEPT ) {
- unsigned l (i->level_ == NONE::value ? i->stream_->defaultRuntimeLimit() : i->level_);
+ unsigned l (i->level_ == NONE::value ? stream->defaultRuntimeLimit() : i->level_);
if (l < limit)
limit = l;
}
area->updateRoutingCache(*this, *stream, limit);
}
-prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp,
+prefix_ void senf::log::Target::write(time_type timestamp,
detail::StreamBase const & stream,
detail::AreaBase const & area, unsigned level,
std::string const & message)
for (; i != i_end; ++i)
if ( (! i->stream_ || i->stream_ == &stream) &&
(! i->area_ || i->area_ == &area) &&
- (i->level_ == NONE::value ? i->stream_->defaultRuntimeLimit() : i->level_) <= level ) {
+ (i->level_ == NONE::value ? stream.defaultRuntimeLimit() : i->level_) <= level ) {
if (i->action_ == ACCEPT)
v_write(timestamp, stream.v_name(), area.v_name(), level, message);
return;
}
///////////////////////////////////////////////////////////////////////////
-// senf::log::TargetRegistry
+// senf::log::detail::TargetRegistry
+
+prefix_ void senf::log::detail::TargetRegistry::write(StreamBase const & stream,
+ AreaBase const & area, unsigned level,
+ std::string const & msg)
+{
+ if (fallbackRouting_) {
+ if (level >= stream.defaultRuntimeLimit())
+ static_cast<Target &>(ConsoleTarget::instance()).v_write(
+ TimeSource::now(), stream.v_name(), area.v_name(), level, msg );
+ }
+ else
+ area.write( TimeSource::now(), stream, level, msg );
+}
+///////////////////////////////////////////////////////////////////////////
+// namespace members
-prefix_ void senf::log::TargetRegistry::write(detail::StreamBase const & stream,
- detail::AreaBase const & area, unsigned level,
- std::string msg)
+prefix_ std::ostream & senf::log::operator<<(std::ostream & os, senf::log::Target::action_t const & action)
{
- boost::posix_time::ptime timestamp (boost::posix_time::microsec_clock::universal_time());
- area.write(timestamp, stream, level, msg);
+ if( action == Target::ACCEPT) os << "ACCEPT";
+ else if( action == Target::REJECT) os << "REJECT";
+ else os << "unknown action";
+ return os;
}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "Target.mpp"
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100