From a005cef7f69cfeca6e5c083ea8b7ebc45fe5207c Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Mon, 9 May 2016 17:53:24 +0200 Subject: Priorities for rooms. --- src/client/toolbar/toolbar.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/client/toolbar/toolbar.cpp') diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 64fc5dc..73a7588 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -189,8 +189,11 @@ void Toolbar::enterEvent(QEvent* e) QWidget::enterEvent(e); } +/** Identifies the responsible manager for this client by searching through the + * configuration file. The manager whose room has the highest priority is chosen. */ QString Toolbar::identifyMgrIP() { + qDebug() << "identify mgr ip"; SYSTEM_SETTINGS(conf); if (!conf.contains("rooms")) { @@ -201,40 +204,41 @@ QString Toolbar::identifyMgrIP() QStringList rooms = conf.value("rooms").toStringList(); // qDebug() << rooms; - for (auto i : rooms) - { - qDebug() << "i: " << i; + /* go through all rooms and check if this client is a member of the room. */ + int last_priority = -1; + QString last_mgr_ip = ""; + for (auto i : rooms) { conf.beginGroup(i); if (!conf.contains("mgrIP")) { qDebug() << "Invalid config file!"; return ""; } + QString mgr_candidate= conf.value("mgrIP").toString(); + int priority = conf.value("priority").toInt(); - // Find the managerIP of current room. - QString mgrIP = conf.value("mgrIP").toString(); - foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) - { + 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; + if (address != QHostAddress(QHostAddress::LocalHost) + && ip == address.toString() && + priority > last_priority) { + last_priority = priority; + last_mgr_ip = mgr_candidate; } } conf.endArray(); } conf.endGroup(); } - return ""; + qDebug() << "best mgr ip is " << last_mgr_ip << " with priority = " << last_priority; + return last_mgr_ip; } /* -- cgit v1.2.3-55-g7522