![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2009 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * email: info@openwns.org 00009 * www: http://www.openwns.org 00010 * _____________________________________________________________________________ 00011 * 00012 * openWNS is free software; you can redistribute it and/or modify it under the 00013 * terms of the GNU Lesser General Public License version 2 as published by the 00014 * Free Software Foundation; 00015 * 00016 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00017 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00018 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00019 * details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 ******************************************************************************/ 00025 00026 #ifndef LOGGER_HPP 00027 #define LOGGER_HPP 00028 00029 #include <WNS/ldk/ldk.hpp> 00030 #include <WNS/logger/Logger.hpp> 00031 #include <WNS/module/Base.hpp> 00032 #include <WNS/logger/Master.hpp> 00033 #include <WNS/Singleton.hpp> 00034 00035 namespace wimac { 00036 00037 const std::string demangledTypename( const std::string& nativeName); 00038 00052 class Logger : 00053 public wns::logger::Logger 00054 { 00055 public: 00056 explicit 00057 Logger() : 00058 wns::logger::Logger(), 00059 priority_(0) 00060 {} 00061 00062 Logger(const std::string& loggerName): 00063 wns::logger::Logger("WiMAC", 00064 loggerName, 00065 wns::simulator::getMasterLogger()), 00066 priority_(0) 00067 {} 00068 00069 Logger( int priority, const std::type_info& type ): 00070 wns::logger::Logger( "WiMAC", demangledTypename(type.name()), 00071 wns::simulator::getMasterLogger()), 00072 priority_(priority) 00073 {} 00074 00075 00076 Logger* prepareForMessage(int priority, const std::type_info& type) 00077 { 00078 priority_ = priority; 00079 lName = demangledTypename(type.name()); 00080 return this; 00081 } 00082 00083 virtual ~Logger() 00084 {} 00085 00086 #ifndef WNS_NO_LOGGING 00087 00088 template<class T1> 00089 void send( T1 t1 ) 00090 { 00091 wns::logger::Message m(t1, priority_); 00092 wns::logger::Logger::send(m); 00093 } 00094 00095 template<class T1, class T2> 00096 void send( T1 t1, T2 t2 ) 00097 { 00098 wns::logger::Message m(t1, priority_); 00099 m << t2; 00100 wns::logger::Logger::send(m); 00101 } 00102 00103 template<class T1, class T2, class T3> 00104 void send( T1 t1, T2 t2, T3 t3 ) 00105 { 00106 wns::logger::Message m(t1, priority_); 00107 m << t2 << t3; 00108 wns::logger::Logger::send(m); 00109 } 00110 00111 template<class T1, class T2, class T3, class T4> 00112 void send( T1 t1, T2 t2, T3 t3, T4 t4 ) 00113 { 00114 wns::logger::Message m(t1, priority_); 00115 m << t2 << t3 << t4; 00116 wns::logger::Logger::send(m); 00117 } 00118 00119 template<class T1, class T2, class T3, class T4, class T5> 00120 void send(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) 00121 { 00122 wns::logger::Message m("", priority_); 00123 m << t1 << t2 << t3 << t4 << t5; 00124 wns::logger::Logger::send(m); 00125 } 00126 00127 template<class T1, class T2, class T3, class T4, class T5, class T6> 00128 void send(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) 00129 { 00130 wns::logger::Message m("", priority_); 00131 m << t1 << t2 << t3 << t4 << t5 << t6; 00132 wns::logger::Logger::send(m); 00133 } 00134 00135 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7> 00136 void send(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) 00137 { 00138 wns::logger::Message m("", priority_); 00139 m << t1 << t2 << t3 << t4 << t5 << t6 << t7; 00140 wns::logger::Logger::send(m); 00141 } 00142 00143 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> 00144 void send(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) 00145 { 00146 wns::logger::Message m("", priority_); 00147 m << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8; 00148 wns::logger::Logger::send(m); 00149 } 00150 00151 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> 00152 void send(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) 00153 { 00154 wns::logger::Message m("", priority_); 00155 m << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8 << t9; 00156 wns::logger::Logger::send(m); 00157 } 00158 #else 00159 00160 template<class T1> 00161 static void DoNothing( T1 ){} 00162 00163 template<class T1, class T2> 00164 static void DoNothing( T1, T2 ) {} 00165 00166 template<class T1, class T2, class T3> 00167 static void DoNothing( T1, T2, T3 ) {} 00168 00169 template<class T1, class T2, class T3, class T4> 00170 static void DoNothing( T1, T2, T3, T4 ) {} 00171 00172 template<class T1, class T2, class T3, class T4, class T5> 00173 static void DoNothing(T1, T2, T3, T4, T5 ) {} 00174 00175 template<class T1, class T2, class T3, class T4, class T5, class T6> 00176 static void DoNothing(T1, T2, T3, T4, T5, T6 ) {} 00177 00178 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7> 00179 static void DoNothing(T1, T2, T3, T4, T5, T6, T7 ) {} 00180 00181 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8> 00182 static void DoNothing(T1, T2, T3, T4, T5, T6, T7, T8 ) {} 00183 00184 template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9> 00185 static void DoNothing(T1, T2, T3, T4, T5, T6, T7, T8, T9 ) {} 00186 00187 #endif 00188 00189 private: 00190 int priority_; 00191 }; 00192 00193 typedef wns::SingletonHolder<Logger> WiMACLogger; 00194 00195 } 00196 00197 #ifndef WNS_NO_LOGGING 00198 00199 #define LOG_TRACE WiMACLogger::getInstance()->prepareForMessage(3, typeid(*this))->send 00200 #define LOG_INFO WiMACLogger::getInstance()->prepareForMessage(2, typeid(*this))->send 00201 #define LOG_WARN WiMACLogger::getInstance()->prepareForMessage(1, typeid(*this))->send 00202 00203 00204 #else 00205 00206 #define LOG_TRACE wimac::Logger::DoNothing 00207 #define LOG_INFO wimac::Logger::DoNothing 00208 #define LOG_WARN wimac::Logger::DoNothing 00209 00210 #endif 00211 00212 #endif 00213
1.5.5