VPTissue Reference Manual
WorkerNode.h
Go to the documentation of this file.
1 #ifndef SIMPT_PAREX_WORKER_NODE_H_INCLUDED
2 #define SIMPT_PAREX_WORKER_NODE_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "NodeAdvertiser.h"
24 
25 #include <QHostAddress>
26 #include <QTcpServer>
27 #include <queue>
28 
29 class QThread;
30 
31 namespace SimPT_Parex {
32 
33 class NodeProtocol;
34 class SimTask;
35 class Simulator;
36 
43 class WorkerNode: public QTcpServer
44 {
45  Q_OBJECT
46 public:
54  WorkerNode(Simulator* simulator, bool verbose = true, QObject* parent = nullptr);
55 
59  virtual ~WorkerNode();
60 
61 signals:
63  void NewTask(const SimTask&);
64 
65 private slots:
66  void ConnectionReceived();
67  void Delete(const std::string& name);
68  void DisplayError(const std::string&) const;
69  void FinishedWork(const SimResult&);
70  void HandleError(QAbstractSocket::SocketError);
71  void StartedWork(const SimTask* task);
72  void StopTask();
73  void ResultSent();
74 
75 private:
76  void StartAdvertiser();
77 
78 private:
79  Simulator* m_simulator;
80  QThread* m_simulator_thread;
81  NodeAdvertiser m_advertiser;
82  bool m_verbose;
83 
84  NodeProtocol* m_protocol;
85  const SimTask* m_current_task;
86 
87  QHostAddress m_last_address;
88  std::queue<const SimTask*> m_queue;
89  std::queue<SimResult> m_results;
90 
91 private:
92  // TODO: Make configurable with cmd line arguments
93  static const int g_broadcast_port;
94 };
95 
96 } // namespace
97 
98 #endif // end-of-include-guard
Interface for the NodeAdvertiser.
see the online Qt documentation
A container class for the final result of a simulation.
Definition: SimResult.h:29
Class that implements the node version of the protocol.
Definition: NodeProtocol.h:35
void NewTask(const SimTask &)
Emitted whenever a new task is ready to be simulated.
Class advertising an available node over the network.
virtual ~WorkerNode()
Destroy the node, closing all open connections.
Definition: WorkerNode.cpp:68
Broadcasts location on the network, then listens to incoming connections.
Definition: WorkerNode.h:43
Interface for SimResult.
Simulator handling requested simulation tasks.
Definition: Simulator.h:37
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
Contains all information needed for a transmitable simulation task.
Definition: SimTask.h:31
see the online Qt documentation
WorkerNode(Simulator *simulator, bool verbose=true, QObject *parent=nullptr)
Constructor immediately starts trying to connect to a server.
Definition: WorkerNode.cpp:42