CARMA C++
LogMsgHandler.h
Go to the documentation of this file.
1 // $Id: LogMsgHandler.h,v 1.1 2010/12/13 21:06:30 eml Exp $
2 
3 #ifndef SZA_UTIL_LOGMSGHANDLER_H
4 #define SZA_UTIL_LOGMSGHANDLER_H
5 
16 #include <iostream>
17 #include <sstream>
18 #include <map>
19 
20 #include "carma/szaarrayutils/lprintf.h"
21 
22 #include "carma/szautil/Mutex.h"
23 
24 namespace sza {
25  namespace util {
26 
27  class LogMsgHandler {
28 
29  public:
30 
31  struct LogMsg {
32 
33  enum Type {
34  TYPE_UNSPEC,
35  TYPE_ERR,
36  TYPE_MESS
37  };
38 
39  LogMsg(unsigned seq) {
40  seq_ = seq;
41  lastReadIndex_ = 0;
42  type_ = TYPE_UNSPEC;
43  }
44 
45  ~LogMsg() {}
46 
47  std::ostringstream os_;
48  unsigned seq_;
49  unsigned lastReadIndex_;
50  Type type_;
51  };
52 
56  LogMsgHandler();
57 
61  virtual ~LogMsgHandler();
62 
63  // Get the next unique sequence number
64 
65  unsigned nextSeq();
66 
67  // Append a string to an existing message
68 
69  void append(unsigned seq, std::string text,
70  LogMsg::Type type=LogMsg::TYPE_UNSPEC);
71 
72  void append(unsigned seq, std::string text,
73  sza::array::LogStream nature);
74 
75  void appendWithSpace(unsigned seq, std::string text,
76  LogMsg::Type type=LogMsg::TYPE_UNSPEC);
77 
78  void appendWithSpace(unsigned seq, std::string text,
79  sza::array::LogStream nature);
80 
81  // Get a tagged message
82 
83  std::string getMessage(unsigned seq);
84  std::string readMessage(unsigned seq);
85 
86  std::string getNextMessageSubstr(unsigned seq, unsigned maxChars, bool& isLast);
87 
88 
89  private:
90 
91  Mutex seqLock_;
92  unsigned seq_;
93 
94  std::map<unsigned, LogMsg*> messages_;
95 
96  // Return the next message
97 
98  void eraseMessage(unsigned seq);
99 
100  // Return the next message
101 
102  LogMsg* findMessage(unsigned seq);
103 
104  }; // End class LogMsgHandler
105 
106  } // End namespace util
107 } // End namespace sza
108 
109 
110 
111 #endif // End #ifndef SZA_UTIL_LOGMSGHANDLER_H
Tagged: Sat Mar 27 16:28:13 PST 2004.