VPTissue Reference Manual
WorkerPool.h
Go to the documentation of this file.
1 #ifndef SIMPT_PAREX_WORKER_POOL_H_INCLUDED
2 #define SIMPT_PAREX_WORKER_POOL_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 "WorkerRepresentative.h"
23 
24 #include <QUdpSocket>
25 #include <QTcpSocket>
26 #include <QObject>
27 #include <QString>
28 #include <QSignalMapper>
29 #include <QTimer>
30 #include <list>
31 
32 namespace SimPT_Parex {
33 
37 class WorkerPool: public QObject
38 {
39  Q_OBJECT
40 public:
41  virtual ~WorkerPool();
42 
48 
54  static WorkerPool *globalInstance();
55 
59  bool WorkerAvailable();
60 
64  void SetMinNumWorkers(int);
65 
69  void Delete(std::string name);
70 
71 signals:
75  void NewWorkerAvailable();
76 
81 
82 public slots:
86  void ReleaseWorker(QObject*);
88 
94 
95 private slots:
96  void handleDatagrams();
97  void Initialize();
98  void StartWorkers();
99  void PeriodicCheck();
100 
101 private:
102  void StartWorker();
103  WorkerPool();
104 
105  QUdpSocket *m_socket;
106  QTcpSocket *m_tcpSocket;
107 
108  QSignalMapper *m_mapper;
109  QSignalMapper *m_release_mapper;
110  std::list<WorkerRepresentative*> m_available_list;
111  std::list<WorkerRepresentative*> m_busy_list;
112  std::list<QString> m_connected_list;
113  bool m_initialized;
114  QTimer *m_initialize_timer;
115 
116  int m_min_nodes;
117 
118  QTimer *m_check_timer;
119 };
120 
121 } // namespace
122 
123 #endif // end-of-include-guard
bool WorkerAvailable()
Checks to see if a worker is ready to do some work.
Definition: WorkerPool.cpp:239
void Delete(std::string name)
Delete an exploration on every node.
Definition: WorkerPool.cpp:276
void ReleaseWorker(QObject *)
When a worker disconnects, this slot should be fired.
Definition: WorkerPool.cpp:223
void MakeProcessAvailable(QObject *)
When a worker has finished his work, this slot should be fired.
Definition: WorkerPool.cpp:207
A pool handling the workers that will do the actual work.
Definition: WorkerPool.h:37
static WorkerPool * globalInstance()
A static method to get the instance of the workerPool.
Definition: WorkerPool.cpp:186
void NewWorkerAvailable()
Emitted when a worker is ready for work.
void SetMinNumWorkers(int)
Set the minimum number of workers.
Definition: WorkerPool.cpp:271
void WorkerReconnected(WorkerRepresentative *)
Emitted when a worker has reconnected after being disconnected.
WorkerRepresentative * getProcess()
Gets a process doing nothing if one is available, otherwise returns 0.
Definition: WorkerPool.cpp:196
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
see the online Qt documentation
A worker taken as representative for multiple workers (handles the communication with the node)...
Interface for WorkerRepresentative.