ControlConnection Class Reference

#include <controlconnection.h>

List of all members.

Public Types

enum  Status { Disconnected, Connecting, Connected }

Signals

void connected ()
void disconnected ()
void connectFailed (QString errmsg)

Public Member Functions

 ControlConnection (TorEvents *events=0)
 ~ControlConnection ()
void connect (QHostAddress addr, quint16 port)
void cancelConnect ()
void disconnect ()
Status status ()
bool send (ControlCommand cmd, ControlReply &reply, QString *errmsg=0)
bool send (ControlCommand cmd, QString *errmsg=0)

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event)

Private Slots

void onReadyRead ()

Private Member Functions

void setStatus (Status status)
bool connect ()
void run ()

Private Attributes

ControlSocket_sock
TorEvents_events
Status _status
QHostAddress _addr
quint16 _port
QMutex _connMutex
QMutex _recvMutex
QQueue< ReceiveWaiter * > _recvQueue

Classes

class  ReceiveWaiter
class  SendCommandEvent
class  SendWaiter


Detailed Description

Definition at line 42 of file controlconnection.h.


Member Enumeration Documentation

enum ControlConnection::Status

Control connection status

Enumerator:
Disconnected  Control connection disconnected.
Connecting  Control connection attempt pending.
Connected  Control connection established.

Definition at line 48 of file controlconnection.h.


Constructor & Destructor Documentation

ControlConnection::ControlConnection ( TorEvents events = 0  ) 

Default constructor.

Definition at line 42 of file controlconnection.cpp.

References _events, and _sock.

ControlConnection::~ControlConnection (  ) 

Destructor.

Definition at line 49 of file controlconnection.cpp.


Member Function Documentation

void ControlConnection::connect ( QHostAddress  addr,
quint16  port 
)

Connect to the specified Tor control interface.

Definition at line 59 of file controlconnection.cpp.

References _addr, and _port.

Referenced by TorControl::connect().

void ControlConnection::cancelConnect (  ) 

Cancels a pending control connection to Tor.

Definition at line 117 of file controlconnection.cpp.

References _connMutex, _status, and Disconnected.

Referenced by TorControl::onStopped().

void ControlConnection::disconnect (  ) 

Disconnect from Tor's control interface.

Definition at line 109 of file controlconnection.cpp.

Referenced by TorControl::disconnect().

ControlConnection::Status ControlConnection::status (  ) 

Returns the status of the control connection.

Definition at line 125 of file controlconnection.cpp.

References _connMutex, and _status.

Referenced by connect(), TorControl::isConnected(), and TorControl::onStopped().

bool ControlConnection::send ( ControlCommand  cmd,
ControlReply reply,
QString *  errmsg = 0 
)

Sends a control command to Tor and waits for the reply.

Definition at line 141 of file controlconnection.cpp.

References _recvMutex, _recvQueue, ControlConnection::ReceiveWaiter::getResult(), ControlCommand::keyword(), and vWarn.

Referenced by TorControl::send(), and TorControl::signal().

bool ControlConnection::send ( ControlCommand  cmd,
QString *  errmsg = 0 
)

Sends a control command to Tor and does not wait for a reply.

Sends a control command to Tor. If the current thread is not the thread that actually owns the socket, the command will be pushed to the correct thread before sending.

Definition at line 173 of file controlconnection.cpp.

References _connMutex, _sock, _status, Connected, err(), ControlConnection::SendWaiter::getResult(), ControlSocket::sendCommand(), and CustomEventType::SendCommandEvent.

void ControlConnection::connected (  )  [signal]

Emitted when a control connection has been established.

Referenced by connect().

void ControlConnection::disconnected (  )  [signal]

Emitted when a control connection has been closed.

Referenced by run().

void ControlConnection::connectFailed ( QString  errmsg  )  [signal]

Emitted when a control connection fails.

Referenced by connect().

bool ControlConnection::eventFilter ( QObject *  obj,
QEvent *  event 
) [protected]

Catches events for the control socket.

Definition at line 241 of file controlconnection.cpp.

References _connMutex, _sock, ControlConnection::SendCommandEvent::command(), ControlSocket::sendCommand(), ControlConnection::SendWaiter::setResult(), and ControlConnection::SendCommandEvent::waiter().

void ControlConnection::onReadyRead (  )  [private, slot]

Called when there is data on the control socket.

Definition at line 206 of file controlconnection.cpp.

References _connMutex, _events, _recvMutex, _recvQueue, _sock, ControlReply::getStatus(), TorEvents::handleEvent(), ControlSocket::readReply(), ControlConnection::ReceiveWaiter::setResult(), ControlReply::toString(), vDebug, vInfo, and vWarn.

Referenced by run().

void ControlConnection::setStatus ( Status  status  )  [private]

Sets the control connection status.

Definition at line 133 of file controlconnection.cpp.

References _connMutex, and _status.

Referenced by connect(), and run().

bool ControlConnection::connect (  )  [private]

Connects to Tor's control interface.

Attempt to establish a connection to Tor's control interface. We will try a maximum of MAX_CONNECT_ATTEMPTS, waiting CONNECT_RETRY_DELAY between each attempt, to give slow Tors a chance to finish binding their control port.

Definition at line 72 of file controlconnection.cpp.

References _addr, _connMutex, _port, _sock, ControlSocket::connect(), CONNECT_RETRY_DELAY, connected(), Connected, connectFailed(), Connecting, Disconnected, i(), MAX_CONNECT_ATTEMPTS, setStatus(), status(), vDebug, vInfo, vNotice, and vWarn.

Referenced by run().

void ControlConnection::run (  )  [private]

Main thread implementation.

Main thread implementation. Creates and connects a control socket, then spins up an event loop.

Definition at line 276 of file controlconnection.cpp.

References _connMutex, _recvMutex, _recvQueue, _sock, connect(), Disconnected, disconnected(), onReadyRead(), ControlConnection::ReceiveWaiter::setResult(), setStatus(), and vDebug.


Member Data Documentation

ControlSocket* ControlConnection::_sock [private]

Socket used to communicate with Tor.

Definition at line 96 of file controlconnection.h.

Referenced by connect(), ControlConnection(), eventFilter(), onReadyRead(), run(), and send().

TorEvents* ControlConnection::_events [private]

Dispatches asynchronous events from Tor.

Definition at line 97 of file controlconnection.h.

Referenced by ControlConnection(), and onReadyRead().

Status ControlConnection::_status [private]

Status of the control connection.

Definition at line 98 of file controlconnection.h.

Referenced by cancelConnect(), send(), setStatus(), and status().

QHostAddress ControlConnection::_addr [private]

Address of Tor's control interface.

Definition at line 99 of file controlconnection.h.

Referenced by connect().

quint16 ControlConnection::_port [private]

Port of Tor's control interface.

Definition at line 100 of file controlconnection.h.

Referenced by connect().

QMutex ControlConnection::_connMutex [private]

Mutex around the control socket.

Definition at line 101 of file controlconnection.h.

Referenced by cancelConnect(), connect(), eventFilter(), onReadyRead(), run(), send(), setStatus(), and status().

QMutex ControlConnection::_recvMutex [private]

Mutex around the queue of ReceiveWaiters.

Definition at line 102 of file controlconnection.h.

Referenced by onReadyRead(), run(), and send().

QQueue<ReceiveWaiter *> ControlConnection::_recvQueue [private]

Objects waiting for a reply.

Definition at line 122 of file controlconnection.h.

Referenced by onReadyRead(), run(), and send().


The documentation for this class was generated from the following files:
Generated on Wed Sep 5 15:49:29 2007 for Vidalia by  doxygen 1.5.3