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 */
24
25
26class UPNPControl : public QObject
27{
28 Q_OBJECT
29
30public:
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
73signals:
74 /** Emitted when the UPnP control thread status changes. */
76
77 /** Emitted when a UPnP error occurs. */
79
80protected:
81 /** Constructor. Initializes and starts a thread in which all blocking UPnP
82 * operations will be performed. */
84 /** Destructor. cleanup() should be called before the object is destroyed. */
86
87 /** Sets the most recent UPnP-related error to <b>error</b> and emits the
88 * error() signal.
89 * \sa error
90 */
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
99private:
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
static void cleanup()
Definition: UPNPControl.cpp:68
void setState(UPNPState state)
void setDesiredState(quint16 desiredDirPort, quint16 desiredOrPort)
Definition: UPNPControl.cpp:89
quint16 _forwardedORPort
Definition: UPNPControl.h:102
UPNPError error() const
QString errorString() const
static UPNPControl * instance()
Definition: UPNPControl.cpp:31
void stateChanged(UPNPControl::UPNPState state)
UPNPState _state
Definition: UPNPControl.h:106
void getDesiredState(quint16 *desiredDirPort, quint16 *desiredOrPort)
Definition: UPNPControl.cpp:78
int discoverTimeout() const
QMutex * _mutex
Definition: UPNPControl.h:104
quint16 _forwardedDirPort
Definition: UPNPControl.h:103
void setError(UPNPError error)
@ AddPortMappingFailed
Definition: UPNPControl.h:37
@ GetPortMappingFailed
Definition: UPNPControl.h:38
@ NoUPNPDevicesFound
Definition: UPNPControl.h:34
@ DeletePortMappingFailed
Definition: UPNPControl.h:39
@ NoValidIGDsFound
Definition: UPNPControl.h:35
@ WSAStartupFailed
Definition: UPNPControl.h:36
void error(UPNPControl::UPNPError error)
@ UpdatingDirPortState
Definition: UPNPControl.h:48
@ UpdatingORPortState
Definition: UPNPControl.h:47
@ ForwardingCompleteState
Definition: UPNPControl.h:49
UPNPError _error
Definition: UPNPControl.h:105
UPNPControlThread * _controlThread
Definition: UPNPControl.h:109
static UPNPControl * _instance
Definition: UPNPControl.h:100