00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file torprocess.h 00024 * \version $Id: torprocess.h 1864 2007-08-23 23:31:35Z edmanm $ 00025 * \brief Starts and stops a Tor process 00026 */ 00027 00028 #ifndef _TORPROCESS_H 00029 #define _TORPROCESS_H 00030 00031 #include <QProcess> 00032 00033 00034 class TorProcess : public QProcess 00035 { 00036 Q_OBJECT 00037 00038 public: 00039 /** Default constructor. */ 00040 TorProcess(); 00041 00042 /** Start the Tor process */ 00043 void start(QString app, QStringList args); 00044 /** Stop the Tor process */ 00045 bool stop(QString *errmsg = 0); 00046 00047 /** Return the Tor process's PID (workaround for some Windows funkiness) */ 00048 quint64 pid(); 00049 00050 /** Enable reading log messages from stdout. */ 00051 void openStdout(); 00052 /** Disable reading log messages from stdout. */ 00053 void closeStdout(); 00054 00055 signals: 00056 /** Emitted when Tor prints a log message to the console */ 00057 void log(QString severity, QString message); 00058 /** Emitted when Tor fails to start, perhaps because the path to Tor was 00059 * bogus. */ 00060 void startFailed(QString errorMessage); 00061 00062 private slots: 00063 /** Called when there is data to be read from stdout */ 00064 void onReadyRead(); 00065 /** Called when an error occurs in the process. */ 00066 void onError(QProcess::ProcessError error); 00067 00068 private: 00069 /** Formats the Tor process arguments for logging. */ 00070 QString formatArguments(const QStringList args); 00071 }; 00072 00073 #endif 00074