#include "portforwarder.h" #include #include "core/boundfuturewatcher.h" PortForwarder::PortForwarder(QObject* parent) : QObject(parent) { } void PortForwarder::Init() { QFuture future = QtConcurrent::run(this, &PortForwarder::Init); QFutureWatcher* watcher = new QFutureWatcher(this); watcher->setFuture(future); connect(watcher, SIGNAL(finished()), SLOT(InitFinished())); } void PortForwarder::InitSync() { portfwd_.init(10000); } void PortForwarder::InitFinished() { QFutureWatcher* watcher = dynamic_cast*>(sender()); Q_ASSERT(watcher); watcher->deleteLater(); emit(InitFinished(watcher->result())); } void PortForwarder::AddPortMapping(quint16 port) { QFuture future = QtConcurrent::run( this, &PortForwarder::AddPortMappingSync, port); BoundFutureWatcher* watcher = new BoundFutureWatcher(this); watcher->setFuture(future); connect(watcher, SIGNAL(finished()). SLOT(AddPortMappingFinished())); } bool PortForwarder::AddPortMappingSync(quint16 port) { return portfwd_.add(port); } void PortForwarder::AddPortMappingFinished() { BoundFutureWatcher* watcher = dynamic_cast*>(sender()); Q_ASSERT(watcher); watcher->deleteLater(); if (watcher->result()) emit(PortMappingAdded(watcher->data())); } void PortForwarder::RemovePortMapping(quint16 port) { QFuture future = QtConcurrent::run( this, &PortForwarder::RemovePortMappingSync, port); BoundFutureWatcher* watcher = new BoundFutureWatcher(this); watcher->setFuture(future); connect(watcher, SIGNAL(finished()). SLOT(RemovePortMappingFinished())); } bool PortForwarder::RemovePortMappingSync(quint16 port) { return portfwd_.remove(port); } void PortForwarder::RemovePortMappingFinished() { BoundFutureWatcher* watcher = dynamic_cast*>(sender()); Q_ASSERT(watcher); watcher->deleteLater(); if (watcher->result()) emit(PortMappingRemoveed(watcher->data())); }