[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2695: Reorg the src/torcontrol logging stuff and add an enum for ' (in vidalia: . trunk/src/torcontrol)
Author: edmanm
Date: 2008-06-12 02:50:05 -0400 (Thu, 12 Jun 2008)
New Revision: 2695
Added:
vidalia/trunk/src/torcontrol/tcglobal.cpp
vidalia/trunk/src/torcontrol/tcglobal.h
Removed:
vidalia/trunk/src/torcontrol/debug.h
Modified:
vidalia/
vidalia/trunk/src/torcontrol/CMakeLists.txt
vidalia/trunk/src/torcontrol/addressmap.cpp
vidalia/trunk/src/torcontrol/controlconnection.cpp
vidalia/trunk/src/torcontrol/controlsocket.cpp
vidalia/trunk/src/torcontrol/torprocess.cpp
vidalia/trunk/src/torcontrol/torservice.cpp
Log:
r508@thebe: edmanm | 2008-06-12 02:10:28 -0400
Reorg the src/torcontrol logging stuff and add an enum for 'orconn' and
'bootstrap' reason fields. The enum is in the tc:: namespace, since multiple
events use these same reasons.
Property changes on: vidalia
___________________________________________________________________
svk:merge ticket from /local/vidalia [r508] on 45a62a8a-8088-484c-baad-c7b3e776dd32
Modified: vidalia/trunk/src/torcontrol/CMakeLists.txt
===================================================================
--- vidalia/trunk/src/torcontrol/CMakeLists.txt 2008-06-12 06:50:00 UTC (rev 2694)
+++ vidalia/trunk/src/torcontrol/CMakeLists.txt 2008-06-12 06:50:05 UTC (rev 2695)
@@ -30,6 +30,7 @@
serverstatusevent.cpp
statusevent.cpp
stream.cpp
+ tcglobal.cpp
torcontrol.cpp
torevents.cpp
torprocess.cpp
Modified: vidalia/trunk/src/torcontrol/addressmap.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/addressmap.cpp 2008-06-12 06:50:00 UTC (rev 2694)
+++ vidalia/trunk/src/torcontrol/addressmap.cpp 2008-06-12 06:50:05 UTC (rev 2695)
@@ -15,7 +15,7 @@
*/
#include <QStringList>
-#include "debug.h"
+#include "tcglobal.h"
#include "addressmap.h"
/** Format of expiry times in address map events. */
Modified: vidalia/trunk/src/torcontrol/controlconnection.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/controlconnection.cpp 2008-06-12 06:50:00 UTC (rev 2694)
+++ vidalia/trunk/src/torcontrol/controlconnection.cpp 2008-06-12 06:50:05 UTC (rev 2695)
@@ -18,7 +18,7 @@
#include <QCoreApplication>
#include <QMutexLocker>
#include <stringutil.h>
-#include "debug.h"
+#include "tcglobal.h"
#include "controlconnection.h"
Modified: vidalia/trunk/src/torcontrol/controlsocket.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/controlsocket.cpp 2008-06-12 06:50:00 UTC (rev 2694)
+++ vidalia/trunk/src/torcontrol/controlsocket.cpp 2008-06-12 06:50:05 UTC (rev 2695)
@@ -15,7 +15,7 @@
*/
#include <stringutil.h>
-#include "debug.h"
+#include "tcglobal.h"
#include "controlsocket.h"
Deleted: vidalia/trunk/src/torcontrol/debug.h
Added: vidalia/trunk/src/torcontrol/tcglobal.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/tcglobal.cpp (rev 0)
+++ vidalia/trunk/src/torcontrol/tcglobal.cpp 2008-06-12 06:50:05 UTC (rev 2695)
@@ -0,0 +1,65 @@
+
+#include "tcglobal.h"
+
+
+namespace tc {
+
+/** Creates a new message using <b>fmt</b> and a severity level of
+ * QtDebugMsg. */
+DebugMessage
+debug(const QString &fmt)
+{
+ return DebugMessage(QtDebugMsg, fmt);
+}
+
+/** Creates a new message using <b>fmt</b> and a severity level of
+ * QtWarningMsg. */
+DebugMessage
+warn(const QString &fmt)
+{
+ return DebugMessage(QtWarningMsg, fmt);
+}
+
+/** Creates a new message using <b>fmt</b> and a severity level of
+ * QtCriticalMsg. */
+DebugMessage
+error(const QString &fmt)
+{
+ return DebugMessage(QtCriticalMsg, fmt);
+}
+
+/** Creates a new message using <b>fmt</b> and a severity level of
+ * QtFatalMsg. */
+DebugMessage
+fatal(const QString &fmt)
+{
+ return DebugMessage(QtFatalMsg, fmt);
+}
+
+/** Converts <b>str</b> to a ConnectionStatusReason enum value. */
+ConnectionStatusReason
+connectionStatusReason(const QString &str)
+{
+ if (!str.compare("MISC", Qt::CaseInsensitive))
+ return MiscellaneousReason;
+ if (!str.compare("IDENTITY", Qt::CaseInsensitive))
+ return IdentityMismatch;
+ if (!str.compare("RESOURCELIMIT", Qt::CaseInsensitive))
+ return ResourceLimitReached;
+ if (!str.compare("DONE", Qt::CaseInsensitive))
+ return ConnectionDone;
+ if (!str.compare("CONNECTREFUSED"))
+ return ConnectionRefused;
+ if (!str.compare("CONNECTRESET", Qt::CaseInsensitive))
+ return ConnectionRefused;
+ if (!str.compare("TIMEOUT", Qt::CaseInsensitive))
+ return ConnectionTimeout;
+ if (!str.compare("NOROUTE", Qt::CaseInsensitive))
+ return NoRouteToHost;
+ if (!str.compare("IOERROR", Qt::CaseInsensitive))
+ return ConnectionIoError;
+ return UnrecognizedReason;
+}
+
+}
+
Added: vidalia/trunk/src/torcontrol/tcglobal.h
===================================================================
--- vidalia/trunk/src/torcontrol/tcglobal.h (rev 0)
+++ vidalia/trunk/src/torcontrol/tcglobal.h 2008-06-12 06:50:05 UTC (rev 2695)
@@ -0,0 +1,75 @@
+
+#ifndef _TCGLOBAL_H
+#define _TCGLOBAL_H
+
+#include <QString>
+
+namespace tc {
+ /** Helper class to handle formatting log messages with arguments. */
+ class DebugMessage {
+ struct Stream {
+ Stream(QtMsgType t, const QString &fmt)
+ : type(t), buf(fmt), ref(1) {}
+ QtMsgType type; /**< DebugMessage severity level. */
+ QString buf; /**< Log message buffer. */
+ int ref; /**< Reference counter. */
+ } *stream;
+
+ public:
+ /** Constructs a new DebugMessage with severity <b>t</b> and the message
+ * format <b>fmt</b>. */
+ inline DebugMessage(QtMsgType t, const QString &fmt)
+ : stream(new Stream(t, fmt)) {}
+ inline DebugMessage(const DebugMessage &o)
+ : stream(o.stream) { ++stream->ref; }
+ virtual ~DebugMessage() {
+ if (!--stream->ref) {
+ stream->buf.prepend("torcontrol: ");
+ qt_message_output(stream->type, qPrintable(stream->buf));
+ delete stream;
+ }
+ }
+
+ inline DebugMessage arg(const QString &a)
+ { stream->buf = stream->buf.arg(a); return *this; }
+ inline DebugMessage arg(int a)
+ { stream->buf = stream->buf.arg(a); return *this; }
+ };
+}
+
+namespace tc {
+ enum ConnectionStatusReason {
+ UnrecognizedReason,
+ MiscellaneousReason,
+ IdentityMismatch,
+ ConnectionDone,
+ ConnectionRefused,
+ ConnectionReset,
+ ConnectionTimeout,
+ ConnectionIoError,
+ NoRouteToHost,
+ ResourceLimitReached
+ };
+
+ /** Converts <b>str</b> to a ConnectionStatusReason enum value. */
+ ConnectionStatusReason connectionStatusReason(const QString &str);
+
+ /** Creates a new message using <b>fmt</b> and a severity level of
+ * QtDebugMsg. */
+ DebugMessage debug(const QString &fmt);
+
+ /** Creates a new message using <b>fmt</b> and a severity level of
+ * QtWarningMsg. */
+ DebugMessage warn(const QString &fmt);
+
+ /** Creates a new message using <b>fmt</b> and a severity level of
+ * QtCriticalMsg. */
+ DebugMessage error(const QString &fmt);
+
+ /** Creates a new message using <b>fmt</b> and a severity level of
+ * QtFatalMsg. */
+ DebugMessage fatal(const QString &fmt);
+}
+
+#endif
+
Modified: vidalia/trunk/src/torcontrol/torprocess.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/torprocess.cpp 2008-06-12 06:50:00 UTC (rev 2694)
+++ vidalia/trunk/src/torcontrol/torprocess.cpp 2008-06-12 06:50:05 UTC (rev 2695)
@@ -16,7 +16,7 @@
#include <QString>
#include <stringutil.h>
-#include "debug.h"
+#include "tcglobal.h"
/* Needed for _PROCESS_INFORMATION so that pid() works on Win32 */
#if defined (Q_OS_WIN32)
Modified: vidalia/trunk/src/torcontrol/torservice.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/torservice.cpp 2008-06-12 06:50:00 UTC (rev 2694)
+++ vidalia/trunk/src/torcontrol/torservice.cpp 2008-06-12 06:50:05 UTC (rev 2695)
@@ -16,7 +16,7 @@
#include <QLibrary>
-#include "debug.h"
+#include "tcglobal.h"
#include "torservice.h"
/** Returned by TorService::exitCode() when we are unable to determine the