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

Last change on this file since 12911 was 11402, checked in by tbretz, 13 years ago
Changed the default qos from kInfo to kMessage
File size: 3.3 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 kFatal = 50, ///< An error which cannot be handled at all happend, the only solution is program termination
21 kDebug = 99, ///< A message used for debugging only
22 };
23
24private:
25 std::ostream &fOut; /// The ostream to which by default Write redirects its output
26
27public:
28 MessageImp(std::ostream &out=std::cout);
29 virtual ~MessageImp() { }
30
31 virtual void IndicateStateChange(const Time &, const std::string &) { }
32 void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state);
33 virtual int Write(const Time &time, const std::string &txt, int qos=kMessage);
34
35 int Update(const std::string &txt, int severity=kMessage);
36 int Update(const char *txt, int severity=kMessage) { return Update(std::string(txt), severity); }
37 int Update(const std::ostringstream &str, int severity=kMessage) { return Update(str.str(), severity); }
38// int Update(int qos, const char *fmt, ...);
39
40 int Debug(const std::string &str) { return Update(str, kDebug); }
41 int Message(const std::string &str) { return Update(str, kMessage); }
42 int Info(const std::string &str) { return Update(str, kInfo); }
43 int Warn(const std::string &str) { return Update(str, kWarn); }
44 int Error(const std::string &str) { return Update(str, kError); }
45 int Fatal(const std::string &str) { return Update(str, kFatal); }
46
47 int Debug(const char *txt) { return Debug(std::string(txt)); }
48 int Message(const char *txt) { return Message(std::string(txt)); }
49 int Info(const char *txt) { return Info(std::string(txt)); }
50 int Warn(const char *txt) { return Warn(std::string(txt)); }
51 int Error(const char *txt) { return Error(std::string(txt)); }
52 int Fatal(const char *txt) { return Fatal(std::string(txt)); }
53
54 int Debug(const std::ostringstream &str) { return Debug(str.str()); }
55 int Message(const std::ostringstream &str) { return Message(str.str()); }
56 int Info(const std::ostringstream &str) { return Info(str.str()); }
57 int Warn(const std::ostringstream &str) { return Warn(str.str()); }
58 int Error(const std::ostringstream &str) { return Error(str.str()); }
59 int Fatal(const std::ostringstream &str) { return Fatal(str.str()); }
60
61 std::ostream &operator()() const { return fOut; }
62 std::ostream &Out() const { return fOut; }
63};
64
65#endif
66
67// ***************************************************************************
68/** @fn MessageImp::IndicateStateChange(const Time &time, const std::string &server)
69
70This function is called to indicate a state change by StateChanged() to
71derived classes.
72
73@param time
74 Time at which the state change happened
75
76@param server
77 Server which emitted the state change
78
79**/
80// ***************************************************************************
Note: See TracBrowser for help on using the repository browser.