[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2631: Add a stateChanged() signal that can be used to provide upda (in vidalia: . branches/upnp/src/vidalia/config)



Author: edmanm
Date: 2008-05-31 20:52:06 -0400 (Sat, 31 May 2008)
New Revision: 2631

Modified:
   vidalia/
   vidalia/branches/upnp/src/vidalia/config/upnpcontrol.cpp
   vidalia/branches/upnp/src/vidalia/config/upnpcontrol.h
Log:
 r397@thebe:  edmanm | 2008-05-31 20:44:02 -0400
 Add a stateChanged() signal that can be used to provide updates on the
 progress of the UPnP control thread. Also register the UPNPError and UPNPState
 enums so they can be used in signals.



Property changes on: vidalia
___________________________________________________________________
 svk:merge ticket from /local/vidalia [r397] on 45a62a8a-8088-484c-baad-c7b3e776dd32

Modified: vidalia/branches/upnp/src/vidalia/config/upnpcontrol.cpp
===================================================================
--- vidalia/branches/upnp/src/vidalia/config/upnpcontrol.cpp	2008-06-01 00:52:04 UTC (rev 2630)
+++ vidalia/branches/upnp/src/vidalia/config/upnpcontrol.cpp	2008-06-01 00:52:06 UTC (rev 2631)
@@ -17,6 +17,7 @@
 #include "upnpcontrol.h"
 
 #include <QMutex>
+#include <QMetaType>
 
 #ifdef Q_OS_WIN32
 #include <winsock2.h>
@@ -42,6 +43,11 @@
   _forwardedORPort = 0;
   _forwardedDirPort = 0;
   _error = UnknownError;
+  _state = IdleState;
+  
+  qRegisterMetaType<UPNPControl::UPNPError>("UPNPControl::UPNPError");
+  qRegisterMetaType<UPNPControl::UPNPState>("UPNPControl::UPNPState");
+
   mutex = new QMutex();
   controlThread = new UPNPControlThread(this);
   controlThread->start();
@@ -75,7 +81,6 @@
   *desiredDirPort = _forwardedDirPort;
   *desiredOrPort = _forwardedORPort;
   mutex->unlock();
-  controlThread->wakeup();
 }
 
 /** Sets the desired DirPort and ORPort port mappings to <b>desiredDirPort</b>
@@ -90,6 +95,8 @@
   controlThread->wakeup();
 }
 
+/** Sets the most recent UPnP-related error to <b>error</b> and emits the
+ * error() signal. */
 void
 UPNPControl::setError(UPNPError upnpError)
 {
@@ -100,6 +107,18 @@
   emit error(upnpError);
 }
 
+/** Sets the current UPnP state to <b>state</b> and emits the stateChanged()
+ * signal. */
+void
+UPNPControl::setState(UPNPState state)
+{
+  mutex->lock();
+  _state = state;
+  mutex->unlock();
+
+  emit stateChanged(state);
+}
+
 /** Returns the type of error that occurred last. */
 UPNPControl::UPNPError
 UPNPControl::error() const

Modified: vidalia/branches/upnp/src/vidalia/config/upnpcontrol.h
===================================================================
--- vidalia/branches/upnp/src/vidalia/config/upnpcontrol.h	2008-06-01 00:52:04 UTC (rev 2630)
+++ vidalia/branches/upnp/src/vidalia/config/upnpcontrol.h	2008-06-01 00:52:06 UTC (rev 2631)
@@ -40,6 +40,15 @@
     DeletePortMappingFailed,
     UnknownError
   };
+  /** UPnP port forwarding state. */
+  enum UPNPState {
+    IdleState,
+    ErrorState, 
+    DiscoverState,
+    UpdatingORPortState,
+    UpdatingDirPortState,
+    ForwardingCompleteState
+  };
 
   /** Returns a pointer to this object's singleton instance. */
   static UPNPControl* Instance();
@@ -61,8 +70,11 @@
   /** Returns the number of milliseconds to wait for devices to respond
    * when attempting to discover UPnP-enabled IGDs. */
   int discoverTimeout() const;
+
+signals:
+  /** Emitted when the UPnP control thread status changes. */
+  void stateChanged(UPNPControl::UPNPState state);
   
-signals:
   /** Emitted when a UPnP error occurs. */
   void error(UPNPControl::UPNPError error);
  
@@ -73,8 +85,17 @@
   /** Destructor. cleanup() should be called before the object is destroyed. */
   ~UPNPControl();
 
-  /** Sets the most recent UPnP-related error to <b>error</b>. */
+  /** Sets the most recent UPnP-related error to <b>error</b> and emits the
+   * error() signal.
+   * \sa error
+   */
   void setError(UPNPError error);
+  
+  /** Sets the current UPnP state to <b>state</b> and emits the stateChanged()
+   * signal.
+   * \sa stateChanged
+   */
+  void setState(UPNPState state);
 
 private:
   static UPNPControl* pInstance; /**< UPNPControl singleton instance. */
@@ -83,6 +104,7 @@
   quint16 _forwardedDirPort; /**< Currently forwarded DirPort. */
   QMutex *mutex; /**< Mutex around variables shared with UPNPControlThread. */
   UPNPError _error; /**< Most recent UPNP error. */
+  UPNPState _state; /**< Current UPNP status. */
 
   friend class UPNPControlThread;
   UPNPControlThread *controlThread; /**< Thread used for UPnP operations. */