mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 15:20:02 +02:00
exceptions TCP (#31)
* WIP * first test * format * test frames * also 0: * WIP * WIP * first test * format * test frames * also 0: * test and less local * pass ret by value * level * WIP * WIP * cleaning up interface * removed ref * another * updated api version * cleanup * cleanup * WIP * fixes * fixed tests
This commit is contained in:
parent
a6144f658e
commit
1db7521cfa
@ -788,6 +788,10 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
*/
|
*/
|
||||||
int getDataBytes(int detPos = -1);
|
int getDataBytes(int detPos = -1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of detectors in the multi structure*/
|
||||||
|
size_t size() const{ return detectors.size();}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set/get dacs value
|
* Set/get dacs value
|
||||||
* @param val value (in V)
|
* @param val value (in V)
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include "versionAPI.h"
|
|
||||||
#include "multiSlsDetectorClient.h"
|
#include "multiSlsDetectorClient.h"
|
||||||
|
#include "versionAPI.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (!(strcmp(argv[i], "--version")) || !(strcmp(argv[i], "-v"))) {
|
if (!(strcmp(argv[i], "--version")) || !(strcmp(argv[i], "-v"))) {
|
||||||
int64_t tempval = APILIB;
|
int64_t tempval = APILIB;
|
||||||
std::cout << argv[0] << " " << GITBRANCH << " (0x" << std::hex << tempval << ")" << std::endl;
|
std::cout << argv[0] << " " << GITBRANCH << " (0x" << std::hex
|
||||||
|
<< tempval << ")" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,5 +28,8 @@ int main(int argc, char *argv[]) {
|
|||||||
int action = slsDetectorDefs::HELP_ACTION;
|
int action = slsDetectorDefs::HELP_ACTION;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
multiSlsDetectorClient(argc, argv, action);
|
try {
|
||||||
|
multiSlsDetectorClient(argc, argv, action);
|
||||||
|
} catch (const sls::RuntimeError &e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ TEST_CASE("rx_fifodepth", "[.cmd]") {
|
|||||||
REQUIRE(oss.str() == "0:rx_fifodepth 100\n");
|
REQUIRE(oss.str() == "0:rx_fifodepth 100\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("frames", "[.cmd]"){
|
TEST_CASE("frames", "[.cmd]") {
|
||||||
auto oss = std::ostringstream{};
|
auto oss = std::ostringstream{};
|
||||||
multiSlsDetectorClient("frames 1000", PUT, nullptr, oss);
|
multiSlsDetectorClient("frames 1000", PUT, nullptr, oss);
|
||||||
REQUIRE(oss.str() == "frames 1000\n");
|
REQUIRE(oss.str() == "frames 1000\n");
|
||||||
@ -36,5 +36,239 @@ TEST_CASE("frames", "[.cmd]"){
|
|||||||
oss = std::ostringstream{};
|
oss = std::ostringstream{};
|
||||||
multiSlsDetectorClient("frames 1", PUT, nullptr, oss);
|
multiSlsDetectorClient("frames 1", PUT, nullptr, oss);
|
||||||
REQUIRE(oss.str() == "frames 1\n");
|
REQUIRE(oss.str() == "frames 1\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("receiver", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("receiver start", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "receiver running\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("receiver", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "receiver running\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("receiver stop", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "receiver idle\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("receiver", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "receiver idle\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("enablefwrite", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("enablefwrite 1", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "enablefwrite 1\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("enablefwrite", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "enablefwrite 1\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("enablefwrite 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "enablefwrite 0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("enableoverwrite", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("overwrite 1", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "overwrite 1\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("overwrite", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "overwrite 1\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("overwrite 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "overwrite 0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("activatecmd", "[.cmd]") {
|
||||||
|
// TODO! read padding from somewhere
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("activate 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "activate 0 padding\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("activate", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "activate 0 padding\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("activate 1", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "activate 1 padding\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("masterfile", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("masterfile 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "masterfile 0\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("masterfile", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "masterfile 0\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("masterfile 1", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "masterfile 1\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("index", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("index 57", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "index 57\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("index", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "index 57\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("index 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "index 0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("rx_tcpport", "[.cmd]") {
|
||||||
|
multiSlsDetector d;
|
||||||
|
int port = 1500;
|
||||||
|
int base = 1954;
|
||||||
|
for (size_t i = 0; i != d.size(); ++i) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
std::string cmd =
|
||||||
|
std::to_string(i) + ":rx_tcpport " + std::to_string(port + i);
|
||||||
|
std::cout << cmd << "\n";
|
||||||
|
multiSlsDetectorClient(cmd, PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == cmd + "\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
REQUIRE_THROWS(
|
||||||
|
multiSlsDetectorClient("rx_tcpport 15", PUT, nullptr, oss));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i != d.size(); ++i) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
std::string cmd = std::to_string(i) + ":rx_tcpport";
|
||||||
|
multiSlsDetectorClient(cmd, GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == cmd + " " + std::to_string(port + i) + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i != d.size(); ++i) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
std::string cmd =
|
||||||
|
std::to_string(i) + ":rx_tcpport " + std::to_string(base + i);
|
||||||
|
multiSlsDetectorClient(cmd, PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == cmd + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("fname", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("fname somename", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "fname somename\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("fname", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "fname somename\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("fname run", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "fname run\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("resetframescaught get framescaught", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("resetframescaught 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "resetframescaught successful\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("framescaught", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "framescaught 0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("r_silent", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_silent 1", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_silent 1\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_silent", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_silent 1\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_silent 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_silent 0\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TEST_CASE("rx_jsonaddheader", "[.cmd]") {
|
||||||
|
// auto oss = std::ostringstream{};
|
||||||
|
// multiSlsDetectorClient("rx_jsonaddheader \"hej\":\"5\"", PUT, nullptr,
|
||||||
|
// oss); REQUIRE(oss.str() == "rx_jsonaddheader \"hej\":\"5\"\n");
|
||||||
|
|
||||||
|
// oss = std::ostringstream{};
|
||||||
|
// multiSlsDetectorClient("rx_jsonaddheader", GET, nullptr, oss);
|
||||||
|
// REQUIRE(oss.str() == "rx_jsonaddheader \"hej\":\"5\"\n");
|
||||||
|
|
||||||
|
// oss = std::ostringstream{};
|
||||||
|
// multiSlsDetectorClient("rx_jsonaddheader \"\"", PUT, nullptr, oss);
|
||||||
|
// REQUIRE(oss.str() == "rx_jsonaddheader\n");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// TEST_CASE("rx_udpsocksize", "[.cmd]") {
|
||||||
|
// auto oss = std::ostringstream{};
|
||||||
|
// multiSlsDetectorClient("rx_udpsocksize 4857600", PUT, nullptr, oss);
|
||||||
|
// REQUIRE(oss.str() == "rx_udpsocksize 4857600\n");
|
||||||
|
|
||||||
|
// oss = std::ostringstream{};
|
||||||
|
// multiSlsDetectorClient("rx_udpsocksize", GET, nullptr, oss);
|
||||||
|
// REQUIRE(oss.str() == "rx_udpsocksize 4857600\n");
|
||||||
|
|
||||||
|
// oss = std::ostringstream{};
|
||||||
|
// multiSlsDetectorClient("rx_udpsocksize 104857600", PUT, nullptr, oss);
|
||||||
|
// REQUIRE(oss.str() == "rx_udpsocksize 104857600\n");
|
||||||
|
// }
|
||||||
|
|
||||||
|
TEST_CASE("r_framesperfile", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_framesperfile 50", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_framesperfile 50\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_framesperfile", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_framesperfile 50\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_framesperfile 10000", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_framesperfile 10000\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("r_discardpolicy", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_discardpolicy discardempty", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_discardpolicy discardempty\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_discardpolicy", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_discardpolicy discardempty\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_discardpolicy discardpartial", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_discardpolicy discardpartial\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_discardpolicy nodiscard", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_discardpolicy nodiscard\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("r_padding", "[.cmd]") {
|
||||||
|
auto oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_padding 0", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_padding 0\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_padding", GET, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_padding 0\n");
|
||||||
|
|
||||||
|
oss = std::ostringstream{};
|
||||||
|
multiSlsDetectorClient("r_padding 1", PUT, nullptr, oss);
|
||||||
|
REQUIRE(oss.str() == "r_padding 1\n");
|
||||||
}
|
}
|
@ -125,11 +125,6 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void validate(T arg, T retval, std::string modename, numberMode hex);
|
void validate(T arg, T retval, std::string modename, numberMode hex);
|
||||||
|
|
||||||
/** Unrecognized Function */
|
|
||||||
int M_nofunc(sls::ServerInterface2 & socket);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Execute command */
|
/** Execute command */
|
||||||
int exec_command(sls::ServerInterface2 &socket);
|
int exec_command(sls::ServerInterface2 &socket);
|
||||||
|
|
||||||
@ -298,10 +293,6 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs {
|
|||||||
/** set dbit offset */
|
/** set dbit offset */
|
||||||
int set_dbit_offset(sls::ServerInterface2 &socket);
|
int set_dbit_offset(sls::ServerInterface2 &socket);
|
||||||
|
|
||||||
|
|
||||||
int LogSocketCrash();
|
|
||||||
void NullObjectError(int& ret, char* mess);
|
|
||||||
|
|
||||||
/** detector type */
|
/** detector type */
|
||||||
detectorType myDetectorType;
|
detectorType myDetectorType;
|
||||||
|
|
||||||
@ -390,6 +381,14 @@ protected:
|
|||||||
std::unique_ptr<sls::ServerSocket> server{nullptr};
|
std::unique_ptr<sls::ServerSocket> server{nullptr};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int VerifyLock(int &ret, char *mess);
|
void VerifyLock();
|
||||||
int VerifyLockAndIdle(int &ret, char *mess, int fnum);
|
void VerifyIdle(sls::ServerInterface2& socket);
|
||||||
|
|
||||||
|
slsReceiverImplementation* impl(){
|
||||||
|
if (receiver!=nullptr){
|
||||||
|
return receiver.get();
|
||||||
|
}else{
|
||||||
|
throw sls::SocketError("Receiver not set up. Please use rx_hostname first.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -571,7 +571,7 @@ void slsReceiverImplementation::setFilePath(const char c[]) {
|
|||||||
if(stat(c,&st) == 0)
|
if(stat(c,&st) == 0)
|
||||||
strcpy(filePath,c);
|
strcpy(filePath,c);
|
||||||
else
|
else
|
||||||
FILE_LOG(logERROR) << "FilePath does not exist: " << filePath;
|
FILE_LOG(logERROR) << "FilePath does not exist: " << c;
|
||||||
}
|
}
|
||||||
FILE_LOG(logINFO) << "File path: " << filePath;
|
FILE_LOG(logINFO) << "File path: " << filePath;
|
||||||
}
|
}
|
||||||
@ -1059,7 +1059,7 @@ int slsReceiverImplementation::setFifoDepth(const uint32_t i) {
|
|||||||
if (fifoDepth != i) {
|
if (fifoDepth != i) {
|
||||||
fifoDepth = i;
|
fifoDepth = i;
|
||||||
if (SetupFifoStructure() == FAIL)
|
if (SetupFifoStructure() == FAIL)
|
||||||
return FAIL;
|
throw sls::RuntimeError("Failed to setup fifo structure");
|
||||||
}
|
}
|
||||||
FILE_LOG(logINFO) << "Fifo Depth: " << i;
|
FILE_LOG(logINFO) << "Fifo Depth: " << i;
|
||||||
return OK;
|
return OK;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -15,12 +15,16 @@ class DataSocket {
|
|||||||
void swap(DataSocket &other) noexcept;
|
void swap(DataSocket &other) noexcept;
|
||||||
DataSocket(const DataSocket &) = delete;
|
DataSocket(const DataSocket &) = delete;
|
||||||
DataSocket &operator=(DataSocket const &) = delete;
|
DataSocket &operator=(DataSocket const &) = delete;
|
||||||
int getSocketId() const {
|
int getSocketId() const { return socketId_; }
|
||||||
return socketId_;
|
|
||||||
}
|
|
||||||
int sendData(const void *buffer, size_t size);
|
int sendData(const void *buffer, size_t size);
|
||||||
|
|
||||||
|
template <typename T> int sendData(T &&data) {
|
||||||
|
return sendData(&data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
int receiveData(void *buffer, size_t size);
|
int receiveData(void *buffer, size_t size);
|
||||||
int read(void *buffer, size_t size);
|
int read(void *buffer, size_t size);
|
||||||
|
int write(void *buffer, size_t size);
|
||||||
int setTimeOut(int t_seconds);
|
int setTimeOut(int t_seconds);
|
||||||
int setReceiveTimeout(int us);
|
int setReceiveTimeout(int us);
|
||||||
void close();
|
void close();
|
||||||
@ -30,9 +34,12 @@ class DataSocket {
|
|||||||
int socketId_ = -1;
|
int socketId_ = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
int ConvertHostnameToInternetAddress(const char *const hostname, struct ::addrinfo **res);
|
int ConvertHostnameToInternetAddress(const char *const hostname,
|
||||||
int ConvertInternetAddresstoIpString(struct ::addrinfo *res, char *ip, const int ipsize);
|
struct ::addrinfo **res);
|
||||||
|
int ConvertInternetAddresstoIpString(struct ::addrinfo *res, char *ip,
|
||||||
|
const int ipsize);
|
||||||
|
|
||||||
struct ::sockaddr_in ConvertHostnameToInternetAddress(const std::string &hostname);
|
struct ::sockaddr_in
|
||||||
|
ConvertHostnameToInternetAddress(const std::string &hostname);
|
||||||
|
|
||||||
}; // namespace sls
|
}; // namespace sls
|
||||||
|
@ -13,16 +13,32 @@ class ServerInterface2 : public DataSocket {
|
|||||||
using defs = slsDetectorDefs;
|
using defs = slsDetectorDefs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerInterface2(int socketId) : DataSocket(socketId){}
|
ServerInterface2(int socketId) : DataSocket(socketId) {}
|
||||||
|
|
||||||
int sendResult(bool update, int ret, void *retval, int retvalSize,
|
int sendResult(int ret, void *retval, int retvalSize, char *mess = nullptr);
|
||||||
char *mess = nullptr);
|
|
||||||
int receiveArg(int &ret, char *mess, void *arg, int sizeofArg);
|
|
||||||
|
|
||||||
|
template <typename T> int sendResult(int ret, T &retval) {
|
||||||
|
return sendResult(ret, &retval, sizeof(retval, nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> int sendResult(T &&retval) {
|
||||||
|
sendData(defs::OK);
|
||||||
|
sendData(retval);
|
||||||
|
return defs::OK;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
int receiveArg(void *arg, int sizeofArg);
|
||||||
|
|
||||||
|
template <typename T> int receiveArg(T &arg) {
|
||||||
|
return receiveArg(&arg, sizeof(arg));
|
||||||
|
}
|
||||||
|
template <typename T> T receive() {
|
||||||
|
T arg;
|
||||||
|
receiveArg(&arg, sizeof(arg));
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
@ -15,13 +15,13 @@ class ServerSocket : public DataSocket {
|
|||||||
public:
|
public:
|
||||||
ServerSocket(int port);
|
ServerSocket(int port);
|
||||||
ServerInterface2 accept();
|
ServerInterface2 accept();
|
||||||
IpAddr getLastClient() noexcept { return lastClient; }
|
IpAddr getLastClient() const noexcept { return lastClient; }
|
||||||
IpAddr getThisClient() noexcept { return thisClient; }
|
IpAddr getThisClient() const noexcept { return thisClient; }
|
||||||
IpAddr getLockedBy() noexcept { return lockedBy; }
|
IpAddr getLockedBy() const noexcept { return lockedBy; }
|
||||||
|
bool differentClients() const noexcept {return lastClient != thisClient;}
|
||||||
void setLockedBy(IpAddr addr) { lockedBy = addr; }
|
void setLockedBy(IpAddr addr) { lockedBy = addr; }
|
||||||
void setLastClient(IpAddr addr) { lastClient = addr; }
|
void setLastClient(IpAddr addr) { lastClient = addr; }
|
||||||
int getPort() const;
|
int getPort() const noexcept { return serverPort; }
|
||||||
void SendResult(int &ret, void *retval, int retvalSize, char *mess);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IpAddr thisClient;
|
IpAddr thisClient;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
/** API versions */
|
/** API versions */
|
||||||
#define GITBRANCH "refgui"
|
#define GITBRANCH "refgui"
|
||||||
#define APIMOENCH 0x181108
|
#define APIMOENCH 0x181108
|
||||||
#define APILIB 0x190405
|
#define APILIB 0x190604
|
||||||
#define APIRECEIVER 0x190405
|
#define APIRECEIVER 0x190604
|
||||||
#define APIGUI 0x190405
|
#define APIGUI 0x190405
|
||||||
#define APIGOTTHARD 0x190604
|
|
||||||
#define APIJUNGFRAU 0x190604
|
|
||||||
#define APIEIGER 0x190604
|
|
||||||
#define APICTB 0x190604
|
#define APICTB 0x190604
|
||||||
|
#define APIEIGER 0x190604
|
||||||
|
#define APIJUNGFRAU 0x190604
|
||||||
|
#define APIGOTTHARD 0x190604
|
@ -70,11 +70,11 @@ int ClientSocket::sendCommandThenRead(int fnum, const void *args,
|
|||||||
|
|
||||||
void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
||||||
|
|
||||||
receiveData(&ret, sizeof(ret));
|
read(&ret, sizeof(ret));
|
||||||
if (ret == slsDetectorDefs::FAIL) {
|
if (ret == slsDetectorDefs::FAIL) {
|
||||||
char mess[MAX_STR_LENGTH]{};
|
char mess[MAX_STR_LENGTH]{};
|
||||||
// get error message
|
// get error message
|
||||||
receiveData(mess, sizeof(mess));
|
read(mess, sizeof(mess));
|
||||||
FILE_LOG(logERROR) << socketType << " returned error: " << mess;
|
FILE_LOG(logERROR) << socketType << " returned error: " << mess;
|
||||||
std::cout << "\n"; // needed to reset the color.
|
std::cout << "\n"; // needed to reset the color.
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// get retval
|
// get retval
|
||||||
receiveData(retval, retval_size);
|
read(retval, retval_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace sls
|
}; // namespace sls
|
||||||
|
@ -51,7 +51,11 @@ int DataSocket::receiveData(void *buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DataSocket::read(void *buffer, size_t size){
|
int DataSocket::read(void *buffer, size_t size){
|
||||||
return ::read(getSocketId(), reinterpret_cast<char *>(buffer), size);
|
return ::read(getSocketId(), buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DataSocket::write(void *buffer, size_t size){
|
||||||
|
return ::write(getSocketId(), buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataSocket::setReceiveTimeout(int us) {
|
int DataSocket::setReceiveTimeout(int us) {
|
||||||
@ -64,13 +68,11 @@ int DataSocket::setReceiveTimeout(int us) {
|
|||||||
|
|
||||||
|
|
||||||
int DataSocket::sendData(const void *buffer, size_t size) {
|
int DataSocket::sendData(const void *buffer, size_t size) {
|
||||||
int dataSent = 0;
|
// int dataSent = 0;
|
||||||
while (dataSent < (int)size) {
|
// while (dataSent < (int)size) {
|
||||||
dataSent +=
|
return ::write(getSocketId(), buffer, size);
|
||||||
write(getSocketId(), reinterpret_cast<const char *>(buffer) + dataSent,
|
// }
|
||||||
size - dataSent);
|
// return dataSent;
|
||||||
}
|
|
||||||
return dataSent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DataSocket::setTimeOut(int t_seconds) {
|
int DataSocket::setTimeOut(int t_seconds) {
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
#include "ServerInterface2.h"
|
#include "ServerInterface2.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
#include <sstream>
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
int ServerInterface2::sendResult(bool update, int ret, void *retval,
|
int ServerInterface2::sendResult(int ret, void *retval, int retvalSize,
|
||||||
int retvalSize, char *mess) {
|
char *mess) {
|
||||||
|
|
||||||
// if (update && ret == defs::OK && server_->DifferentClients()) {
|
write(&ret, sizeof(ret));
|
||||||
// ret = defs::FORCE_UPDATE;
|
|
||||||
// }
|
|
||||||
sendData(&ret, sizeof(ret));
|
|
||||||
if (ret == defs::FAIL) {
|
if (ret == defs::FAIL) {
|
||||||
// send error message
|
if (mess != nullptr) {
|
||||||
if (mess)
|
write(mess, MAX_STR_LENGTH);
|
||||||
sendData(mess, MAX_STR_LENGTH);
|
} else {
|
||||||
// debugging feature. should not happen.
|
|
||||||
else
|
|
||||||
FILE_LOG(logERROR) << "No error message provided for this "
|
FILE_LOG(logERROR) << "No error message provided for this "
|
||||||
"failure. Will mess up TCP\n";
|
"failure. Will mess up TCP\n";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write(retval, retvalSize);
|
||||||
}
|
}
|
||||||
sendData(retval, retvalSize);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerInterface2::receiveArg(int &ret, char *mess, void *arg,
|
int ServerInterface2::receiveArg(void *arg, int sizeofArg) {
|
||||||
int sizeofArg) {
|
|
||||||
assert(sizeofArg > 0);
|
assert(sizeofArg > 0);
|
||||||
int bytes_read = read(arg, sizeofArg);
|
int bytes_read = read(arg, sizeofArg);
|
||||||
if (bytes_read == sizeofArg) {
|
if (bytes_read == sizeofArg) {
|
||||||
return defs::OK;
|
return defs::OK;
|
||||||
} else {
|
} else {
|
||||||
FILE_LOG(logERROR) << "Read: " << bytes_read << " instead of "
|
std::ostringstream ss;
|
||||||
<< sizeofArg;
|
ss << "TCP socket error read " << bytes_read << " bytes instead of "
|
||||||
return defs::FAIL;
|
<< sizeofArg << " bytes";
|
||||||
|
|
||||||
|
throw sls::SocketError(ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,26 +52,4 @@ ServerInterface2 ServerSocket::accept() {
|
|||||||
return ServerInterface2(newSocket);
|
return ServerInterface2(newSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ServerSocket::getPort() const { 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
|
}; // namespace sls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user