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
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

StatisticsTargets.cc

Go to the documentation of this file.
00001 // $Id: StatisticsTargets.cc 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2009
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 #include "StatisticsTargets.hh"
00027 #include "StatisticsTargets.ih"
00028 
00029 // Custom includes
00030 #include <boost/bind.hpp>
00031 #include <senf/Utils/Console/ParsedCommand.hh>
00032 #include "Statistics.hh"
00033 
00034 //#include "StatisticsTargets.mpp"
00035 #define prefix_
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 // senf::detail::StatisticsLoggerRegistry
00040 
00041 prefix_ void
00042 senf::detail::StatisticsLoggerRegistry::apply(StatisticsBase & stats,
00043                                               unsigned rank, console::DirectoryNode & dir)
00044 {
00045     Adders::const_iterator i (adders_.begin());
00046     Adders::const_iterator const i_end (adders_.end());
00047     for (; i != i_end; ++i)
00048         (*i)(stats, rank, dir);
00049 }
00050 
00051 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00052 
00053 namespace {
00054 
00055     struct RegisterStatisticsLogger
00056     {
00057         RegisterStatisticsLogger();
00058 
00059         static void adder(senf::StatisticsBase & stats,
00060                           unsigned rank, senf::console::DirectoryNode & dir);
00061 
00062         static void consoleCreate(senf::StatisticsBase & stats,
00063                                   unsigned rank, std::string const & prefix);
00064     };
00065 
00066     RegisterStatisticsLogger registerStatisticsLogger;
00067 }
00068 
00069 prefix_ RegisterStatisticsLogger::RegisterStatisticsLogger()
00070 {
00071     senf::detail::StatisticsLoggerRegistry::instance().add(&adder);
00072 }
00073 
00074 prefix_ void RegisterStatisticsLogger::adder(senf::StatisticsBase & stats,
00075                                              unsigned rank, senf::console::DirectoryNode & dir)
00076 {
00077     namespace kw = senf::console::kw;
00078     namespace fty = senf::console::factory;
00079     dir.add("logger", fty::Command<void (std::string const &)>(
00080                 boost::bind(&consoleCreate, boost::ref(stats), rank, _1))
00081             .arg("prefix","Optional prefix string to add to each log message",
00082                  kw::default_value = "")
00083             .doc("Send log messages to statistics log stream") );
00084 }
00085 
00086 prefix_ void RegisterStatisticsLogger::consoleCreate(senf::StatisticsBase & stats,
00087                                                      unsigned rank, std::string const & prefix)
00088 {
00089     stats.output(rank).connect(senf::StatisticsLogger(prefix),
00090                                "senf::StatisticsLogger(\"" + prefix + "\")");
00091 }
00092 
00093 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00094 #undef prefix_
00095 //#include "StatisticsTargets.mpp"
00096 
00097 
00098 // Local Variables:
00099 // mode: c++
00100 // fill-column: 100
00101 // comment-column: 40
00102 // c-file-style: "senf"
00103 // indent-tabs-mode: nil
00104 // ispell-local-dictionary: "american"
00105 // compile-command: "scons -u test"
00106 // End:

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