00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _TCGLOBAL_H
00018 #define _TCGLOBAL_H
00019
00020 #include <QString>
00021
00022
00023 namespace tc {
00024
00025 class DebugMessage {
00026 struct Stream {
00027 Stream(QtMsgType t, const QString &fmt)
00028 : type(t), buf(fmt), ref(1) {}
00029 QtMsgType type;
00030 QString buf;
00031 int ref;
00032 } *stream;
00033
00034 public:
00035
00036
00037 inline DebugMessage(QtMsgType t, const QString &fmt)
00038 : stream(new Stream(t, fmt)) {}
00039 inline DebugMessage(const DebugMessage &o)
00040 : stream(o.stream) { ++stream->ref; }
00041 virtual ~DebugMessage() {
00042 if (!--stream->ref) {
00043 stream->buf.prepend("torcontrol: ");
00044 qt_message_output(stream->type, qPrintable(stream->buf));
00045 delete stream;
00046 }
00047 }
00048
00049 inline DebugMessage arg(const QString &a)
00050 { stream->buf = stream->buf.arg(a); return *this; }
00051 inline DebugMessage arg(int a)
00052 { stream->buf = stream->buf.arg(a); return *this; }
00053 };
00054 }
00055
00056 namespace tc {
00057 enum ConnectionStatusReason {
00058 UnrecognizedReason,
00059 MiscellaneousReason,
00060 IdentityMismatch,
00061 ConnectionDone,
00062 ConnectionRefused,
00063 ConnectionReset,
00064 ConnectionTimeout,
00065 ConnectionIoError,
00066 NoRouteToHost,
00067 ResourceLimitReached
00068 };
00069
00070 enum Severity {
00071 UnrecognizedSeverity,
00072 SeverityDebug,
00073 SeverityInfo,
00074 SeverityNotice,
00075 SeverityWarn,
00076 SeverityError
00077 };
00078
00079
00080 Severity toSeverity(const QString &str);
00081
00082
00083 ConnectionStatusReason toConnectionStatusReason(const QString &str);
00084
00085
00086
00087 DebugMessage debug(const QString &fmt);
00088
00089
00090
00091 DebugMessage warn(const QString &fmt);
00092
00093
00094
00095 DebugMessage error(const QString &fmt);
00096
00097
00098
00099 DebugMessage fatal(const QString &fmt);
00100 }
00101
00102 #endif
00103