My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
LogMsgHandler.h
Go to the documentation of this file.
1 // $Id: LogMsgHandler.h,v 1.1.1.1 2009/07/06 23:57:25 eml Exp $
2 
3 #ifndef GCP_UTIL_LOGMSGHANDLER_H
4 #define GCP_UTIL_LOGMSGHANDLER_H
5 
16 #include <iostream>
17 #include <sstream>
18 #include <map>
19 
20 #include "gcp/util/common/Mutex.h"
21 
22 namespace gcp {
23  namespace util {
24 
25  class LogMsgHandler {
26 
27  public:
28 
29  struct LogMsg {
30 
31  enum Type {
32  TYPE_UNSPEC,
33  TYPE_ERR,
34  TYPE_MESS
35  };
36 
37  LogMsg(unsigned seq) {
38  seq_ = seq;
39  lastReadIndex_ = 0;
40  type_ = TYPE_UNSPEC;
41  }
42 
43  ~LogMsg() {}
44 
45  std::ostringstream os_;
46  unsigned seq_;
47  unsigned lastReadIndex_;
48  Type type_;
49  };
50 
54  LogMsgHandler();
55 
59  virtual ~LogMsgHandler();
60 
61  // Get the next unique sequence number
62 
63  unsigned nextSeq();
64 
65  // Append a string to an existing message
66 
67  void append(unsigned seq, std::string text, LogMsg::Type type=LogMsg::TYPE_UNSPEC);
68 
69  void appendWithSpace(unsigned seq, std::string text, LogMsg::Type type=LogMsg::TYPE_UNSPEC);
70 
71  // Get a tagged message
72 
73  std::string getMessage(unsigned seq);
74  std::string readMessage(unsigned seq);
75 
76  std::string getNextMessageSubstr(unsigned seq, unsigned maxChars, bool& isLast);
77 
78 
79  private:
80 
81  Mutex seqLock_;
82  unsigned seq_;
83 
84  std::map<unsigned, LogMsg*> messages_;
85 
86  // Return the next message
87 
88  void eraseMessage(unsigned seq);
89 
90  // Return the next message
91 
92  LogMsg* findMessage(unsigned seq);
93 
94  }; // End class LogMsgHandler
95 
96  } // End namespace util
97 } // End namespace gcp
98 
99 
100 
101 #endif // End #ifndef GCP_UTIL_LOGMSGHANDLER_H
LogMsgHandler()
Definition: LogMsgHandler.cc:13
std::string getNextMessageSubstr(unsigned seq, unsigned maxChars, bool &isLast)
Definition: LogMsgHandler.cc:146
Definition: Mutex.h:16
virtual ~LogMsgHandler()
Definition: LogMsgHandler.cc:21
Definition: LogMsgHandler.h:29
std::string getMessage(unsigned seq)
Definition: LogMsgHandler.cc:85
Definition: LogMsgHandler.h:25
std::string readMessage(unsigned seq)
Definition: LogMsgHandler.cc:137