source: trunk/FACT++/src/MessageImp.h@ 15470

Last change on this file since 15470 was 14497, checked in by tbretz, 12 years ago
Added some basic infrastructure to send alarms e.g. to smartfact.
File size: 4.0 KB
Line 
1#ifndef FACT_MessageImp
2#define FACT_MessageImp
3
4#include <string>
5#include <sstream>
6#include <iostream>
7
8class Time;
9
10class MessageImp
11{
12public:
13 /// Severity of a message
14 enum Severity
15 {
16 kMessage = 10, ///< Just a message, usually obsolete
17 kInfo = 20, ///< An info telling something which can be interesting to know
18 kWarn = 30, ///< A warning, things that somehow might result in unexpected or unwanted bahaviour
19 kError = 40, ///< Error, something unexpected happened, but can still be handled by the program
20 kAlarm = 45, ///< Error, something unexpected happened, but needs user intervention (i.e. it needs a signal to the user)
21 kFatal = 50, ///< An error which cannot be handled at all happend, the only solution is program termination
22 kComment = 90, ///< A comment which is always printed
23 kDebug = 99, ///< A message used for debugging only
24 };
25
26private:
27 std::ostream &fOut; /// The ostream to which by default Write redirects its output
28
29public:
30 MessageImp(std::ostream &out=std::cout);
31 virtual ~MessageImp() { }
32
33 virtual void IndicateStateChange(const Time &, const std::string &) { }
34 void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state);
35 virtual int Write(const Time &time, const std::string &txt, int qos=kMessage);
36
37 int Update(const std::string &txt, int severity=kMessage);
38 int Update(const char *txt, int severity=kMessage) { return Update(std::string(txt), severity); }
39 int Update(const std::ostringstream &str, int severity=kMessage) { return Update(str.str(), severity); }
40// int Update(int qos, const char *fmt, ...);
41
42 int Debug(const std::string &str) { return Update(str, kDebug); }
43 int Message(const std::string &str) { return Update(str, kMessage); }
44 int Info(const std::string &str) { return Update(str, kInfo); }
45 int Warn(const std::string &str) { return Update(str, kWarn); }
46 int Error(const std::string &str) { return Update(str, kError); }
47 int Alarm(const std::string &str) { return Update(str, kAlarm); }
48 int Fatal(const std::string &str) { return Update(str, kFatal); }
49 int Comment(const std::string &str) { return Update(str, kComment); }
50
51 int Debug(const char *txt) { return Debug(std::string(txt)); }
52 int Message(const char *txt) { return Message(std::string(txt)); }
53 int Info(const char *txt) { return Info(std::string(txt)); }
54 int Warn(const char *txt) { return Warn(std::string(txt)); }
55 int Error(const char *txt) { return Error(std::string(txt)); }
56 int Alarm(const char *txt) { return Alarm(std::string(txt)); }
57 int Fatal(const char *txt) { return Fatal(std::string(txt)); }
58 int Comment(const char *txt) { return Comment(std::string(txt)); }
59
60 int Debug(const std::ostringstream &str) { return Debug(str.str()); }
61 int Message(const std::ostringstream &str) { return Message(str.str()); }
62 int Info(const std::ostringstream &str) { return Info(str.str()); }
63 int Warn(const std::ostringstream &str) { return Warn(str.str()); }
64 int Alarm(const std::ostringstream &str) { return Alarm(str.str()); }
65 int Error(const std::ostringstream &str) { return Error(str.str()); }
66 int Fatal(const std::ostringstream &str) { return Fatal(str.str()); }
67 int Comment(const std::ostringstream &str) { return Comment(str.str()); }
68
69 std::ostream &operator()() const { return fOut; }
70 std::ostream &Out() const { return fOut; }
71};
72
73#endif
74
75// ***************************************************************************
76/** @fn MessageImp::IndicateStateChange(const Time &time, const std::string &server)
77
78This function is called to indicate a state change by StateChanged() to
79derived classes.
80
81@param time
82 Time at which the state change happened
83
84@param server
85 Server which emitted the state change
86
87**/
88// ***************************************************************************
Note: See TracBrowser for help on using the repository browser.