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 1238 2006-09-25 17:50:57Z 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 
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   };
00061  
00062   /** Default Constructor */
00063   TorEvents();
00064 
00065   /** Adds an event and interested object to the event list */
00066   void add(TorEvent event, QObject *obj);
00067   /** Removes an event and object from the event list */
00068   void remove(TorEvent event, QObject *obj);
00069   /** Returns true if an event has any registered handlers */
00070   bool contains(TorEvent event);
00071   /** Returns the list of events in which we're interested */
00072   QList<TorEvent> eventList();
00073 
00074   /** Parses an event message and emits the proper signal */
00075   void handleEvent(ControlReply reply);
00076 
00077   /** Dispatches a given event to all its handler targets. */
00078   void dispatch(TorEvent e, QEvent *event);
00079   
00080   /** Converts an Event to a string */
00081   static QString toString(TorEvents::TorEvent e);
00082   /** Converts a log severity to an event */
00083   static TorEvent toTorEvent(LogEvent::Severity severity);
00084 
00085 
00086 private:
00087   /** Stores a mapping of Tor events to a list of the objects interested in
00088    * hearing about those events. */
00089   QMultiHash<TorEvent, QObject*> _eventList;
00090   
00091   /** Parses the event type from the event message */
00092   static TorEvent parseEventType(ReplyLine line);
00093   /** Converts a string to an Event */
00094   static TorEvent toTorEvent(QString event);
00095   
00096   /** Handle a bandwidth update event */
00097   void handleBandwidthUpdate(ReplyLine line);
00098   /** Handle a circuit status event */
00099   void handleCircuitStatus(ReplyLine line);
00100   /** Handle a stream status event */
00101   void handleStreamStatus(ReplyLine line);
00102   /** Handle a log message event */
00103   void handleLogMessage(ReplyLine line);
00104   /** Handle an OR connection status event. */
00105   void handleOrConnStatus(ReplyLine line);
00106   /** Handles a new list of descriptors event. */
00107   void handleNewDescriptor(ReplyLine line);
00108 };
00109 
00110 #endif
00111 

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