diff options
author | Björn Hagemeister | 2014-08-25 18:08:15 +0200 |
---|---|---|
committer | Björn Hagemeister | 2014-08-25 18:08:15 +0200 |
commit | 6cb63e7e30906f428c601ba00fd15c14e07093cf (patch) | |
tree | f83ea27e10616a384c26480e662854cf02ac8834 | |
parent | New Feature: Button for reloading room configuration of choosable room. (diff) | |
download | pvs2-6cb63e7e30906f428c601ba00fd15c14e07093cf.tar.gz pvs2-6cb63e7e30906f428c601ba00fd15c14e07093cf.tar.xz pvs2-6cb63e7e30906f428c601ba00fd15c14e07093cf.zip |
Client is able to auto - connect to the same room belonging manager.
-rw-r--r-- | src/client/connectwindow/connectwindow.cpp | 9 | ||||
-rw-r--r-- | src/client/connectwindow/connectwindow.h | 2 | ||||
-rw-r--r-- | src/client/main.cpp | 13 | ||||
-rw-r--r-- | src/client/net/serverdiscovery.cpp | 36 | ||||
-rw-r--r-- | src/client/net/serverdiscovery.h | 4 | ||||
-rw-r--r-- | src/client/toolbar/toolbar.cpp | 84 | ||||
-rw-r--r-- | src/client/toolbar/toolbar.h | 2 |
7 files changed, 130 insertions, 20 deletions
diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 7f24281..90cba27 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -158,13 +158,13 @@ void ConnectWindow::showEvent(QShowEvent* event) * if not --> connect to given sessionName. * @param sessionName */ -void ConnectWindow::connectToSession(const QByteArray sessionName) +void ConnectWindow::connectToSession(const QByteArray sessionName, QString mgrIP) { if (_connected || _state != Idle) return; _state = Scanning; this->updateState(); - _serverDiscovery.start(sessionName); + _serverDiscovery.start(sessionName, mgrIP); } /* @@ -199,7 +199,8 @@ void ConnectWindow::onBtnConnection() { // Connect (scan for session) _tryReconnect = true; - connectToSession(_ui->lineEditName->text().toUtf8()); + // qDebug() << _ui->lineEditName->text().toUtf8(); + connectToSession(_ui->lineEditName->text().toUtf8(), NULL); } } @@ -279,5 +280,5 @@ void ConnectWindow::onConnectionDisconnected() _state = Idle; this->updateState(); if (_tryReconnect) - connectToSession(_ui->lineEditName->text().toUtf8()); + connectToSession(_ui->lineEditName->text().toUtf8(), NULL); } diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index df112fe..a786119 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -54,7 +54,7 @@ public: explicit ConnectWindow(QWidget *parent = NULL); virtual ~ConnectWindow(); - void connectToSession(const QByteArray sessionName); + void connectToSession(const QByteArray sessionName, QString mgrIP); private: Ui::ConnectWindow *_ui; diff --git a/src/client/main.cpp b/src/client/main.cpp index 0907528..b268ca3 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -5,7 +5,7 @@ int main(int argc, char** argv) { if (argc > 2) { - std::cerr << "Usage: " << argv[0] << " [sessionId]" << std::endl; + std::cerr << "Usage: " << argv[0] << " [sessionId] | --auto" << std::endl; exit(EXIT_FAILURE); } @@ -42,7 +42,16 @@ int main(int argc, char** argv) translator.load(":pvsclient"); app.installTranslator(&translator); + if (argc == 2) { + if (argv[1] == std::string("--auto")) { + qDebug() << "Calling Toolbar(true)"; + Toolbar *pvsclient = new Toolbar(true); // auto connect client without session ID. + } else { + Toolbar *pvsclient = new Toolbar(QByteArray(argv[1])); // connect client with given session ID. + } + } else { + Toolbar *pvsclient = new Toolbar(); // create normal client. + } - Toolbar *pvsclient = argc == 2 ? new Toolbar(QByteArray(argv[1])) : new Toolbar(); return app.exec(); } diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp index a4edb46..2cd0796 100644 --- a/src/client/net/serverdiscovery.cpp +++ b/src/client/net/serverdiscovery.cpp @@ -45,8 +45,14 @@ ServerDiscovery::~ServerDiscovery() /***************************************************************************//** * @brief start */ -void ServerDiscovery::start(const QByteArray& sessionName) +void ServerDiscovery::start(const QByteArray& sessionName, QString mgrIP) { + if (mgrIP != NULL) { + _mgrIP.setAddress(mgrIP); + } else { + _mgrIP = NULL; + } + //assert(!this->isActive()); // Set the session which is searched @@ -98,21 +104,31 @@ void ServerDiscovery::doDiscovery() _packet.setField(_SALT1, salt1); _packet.setField(_SALT2, _salt2); _packet.setField(_IPLIST, iplist); - foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) + + // Check if specifig manager IP is given. If not broadcast in whole network. + if (_mgrIP != QHostAddress::Null) + { + qDebug() << "Broadcasting to " << _mgrIP.toString(); + if (!_packet.writeMessage(&_discoverySocket, _mgrIP, SERVICE_DISCOVERY_PORT)) + qDebug("Failed"); + } else { - foreach (QNetworkAddressEntry entry, interface.addressEntries()) + foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) { - if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) + foreach (QNetworkAddressEntry entry, interface.addressEntries()) { - qDebug() << "Broadcasting to " << entry.broadcast().toString(); - if (!_packet.writeMessage(&_discoverySocket, entry.broadcast(), SERVICE_DISCOVERY_PORT)) - qDebug("FAILED"); + if (!entry.broadcast().isNull() && entry.ip() != QHostAddress::LocalHost && entry.ip() != QHostAddress::LocalHostIPv6) + { + qDebug() << "Broadcasting to " << entry.broadcast().toString(); + if (!_packet.writeMessage(&_discoverySocket, entry.broadcast(), SERVICE_DISCOVERY_PORT)) + qDebug("FAILED"); + } } } + qDebug("Broadcasting to 255.255.255.255"); + if (!_packet.writeMessage(&_discoverySocket, QHostAddress::Broadcast, SERVICE_DISCOVERY_PORT)) + qDebug("FAILED"); } - qDebug("Broadcasting to 255.255.255.255"); - if (!_packet.writeMessage(&_discoverySocket, QHostAddress::Broadcast, SERVICE_DISCOVERY_PORT)) - qDebug("FAILED"); // Start the timer again with a larger interval if (_discoveryTimer.interval() < 5000) diff --git a/src/client/net/serverdiscovery.h b/src/client/net/serverdiscovery.h index 093b841..fee9fd0 100644 --- a/src/client/net/serverdiscovery.h +++ b/src/client/net/serverdiscovery.h @@ -19,7 +19,7 @@ class ServerDiscovery : public QObject explicit ServerDiscovery(QObject *parent = 0); ~ServerDiscovery(); - void start(const QByteArray& sessionName); + void start(const QByteArray& sessionName, QString mgrIP); void stop(); inline bool isActive(){ return _discoveryTimer.isActive(); } @@ -32,6 +32,8 @@ class ServerDiscovery : public QObject QUdpSocket _discoverySocket; NetworkMessage _packet; + QHostAddress _mgrIP; + static const int UDPBUFSIZ = 9000; static const int SALT_LEN = 18; diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 837bc08..0f90492 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -4,18 +4,20 @@ * Created on: 21.01.2013 * Author: sr */ +#include <QNetworkInterface> #include "../../shared/settings.h" #include "../net/serverconnection.h" #include "../vnc/vncwindow.h" #include "../vnc/vncserver.h" +#include "../util/util.h" #include "toolbar.h" #include "ui_toolbar.h" /***************************************************************************//** - * @brief Constructor of the Toolbar. + * @brief * * Does exact teh same as Toolbar::Toolbar(QWidget *parent) but additionally * instantly tries to connect to a pvsmgr with the given sessionName. @@ -27,7 +29,36 @@ Toolbar::Toolbar(const QByteArray sessionName, QWidget *parent) : Toolbar(parent) { - _connectWindow->connectToSession(sessionName); + qDebug() << "sessionName - constructor"; + _connectWindow->connectToSession(sessionName, NULL); +} + +/***************************************************************************//** + * @brief Constructor of the Toolbar. + * + * Does exact the same as Toolbar::Toolbar(QWidget *parent) but additionally + * instantly tries to connect to the pvsmgr in its room without sessionName. + * @param autoConnect + * @param parent + */ +Toolbar::Toolbar(const bool autoConnect, QWidget *parent) : Toolbar(parent) +{ + qDebug() << "auto - constructor!"; + + if (autoConnect) { + // Getting manager ip. + QString mgrIp = identifyMgrIP(); + qDebug() << "mgrIP: " << mgrIp; + if (mgrIp != NULL) { + qDebug() << "Starting WITH specific mgrIP"; + _connectWindow->connectToSession("", mgrIp); + } else { + qDebug() << "Starting WITHOUT specific mgrIP"; + _connectWindow->connectToSession("", NULL); + } + } else { + _connectWindow->connectToSession("", NULL); + } } /***************************************************************************//** @@ -144,6 +175,55 @@ void Toolbar::enterEvent(QEvent* e) QWidget::enterEvent(e); } +QString Toolbar::identifyMgrIP() +{ + SYSTEM_SETTINGS(conf); + qDebug() << "Settings contain" << conf.allKeys(); + + if (!conf.contains("rooms")) { + qDebug() << "Invalid config file!"; + return NULL; + } + + QStringList rooms = conf.value("rooms").toStringList(); + qDebug() << rooms; + + for (auto i : rooms) + { + qDebug() << "i: " << i; + conf.beginGroup(i); + if (!conf.contains("mgrIP")) { + qDebug() << "Invalid config file!"; + return NULL; + } + + // Find the managerIP of current room. + QString mgrIP = conf.value("mgrIP").toString(); + foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) + { + int size = conf.beginReadArray("client"); + for (int j = 0; j < size; ++j) { + conf.setArrayIndex(j); + /* + * + * CFG to test this + * http://git.openslx.org/tm-scripts.git/plain/server/modules/pvs2-freiburg/etc/xdg/openslx/pvs2client.ini + * + */ + QString ip = conf.value("ip").toString(); + if (address != QHostAddress(QHostAddress::LocalHost) && ip == address.toString()) + { + qDebug("Found this ip in config."); + return mgrIP; + } + } + conf.endArray(); + } + conf.endGroup(); + } + return NULL; +} + /* * Slots */ diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index 80ddd69..84f6d2d 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -32,6 +32,7 @@ class Toolbar : public QWidget public: Toolbar(QWidget *parent = 0); Toolbar(const QByteArray sessionName, QWidget *parent = 0); + Toolbar(const bool autoConnect, QWidget *parent = 0); virtual ~Toolbar(); private: @@ -49,6 +50,7 @@ private: void leaveEvent(QEvent* e); void enterEvent(QEvent* e); + QString identifyMgrIP(); private slots: void onVncServerIsRunning(int port); |