Logo Search packages:      
Sourcecode: vidalia version File versions


**  This file is part of Vidalia, and is subject to the license terms in the
**  LICENSE file, found in the top level directory of this distribution. If 
**  you did not receive the LICENSE file with this file, you may obtain it
**  from the Vidalia source package distributed by the Vidalia Project at
**  http://www.vidalia-project.net/. No part of Vidalia, including this file,
**  may be copied, modified, propagated, or distributed except according to
**  the terms described in the LICENSE file.

** \file upnpcontrol.cpp
** \version $Id: upnpcontrol.cpp 2638 2008-06-01 23:42:53Z edmanm $
** \brief Singleton object for interacting with UPNP device

#include "upnpcontrol.h"

#include <QMutex>
#include <QMetaType>

#ifdef Q_OS_WIN32
#include <winsock2.h>

#include "upnpcontrolthread.h"

/** UPNPControl singleton instance. */
UPNPControl* UPNPControl::_instance = 0;

/** Returns a pointer to this object's singleton instance. */
UPNPControl* UPNPControl::instance()
  if (0 == _instance)
    _instance = new UPNPControl;
  return _instance;

/** Constructor. Initializes and starts a thread in which all blocking UPnP
 * operations will be performed. */
  _forwardedORPort = 0;
  _forwardedDirPort = 0;
  _error = UnknownError;
  _state = IdleState;

  _mutex = new QMutex();
  _controlThread = new UPNPControlThread(this);

/** Destructor. cleanup() should be called before the object is destroyed.
 * \sa cleanup()
  delete _mutex;
  delete _controlThread;

/** Terminates the UPnP control thread and frees memory allocated to this
 * object's singleton instance. */
  delete _instance;
  _instance = 0;

/** Sets <b>desiredDirPort</b> and <b>desiredOrPort</b> to the currently
 * forwarded DirPort and ORPort values. */
UPNPControl::getDesiredState(quint16 *desiredDirPort, quint16 *desiredOrPort)
  *desiredDirPort = _forwardedDirPort;
  *desiredOrPort = _forwardedORPort;

/** Sets the desired DirPort and ORPort port mappings to <b>desiredDirPort</b>
 * and <b>desiredOrPort</b>, respectively. */
UPNPControl::setDesiredState(quint16 desiredDirPort, quint16 desiredOrPort)
  _forwardedDirPort = desiredDirPort;
  _forwardedORPort = desiredOrPort;

/** Sets the most recent UPnP-related error to <b>error</b> and emits the
 * error() signal. */
UPNPControl::setError(UPNPError upnpError)
  _error = upnpError;
  emit error(upnpError);

/** Sets the current UPnP state to <b>state</b> and emits the stateChanged()
 * signal. */
UPNPControl::setState(UPNPState state)
  _state = state;

  emit stateChanged(state);

/** Returns the type of error that occurred last. */
UPNPControl::error() const
  QMutexLocker locker(_mutex);
  return _error;

/** Returns a QString describing the type of error that occurred last. */
UPNPControl::errorString() const
  UPNPError error = this->error();

  switch (error) {
    case Success:
      return tr("Success");
    case NoUPNPDevicesFound:
      return tr("No UPnP-enabled devices found");
    case NoValidIGDsFound:
      return tr("No valid UPnP-enabled Internet gateway devices found");
    case WSAStartupFailed:
      return tr("WSAStartup failed");
    case AddPortMappingFailed:
      return tr("Failed to add a port mapping");
    case GetPortMappingFailed:
      return tr("Failed to retrieve a port mapping");
    case DeletePortMappingFailed:
      return tr("Failed to remove a port mapping");
      return tr("Unknown error");

/** Returns the number of milliseconds to wait for devices to respond
 * when attempting to discover UPnP-enabled IGDs. */
UPNPControl::discoverTimeout() const

Generated by  Doxygen 1.6.0   Back to index