tcglobal.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /* 
00012 ** \file tcglobal.h
00013 ** \version $Id: tcglobal.h 4054 2009-08-17 02:25:08Z edmanm $
00014 ** \brief Provides common methods and constants used by the torcontrol library
00015 */
00016 
00017 #ifndef _TCGLOBAL_H
00018 #define _TCGLOBAL_H
00019 
00020 #include <QString>
00021 #include <QMetaType>
00022 
00023 namespace tc {
00024   /** Helper class to handle formatting log messages with arguments. */
00025   class DebugMessage {
00026     struct Stream {
00027       Stream(QtMsgType t, const QString &fmt)
00028         : type(t), buf(fmt), ref(1) {}
00029       QtMsgType type; /**< DebugMessage severity level. */
00030       QString buf;    /**< Log message buffer. */
00031       int ref;        /**< Reference counter. */
00032     } *stream;
00033 
00034   public:
00035     /** Constructs a new DebugMessage with severity <b>t</b> and the message
00036      * format <b>fmt</b>. */
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   /** Severity values used in log message and status events. */
00070   enum Severity {
00071     UnrecognizedSeverity = 0, /**< An unrecognized severity value. */
00072     DebugSeverity  = (1u<<4), /**< Hyper-verbose events used for debugging. */
00073     InfoSeverity   = (1u<<3), /**< Verbose events that can occur frequently. */
00074     NoticeSeverity = (1u<<2), /**< A not-so-bad event. */
00075     WarnSeverity   = (1u<<1), /**< An important, but non-fatal event. */
00076     ErrorSeverity  = (1u<<0)  /**< A critical event. */
00077   };
00078   /** SOCKS error types used by Tor status event notifications. These are
00079    * emitted in the TorControl::socksError() signal. */
00080   enum SocksError {
00081     DangerousSocksTypeError, /**< The SOCKS type uses only IP addresses. */
00082     UnknownSocksProtocolError, /**< Unknown SOCKS protocol type. */
00083     BadSocksHostnameError /**< Application provided an invalid hostname. */
00084   };
00085   /** Reasons that use of the user's current Tor version would be
00086    * discouraged. */
00087   enum TorVersionStatus {
00088     ObsoleteTorVersion,
00089     UnrecommendedTorVersion,
00090     NewTorVersion
00091   };
00092 
00093   /** Converts <b>str</b> to a Severity enum value. */
00094   Severity severityFromString(const QString &str);
00095 
00096   /** Converts <b>str</b> to a ConnectionStatusReason enum value. */
00097   ConnectionStatusReason connectionStatusReasonFromString(const QString &str);
00098 
00099   /** Creates a new message using <b>fmt</b> and a severity level of
00100    * QtDebugMsg. */
00101   DebugMessage debug(const QString &fmt);
00102 
00103   /** Creates a new message using <b>fmt</b> and a severity level of
00104    * QtWarningMsg. */
00105   DebugMessage warn(const QString &fmt);
00106 
00107   /** Creates a new message using <b>fmt</b> and a severity level of
00108    * QtCriticalMsg. */
00109   DebugMessage error(const QString &fmt);
00110 
00111   /** Creates a new message using <b>fmt</b> and a severity level of
00112    * QtFatalMsg. */
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 
Generated on Mon Aug 30 22:58:55 2010 for Vidalia by  doxygen 1.6.3