torevents.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 torevents.h
00024  * \version $Id: torevents.h 1797 2007-07-03 01:30:35Z edmanm $
00025  * \brief Parses and dispatches events from Tor
00026  */
00027 
00028 #ifndef _TOREVENTS_H
00029 #define _TOREVENTS_H
00030 
00031 #include <QObject>
00032 #include <QMultiHash>
00033 #include <QList>
00034 
00035 #include "eventtype.h"
00036 #include "logevent.h"
00037 #include "bandwidthevent.h"
00038 #include "circuitevent.h"
00039 #include "streamevent.h"
00040 #include "orconnevent.h"
00041 #include "newdescriptorevent.h"
00042 #include "addressmapevent.h"
00043 #include "controlreply.h"
00044 
00045 
00046 class TorEvents : public QObject
00047 {
00048   Q_OBJECT
00049 
00050 public:
00051   /** Asynchronous events sent from Tor to the controller */
00052   enum TorEvent {
00053     Unknown,
00054     Bandwidth,
00055     LogDebug, LogInfo, LogNotice, LogWarn, LogError,
00056     CircuitStatus,
00057     StreamStatus,
00058     OrConnStatus,
00059     NewDescriptor,
00060     AddressMap
00061   };
00062  
00063   /** Default Constructor */
00064   TorEvents();
00065 
00066   /** Adds an event and interested object to the event list */
00067   void add(TorEvent event, QObject *obj);
00068   /** Removes <b>obj</b> from the list of target objects for event 
00069    * <b>e</b>. */
00070   void remove(TorEvent event, QObject *obj);
00071   /** Returns true if an event has any registered handlers */
00072   bool contains(TorEvent event);
00073   /** Returns the list of events in which we're interested */
00074   QList<TorEvent> eventList();
00075 
00076   /** Parses an event message and emits the proper signal */
00077   void handleEvent(ControlReply reply);
00078 
00079   /** Dispatches a given event to all its handler targets. */
00080   void dispatch(TorEvent e, QEvent *event);
00081   
00082   /** Converts an Event to a string */
00083   static QString toString(TorEvents::TorEvent e);
00084   /** Converts a log severity to an event */
00085   static TorEvent toTorEvent(LogEvent::Severity severity);
00086 
00087 
00088 private:
00089   /** Stores a mapping of Tor events to a list of the objects interested in
00090    * hearing about those events. */
00091   QMultiHash<TorEvent, QObject*> _eventList;
00092   
00093   /** Parses the event type from the event message */
00094   static TorEvent parseEventType(ReplyLine line);
00095   /** Converts a string to an Event */
00096   static TorEvent toTorEvent(QString event);
00097   
00098   /** Handle a bandwidth update event */
00099   void handleBandwidthUpdate(ReplyLine line);
00100   /** Handle a circuit status event */
00101   void handleCircuitStatus(ReplyLine line);
00102   /** Handle a stream status event */
00103   void handleStreamStatus(ReplyLine line);
00104   /** Handle a log message event */
00105   void handleLogMessage(ReplyLine line);
00106   /** Handle an OR connection status event. */
00107   void handleOrConnStatus(ReplyLine line);
00108   /** Handles a new list of descriptors event. */
00109   void handleNewDescriptor(ReplyLine line);
00110   /** Handles a new or updated address map event. */
00111   void handleAddressMap(ReplyLine line);
00112 };
00113 
00114 #endif
00115 

Generated on Wed Sep 5 15:49:28 2007 for Vidalia by  doxygen 1.5.3