torevents.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.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to
00008 **  the terms described in the LICENSE file.
00009 */
00010 
00011 /* 
00012 ** \file torevents.h
00013 ** \version $Id: torevents.h 2780 2008-06-21 21:48:32Z edmanm $
00014 ** \brief Parses and dispatches events from Tor
00015 */
00016 
00017 #ifndef _TOREVENTS_H
00018 #define _TOREVENTS_H
00019 
00020 #include <QObject>
00021 #include <QMultiHash>
00022 #include <QList>
00023 
00024 #include "eventtype.h"
00025 #include "logevent.h"
00026 #include "bandwidthevent.h"
00027 #include "circuitevent.h"
00028 #include "streamevent.h"
00029 #include "orconnevent.h"
00030 #include "newdescriptorevent.h"
00031 #include "addressmapevent.h"
00032 #include "statusevent.h"
00033 #include "controlreply.h"
00034 
00035 
00036 class TorEvents : public QObject
00037 {
00038   Q_OBJECT
00039 
00040 public:
00041   /** Asynchronous events sent from Tor to the controller */
00042   enum TorEvent {
00043     Unknown,
00044     Bandwidth,
00045     LogDebug, LogInfo, LogNotice, LogWarn, LogError,
00046     CircuitStatus,
00047     StreamStatus,
00048     OrConnStatus,
00049     NewDescriptor,
00050     AddressMap,
00051     GeneralStatus,
00052     ClientStatus,
00053     ServerStatus
00054   };
00055  
00056   /** Default Constructor */
00057   TorEvents();
00058 
00059   /** Adds an event and interested object to the event list */
00060   void add(TorEvent event, QObject *obj);
00061   /** Removes <b>obj</b> from the list of target objects for event 
00062    * <b>e</b>. */
00063   void remove(TorEvent event, QObject *obj);
00064   /** Returns true if an event has any registered handlers */
00065   bool contains(TorEvent event);
00066   /** Returns the list of events in which we're interested */
00067   QList<TorEvent> eventList();
00068 
00069   /** Parses an event message and emits the proper signal */
00070   void handleEvent(const ControlReply &reply);
00071 
00072   /** Dispatches a given event to all its handler targets. */
00073   void dispatch(TorEvent e, QEvent *event);
00074   
00075   /** Converts an Event to a string */
00076   static QString toString(TorEvents::TorEvent e);
00077   /** Converts a log severity to an event */
00078   static TorEvent toTorEvent(LogEvent::Severity severity);
00079 
00080 
00081 private:
00082   /** Stores a mapping of Tor events to a list of the objects interested in
00083    * hearing about those events. */
00084   QMultiHash<TorEvent, QObject*> _eventList;
00085   
00086   /** Parses the event type from the event message */
00087   static TorEvent parseEventType(const ReplyLine &line);
00088   /** Converts a string to an Event */
00089   static TorEvent toTorEvent(const QString &event);
00090   
00091   /** Handle a bandwidth update event */
00092   void handleBandwidthUpdate(const ReplyLine &line);
00093   /** Handle a circuit status event */
00094   void handleCircuitStatus(const ReplyLine &line);
00095   /** Handle a stream status event */
00096   void handleStreamStatus(const ReplyLine &line);
00097   /** Handle a log message event */
00098   void handleLogMessage(const ReplyLine &line);
00099   /** Handle an OR connection status event. */
00100   void handleOrConnStatus(const ReplyLine &line);
00101   /** Handles a new list of descriptors event. */
00102   void handleNewDescriptor(const ReplyLine &line);
00103   /** Handles a new or updated address map event. */
00104   void handleAddressMap(const ReplyLine &line);
00105   /** Handles a Tor status event. */
00106   void handleStatusEvent(TorEvent type, const ReplyLine &line);
00107   
00108   /** Parses and posts a Tor client status event. */
00109   void dispatchClientStatusEvent(tc::Severity severity,
00110                                  const QString &action,
00111                                  const QHash<QString,QString> &args);
00112   /** Parses and posts a Tor server status event. */
00113   void dispatchServerStatusEvent(tc::Severity severity,
00114                                  const QString &action,
00115                                  const QHash<QString,QString> &args);
00116   /** Parses and posts a general Tor status event. */
00117   void dispatchGeneralStatusEvent(tc::Severity severity,
00118                                   const QString &action,
00119                                   const QHash<QString,QString> &args);
00120 };
00121 
00122 #endif
00123 

Generated on Wed Nov 26 21:03:58 2008 for Vidalia by  doxygen 1.5.6