// $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
/** \file
\brief Target inline non-template implementation */
-//#include "Target.ih"
+#include "Target.ih"
// Custom includes
-#include <algorithm>
+#include "AreaRegistry.hh"
#define prefix_ inline
///////////////////////////////cci.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// senf::log::Target
-prefix_ void senf::log::Target::route(detail::StreamBase const * stream,
- detail::AreaBase const * area, unsigned level)
+prefix_ void senf::log::Target::route(action_t action, int index)
{
- rib_.push_back(RoutingEntry(stream, area, level));
-
- // Update the area/stream routing cache
- if (area)
- updateAreaCache(*area, stream, level);
- else {
- AreaRegistry::Registry::iterator i (AreaRegistry::instance().registry_.begin());
- AreaRegistry::Registry::iterator const i_end (AreaRegistry::instance().registry_.end());
- for (; i != i_end; ++i)
- updateAreaCache(*(i->second), stream, level);
- }
-
+ route(0, 0, NONE::value, action, index);
}
-prefix_ void
-senf::log::Target::updateAreaCache(detail::AreaBase const & area,
- detail::StreamBase const * stream, unsigned level)
+prefix_ void senf::log::Target::unroute(action_t action)
{
- if (stream) {
- if (level < area.streamLimit(*stream))
- area.setStreamLimit(*stream, level);
- } else {
- StreamRegistry::Registry::iterator i (StreamRegistry::instance().registry_.begin());
- StreamRegistry::Registry::iterator const i_end (StreamRegistry::instance().registry_.end());
- for(; i != i_end; ++i)
- if (level < area.streamLimit(*(i->second)))
- area.setStreamLimit(*(i->second),level);
- }
+ unroute(0, 0, NONE::value, action);
}
-prefix_ void senf::log::Target::unroute(detail::StreamBase const * stream,
- detail::AreaBase const * area, unsigned level)
+prefix_ senf::log::Target::iterator senf::log::Target::begin()
+ const
{
- rib_.erase(std::remove(rib_.begin(), rib_.end(), RoutingEntry(stream, area, level)),
- rib_.end());
+ return rib_.begin();
+}
+
+prefix_ senf::log::Target::iterator senf::log::Target::end()
+ const
+{
+ return rib_.end();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::log::Target::RoutingEntry
+
+prefix_ senf::log::Target::RoutingEntry::RoutingEntry(detail::StreamBase const * stream,
+ detail::AreaBase const * area,
+ unsigned level, action_t action)
+ : stream_(stream), area_(area), level_(level), action_(action)
+{}
+
+prefix_ senf::log::Target::RoutingEntry::RoutingEntry()
+ : stream_(0), area_(0), level_(0), action_(ACCEPT)
+{}
+
+prefix_ bool senf::log::Target::RoutingEntry::operator==(RoutingEntry const & other)
+{
+ return
+ stream_ == other.stream_ &&
+ area_ == other.area_ &&
+ level_ == other.level_ &&
+ action_ == other.action_;
+}
+
+prefix_ std::string senf::log::Target::RoutingEntry::stream()
+ const
+{
+ return stream_ ? stream_->v_name() : "";
+}
+
+prefix_ std::string senf::log::Target::RoutingEntry::area()
+ const
+{
+ return area_ ? area_->v_name() : "";
+}
- ///\fixme Update area/stream routing cache
- // Not doing anything here does not produce incorrect behavior, since removing a route
- // can never lower the logging limit. Not updating the cache just reduces the performance.
+prefix_ unsigned senf::log::Target::RoutingEntry::level()
+ const
+{
+ return level_;
+}
+
+prefix_ senf::log::Target::action_t senf::log::Target::RoutingEntry::action()
+ const
+{
+ return action_;
}
///////////////////////////////////////////////////////////////////////////
-// senf::log::TargetRegistry
+// senf::log::detail::TargetRegistry
+
+prefix_ void senf::log::detail::TargetRegistry::routed()
+{
+ fallbackRouting_ = false;
+}
+
+prefix_ bool senf::log::detail::TargetRegistry::fallbackRouting()
+{
+ return fallbackRouting_;
+}
+
+////////////////////////////////////////
+// private members
+
+prefix_ senf::log::detail::TargetRegistry::TargetRegistry()
+ : fallbackRouting_(true)
+{}
-prefix_ void senf::log::TargetRegistry::registerTarget(Target * target)
+prefix_ void senf::log::detail::TargetRegistry::registerTarget(Target * target)
{
targets_.insert(target);
}
-prefix_ void senf::log::TargetRegistry::unregisterTarget(Target * target)
+prefix_ void senf::log::detail::TargetRegistry::unregisterTarget(Target * target)
{
targets_.erase(target);
}