User Manual, Developers Guide and API Documentation

Master.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <WNS/logger/Master.hpp>
00029 #include <WNS/Assure.hpp>
00030 
00031 #include <iomanip>
00032 
00033 using namespace wns::logger;
00034 
00035 Master::Master() :
00036     doLogging(true),
00037     haveBacktrace(false),
00038     numberOfLinesForBacktrace(10000),
00039     backtrace()
00040 {
00041 }
00042 
00043 Master::Master(const pyconfig::View& pyco) :
00044     doLogging(true),
00045     haveBacktrace(false),
00046     numberOfLinesForBacktrace(10000),
00047     backtrace()
00048 {
00049     this->configure(pyco);
00050 }
00051 
00052 
00053 Master::~Master()
00054 {
00055     this->clearLoggerChain();
00056 }
00057 
00058 void
00059 Master::configure(const pyconfig::View& pyco)
00060 {
00061     this->doLogging = pyco.get<bool>("enabled");
00062     this->haveBacktrace = pyco.get<bool>("backtrace.enabled");
00063     this->numberOfLinesForBacktrace = pyco.get<size_t>("backtrace.length");
00064 
00065     this->clearLoggerChain();
00066 
00067     for (int ii = 0; ii < pyco.len("loggerChain"); ++ii)
00068     {
00069         pyconfig::View loggerView = pyco.getView("loggerChain", ii);
00070         std::string formatStrategy = loggerView.get<std::string>("format.__plugin__");
00071         FormatStrategyCreator* fsc = FormatStrategyFactory::creator(formatStrategy);
00072 
00073         std::string outputStrategy = loggerView.get<std::string>("output.__plugin__");
00074         OutputStrategyCreator* osc = OutputStrategyFactory::creator(outputStrategy);
00075 
00076         loggerChain[osc->create()] = fsc->create(loggerView.getView("format"));
00077     }
00078 }
00079 
00080 void
00081 Master::registerLogger(const std::string& aModuleRef,
00082                const std::string& aLocationRef)
00083 {
00084     for (LoggerChain::iterator itr = loggerChain.begin();
00085          itr != loggerChain.end();
00086          ++itr)
00087     {
00088         *(itr->first) << itr->second->formatRegistration(aModuleRef, aLocationRef);
00089     }
00090 }
00091 
00092 void Master::saveForBacktrace(const RawMessage& m)
00093 {
00094     backtrace.push_back(m);
00095     if (backtrace.size() > numberOfLinesForBacktrace)
00096     {
00097         backtrace.pop_front();
00098     }
00099 }
00100 
00101 void Master::outputBacktrace() const
00102 {
00103         for(std::deque<RawMessage>::const_iterator itr = backtrace.begin();
00104         itr != backtrace.end();
00105         ++itr)
00106     {
00107                 outputMessage(*itr);
00108         }
00109 }
00110 
00111 
00112 bool Master::isEnabled() const
00113 {
00114     return this->doLogging;
00115 }
00116 
00117 
00118 void Master::outputMessage(const RawMessage& m) const
00119 {
00120     for(LoggerChain::const_iterator itr = loggerChain.begin();
00121         itr != loggerChain.end();
00122         ++itr)
00123     {
00124         *(itr->first) << itr->second->formatMessage(m);
00125     }
00126 }
00127 
00128 void Master::clearLoggerChain()
00129 {
00130     while(!loggerChain.empty())
00131     {
00132         LoggerChain::iterator i = loggerChain.begin();
00133         delete i->first;
00134         delete i->second;
00135         loggerChain.erase(i);
00136     }
00137 }
00138 
00139 

Generated on Fri May 25 03:31:47 2012 for openWNS by  doxygen 1.5.5