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