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 00004 ** you did not receive the LICENSE file with this file, you may obtain it 00005 ** from the 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 00008 ** the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file torprocess.h 00013 ** \version $Id: torprocess.h 2362 2008-02-29 04:30:11Z edmanm $ 00014 ** \brief Starts and stops a Tor process 00015 */ 00016 00017 #ifndef _TORPROCESS_H 00018 #define _TORPROCESS_H 00019 00020 #include <QProcess> 00021 00022 00023 class TorProcess : public QProcess 00024 { 00025 Q_OBJECT 00026 00027 public: 00028 /** Default constructor. */ 00029 TorProcess(QObject *parent = 0); 00030 00031 /** Start the Tor process */ 00032 void start(const QString &app, const QStringList &args); 00033 /** Stop the Tor process */ 00034 bool stop(QString *errmsg = 0); 00035 00036 /** Return the Tor process's PID (workaround for some Windows funkiness) */ 00037 quint64 pid(); 00038 00039 /** Enable reading log messages from stdout. */ 00040 void openStdout(); 00041 /** Disable reading log messages from stdout. */ 00042 void closeStdout(); 00043 00044 /** Returns the version reported by the Tor executable specified in 00045 * <b>exe</b>, or a default-constructed QString on failure. */ 00046 static QString version(const QString &exe); 00047 00048 signals: 00049 /** Emitted when Tor prints a log message to the console */ 00050 void log(const QString &severity, const QString &message); 00051 /** Emitted when Tor fails to start, perhaps because the path to Tor was 00052 * bogus. */ 00053 void startFailed(const QString &errorMessage); 00054 00055 private slots: 00056 /** Called when there is data to be read from stdout */ 00057 void onReadyRead(); 00058 /** Called when an error occurs in the process. */ 00059 void onError(QProcess::ProcessError error); 00060 00061 private: 00062 /** Formats the Tor process arguments for logging. */ 00063 QString formatArguments(const QStringList &args); 00064 }; 00065 00066 #endif 00067