Vidalia  0.3.1
UPNPControl.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If
4 ** you did not receive the LICENSE file with this file, you may obtain it
5 ** from the Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file UPNPControl.h
13 ** \brief Singleton object for interacting with UPNP device
14 */
15 
16 #ifndef _UPNPCONTROL_H
17 #define _UPNPCONTROL_H
18 
19 #include <QObject>
20 #include <QMutex>
21 
22 /* Forward declaration to make it build */
23 class UPNPControlThread;
24 
25 
26 class UPNPControl : public QObject
27 {
28  Q_OBJECT
29 
30 public:
31  /** UPnP-related error values. */
32  enum UPNPError {
41  };
42  /** UPnP port forwarding state. */
43  enum UPNPState {
50  };
51 
52  /** Returns a pointer to this object's singleton instance. */
53  static UPNPControl* instance();
54  /** Terminates the UPnP control thread and frees memory allocated to this
55  * object's singleton instance. */
56  static void cleanup();
57  /** Sets <b>desiredDirPort</b> and <b>desiredOrPort</b> to the currently
58  * forwarded DirPort and ORPort values. */
59  void getDesiredState(quint16 *desiredDirPort, quint16 *desiredOrPort);
60  /** Sets the desired DirPort and ORPort port mappings to
61  * <b>desiredDirPort</b> and <b>desiredOrPort</b>, respectively. */
62  void setDesiredState(quint16 desiredDirPort, quint16 desiredOrPort);
63 
64  /** Returns the type of error that occurred last. */
65  UPNPError error() const;
66  /** Returns a QString describing the type of error that occurred last. */
67  QString errorString() const;
68 
69  /** Returns the number of milliseconds to wait for devices to respond
70  * when attempting to discover UPnP-enabled IGDs. */
71  int discoverTimeout() const;
72 
73 signals:
74  /** Emitted when the UPnP control thread status changes. */
76 
77  /** Emitted when a UPnP error occurs. */
79 
80 protected:
81  /** Constructor. Initializes and starts a thread in which all blocking UPnP
82  * operations will be performed. */
83  UPNPControl();
84  /** Destructor. cleanup() should be called before the object is destroyed. */
85  ~UPNPControl();
86 
87  /** Sets the most recent UPnP-related error to <b>error</b> and emits the
88  * error() signal.
89  * \sa error
90  */
91  void setError(UPNPError error);
92 
93  /** Sets the current UPnP state to <b>state</b> and emits the stateChanged()
94  * signal.
95  * \sa stateChanged
96  */
97  void setState(UPNPState state);
98 
99 private:
100  static UPNPControl* _instance; /**< UPNPControl singleton instance. */
101 
102  quint16 _forwardedORPort; /**< Currently forwarded ORPort. */
103  quint16 _forwardedDirPort; /**< Currently forwarded DirPort. */
104  QMutex* _mutex; /**< Mutex around variables shared with UPNPControlThread. */
105  UPNPError _error; /**< Most recent UPNP error. */
106  UPNPState _state; /**< Current UPNP status. */
107 
108  friend class UPNPControlThread;
109  UPNPControlThread* _controlThread; /**< Thread used for UPnP operations. */
110 };
111 
112 #endif
113 
UPNPControl::_controlThread
UPNPControlThread * _controlThread
Definition: UPNPControl.h:109
UPNPControl::AddPortMappingFailed
@ AddPortMappingFailed
Definition: UPNPControl.h:37
UPNPControl::instance
static UPNPControl * instance()
Definition: UPNPControl.cpp:31
UPNPControl::_mutex
QMutex * _mutex
Definition: UPNPControl.h:104
UPNPControl::ForwardingCompleteState
@ ForwardingCompleteState
Definition: UPNPControl.h:49
UPNPControl::_state
UPNPState _state
Definition: UPNPControl.h:106
UPNPControl::setError
void setError(UPNPError error)
Definition: UPNPControl.cpp:102
UPNPControl::NoUPNPDevicesFound
@ NoUPNPDevicesFound
Definition: UPNPControl.h:34
UPNPControl::UPNPState
UPNPState
Definition: UPNPControl.h:43
UPNPControl::UpdatingDirPortState
@ UpdatingDirPortState
Definition: UPNPControl.h:48
UPNPControl::UnknownError
@ UnknownError
Definition: UPNPControl.h:40
UPNPControl::IdleState
@ IdleState
Definition: UPNPControl.h:44
UPNPControl::discoverTimeout
int discoverTimeout() const
Definition: UPNPControl.cpp:160
UPNPControl::_forwardedDirPort
quint16 _forwardedDirPort
Definition: UPNPControl.h:103
UPNPControl::errorString
QString errorString() const
Definition: UPNPControl.cpp:133
UPNPControl::setState
void setState(UPNPState state)
Definition: UPNPControl.cpp:114
UPNPControl::GetPortMappingFailed
@ GetPortMappingFailed
Definition: UPNPControl.h:38
UPNPControl::Success
@ Success
Definition: UPNPControl.h:33
UPNPControl::_instance
static UPNPControl * _instance
Definition: UPNPControl.h:100
UPNPControl::cleanup
static void cleanup()
Definition: UPNPControl.cpp:68
UPNPControl::NoValidIGDsFound
@ NoValidIGDsFound
Definition: UPNPControl.h:35
UPNPControl::UPNPError
UPNPError
Definition: UPNPControl.h:32
UPNPControl::ErrorState
@ ErrorState
Definition: UPNPControl.h:45
UPNPControl::UPNPControl
UPNPControl()
Definition: UPNPControl.cpp:42
UPNPControl::UpdatingORPortState
@ UpdatingORPortState
Definition: UPNPControl.h:47
UPNPControl::DeletePortMappingFailed
@ DeletePortMappingFailed
Definition: UPNPControl.h:39
UPNPControl::WSAStartupFailed
@ WSAStartupFailed
Definition: UPNPControl.h:36
UPNPControl::DiscoverState
@ DiscoverState
Definition: UPNPControl.h:46
UPNPControl::error
UPNPError error() const
Definition: UPNPControl.cpp:125
UPNPControl::_forwardedORPort
quint16 _forwardedORPort
Definition: UPNPControl.h:102
UPNPControl::getDesiredState
void getDesiredState(quint16 *desiredDirPort, quint16 *desiredOrPort)
Definition: UPNPControl.cpp:78
UPNPControl::_error
UPNPError _error
Definition: UPNPControl.h:105
UPNPControl::stateChanged
void stateChanged(UPNPControl::UPNPState state)
UPNPControl::setDesiredState
void setDesiredState(quint16 desiredDirPort, quint16 desiredOrPort)
Definition: UPNPControl.cpp:89
UPNPControl::~UPNPControl
~UPNPControl()
Definition: UPNPControl.cpp:59
UPNPControl
Definition: UPNPControl.h:26
UPNPControlThread
Definition: UPNPControlThread.h:33