This commit is contained in:
maliakal_d 2019-06-11 15:43:24 +02:00
parent cb2c39c62f
commit d3467432a9
2 changed files with 9 additions and 86 deletions

View File

@ -1,119 +1,42 @@
#pragma once #pragma once
#include "qDefs.h"
#include "sls_detector_defs.h"
class qDetectorMain; class qDetectorMain;
class multiSlsDetector; class multiSlsDetector;
class ServerSocket; class ServerSocket;
#include <QWidget>
#include <vector> #include <vector>
/**
*@short Sets up the gui server
*/
class qServer : public QWidget, public virtual slsDetectorDefs { class qServer : public QWidget, public virtual slsDetectorDefs {
Q_OBJECT Q_OBJECT
public: public:
/**
* The constructor
*/
qServer(qDetectorMain *t); qServer(qDetectorMain *t);
/**
* Destructor
*/
~qServer(); ~qServer();
/**
* Create (Control and Stop) Gui Servers
*/
void CreateServers(); void CreateServers();
/**
* Destroy (Control and Stop) Gui Servers
*/
void DestroyServers(); void DestroyServers();
private: private:
/**
* Assigns functions to the fnum enum
*/
void FunctionTable(); void FunctionTable();
/**
* Decodes Function
* @param sock control or stop socket
* @returns OK or FAIL
*/
int DecodeFunction(ServerSocket *sock); int DecodeFunction(ServerSocket *sock);
/**
* Shut down Sockets
*/
void ShutDownSockets(); void ShutDownSockets();
/**
* Server thread
* @param pointer to control or stop socket
*/
void ServerThread(ServerSocket* sock); void ServerThread(ServerSocket* sock);
/**
* Get Detector Status
* @returns success of operation
*/
int GetStatus(ServerSocket* sock); int GetStatus(ServerSocket* sock);
/**
* Starts Acquisition
* @returns success of operation
*/
int StartAcquisition(ServerSocket* sock); int StartAcquisition(ServerSocket* sock);
/**
* Stops Acquisition
* @returns success of operation
*/
int StopsAcquisition(ServerSocket* sock); int StopsAcquisition(ServerSocket* sock);
/**
* Acquire - blocking
* @returns success of operation
*/
int Acquire(ServerSocket* sock); int Acquire(ServerSocket* sock);
/**
* Exit Server
* @returns GOODBYE
*/
int ExitServer(ServerSocket* sock); int ExitServer(ServerSocket* sock);
/** function list */ /** function list */
typedef int (qServer::*some_func_t)(ServerSocket*); typedef int (qServer::*some_func_t)(ServerSocket*);
typedef std::vector<some_func_t> sflist; typedef std::vector<some_func_t> sflist;
bool guiServerRunning;
/** if the gui server thread is running*/
bool threadRunning;
/** if thread started */
bool threadStarted; bool threadStarted;
/**The measurement tab object*/
qDetectorMain *mainTab; qDetectorMain *mainTab;
/** control port */
int controlPort; int controlPort;
/** stop port */
int stopPort; int stopPort;
/** control socket */
ServerSocket *controlSocket; ServerSocket *controlSocket;
/** stop socket */
ServerSocket *stopSocket; ServerSocket *stopSocket;
signals: signals:

View File

@ -1,8 +1,8 @@
#include "qServer.h" #include "qServer.h"
#include "qDefs.h"
#include "qDetectorMain.h" #include "qDetectorMain.h"
#include "ServerSocket.h" #include "ServerSocket.h"
#include "multiSlsDetector.h"
#include "string_utils.h" #include "string_utils.h"
#include <iostream> #include <iostream>
@ -10,7 +10,7 @@
#include <future> #include <future>
qServer::qServer(qDetectorMain *t) qServer::qServer(qDetectorMain *t)
: threadRunning(false), threadStarted(false), mainTab(t), : guiServerRunning(false), threadStarted(false), mainTab(t),
controlPort(DEFAULT_GUI_PORTNO), stopPort(DEFAULT_GUI_PORTNO + 1), controlPort(DEFAULT_GUI_PORTNO), stopPort(DEFAULT_GUI_PORTNO + 1),
controlSocket(nullptr), stopSocket(nullptr) { controlSocket(nullptr), stopSocket(nullptr) {
FILE_LOG(logDEBUG) << "Client Server ready"; FILE_LOG(logDEBUG) << "Client Server ready";
@ -52,7 +52,7 @@ int qServer::DecodeFunction(ServerSocket *sock) {
} }
void qServer::ShutDownSockets() { void qServer::ShutDownSockets() {
threadRunning = false; guiServerRunning = false;
if (controlSocket) { if (controlSocket) {
controlSocket->shutDownSocket(); controlSocket->shutDownSocket();
delete controlSocket; delete controlSocket;
@ -66,9 +66,9 @@ void qServer::ShutDownSockets() {
} }
void qServer::CreateServers() { void qServer::CreateServers() {
if (!threadRunning) { if (!guiServerRunning) {
FILE_LOG(logINFO) << "Starting Gui Servers"; FILE_LOG(logINFO) << "Starting Gui Servers";
threadRunning = true; guiServerRunning = true;
try { try {
// start control server // start control server
@ -91,7 +91,7 @@ void qServer::CreateServers() {
} }
void qServer::DestroyServers() { void qServer::DestroyServers() {
if (threadRunning) { if (guiServerRunning) {
FILE_LOG(logINFO) << "Stopping Gui Servers"; FILE_LOG(logINFO) << "Stopping Gui Servers";
ShutDownSockets(); ShutDownSockets();
FILE_LOG(logDEBUG) << "Server threads stopped successfully."; FILE_LOG(logDEBUG) << "Server threads stopped successfully.";
@ -101,11 +101,11 @@ void qServer::DestroyServers() {
void qServer::ServerThread(ServerSocket* sock) { void qServer::ServerThread(ServerSocket* sock) {
FILE_LOG(logDEBUG) << "Starting Gui Server at port " << sock->getPort(); FILE_LOG(logDEBUG) << "Starting Gui Server at port " << sock->getPort();
while (threadRunning)) { while (guiServerRunning)) {
try{ try{
sock->accept(); sock->accept();
if (DecodeFunction(sock) == GOODBYE) { if (DecodeFunction(sock) == GOODBYE) {
threadRunning = false; guiServerRunning = false;
} }
sock->close(); sock->close();
} }