mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-20 18:45:27 +01:00
merge from refgui. not completed
This commit is contained in:
0
slsSupportLib/CMakeLists.txt
Normal file → Executable file
0
slsSupportLib/CMakeLists.txt
Normal file → Executable file
0
slsSupportLib/include/ClientInterface.h
Normal file → Executable file
0
slsSupportLib/include/ClientInterface.h
Normal file → Executable file
21
slsSupportLib/include/ClientSocket.h
Normal file → Executable file
21
slsSupportLib/include/ClientSocket.h
Normal file → Executable file
@@ -9,29 +9,36 @@ namespace sls {
|
||||
|
||||
class ClientSocket : public DataSocket {
|
||||
public:
|
||||
ClientSocket(const bool isRx, const std::string &hostname, uint16_t port_number);
|
||||
ClientSocket(const bool isRx, struct sockaddr_in addr);
|
||||
ClientSocket(std::string stype, const std::string &hostname, uint16_t port_number);
|
||||
ClientSocket(std::string stype, struct sockaddr_in addr);
|
||||
int sendCommandThenRead(int fnum, void *args, size_t args_size, void *retval,
|
||||
size_t retval_size);
|
||||
|
||||
private:
|
||||
void readReply(int &ret, void *retval, size_t retval_size);
|
||||
struct sockaddr_in serverAddr {};
|
||||
bool isReceiver;
|
||||
std::string socketType;
|
||||
};
|
||||
|
||||
class ReceiverSocket : public ClientSocket {
|
||||
public:
|
||||
ReceiverSocket(const std::string &hostname, uint16_t port_number)
|
||||
: ClientSocket(true, hostname, port_number){};
|
||||
ReceiverSocket(struct sockaddr_in addr) : ClientSocket(true, addr){};
|
||||
: ClientSocket("Receiver", hostname, port_number){};
|
||||
ReceiverSocket(struct sockaddr_in addr) : ClientSocket("Receiver", addr){};
|
||||
};
|
||||
|
||||
class DetectorSocket : public ClientSocket {
|
||||
public:
|
||||
DetectorSocket(const std::string &hostname, uint16_t port_number)
|
||||
: ClientSocket(false, hostname, port_number){};
|
||||
DetectorSocket(struct sockaddr_in addr) : ClientSocket(false, addr){};
|
||||
: ClientSocket("Detector", hostname, port_number){};
|
||||
DetectorSocket(struct sockaddr_in addr) : ClientSocket("Detector", addr){};
|
||||
};
|
||||
|
||||
class GuiSocket : public ClientSocket {
|
||||
public:
|
||||
GuiSocket(const std::string &hostname, uint16_t port_number)
|
||||
: ClientSocket("Gui", hostname, port_number){};
|
||||
GuiSocket(struct sockaddr_in addr) : ClientSocket("Gui", addr){};
|
||||
};
|
||||
|
||||
}; // namespace sls
|
||||
|
||||
0
slsSupportLib/include/CmdLineParser.h
Normal file → Executable file
0
slsSupportLib/include/CmdLineParser.h
Normal file → Executable file
1
slsSupportLib/include/DataSocket.h
Normal file → Executable file
1
slsSupportLib/include/DataSocket.h
Normal file → Executable file
@@ -22,6 +22,7 @@ class DataSocket {
|
||||
size_t receiveData(void *buffer, size_t size);
|
||||
int setTimeOut(int t_seconds);
|
||||
void close();
|
||||
void shutDownSocket();
|
||||
|
||||
private:
|
||||
int socketId_ = -1;
|
||||
|
||||
0
slsSupportLib/include/MySocketTCP.h
Normal file → Executable file
0
slsSupportLib/include/MySocketTCP.h
Normal file → Executable file
0
slsSupportLib/include/ServerInterface.h
Normal file → Executable file
0
slsSupportLib/include/ServerInterface.h
Normal file → Executable file
7
slsSupportLib/include/ServerSocket.h
Normal file → Executable file
7
slsSupportLib/include/ServerSocket.h
Normal file → Executable file
@@ -14,12 +14,15 @@ class ServerSocket : public DataSocket {
|
||||
public:
|
||||
ServerSocket(int port);
|
||||
DataSocket accept();
|
||||
const std::string &getLastClient() { return lastClient_; }
|
||||
const std::string &getLastClient();
|
||||
const int getPort();
|
||||
void SendResult(int &ret, void *retval, int retvalSize, char* mess);
|
||||
|
||||
private:
|
||||
std::string lastClient_ = std::string(INET_ADDRSTRLEN, '\0');
|
||||
std::string thisClient_ = std::string(INET_ADDRSTRLEN, '\0');
|
||||
int serverPort;
|
||||
// char lastClient_[INET_ADDRSTRLEN]{};
|
||||
};
|
||||
|
||||
}; //namespace sls
|
||||
}; // namespace sls
|
||||
0
slsSupportLib/include/Timer.h
Normal file → Executable file
0
slsSupportLib/include/Timer.h
Normal file → Executable file
0
slsSupportLib/include/ZmqSocket.h
Normal file → Executable file
0
slsSupportLib/include/ZmqSocket.h
Normal file → Executable file
0
slsSupportLib/include/ansi.h
Normal file → Executable file
0
slsSupportLib/include/ansi.h
Normal file → Executable file
0
slsSupportLib/include/container_utils.h
Normal file → Executable file
0
slsSupportLib/include/container_utils.h
Normal file → Executable file
0
slsSupportLib/include/error_defs.h
Normal file → Executable file
0
slsSupportLib/include/error_defs.h
Normal file → Executable file
0
slsSupportLib/include/file_utils.h
Normal file → Executable file
0
slsSupportLib/include/file_utils.h
Normal file → Executable file
0
slsSupportLib/include/genericSocket.h
Normal file → Executable file
0
slsSupportLib/include/genericSocket.h
Normal file → Executable file
3
slsSupportLib/include/logger.h
Normal file → Executable file
3
slsSupportLib/include/logger.h
Normal file → Executable file
@@ -18,6 +18,7 @@
|
||||
|
||||
#ifndef FILELOG_MAX_LEVEL
|
||||
#define FILELOG_MAX_LEVEL logINFO
|
||||
//#define FILELOG_MAX_LEVEL logDEBUG5
|
||||
#endif
|
||||
|
||||
|
||||
@@ -80,7 +81,7 @@ class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
|
||||
|
||||
inline std::string NowTime()
|
||||
{
|
||||
char buffer[11];
|
||||
char buffer[12];
|
||||
const int buffer_len = sizeof(buffer);
|
||||
time_t t;
|
||||
time(&t);
|
||||
|
||||
0
slsSupportLib/include/network_utils.h
Normal file → Executable file
0
slsSupportLib/include/network_utils.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/allocators.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/allocators.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/document.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/document.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/encodedstream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/encodedstream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/encodings.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/encodings.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/error/en.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/error/en.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/error/error.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/error/error.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/filereadstream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/filereadstream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/filewritestream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/filewritestream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/fwd.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/fwd.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/biginteger.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/biginteger.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/diyfp.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/diyfp.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/dtoa.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/dtoa.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/ieee754.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/ieee754.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/itoa.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/itoa.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/meta.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/meta.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/pow10.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/pow10.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/regex.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/regex.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/stack.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/stack.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/strfunc.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/strfunc.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/strtod.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/strtod.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/swap.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/internal/swap.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/istreamwrapper.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/istreamwrapper.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/memorybuffer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/memorybuffer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/memorystream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/memorystream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/msinttypes/inttypes.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/msinttypes/inttypes.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/msinttypes/stdint.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/msinttypes/stdint.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/ostreamwrapper.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/ostreamwrapper.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/pointer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/pointer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/prettywriter.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/prettywriter.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/rapidjson.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/rapidjson.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/reader.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/reader.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/schema.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/schema.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/stream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/stream.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/stringbuffer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/stringbuffer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/writer.h
Normal file → Executable file
0
slsSupportLib/include/rapidjson/writer.h
Normal file → Executable file
@@ -204,7 +204,6 @@ public:
|
||||
enum fileFormat {
|
||||
GET_FILE_FORMAT=-1,/**< the receiver will return its file format */
|
||||
BINARY, /**< binary format */
|
||||
ASCII, /**< ascii format */
|
||||
HDF5, /**< hdf5 format */
|
||||
NUM_FILE_FORMATS
|
||||
};
|
||||
@@ -307,8 +306,7 @@ public:
|
||||
*/
|
||||
enum dimension {
|
||||
X=0, /**< X dimension */
|
||||
Y=1, /**< Y dimension */
|
||||
Z=2 /**< Z dimension */
|
||||
Y=1 /**< Y dimension */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -350,9 +348,7 @@ public:
|
||||
GET_EXTERNAL_COMMUNICATION_MODE=-1,/**<return flag for communication mode */
|
||||
AUTO_TIMING, /**< internal timing */
|
||||
TRIGGER_EXPOSURE, /**< trigger mode i.e. exposure is triggered */
|
||||
TRIGGER_READOUT, /**< stop trigger mode i.e. readout is triggered by external signal */
|
||||
GATE_FIX_NUMBER, /**< gated and reads out after a fixed number of gates */
|
||||
GATE_WITH_START_TRIGGER, /**< gated with start trigger */
|
||||
GATED, /**< gated */
|
||||
BURST_TRIGGER /**< trigger a burst of frames */
|
||||
};
|
||||
/**
|
||||
@@ -596,6 +592,7 @@ public:
|
||||
case GOTTHARD: return std::string("Gotthard"); \
|
||||
case JUNGFRAU: return std::string("Jungfrau"); \
|
||||
case CHIPTESTBOARD: return std::string("JungfrauCTB"); \
|
||||
case MOENCH: return std::string("Moench"); \
|
||||
default: return std::string("Unknown"); \
|
||||
}};
|
||||
|
||||
@@ -608,6 +605,7 @@ public:
|
||||
if (type=="Gotthard") return GOTTHARD; \
|
||||
if (type=="Jungfrau") return JUNGFRAU; \
|
||||
if (type=="JungfrauCTB") return CHIPTESTBOARD; \
|
||||
if (type=="Moench") return MOENCH; \
|
||||
return GENERIC; \
|
||||
};
|
||||
|
||||
@@ -634,7 +632,6 @@ public:
|
||||
*/
|
||||
static std::string getFileFormatType(fileFormat f){\
|
||||
switch (f) { \
|
||||
case ASCII: return std::string("ascii"); \
|
||||
case HDF5: return std::string("hdf5"); \
|
||||
case BINARY: return std::string("binary"); \
|
||||
default: return std::string("unknown"); \
|
||||
@@ -729,6 +726,7 @@ public:
|
||||
case FORCESWITCHG1: return std::string("forceswitchg1");\
|
||||
case FORCESWITCHG2: return std::string("forceswitchg2");\
|
||||
case VERYLOWGAIN: return std::string("verylowgain");\
|
||||
case UNINITIALIZED: return std::string("uninitialized"); \
|
||||
default: return std::string("undefined"); \
|
||||
}};
|
||||
|
||||
@@ -760,17 +758,15 @@ public:
|
||||
|
||||
/**
|
||||
returns external communication mode std::string from index
|
||||
\param f can be AUTO_TIMING, TRIGGER_EXPOSURE, TRIGGER_READOUT, GATE_FIX_NUMBER, GATE_WITH_START_TRIGGER, BURST_TRIGGER, GET_EXTERNAL_COMMUNICATION_MODE
|
||||
\returns auto, trigger, ro_trigger, gating, triggered_gating, unknown
|
||||
\param f can be AUTO_TIMING, TRIGGER_EXPOSURE, GATED, BURST_TRIGGER, GET_EXTERNAL_COMMUNICATION_MODE
|
||||
\returns auto, trigger, gating, burst_trigger, unknown
|
||||
*/
|
||||
|
||||
static std::string externalCommunicationType(externalCommunicationMode f){ \
|
||||
switch(f) { \
|
||||
case AUTO_TIMING: return std::string( "auto"); \
|
||||
case TRIGGER_EXPOSURE: return std::string("trigger"); \
|
||||
case TRIGGER_READOUT: return std::string("ro_trigger"); \
|
||||
case GATE_FIX_NUMBER: return std::string("gating"); \
|
||||
case GATE_WITH_START_TRIGGER: return std::string("triggered_gating"); \
|
||||
case GATED: return std::string("gating"); \
|
||||
case BURST_TRIGGER: return std::string("burst_trigger"); \
|
||||
default: return std::string( "unknown"); \
|
||||
} };
|
||||
@@ -779,16 +775,14 @@ public:
|
||||
|
||||
/**
|
||||
returns external communication mode index from std::string
|
||||
\param sval can be auto, trigger, ro_trigger, gating, triggered_gating
|
||||
\returns AUTO_TIMING, TRIGGER_EXPOSURE, TRIGGER_READOUT, GATE_FIX_NUMBER, GATE_WITH_START_TRIGGER, BURST_TRIGGER, GET_EXTERNAL_COMMUNICATION_MODE
|
||||
\param sval can be auto, trigger, gating, burst_trigger
|
||||
\returns AUTO_TIMING, TRIGGER_EXPOSURE, GATED, BURST_TRIGGER, GET_EXTERNAL_COMMUNICATION_MODE
|
||||
*/
|
||||
|
||||
static externalCommunicationMode externalCommunicationType(std::string sval){\
|
||||
if (sval=="auto") return AUTO_TIMING;\
|
||||
if (sval=="trigger") return TRIGGER_EXPOSURE; \
|
||||
if (sval=="ro_trigger") return TRIGGER_READOUT;\
|
||||
if (sval=="gating") return GATE_FIX_NUMBER;\
|
||||
if (sval=="triggered_gating") return GATE_WITH_START_TRIGGER;\
|
||||
if (sval=="gating") return GATED;\
|
||||
if (sval=="burst_trigger") return BURST_TRIGGER;\
|
||||
return GET_EXTERNAL_COMMUNICATION_MODE; \
|
||||
};
|
||||
@@ -800,7 +794,6 @@ public:
|
||||
static std::string fileFormats(fileFormat f){\
|
||||
switch (f) { \
|
||||
case BINARY: return std::string("binary"); \
|
||||
case ASCII: return std::string("ascii"); \
|
||||
case HDF5: return std::string("hdf5"); \
|
||||
default: return std::string("unknown"); \
|
||||
}};
|
||||
|
||||
44
slsSupportLib/include/sls_detector_exceptions.h
Normal file → Executable file
44
slsSupportLib/include/sls_detector_exceptions.h
Normal file → Executable file
@@ -27,42 +27,50 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct SharedMemoryError : public RuntimeError {
|
||||
struct CriticalError : public RuntimeError {
|
||||
public:
|
||||
SharedMemoryError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
CriticalError(std::string msg):RuntimeError(msg) {}
|
||||
};
|
||||
|
||||
struct SocketError : public RuntimeError {
|
||||
struct SharedMemoryError : public CriticalError {
|
||||
public:
|
||||
SocketError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
SharedMemoryError(std::string msg):CriticalError(msg) {}
|
||||
};
|
||||
|
||||
struct ZmqSocketError : public RuntimeError {
|
||||
struct SocketError : public CriticalError {
|
||||
public:
|
||||
ZmqSocketError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
SocketError(std::string msg):CriticalError(msg) {}
|
||||
};
|
||||
|
||||
struct NotImplementedError : public RuntimeError {
|
||||
struct ZmqSocketError : public CriticalError {
|
||||
public:
|
||||
NotImplementedError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
ZmqSocketError(std::string msg):CriticalError(msg) {}
|
||||
};
|
||||
|
||||
struct DetectorError : public RuntimeError {
|
||||
struct NonCriticalError : public RuntimeError {
|
||||
public:
|
||||
DetectorError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
NonCriticalError(std::string msg):RuntimeError(msg) {}
|
||||
};
|
||||
|
||||
struct ReceiverError : public RuntimeError {
|
||||
struct NotImplementedError : public NonCriticalError {
|
||||
public:
|
||||
ReceiverError(std::string msg):RuntimeError(msg) {}
|
||||
|
||||
NotImplementedError(std::string msg):NonCriticalError(msg) {}
|
||||
};
|
||||
|
||||
struct DetectorError : public NonCriticalError {
|
||||
public:
|
||||
DetectorError(std::string msg):NonCriticalError(msg) {}
|
||||
};
|
||||
|
||||
struct ReceiverError : public NonCriticalError {
|
||||
public:
|
||||
ReceiverError(std::string msg):NonCriticalError(msg) {}
|
||||
};
|
||||
|
||||
struct GuiError : public NonCriticalError {
|
||||
public:
|
||||
GuiError(std::string msg):NonCriticalError(msg) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
0
slsSupportLib/include/sls_detector_funcs.h
Normal file → Executable file
0
slsSupportLib/include/sls_detector_funcs.h
Normal file → Executable file
0
slsSupportLib/include/string_utils.h
Normal file → Executable file
0
slsSupportLib/include/string_utils.h
Normal file → Executable file
@@ -1,8 +1,10 @@
|
||||
/** API versions */
|
||||
#define APIRECEIVER 0x180927
|
||||
#define APIEIGER 0x181031
|
||||
#define APIJUNGFRAU 0x190111
|
||||
#define GITBRANCH "refgui"
|
||||
#define APIGOTTHARD 0x190108
|
||||
#define APICTB 0x190402
|
||||
#define APIMOENCH 0x181108
|
||||
|
||||
#define APIEIGER 0x190405
|
||||
#define APIJUNGFRAU 0x190405
|
||||
#define APILIB 0x190405
|
||||
#define APIRECEIVER 0x190405
|
||||
#define APIGUI 0x190405
|
||||
#define APICTB 0x190405
|
||||
|
||||
0
slsSupportLib/src/ClientInterface.cpp
Normal file → Executable file
0
slsSupportLib/src/ClientInterface.cpp
Normal file → Executable file
33
slsSupportLib/src/ClientSocket.cpp
Normal file → Executable file
33
slsSupportLib/src/ClientSocket.cpp
Normal file → Executable file
@@ -10,8 +10,8 @@
|
||||
#include <unistd.h>
|
||||
namespace sls {
|
||||
|
||||
ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t port)
|
||||
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), isReceiver(isRx) {
|
||||
ClientSocket::ClientSocket(std::string stype, const std::string &host, uint16_t port)
|
||||
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), socketType(stype) {
|
||||
|
||||
struct addrinfo hints, *result;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
@@ -34,22 +34,20 @@ ClientSocket::ClientSocket(const bool isRx, const std::string &host, uint16_t po
|
||||
|
||||
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
|
||||
freeaddrinfo(result);
|
||||
const std::string name{(isReceiver ? "Receiver" : "Detector")};
|
||||
std::string msg = "ClientSocket: Cannot connect to " + name + ":" + host + " on port " +
|
||||
std::to_string(port) + "\n";
|
||||
std::string msg = "ClientSocket: Cannot connect to " + socketType + ":" +
|
||||
host + " on port " + std::to_string(port) + "\n";
|
||||
throw SocketError(msg);
|
||||
}
|
||||
freeaddrinfo(result);
|
||||
}
|
||||
|
||||
ClientSocket::ClientSocket(const bool isRx, struct sockaddr_in addr)
|
||||
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), isReceiver(isRx) {
|
||||
ClientSocket::ClientSocket(std::string sType, struct sockaddr_in addr)
|
||||
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), socketType(sType) {
|
||||
|
||||
if (::connect(getSocketId(), (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
||||
char address[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, &addr.sin_addr, address, INET_ADDRSTRLEN);
|
||||
const std::string name{(isReceiver ? "Receiver" : "Detector")};
|
||||
std::string msg = "ClientSocket: Cannot connect to " + name + ":" + address + " on port " +
|
||||
std::string msg = "ClientSocket: Cannot connect to " + socketType + ":" + address + " on port " +
|
||||
std::to_string(addr.sin_port) + "\n";
|
||||
throw SocketError(msg);
|
||||
}
|
||||
@@ -67,30 +65,25 @@ int ClientSocket::sendCommandThenRead(int fnum, void *args, size_t args_size, vo
|
||||
void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
||||
|
||||
receiveData(&ret, sizeof(ret));
|
||||
bool unrecognizedFunction = false;
|
||||
if (ret == slsDetectorDefs::FAIL) {
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
// get error message
|
||||
receiveData(mess, sizeof(mess));
|
||||
// cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
|
||||
cprintf(RED, "%s returned error: %s", (isReceiver ? "Receiver" : "Detector"), mess);
|
||||
FILE_LOG(logERROR) << socketType << " returned error: " << mess;
|
||||
std::cout << "\n"; // needed to reset the color.
|
||||
|
||||
// unrecognized function, do not ask for retval
|
||||
if (strstr(mess, "Unrecognized Function") != nullptr)
|
||||
unrecognizedFunction = true;
|
||||
|
||||
// Do we need to know hostname here?
|
||||
// In that case save it???
|
||||
if (isReceiver) {
|
||||
if (socketType == "Receiver") {
|
||||
throw ReceiverError(mess);
|
||||
} else {
|
||||
} else if (socketType == "Detector") {
|
||||
throw DetectorError(mess);
|
||||
} else {
|
||||
throw GuiError(mess);
|
||||
}
|
||||
}
|
||||
// get retval
|
||||
if (!unrecognizedFunction)
|
||||
receiveData(retval, retval_size);
|
||||
receiveData(retval, retval_size);
|
||||
}
|
||||
|
||||
}; // namespace sls
|
||||
|
||||
0
slsSupportLib/src/CmdLineParser.cpp
Normal file → Executable file
0
slsSupportLib/src/CmdLineParser.cpp
Normal file → Executable file
5
slsSupportLib/src/DataSocket.cpp
Normal file → Executable file
5
slsSupportLib/src/DataSocket.cpp
Normal file → Executable file
@@ -88,6 +88,11 @@ void DataSocket::close() {
|
||||
}
|
||||
}
|
||||
|
||||
void DataSocket::shutDownSocket() {
|
||||
shutdown(getSocketId(), SHUT_RDWR);
|
||||
close();
|
||||
}
|
||||
|
||||
struct sockaddr_in ConvertHostnameToInternetAddress(const std::string &hostname) {
|
||||
struct addrinfo hints, *result;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
|
||||
0
slsSupportLib/src/ServerInterface.cpp
Normal file → Executable file
0
slsSupportLib/src/ServerInterface.cpp
Normal file → Executable file
54
slsSupportLib/src/ServerSocket.cpp
Normal file → Executable file
54
slsSupportLib/src/ServerSocket.cpp
Normal file → Executable file
@@ -1,25 +1,31 @@
|
||||
#include "ServerSocket.h"
|
||||
#include "DataSocket.h"
|
||||
#include "logger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#define DEFAULT_PACKET_SIZE 1286
|
||||
#define SOCKET_BUFFER_SIZE (100 * 1024 * 1024) //100 MB
|
||||
#define SOCKET_BUFFER_SIZE (100 * 1024 * 1024) // 100 MB
|
||||
#define DEFAULT_BACKLOG 5
|
||||
|
||||
namespace sls {
|
||||
|
||||
ServerSocket::ServerSocket(int port) : DataSocket(socket(AF_INET, SOCK_STREAM, 0)) {
|
||||
|
||||
std::cout << "Server constructed\n";
|
||||
ServerSocket::ServerSocket(int port)
|
||||
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), serverPort(port) {
|
||||
|
||||
struct sockaddr_in serverAddr;
|
||||
serverAddr.sin_family = AF_INET;
|
||||
serverAddr.sin_port = htons(port);
|
||||
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if (bind(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
|
||||
if (bind(getSocketId(), (struct sockaddr *)&serverAddr,
|
||||
sizeof(serverAddr)) != 0) {
|
||||
close();
|
||||
throw std::runtime_error("Server ERROR: cannot bind socket");
|
||||
}
|
||||
@@ -32,16 +38,42 @@ ServerSocket::ServerSocket(int port) : DataSocket(socket(AF_INET, SOCK_STREAM, 0
|
||||
DataSocket ServerSocket::accept() {
|
||||
struct sockaddr_in clientAddr;
|
||||
socklen_t addr_size = sizeof clientAddr;
|
||||
int newSocket = ::accept(getSocketId(), (struct sockaddr *)&clientAddr, &addr_size);
|
||||
int newSocket =
|
||||
::accept(getSocketId(), (struct sockaddr *)&clientAddr, &addr_size);
|
||||
if (newSocket == -1) {
|
||||
throw std::runtime_error("Server ERROR: socket accept failed\n");
|
||||
}
|
||||
inet_ntop(AF_INET, &(clientAddr.sin_addr), &thisClient_.front(), INET_ADDRSTRLEN);
|
||||
std::cout << "lastClient: " << lastClient_ << " thisClient: " << thisClient_ << '\n';
|
||||
//Here goes any check for locks etc
|
||||
inet_ntop(AF_INET, &(clientAddr.sin_addr), &thisClient_.front(),
|
||||
INET_ADDRSTRLEN);
|
||||
std::cout << "lastClient: " << lastClient_ << " thisClient: " << thisClient_
|
||||
<< '\n';
|
||||
// Here goes any check for locks etc
|
||||
lastClient_ = thisClient_;
|
||||
|
||||
return DataSocket(newSocket);
|
||||
}
|
||||
|
||||
}; //namespace sls
|
||||
const std::string &ServerSocket::getLastClient() { return lastClient_; }
|
||||
|
||||
const int ServerSocket::getPort() { return serverPort; }
|
||||
|
||||
void ServerSocket::SendResult(int &ret, void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// send success of operation
|
||||
sendData(&ret, sizeof(ret));
|
||||
|
||||
if (ret == slsDetectorDefs::FAIL) {
|
||||
// create error message if empty
|
||||
if (!strlen(mess)) {
|
||||
strcpy(mess, "No error message provided for this failure in server. Will mess up TCP.");
|
||||
}
|
||||
|
||||
sendData(mess, MAX_STR_LENGTH);
|
||||
throw sls::RuntimeError(mess);
|
||||
}
|
||||
// send return value
|
||||
sendData(retval, retvalSize);
|
||||
}
|
||||
|
||||
|
||||
}; // namespace sls
|
||||
|
||||
0
slsSupportLib/src/file_utils.cpp
Normal file → Executable file
0
slsSupportLib/src/file_utils.cpp
Normal file → Executable file
0
slsSupportLib/src/network_utils.cpp
Normal file → Executable file
0
slsSupportLib/src/network_utils.cpp
Normal file → Executable file
0
slsSupportLib/src/string_utils.cpp
Normal file → Executable file
0
slsSupportLib/src/string_utils.cpp
Normal file → Executable file
0
slsSupportLib/tests/CMakeLists.txt
Normal file → Executable file
0
slsSupportLib/tests/CMakeLists.txt
Normal file → Executable file
0
slsSupportLib/tests/test-ClientInterface.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-ClientInterface.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-CmdLineParser.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-CmdLineParser.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-Timer.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-Timer.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-container_utils.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-container_utils.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-network_utils.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-network_utils.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-string_utils.cpp
Normal file → Executable file
0
slsSupportLib/tests/test-string_utils.cpp
Normal file → Executable file
Reference in New Issue
Block a user