Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Target.hh

Go to the documentation of this file.
00001 // $Id: Target.hh 1757 2011-01-06 16:52:09Z tho $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Utils_Logger_Target_
00027 #define HH_SENF_Utils_Logger_Target_ 1
00028 
00029 // Custom includes
00030 #include <vector>
00031 #include <boost/utility.hpp>
00032 #include <senf/Utils/Exception.hh>
00033 #include <senf/Utils/Console/LazyDirectory.hh>
00034 #include "TimeSource.hh"
00035 #include "Levels.hh"
00036 
00037 //#include "Target.mpp"
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 
00050 namespace senf {
00051 namespace log {
00052 
00053     namespace detail { class TargetRegistry; }
00054     namespace detail { class AreaBase; }
00055     namespace detail { struct LogParameters; }
00056     namespace detail { struct StreamBase; }
00057 
00142     class Target : private boost::noncopyable
00143     {
00144     public:
00145         //-////////////////////////////////////////////////////////////////////////
00146         // Types
00147 
00153         enum action_t {
00154             ACCEPT 
00155           , REJECT 
00156         };
00157 
00165         struct RoutingEntry
00166         {
00167             std::string stream() const; 
00168             std::string area() const;   
00169             unsigned level() const;     
00170             action_t action() const;    
00171 
00172 #           ifdef DOXYGEN
00173         private:
00174 #           endif
00175 
00176             RoutingEntry();
00177             bool operator==(RoutingEntry const & other) const;
00178 
00179         private:
00180             RoutingEntry(detail::StreamBase const * stream, detail::AreaBase const * area,
00181                          unsigned level, action_t action);
00182 
00183             detail::StreamBase const * stream_;
00184             detail::AreaBase const * area_;
00185             unsigned level_;
00186             action_t action_;
00187 
00188             friend class Target;
00189         };
00190 
00191     private:
00192         typedef std::vector<RoutingEntry> RIB;
00193 
00194     public:
00195         typedef RIB::const_iterator iterator; 
00196         typedef RIB::size_type size_type;
00197 
00198         //-////////////////////////////////////////////////////////////////////////
00200         //\{
00201 
00202         explicit Target(std::string const & name);
00203         virtual ~Target();
00204 
00205         //\}
00206         //-////////////////////////////////////////////////////////////////////////
00208         //\{
00209 
00210 #       ifdef DOXYGEN
00211 
00212         template <class Stream, class Area, class Level> void route(
00213             action_t action = ACCEPT, int index = -1); 
00214 
00240 #       endif
00241 
00242         void route(std::string const & stream, std::string const & area = "",
00243                    unsigned level = NONE::value, action_t action = ACCEPT, int index = -1);
00245 
00267 #       ifdef DOXYGEN
00268 
00269         template <class Stream, class Area, class Level>
00270         void unroute(action_t action = ACCEPT);
00272 
00287 #       endif
00288 
00289         void unroute(std::string const & stream, std::string const & area = "",
00290                      unsigned level = NONE::value, action_t action = ACCEPT);
00292 
00307         void unroute(int index=-1);     
00308 
00315 #       ifndef DOXYGEN
00316 
00317         void route(action_t action = ACCEPT, int index = -1);
00318         template <class A1>
00319         void route(action_t action = ACCEPT, int index = -1);
00320         template <class A1, class A2>
00321         void route(action_t action = ACCEPT, int index = -1);
00322         template <class A1, class A2, class A3>
00323         void route(action_t action = ACCEPT, int index = -1);
00324 
00325         void unroute(action_t action = ACCEPT);
00326         template <class A1>
00327         void unroute(action_t action = ACCEPT);
00328         template <class A1, class A2>
00329         void unroute(action_t action = ACCEPT);
00330         template <class A1, class A2, class A3>
00331         void unroute(action_t action = ACCEPT);
00332 
00333 #       endif
00334 
00335         //\}
00336 
00338         struct InvalidStreamException : public senf::Exception
00339         { InvalidStreamException()
00340               : senf::Exception("senf::log::Target::InvalidStreamException") {} };
00341 
00343         struct InvalidAreaException : public senf::Exception
00344         { InvalidAreaException()
00345               : senf::Exception("senf::log::Target::InvalidAreaException") {} };
00346 
00347         iterator begin() const;         
00348         iterator end() const;           
00349 
00350         RoutingEntry const & operator[](size_type i) const; 
00351 
00352         size_type size() const;         
00353         bool empty() const;             
00354 
00355         void flush();                   
00356 
00357         senf::console::ScopedDirectory<> & consoleDir(); 
00358 
00359     private:
00360         void route(detail::StreamBase const * stream, detail::AreaBase const * area,
00361                    unsigned level, action_t action, int index);
00362         void unroute(detail::StreamBase const * stream, detail::AreaBase const * area,
00363                      unsigned level, action_t action);
00364 
00365         void updateRoutingCache(detail::StreamBase const * stream, detail::AreaBase const * area);
00366 
00367         void write(time_type timestamp, detail::StreamBase const & stream,
00368                    detail::AreaBase const & area, unsigned level, std::string const & message);
00369 
00370         void consoleList(std::ostream & os);
00371         void consoleRoute(int index, detail::LogParameters const & pm, action_t action);
00372         void consoleUnroute(detail::LogParameters const & pm, action_t action);
00373 
00374 #   ifdef DOXYGEN
00375     protected:
00376 #   endif
00377 
00378         virtual void v_write(time_type timestamp, std::string const & stream,
00379                              std::string const & area, unsigned level,
00380                              std::string const & message) = 0;
00382 
00399 #   ifdef DOXYGEN
00400     private:
00401 #   endif
00402 
00403         RIB rib_;
00404 
00405         console::LazyDirectory consoleDir_;
00406 
00407         friend class detail::AreaBase;
00408         friend class detail::TargetRegistry;
00409     };
00410 
00414     std::ostream & operator<<(std::ostream & os, Target::action_t const & action);
00415 
00416 }}
00417 
00418 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00419 #include "Target.cci"
00420 //#include "Target.ct"
00421 #include "Target.cti"
00422 #endif
00423 
00424 
00425 // Local Variables:
00426 // mode: c++
00427 // fill-column: 100
00428 // comment-column: 40
00429 // c-file-style: "senf"
00430 // indent-tabs-mode: nil
00431 // ispell-local-dictionary: "american"
00432 // compile-command: "scons -u test"
00433 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research