From 1fca5db8d71539d2621064a0f756f128970736ac Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 27 May 2014 14:56:47 +0200 Subject: Unite BC and MC. Reducing complexity --- src/server/mainwindow/mainwindow.cpp | 79 ++++++++++++++---------------------- 1 file changed, 30 insertions(+), 49 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 11071f6..5fdf3db 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -56,7 +56,7 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _tutorFrame = NULL; _selectedFrame = NULL; - _mode = Mode::Idle; + _mode = Mode::Multicast; _streamingSource = NULL; _sessionNameWindow = new SessionNameWindow(this); @@ -434,56 +434,37 @@ bool MainWindow::isValidClient(Client* client) return false; } - /***************************************************************************//** - * @brief broadcast - * @param from - */ -void MainWindow::broadcast(Client *from) -{ - _mode = Mode::Broadcast; - - // if there is a server running which is not "from" stop it. - if (_streamingSource != NULL && _streamingSource != from) - _streamingSource->stopVncServer(); - _streamingSource = from; - - // Server must not listen to anybody - _streamingSource->stopVncClient(); - - // Set desired projection source on all clients, if not "from" or oflline - for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL && (*it)->client() != _streamingSource) - _watchers.insert((*it)->client()->id(), (*it)->client()); - - if (_streamingSource->isActiveVncServer()) - // From is already active - this->onVncServerStateChange(_streamingSource); - else - // Could not take shortcut, start VNC server on source - _streamingSource->startVncServer(); -} - - -/***************************************************************************//** - * @brief MainWindow::unicast + * @brief MainWindow::changeProjection * @param from + * @param mode * @param to - * @param blockOthers */ -void MainWindow::multicast(Client *from, Client *to, bool blockOthers) +void MainWindow::changeProjection(Client *from, Mode mode, Client *to) { - // If first call in this mode clear the watchers - if (_mode != (blockOthers ? Mode::LockedMulticast : Mode::Multicast)) { - _watchers.clear(); - _mode = blockOthers ? Mode::LockedMulticast : Mode::Multicast; + if (mode == Mode::Broadcast) + { + // Set all clients as watchers + for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) + if ((*it)->client() != NULL && (*it)->client() != _streamingSource) + _watchers.insert((*it)->client()->id(), (*it)->client()); + } + else // mode != Mode::Broadcast + { + // If this is the first call in this mode clear the watchers + if ((mode == Mode::LockedMulticast && _mode != Mode::LockedMulticast) + || (mode == Mode::Multicast && _mode != Mode::Multicast)) + _watchers.clear(); + + // If "to" already watches "from" stop it + if (_watchers.contains(to->id())) + _watchers.remove(to->id()); + else // list "to" as watcher + _watchers.insert(to->id(), to); } - // If already watching drop it - if (_watchers.contains(to->id())) - _watchers.remove(to->id()); - else // List "to" as watcher - _watchers.insert(to->id(), to); + // Set the mode + _mode = mode; // if there is a server running which is not "from" stop it. if (_streamingSource != NULL && _streamingSource != from) @@ -519,7 +500,7 @@ void MainWindow::onButtonTutorToAll() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - broadcast(_tutorFrame->client()); + changeProjection(_tutorFrame->client(), Mode::Broadcast); } /***************************************************************************//** @@ -534,7 +515,7 @@ void MainWindow::onButtonStudentToAll() if (_selectedFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrSourceOffline); else - broadcast(_selectedFrame->client()); + changeProjection(_selectedFrame->client(), Mode::Broadcast); } /***************************************************************************//** @@ -554,7 +535,7 @@ void MainWindow::onButtonTutorToStudent() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - multicast(_tutorFrame->client(), _selectedFrame->client()); + changeProjection(_tutorFrame->client(), Mode::Multicast, _selectedFrame->client()); } /***************************************************************************//** @@ -574,7 +555,7 @@ void MainWindow::onButtonStudentToTutor() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - multicast(_selectedFrame->client(), _tutorFrame->client()); + changeProjection(_selectedFrame->client(), Mode::Multicast, _tutorFrame->client()); } @@ -594,7 +575,7 @@ void MainWindow::onButtonStudentToTutorExclusive() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - multicast(_tutorFrame->client(), _selectedFrame->client(), true); + changeProjection(_tutorFrame->client(), Mode::LockedMulticast, _selectedFrame->client()); } -- cgit v1.2.3-55-g7522