torprocess.h

Go to the documentation of this file.
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 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief Starts and stops a Tor process
00026  */
00027 
00028 #ifndef _TORPROCESS_H
00029 #define _TORPROCESS_H
00030 
00031 #include <QProcess>
00032 #include <QFileInfo>
00033 #include <QVariant>
00034 #include <QMap>
00035 #include <QDateTime>
00036 
00037 
00038 class TorProcess : public QProcess
00039 {
00040   Q_OBJECT
00041 
00042 public:
00043   /** Default constructor. */
00044   TorProcess();
00045 
00046   /** Start the Tor process */
00047   void start(QString app, QString args);
00048   /** Stop the Tor process */
00049   bool stop(QString *errmsg = 0);
00050 
00051 
00052   /** Return the Tor process's PID (workaround for some Windows funkiness) */
00053   quint64 pid();
00054 
00055   /** Enable reading log messages from stdout. */
00056   void openStdout();
00057   /** Disable reading log messages from stdout. */
00058   void closeStdout();
00059 
00060 signals:
00061   /** Emitted when Tor prints a log message to the console */
00062   void log(QString severity, QString message);
00063   /** Emitted when Tor fails to start, perhaps because the path to Tor was
00064    * bogus. */
00065   void startFailed(QString errorMessage);
00066   
00067 private slots:
00068   /** Called when there is data to be read from stdout */
00069   void onReadyRead();
00070   /** Called when an error occurs in the process. */
00071   void onError(QProcess::ProcessError error);
00072 
00073 private:
00074   /** Status of logging to stdout. */
00075   enum LogState {
00076     Open,     /**< stdout logs enabled. */
00077     Closing,  /**< stdout in the process of closing. */
00078     Closed    /**< stdout logs closed. */
00079   };
00080   /** Current state of logging on stdout. */
00081   LogState _logState;
00082   /** Timestamp of when stdout logs closed. */
00083   QDateTime _logCloseTime;
00084 };
00085 
00086 #endif
00087 

Generated on Mon Oct 23 20:08:16 2006 for Vidalia by  doxygen 1.5.0