Show
Ignore:
Timestamp:
01/15/06 17:36:23 (3 years ago)
Author:
edmanm
Message:

Check in a bulk of the asynchronous event handling code. Some work remains.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/control/torcontrol.h

    r84 r90  
    3030#include "controlconnection.h" 
    3131#include "torprocess.h" 
     32#include "messagepump.h" 
     33#include "torevents.h" 
     34 
    3235 
    3336class TorControl : public QObject 
     
    3841  /** Signals that can be sent by the controller */ 
    3942  enum Signal { 
    40     Reload, 
    41     Shutdown, 
    42     Dump, 
    43     Debug, 
    44     Halt 
     43    SignalReload, SignalShutdown, SignalDump, SignalDebug, SignalHalt 
    4544  }; 
    46    
     45  
     46 
    4747  /** Default constructor */ 
    4848  TorControl(); 
    49    
    5049  /** Default destructor */ 
    5150  ~TorControl(); 
     
    5352  /** Start the Tor process */ 
    5453  bool start(QString *errmsg = 0); 
    55  
    5654  /** Stop the Tor process */ 
    5755  bool stop(QString *errmsg = 0); 
    58  
    5956  /** Detect if the Tor process is running */ 
    6057  bool isRunning(); 
     
    6259  /** Connect to Tor's control socket */ 
    6360  bool connect(QString *errmsg = 0); 
    64  
    6561  /** Disconnect from Tor's control socket */ 
    6662  void disconnect(); 
    67  
    6863  /** Check if we're connected to Tor's control socket */ 
    6964  bool isConnected(); 
     
    7469  /** Sends a GETINFO message to Tor based on the given keys */ 
    7570  bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0); 
    76  
    7771  /** Sends a GETINFO message for a single info value to Tor */ 
    7872  bool getInfo(QString key, QString &val, QString *errmsg = 0); 
     
    8478  QString getTorVersion(QString *errmsg = 0); 
    8579 
     80  /** Register another event of interest with Tor */ 
     81  bool addEvent(TorEvents::Event e, QString *errmsg = 0); 
     82  /** Remove a previously registered event */ 
     83  bool removeEvent(TorEvents::Event e, QString *errmsg = 0); 
     84 
    8685 
    8786signals: 
    8887  /** Emitted when the Tor process has started */ 
    8988  void started(); 
    90    
    9189  /** Emitted when the Tor process has stopped */ 
    9290  void stopped(int exitCode, QProcess::ExitStatus exitStatus); 
    93  
    9491  /** Emitted when the controller has connected to Tor */ 
    9592  void connected(); 
    96  
    9793  /** Emitted when the controller has disconnected from Tor */ 
    9894  void disconnected(); 
     95  /** Emitted when a bandwidth update is received from Tor */ 
     96  void bandwidth(quint64 bytesIn, quint64 bytesOut); 
     97  /** Emitted when a log message is received from Tor */ 
     98  void log(TorEvents::LogSeverity severity, QString msg); 
     99  /** Emitted when a circuit status event is received from Tor */ 
     100  void circuit(quint64 circId, TorEvents::CircuitStatus status, QString path); 
     101  /** Emitted when a stream status event is received from Tor */ 
     102  void stream(quint64 streamId, TorEvents::StreamStatus status, 
     103              quint64 circId, QString target); 
    99104 
    100  
     105   
    101106private: 
    102107  /** Instantiates a socket used to connect to Tor's control port */ 
     
    104109  /** Manages and monitors the Tor process */ 
    105110  TorProcess _torProcess;   
     111  /** Handles sending and receiving messages from Tor over the control 
     112   * connection */ 
     113  MessagePump *_messages; 
     114  /** Dispatches asynchronous events sent by Tor */ 
     115  TorEvents _events; 
     116  /** Keep track of which events we're interested in */ 
     117  QStringList _eventList; 
    106118 
     119  /** Register events of interest with Tor */ 
     120  bool registerEvents(QString *errmsg); 
     121  /** Sends a message to Tor and discards the response */ 
     122  bool send(ControlCommand cmd, QString *errmsg = 0); 
     123  /** Send a message to Tor and read the response */ 
     124  bool send(ControlCommand cmd, ControlReply &reply, QString *errmsg = 0); 
     125   
     126   
    107127/* The slots below simply relay signals from the appropriate member objects */ 
    108128private slots: 
     
    111131  void onConnected(); 
    112132  void onDisconnected(); 
     133  void onBandwidthUpdate(quint64 bytesIn, quint64 bytesOut); 
     134  void onLogMessage(TorEvents::LogSeverity severity, QString msg); 
     135  void onCircuitStatus(quint64 circId,  
     136                       TorEvents::CircuitStatus status, QString path); 
     137  void onStreamStatus(quint64 streamId, TorEvents::StreamStatus status, 
     138                      quint64 circId, QString target); 
    113139}; 
    114140