X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.cci;h=da1ee4ed73f7008614f32b997387ef7ca0dd58f6;hb=82ad2ed94c12c3e53097fef92978de8c28239fab;hp=f58865e585a4ff82f19180218f88eb30d06c9ee7;hpb=f6f670f2dbc82b77db29df6cd452f2b351b9662a;p=senf.git diff --git a/Utils/Logger/Target.cci b/Utils/Logger/Target.cci index f58865e..da1ee4e 100644 --- a/Utils/Logger/Target.cci +++ b/Utils/Logger/Target.cci @@ -23,10 +23,9 @@ /** \file \brief Target inline non-template implementation */ -//#include "Target.ih" +#include "Target.ih" // Custom includes -#include #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// @@ -34,103 +33,104 @@ /////////////////////////////////////////////////////////////////////////// // senf::log::Target -prefix_ void senf::log::Target::route(std::string const & stream, action_t action) +prefix_ senf::log::Target::iterator senf::log::Target::begin() + const { - detail::StreamBase const * s (StreamRegistry::instance().lookup(stream)); - if (!s) - throw InvalidStreamException(); - route(s, 0, NONE::value, action); + return rib_.begin(); } -prefix_ void senf::log::Target::route(std::string const & stream, std::string const & area, - action_t action) +prefix_ senf::log::Target::iterator senf::log::Target::end() + const { - detail::StreamBase const * s (StreamRegistry::instance().lookup(stream)); - if (!s) - throw InvalidStreamException(); - detail::AreaBase const * a (AreaRegistry::instance().lookup(area)); - if (!a) - throw InvalidAreaException(); - route(s, a, NONE::value, action); + return rib_.end(); } -prefix_ void senf::log::Target::route(std::string const & stream, unsigned level, action_t action) -{ - detail::StreamBase const * s (StreamRegistry::instance().lookup(stream)); - if (!s) - throw InvalidStreamException(); - route(s, 0, level, action); +/////////////////////////////////////////////////////////////////////////// +// 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_ void senf::log::Target::route(std::string const & stream, std::string const & area, - unsigned level, action_t action) +prefix_ std::string senf::log::Target::RoutingEntry::stream() + const { - detail::StreamBase const * s (StreamRegistry::instance().lookup(stream)); - if (!s) - throw InvalidStreamException(); - detail::AreaBase const * a (AreaRegistry::instance().lookup(area)); - if (!a) - throw InvalidAreaException(); - route(s, a, level, action); + return stream_ ? stream_->v_name() : ""; } -//////////////////////////////////////// -// private members +prefix_ std::string senf::log::Target::RoutingEntry::area() + const +{ + return area_ ? area_->v_name() : ""; +} -prefix_ void senf::log::Target::route(detail::StreamBase const * stream, - detail::AreaBase const * area, unsigned level, - action_t action) +prefix_ unsigned senf::log::Target::RoutingEntry::level() + const { - rib_.push_back(RoutingEntry(stream, area, level, action)); - if (action == ACCEPT) - updateRoutingCache(stream, area); + return level_; } -prefix_ void senf::log::Target::unroute(detail::StreamBase const * stream, - detail::AreaBase const * area, unsigned level, - action_t action) +prefix_ senf::log::Target::action_t senf::log::Target::RoutingEntry::action() + const { - rib_.erase(std::remove(rib_.begin(), rib_.end(), RoutingEntry(stream, area, level, action)), - rib_.end()); - if (action == ACCEPT) - updateRoutingCache(stream, area); + return action_; } /////////////////////////////////////////////////////////////////////////// -// 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_) -{} +// senf::log::detail::TargetRegistry -prefix_ senf::log::Target::RoutingEntry::RoutingEntry() - : stream(0), area(0), level(0), action(ACCEPT) -{} +prefix_ void senf::log::detail::TargetRegistry::write(StreamBase const & stream, + AreaBase const & area, unsigned level, + std::string msg) +{ + area.write((*timeSource_)(), stream, level, msg); +} -prefix_ bool senf::log::Target::RoutingEntry::operator==(RoutingEntry const & other) -{ - return - stream == other.stream && - area == other.area && - level == other.level && - action == other.action; +prefix_ void senf::log::detail::TargetRegistry::timeSource(std::auto_ptr source) +{ + timeSource_.reset(source.release()); } -/////////////////////////////////////////////////////////////////////////// -// senf::log::TargetRegistry +//////////////////////////////////////// +// private members -prefix_ void senf::log::TargetRegistry::registerTarget(Target * target) +prefix_ senf::log::detail::TargetRegistry::TargetRegistry() + : timeSource_(new SystemTimeSource()) +{} + +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); } +/////////////////////////////////////////////////////////////////////////// +// namespace senf::log members + +prefix_ void senf::log::timeSource(std::auto_ptr source) +{ + detail::TargetRegistry::instance().timeSource(source); +} + /////////////////////////////cci.e/////////////////////////////////////// #undef prefix_