User Manual, Developers Guide and API Documentation

Master.hpp

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 #ifndef WNS_LOGGER_MASTER_HPP
00029 #define WNS_LOGGER_MASTER_HPP
00030 
00031 #include <WNS/pyconfig/View.hpp>
00032 #include <WNS/PyConfigViewCreator.hpp>
00033 #include <WNS/logger/OutputStrategy.hpp>
00034 #include <WNS/logger/FormatStrategy.hpp>
00035 
00036 #include <WNS/simulator/ISimulator.hpp>
00037 #include <WNS/events/scheduler/Interface.hpp>
00038 
00039 #include <string>
00040 #include <map>
00041 #include <deque>
00042 
00043 namespace wns { namespace logger {
00055     class Master
00056     {
00057         typedef std::map<OutputStrategy*, FormatStrategy*> LoggerChain;
00058     public:
00066         explicit
00067         Master();
00068 
00079         explicit
00080         Master(const pyconfig::View& pyco);
00081 
00085         virtual
00086         ~Master();
00087 
00088         void
00089         configure(const pyconfig::View& pyco);
00090 
00095         void
00096         registerLogger(const std::string& aModuleRef,
00097                    const std::string& aLocationRef);
00098 
00105         void
00106         write(const std::string& aModuleRef,
00107               const std::string& aLocationRef,
00108               const std::string& aMsgRef)
00109         {
00110             if (doLogging)
00111             {
00112                 // If we have loggin enabled we have to process
00113                 // the message
00114                 RawMessage m;
00119                 m.time = wns::simulator::getEventScheduler()->getTime();
00120                 m.module = aModuleRef;
00121                 m.location = aLocationRef;
00122                 m.message = aMsgRef;
00123 
00124                 if (haveBacktrace)
00125                 {
00126                     // if we have logging enabled, and the
00127                     // backtracing is enabled we will not
00128                     // write the message, but rather keep it
00129                     // in the backtrace buffer
00130                     saveForBacktrace(m);
00131                 }
00132                 else
00133                 {
00134                     // if we have logging enabled and
00135                     // backtrace disable we are going to
00136                     // write the message
00137                     outputMessage(m);
00138                 }
00139             }
00140             // If we have don't have debugging and backtrace
00141             // enabled we will do nothing
00142         };
00143 
00147         void outputBacktrace() const;
00148 
00149         bool isEnabled() const;
00150 
00151     private:
00152         bool doLogging;
00153         bool haveBacktrace;
00154         size_t numberOfLinesForBacktrace;
00155         std::deque<RawMessage> backtrace;
00156 
00157         LoggerChain loggerChain;
00158 
00159         void saveForBacktrace(const RawMessage& m);
00160         void outputMessage(const RawMessage& m) const;
00161         void clearLoggerChain();
00162     }; // Master
00163 
00164 } // logger
00165 } // wns
00166 #endif // not defined WNS_LOGGER_MASTER_HPP
00167 
00168 

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