VPTissue Reference Manual
Server.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "Server.h"
21 
22 #include "ClientHandler.h"
23 #include "ExplorationManager.h"
24 #include "QHostAnyAddress.h"
25 #include "WorkerPool.h"
26 
27 #include <iostream>
28 #include <string>
29 
30 namespace SimPT_Parex {
31 
32 class Exploration;
33 
34 Server::Server(int minimumNodes, int port, QObject *parent)
35  : QTcpServer(parent), m_exploration_manager(std::make_shared<ExplorationManager>())
36 {
37  std::cout << "Starting server..." << std::endl;
38 
40 
41  connect(this, SIGNAL(newConnection()), this, SLOT(HandleConnection()));
42 
43  if (!listen(QHostAnyAddress(), port)) {
44  std::cout << "Error in set-up listening" << std::endl;
45  }
46 
47  std::cout << "Server is listening on address " << serverAddress().toString().toStdString() << " on port " << serverPort() << std::endl;
48 }
49 
51 {
52  close();
53 }
54 
55 void Server::HandleConnection()
56 {
57  std::cout << "Incoming client connection detected" << std::endl;
58 
59  QTcpSocket *socket = nextPendingConnection();
60  if (socket) {
61  new ClientHandler(socket, m_exploration_manager, this); // QObject parent will clean up this client handler
62  }
63 }
64 
65 } // namespace
STL namespace.
see the online Qt documentation
Connection from the server to one client, handles client messages and requests.
Definition: ClientHandler.h:37
static WorkerPool * globalInstance()
A static method to get the instance of the workerPool.
Definition: WorkerPool.cpp:186
Server(int minimumNodes, int port=8888, QObject *parent=nullptr)
Constructor.
Definition: Server.cpp:34
virtual ~Server()
Destructor.
Definition: Server.cpp:50
Interface for ClientHandler.
void SetMinNumWorkers(int)
Set the minimum number of workers.
Definition: WorkerPool.cpp:271
Interface for ExplorationManager.
Interface for WorkerPool.
Collects all explorations and works with WorkerPool to actually execute them.
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
see the online Qt documentation
Interface for Server.
Hack for QT 4 -> Qt 5 transition.