mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 15:00:02 +02:00
WIP
This commit is contained in:
parent
cb2c39c62f
commit
d3467432a9
@ -1,119 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "qDefs.h"
|
||||
#include "sls_detector_defs.h"
|
||||
class qDetectorMain;
|
||||
|
||||
class multiSlsDetector;
|
||||
class ServerSocket;
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
*@short Sets up the gui server
|
||||
*/
|
||||
class qServer : public QWidget, public virtual slsDetectorDefs {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
qServer(qDetectorMain *t);
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~qServer();
|
||||
|
||||
/**
|
||||
* Create (Control and Stop) Gui Servers
|
||||
*/
|
||||
void CreateServers();
|
||||
|
||||
/**
|
||||
* Destroy (Control and Stop) Gui Servers
|
||||
*/
|
||||
void DestroyServers();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Assigns functions to the fnum enum
|
||||
*/
|
||||
void FunctionTable();
|
||||
|
||||
/**
|
||||
* Decodes Function
|
||||
* @param sock control or stop socket
|
||||
* @returns OK or FAIL
|
||||
*/
|
||||
int DecodeFunction(ServerSocket *sock);
|
||||
|
||||
/**
|
||||
* Shut down Sockets
|
||||
*/
|
||||
void ShutDownSockets();
|
||||
|
||||
/**
|
||||
* Server thread
|
||||
* @param pointer to control or stop socket
|
||||
*/
|
||||
void ServerThread(ServerSocket* sock);
|
||||
|
||||
/**
|
||||
* Get Detector Status
|
||||
* @returns success of operation
|
||||
*/
|
||||
int GetStatus(ServerSocket* sock);
|
||||
|
||||
/**
|
||||
* Starts Acquisition
|
||||
* @returns success of operation
|
||||
*/
|
||||
int StartAcquisition(ServerSocket* sock);
|
||||
|
||||
/**
|
||||
* Stops Acquisition
|
||||
* @returns success of operation
|
||||
*/
|
||||
int StopsAcquisition(ServerSocket* sock);
|
||||
|
||||
/**
|
||||
* Acquire - blocking
|
||||
* @returns success of operation
|
||||
*/
|
||||
int Acquire(ServerSocket* sock);
|
||||
|
||||
/**
|
||||
* Exit Server
|
||||
* @returns GOODBYE
|
||||
*/
|
||||
int ExitServer(ServerSocket* sock);
|
||||
|
||||
/** function list */
|
||||
typedef int (qServer::*some_func_t)(ServerSocket*);
|
||||
typedef std::vector<some_func_t> sflist;
|
||||
|
||||
/** if the gui server thread is running*/
|
||||
bool threadRunning;
|
||||
|
||||
/** if thread started */
|
||||
bool guiServerRunning;
|
||||
bool threadStarted;
|
||||
|
||||
/**The measurement tab object*/
|
||||
qDetectorMain *mainTab;
|
||||
|
||||
/** control port */
|
||||
int controlPort;
|
||||
|
||||
/** stop port */
|
||||
int stopPort;
|
||||
|
||||
/** control socket */
|
||||
ServerSocket *controlSocket;
|
||||
|
||||
/** stop socket */
|
||||
ServerSocket *stopSocket;
|
||||
|
||||
signals:
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "qServer.h"
|
||||
#include "qDefs.h"
|
||||
#include "qDetectorMain.h"
|
||||
|
||||
#include "ServerSocket.h"
|
||||
#include "multiSlsDetector.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <iostream>
|
||||
@ -10,7 +10,7 @@
|
||||
#include <future>
|
||||
|
||||
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),
|
||||
controlSocket(nullptr), stopSocket(nullptr) {
|
||||
FILE_LOG(logDEBUG) << "Client Server ready";
|
||||
@ -52,7 +52,7 @@ int qServer::DecodeFunction(ServerSocket *sock) {
|
||||
}
|
||||
|
||||
void qServer::ShutDownSockets() {
|
||||
threadRunning = false;
|
||||
guiServerRunning = false;
|
||||
if (controlSocket) {
|
||||
controlSocket->shutDownSocket();
|
||||
delete controlSocket;
|
||||
@ -66,9 +66,9 @@ void qServer::ShutDownSockets() {
|
||||
}
|
||||
|
||||
void qServer::CreateServers() {
|
||||
if (!threadRunning) {
|
||||
if (!guiServerRunning) {
|
||||
FILE_LOG(logINFO) << "Starting Gui Servers";
|
||||
threadRunning = true;
|
||||
guiServerRunning = true;
|
||||
|
||||
try {
|
||||
// start control server
|
||||
@ -91,7 +91,7 @@ void qServer::CreateServers() {
|
||||
}
|
||||
|
||||
void qServer::DestroyServers() {
|
||||
if (threadRunning) {
|
||||
if (guiServerRunning) {
|
||||
FILE_LOG(logINFO) << "Stopping Gui Servers";
|
||||
ShutDownSockets();
|
||||
FILE_LOG(logDEBUG) << "Server threads stopped successfully.";
|
||||
@ -101,11 +101,11 @@ void qServer::DestroyServers() {
|
||||
void qServer::ServerThread(ServerSocket* sock) {
|
||||
FILE_LOG(logDEBUG) << "Starting Gui Server at port " << sock->getPort();
|
||||
|
||||
while (threadRunning)) {
|
||||
while (guiServerRunning)) {
|
||||
try{
|
||||
sock->accept();
|
||||
if (DecodeFunction(sock) == GOODBYE) {
|
||||
threadRunning = false;
|
||||
guiServerRunning = false;
|
||||
}
|
||||
sock->close();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user