00001
00002 #ifndef LOG_STREAM_MANAGER_H
00003 #define LOG_STREAM_MANAGER_H
00004
00005 #include <iostream>
00006 #include <fstream>
00007 #include <sstream>
00008 #include <string>
00009 #include <iomanip>
00010 using namespace std;
00011 #include <boost/shared_ptr.hpp>
00012 #include <boost/utility.hpp>
00013
00014 #include "communication_layer.hpp"
00015 #include "utility.hpp"
00016
00017 class Packet;
00018 typedef boost::shared_ptr<Packet> PacketPtr;
00019 class NodeId;
00020
00025 class LogStreamManager : boost::noncopyable {
00026 private:
00027
00032 enum LogEvents {
00033 LogEvents_PktSend,
00034 LogEvents_PktRecv,
00035 LogEvents_Stats,
00036 LogEvents_UserDefined,
00037 LogEvents_Debug
00038 };
00039 friend ostream& operator<< (ostream& s, const LogEvents& logEvent);
00040
00041 public:
00043 typedef LogStreamManager* LogStreamManagerPtr;
00044
00049 static inline LogStreamManagerPtr instance();
00050
00057 void logPktSendItem(const NodeId& nodeId,
00058 const CommunicationLayer::Types& layer, const Packet& recvPkt);
00059
00066 void logPktRecvItem(const NodeId& nodeId,
00067 const CommunicationLayer::Types& layer, const Packet& recvPkt);
00068
00069
00070
00071
00072
00073
00074
00075
00076
00088 void logStatsItem(const string& statsKeyString,
00089 const string& statsValueString);
00090
00101 void logStatsItem(const NodeId& nodeId,
00102 const string& statsKeyString, const string& statsValueString);
00103
00108 void logUserDefinedItem(const string& userString);
00109
00114 void logDebugItem(const string& debugString);
00115
00120 inline void setAllStreams(ostreamPtr newStream);
00121
00127 inline void setPktSendStream(ostreamPtr newStream);
00128
00134 inline void setPktRecvStream(ostreamPtr newStream);
00135
00141 inline void setEnergyStream(ostreamPtr newStream);
00142
00148 inline void setNewSenseEventStream(ostreamPtr newStream);
00149
00155 inline void setSensedEventStream(ostreamPtr newStream);
00156
00162 inline void setStatsStream(ostreamPtr newStream);
00163
00169 inline void setUserDefinedStream(ostreamPtr newStream);
00170
00176 inline void setDebugStream(ostreamPtr newStream);
00177
00178 private:
00179
00182 static LogStreamManagerPtr m_instance;
00183
00188 ostreamPtr m_pktSendStream;
00189
00194 ostreamPtr m_pktRecvStream;
00195
00200 ostreamPtr m_energyStream;
00201
00206 ostreamPtr m_newSenseEventStream;
00207
00212 ostreamPtr m_sensedEventStream;
00213
00218 ostreamPtr m_statsStream;
00219
00224 ostreamPtr m_userDefinedStream;
00225
00230 ostreamPtr m_debugStream;
00231
00233 LogStreamManager();
00234
00238 ~LogStreamManager();
00239
00246 string currentTimeString() const;
00247
00254 string layerString(const CommunicationLayer::Types& layer) const;
00255
00262 string eventString(const LogEvents& event) const;
00263
00270 string nodeIdString(const NodeId& nodeId) const;
00271
00272 };
00273 typedef LogStreamManager* LogStreamManagerPtr;
00274
00276
00278
00279 inline LogStreamManagerPtr LogStreamManager::instance()
00280 {
00281
00282 if(m_instance == 0) {
00283 m_instance = new LogStreamManager();
00284 }
00285 return m_instance;
00286 }
00287
00288 inline void LogStreamManager::setAllStreams(ostreamPtr newStream)
00289 {
00290 assert(newStream != 0);
00291
00292 setPktSendStream(newStream);
00293 setPktRecvStream(newStream);
00294 setEnergyStream(newStream);
00295 setNewSenseEventStream(newStream);
00296 setSensedEventStream(newStream);
00297 setStatsStream(newStream);
00298 setUserDefinedStream(newStream);
00299 setDebugStream(newStream);
00300 }
00301
00302 inline void LogStreamManager::setPktSendStream(ostreamPtr newStream)
00303 {
00304 assert(newStream != 0);
00305 m_pktSendStream = newStream;
00306 }
00307
00308 inline void LogStreamManager::setPktRecvStream(ostreamPtr newStream)
00309 {
00310 assert(newStream != 0);
00311 m_pktRecvStream = newStream;
00312 }
00313
00314 inline void LogStreamManager::setEnergyStream(ostreamPtr newStream)
00315 {
00316 assert(newStream != 0);
00317 m_energyStream = newStream;
00318 }
00319
00320 inline void LogStreamManager::setNewSenseEventStream(ostreamPtr newStream)
00321 {
00322 assert(newStream != 0);
00323 m_newSenseEventStream = newStream;
00324 }
00325
00326 inline void LogStreamManager::setSensedEventStream(ostreamPtr newStream)
00327 {
00328 assert(newStream != 0);
00329 m_sensedEventStream = newStream;
00330 }
00331
00332 inline void LogStreamManager::setStatsStream(ostreamPtr newStream)
00333 {
00334 assert(newStream != 0);
00335 m_statsStream = newStream;
00336 }
00337
00338 inline void LogStreamManager::setUserDefinedStream(ostreamPtr newStream)
00339 {
00340 assert(newStream != 0);
00341 m_userDefinedStream = newStream;
00342 }
00343
00344 inline void LogStreamManager::setDebugStream(ostreamPtr newStream)
00345 {
00346 assert(newStream != 0);
00347 m_debugStream = newStream;
00348 }
00349
00351
00353
00354 inline ostream& operator<< (ostream& s,
00355 const LogStreamManager::LogEvents& logEvent)
00356 {
00357
00358 switch (logEvent) {
00359 case LogStreamManager::LogEvents_PktSend:
00360 s << "pktSend";
00361 break;
00362 case LogStreamManager::LogEvents_PktRecv:
00363 s << "pktRecv";
00364 break;
00365 case LogStreamManager::LogEvents_Stats:
00366 s << "stats";
00367 break;
00368 case LogStreamManager::LogEvents_UserDefined:
00369 s << "userDefined";
00370 break;
00371 case LogStreamManager::LogEvents_Debug:
00372 s << "debug";
00373 break;
00374 }
00375
00376 return s;
00377
00378 }
00379
00380 #endif // LOG_STREAM_MANAGER_H
00381