FACT++  1.0
MessageImp.h
Go to the documentation of this file.
1 #ifndef FACT_MessageImp
2 #define FACT_MessageImp
3 
4 #include <string>
5 #include <sstream>
6 #include <iostream>
7 
8 class Time;
9 
11 {
12 public:
14  enum Severity
15  {
16  kMessage = 10,
17  kInfo = 20,
18  kWarn = 30,
19  kError = 40,
20  kAlarm = 45,
21  kFatal = 50,
22  kComment = 90,
23  kDebug = 99,
24  };
25 
26 private:
27  std::ostream &fOut;
28  uint32_t fLastMjd;
29 
30  int WriteImp(const Time &time, const std::string &txt, int qos=kMessage);
31 
32 public:
33  MessageImp(std::ostream &out=std::cout);
34  virtual ~MessageImp() { }
35 
36  virtual void IndicateStateChange(const Time &, const std::string &) { }
37  void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state);
38  virtual int Write(const Time &time, const std::string &txt, int qos=kMessage);
39 
40  int Update(const std::string &txt, int severity=kMessage);
41  int Update(const char *txt, int severity=kMessage) { return Update(std::string(txt), severity); }
42  int Update(const std::ostringstream &str, int severity=kMessage) { return Update(str.str(), severity); }
43 // int Update(int qos, const char *fmt, ...);
44 
45  int Debug(const std::string &str) { return Update(str, kDebug); }
46  int Message(const std::string &str) { return Update(str, kMessage); }
47  int Info(const std::string &str) { return Update(str, kInfo); }
48  int Warn(const std::string &str) { return Update(str, kWarn); }
49  int Error(const std::string &str) { return Update(str, kError); }
50  int Alarm(const std::string &str) { return Update(str, kAlarm); }
51  int Fatal(const std::string &str) { return Update(str, kFatal); }
52  int Comment(const std::string &str) { return Update(str, kComment); }
53 
54  int Debug(const char *txt) { return Debug(std::string(txt)); }
55  int Message(const char *txt) { return Message(std::string(txt)); }
56  int Info(const char *txt) { return Info(std::string(txt)); }
57  int Warn(const char *txt) { return Warn(std::string(txt)); }
58  int Error(const char *txt) { return Error(std::string(txt)); }
59  int Alarm(const char *txt) { return Alarm(std::string(txt)); }
60  int Fatal(const char *txt) { return Fatal(std::string(txt)); }
61  int Comment(const char *txt) { return Comment(std::string(txt)); }
62 
63  int Debug(const std::ostringstream &str) { return Debug(str.str()); }
64  int Message(const std::ostringstream &str) { return Message(str.str()); }
65  int Info(const std::ostringstream &str) { return Info(str.str()); }
66  int Warn(const std::ostringstream &str) { return Warn(str.str()); }
67  int Alarm(const std::ostringstream &str) { return Alarm(str.str()); }
68  int Error(const std::ostringstream &str) { return Error(str.str()); }
69  int Fatal(const std::ostringstream &str) { return Fatal(str.str()); }
70  int Comment(const std::ostringstream &str) { return Comment(str.str()); }
71 
72  std::ostream &operator()() const { return fOut; }
73  std::ostream &Out() const { return fOut; }
74 
75  virtual bool MessageQueueEmpty() const { return true; }
76 };
77 
78 #endif
79 
80 // ***************************************************************************
93 // ***************************************************************************
std::ostream & operator()() const
Definition: MessageImp.h:72
int Update(const std::ostringstream &str, int severity=kMessage)
Definition: MessageImp.h:42
int Update(const char *txt, int severity=kMessage)
Definition: MessageImp.h:41
int Comment(const std::string &str)
Definition: MessageImp.h:52
int Debug(const std::ostringstream &str)
Definition: MessageImp.h:63
virtual ~MessageImp()
Definition: MessageImp.h:34
virtual bool MessageQueueEmpty() const
Definition: MessageImp.h:75
int Comment(const std::ostringstream &str)
Definition: MessageImp.h:70
int Debug(const char *txt)
Definition: MessageImp.h:54
A warning, things that somehow might result in unexpected or unwanted bahaviour.
Definition: MessageImp.h:18
int Error(const std::ostringstream &str)
Definition: MessageImp.h:68
int Debug(const std::string &str)
Definition: MessageImp.h:45
int Fatal(const char *txt)
Definition: MessageImp.h:60
The base implementation of a distributed messaging system.
Definition: MessageImp.h:10
void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state)
Definition: MessageImp.cc:64
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
int Info(const std::ostringstream &str)
Definition: MessageImp.h:65
int Alarm(const std::ostringstream &str)
Definition: MessageImp.h:67
int Alarm(const std::string &str)
Definition: MessageImp.h:50
int Info(const char *txt)
Definition: MessageImp.h:56
int Warn(const std::ostringstream &str)
Definition: MessageImp.h:66
int WriteImp(const Time &time, const std::string &txt, int qos=kMessage)
Mjd of last message.
Definition: MessageImp.cc:108
std::ostream & Out() const
Definition: MessageImp.h:73
int Comment(const char *txt)
Definition: MessageImp.h:61
An info telling something which can be interesting to know.
Definition: MessageImp.h:17
int Message(const char *txt)
Definition: MessageImp.h:55
Severity
Severity of a message.
Definition: MessageImp.h:14
Just a message, usually obsolete.
Definition: MessageImp.h:16
virtual int Write(const Time &time, const std::string &txt, int qos=kMessage)
Definition: MessageImp.cc:133
uint16_t qos
Definition: HeadersGPS.h:29
A message used for debugging only.
Definition: MessageImp.h:23
uint32_t fLastMjd
The ostream to which by default Write redirects its output.
Definition: MessageImp.h:28
std::ostream & fOut
Definition: MessageImp.h:27
int Error(const std::string &str)
Definition: MessageImp.h:49
int Update(const std::string &txt, int severity=kMessage)
Definition: MessageImp.cc:156
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
int Warn(const std::string &str)
Definition: MessageImp.h:48
int Fatal(const std::ostringstream &str)
Definition: MessageImp.h:69
MessageImp(std::ostream &out=std::cout)
Definition: MessageImp.cc:39
Error, something unexpected happened, but can still be handled by the program.
Definition: MessageImp.h:19
A comment which is always printed.
Definition: MessageImp.h:22
Error, something unexpected happened, but needs user intervention (i.e. it needs a signal to the user...
Definition: MessageImp.h:20
int Error(const char *txt)
Definition: MessageImp.h:58
int Info(const std::string &str)
Definition: MessageImp.h:47
int Message(const std::string &str)
Definition: MessageImp.h:46
int Fatal(const std::string &str)
Definition: MessageImp.h:51
virtual void IndicateStateChange(const Time &, const std::string &)
Definition: MessageImp.h:36
An error which cannot be handled at all happend, the only solution is program termination.
Definition: MessageImp.h:21
int Warn(const char *txt)
Definition: MessageImp.h:57
int Alarm(const char *txt)
Definition: MessageImp.h:59
int Message(const std::ostringstream &str)
Definition: MessageImp.h:64