tcglobal.h
Go to the documentation of this file.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 #include <QMetaType>
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 = 0,
00072 DebugSeverity = (1u<<4),
00073 InfoSeverity = (1u<<3),
00074 NoticeSeverity = (1u<<2),
00075 WarnSeverity = (1u<<1),
00076 ErrorSeverity = (1u<<0)
00077 };
00078
00079
00080 enum SocksError {
00081 DangerousSocksTypeError,
00082 UnknownSocksProtocolError,
00083 BadSocksHostnameError
00084 };
00085
00086
00087 enum TorVersionStatus {
00088 ObsoleteTorVersion,
00089 UnrecommendedTorVersion,
00090 NewTorVersion
00091 };
00092
00093
00094 Severity severityFromString(const QString &str);
00095
00096
00097 ConnectionStatusReason connectionStatusReasonFromString(const QString &str);
00098
00099
00100
00101 DebugMessage debug(const QString &fmt);
00102
00103
00104
00105 DebugMessage warn(const QString &fmt);
00106
00107
00108
00109 DebugMessage error(const QString &fmt);
00110
00111
00112
00113 DebugMessage fatal(const QString &fmt);
00114 }
00115
00116 Q_DECLARE_METATYPE(tc::Severity)
00117 Q_DECLARE_METATYPE(tc::SocksError)
00118 Q_DECLARE_METATYPE(tc::TorVersionStatus)
00119
00120 #endif
00121