#include <upnpcontrolthread.h>
Public Member Functions | |
UPNPControlThread (UPNPControl *control) | |
~UPNPControlThread () | |
void | stop () |
void | wakeup () |
Static Public Attributes | |
static const int | UPNPCONTROL_DISCOVER_TIMEOUT = 2000 |
Protected Member Functions | |
void | run () |
Private Member Functions | |
void | configurePorts () |
UPNPControl::UPNPError | initializeUPNP () |
UPNPControl::UPNPError | updatePort (quint16 oldPort, quint16 newPort) |
UPNPControl::UPNPError | forwardPort (quint16 port) |
UPNPControl::UPNPError | disablePort (quint16 port) |
Private Attributes | |
QTime | _upnpInitialized |
bool | _keepRunning |
UPNPControl * | _control |
QWaitCondition * | _waitCondition |
QMutex * | _waitMutex |
quint16 | _dirPort |
quint16 | _orPort |
struct UPNPUrls | urls |
struct IGDdatas | data |
char | lanaddr [16] |
Definition at line 32 of file upnpcontrolthread.h.
UPNPControlThread::UPNPControlThread | ( | UPNPControl * | control | ) |
Constructor. control will be used for retrieving the desired port forwarding state.
Definition at line 39 of file upnpcontrolthread.cpp.
References _control, _dirPort, _keepRunning, _orPort, _upnpInitialized, _waitCondition, and _waitMutex.
UPNPControlThread::~UPNPControlThread | ( | ) |
Destructor. The UPnP control thread must be stopped prior to destroying this object.
Destructor. The UPnP control thread must be stopped prior to destroying this object.
Definition at line 56 of file upnpcontrolthread.cpp.
References _waitCondition, and _waitMutex.
void UPNPControlThread::stop | ( | ) |
Terminates the UPnP control thread's run() loop.
Terminates the UPnP control thread's run() loop.
Definition at line 172 of file upnpcontrolthread.cpp.
References _keepRunning, _waitCondition, and _waitMutex.
Referenced by UPNPControl::cleanup().
void UPNPControlThread::wakeup | ( | ) |
Wakes up the UPnP control thread's run() loop.
Wakes up the UPnP control thread's run() loop.
Definition at line 194 of file upnpcontrolthread.cpp.
References _waitCondition, and _waitMutex.
Referenced by UPNPControl::setDesiredState().
void UPNPControlThread::run | ( | ) | [protected] |
Thread entry point. The thread has a main loop that periodically wakes up and updates the configured port mappings. Upon exiting, all port mappings will be removed.
Thread entry point. The thread has a main loop that periodically wakes up and updates the configured port mappings. Upon exiting, all port mappings will be removed.
Definition at line 66 of file upnpcontrolthread.cpp.
References _dirPort, _keepRunning, _orPort, _waitCondition, _waitMutex, configurePorts(), UPNPControl::IdleState, UPNPControl::instance(), UPNPControl::setState(), updatePort(), and UPNPCONTROL_MAX_WAIT_MSEC.
void UPNPControlThread::configurePorts | ( | ) | [private] |
Sets up port forwarding according the previously-configured desired state. The desired state is set using UPNPControl's setDesiredState() method.
Sets up port forwarding according the previously-configured desired state. The desired state is set using UPNPControl's setDesiredState() method.
Definition at line 105 of file upnpcontrolthread.cpp.
References _control, _dirPort, _orPort, _upnpInitialized, err(), UPNPControl::ErrorState, UPNPControl::ForwardingCompleteState, UPNPControl::getDesiredState(), UPNPControl::instance(), UPNPControl::setError(), UPNPControl::setState(), UPNPControl::Success, updatePort(), UPNPControl::UpdatingDirPortState, UPNPControl::UpdatingORPortState, and UPNPCONTROL_REINIT_MSEC.
Referenced by run().
UPNPControl::UPNPError UPNPControlThread::initializeUPNP | ( | ) | [private] |
Discovers UPnP-enabled IGDs on the network. This method will block for UPNPCONTROL_DISCOVER_TIMEOUT milliseconds.
Discovers UPnP-enabled IGDs on the network. Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch This method will block for UPNPCONTROL_DISCOVER_TIMEOUT milliseconds.
Definition at line 244 of file upnpcontrolthread.cpp.
References data, UPNPControl::DiscoverState, freeUPNPDevlist(), UPNPControl::instance(), lanaddr, UPNPControl::NoUPNPDevicesFound, UPNPControl::NoValidIGDsFound, UPNPControl::setState(), UPNPControl::Success, UPNP_GetValidIGD(), UPNPCONTROL_DISCOVER_TIMEOUT, upnpDiscover(), urls, vInfo, and vWarn.
Referenced by updatePort().
UPNPControl::UPNPError UPNPControlThread::updatePort | ( | quint16 | oldPort, | |
quint16 | newPort | |||
) | [private] |
Updates the port mapping for oldPort, changing it to newPort.
Definition at line 204 of file upnpcontrolthread.cpp.
References _upnpInitialized, disablePort(), forwardPort(), initializeUPNP(), UPNPControl::Success, vWarn, and UPNPControl::WSAStartupFailed.
Referenced by configurePorts(), and run().
UPNPControl::UPNPError UPNPControlThread::forwardPort | ( | quint16 | port | ) | [private] |
Adds a port forwarding mapping from external:port to internal:port. Returns 0 on success, or non-zero on failure.
Definition at line 275 of file upnpcontrolthread.cpp.
References UPNPControl::AddPortMappingFailed, UPNPUrls::controlURL, data, UPNPControl::GetPortMappingFailed, lanaddr, IGDdatas::servicetype, UPNPControl::Success, UPNP_AddPortMapping(), UPNP_GetSpecificPortMappingEntry(), UPNPCOMMAND_SUCCESS, urls, vInfo, and vWarn.
Referenced by updatePort().
UPNPControl::UPNPError UPNPControlThread::disablePort | ( | quint16 | port | ) | [private] |
Removes the port mapping for port. Returns 0 on success or non-zero on failure.
Removes the port mapping for port. Returns 0 on success or non-zero on failure.
Definition at line 318 of file upnpcontrolthread.cpp.
References UPNPUrls::controlURL, data, UPNPControl::DeletePortMappingFailed, IGDdatas::servicetype, UPNPControl::Success, UPNP_DeletePortMapping(), UPNPCOMMAND_SUCCESS, urls, vInfo, and vWarn.
Referenced by updatePort().
const int UPNPControlThread::UPNPCONTROL_DISCOVER_TIMEOUT = 2000 [static] |
Specifies the number of milliseconds to wait for devices to respond when attempting to discover UPnP-enabled IGDs.
Definition at line 39 of file upnpcontrolthread.h.
Referenced by UPNPControl::discoverTimeout(), and initializeUPNP().
QTime UPNPControlThread::_upnpInitialized [private] |
Time at which the UPnP state was last set.
Definition at line 76 of file upnpcontrolthread.h.
Referenced by configurePorts(), updatePort(), and UPNPControlThread().
bool UPNPControlThread::_keepRunning [private] |
True if the control thread should keep running.
Definition at line 77 of file upnpcontrolthread.h.
Referenced by run(), stop(), and UPNPControlThread().
UPNPControl* UPNPControlThread::_control [private] |
Stores desired UPnP state.
Definition at line 78 of file upnpcontrolthread.h.
Referenced by configurePorts(), and UPNPControlThread().
QWaitCondition* UPNPControlThread::_waitCondition [private] |
Used to wake up the control thread.
Definition at line 79 of file upnpcontrolthread.h.
Referenced by run(), stop(), UPNPControlThread(), wakeup(), and ~UPNPControlThread().
QMutex* UPNPControlThread::_waitMutex [private] |
Mutex around shared variables.
Definition at line 80 of file upnpcontrolthread.h.
Referenced by run(), stop(), UPNPControlThread(), wakeup(), and ~UPNPControlThread().
quint16 UPNPControlThread::_dirPort [private] |
Desired DirPort.
Definition at line 81 of file upnpcontrolthread.h.
Referenced by configurePorts(), run(), and UPNPControlThread().
quint16 UPNPControlThread::_orPort [private] |
Desired ORPort.
Definition at line 82 of file upnpcontrolthread.h.
Referenced by configurePorts(), run(), and UPNPControlThread().
struct UPNPUrls UPNPControlThread::urls [read, private] |
Definition at line 85 of file upnpcontrolthread.h.
Referenced by disablePort(), forwardPort(), and initializeUPNP().
struct IGDdatas UPNPControlThread::data [read, private] |
Definition at line 86 of file upnpcontrolthread.h.
Referenced by disablePort(), forwardPort(), and initializeUPNP().
char UPNPControlThread::lanaddr[16] [private] |
Definition at line 87 of file upnpcontrolthread.h.
Referenced by forwardPort(), and initializeUPNP().