changed constructor

This commit is contained in:
Erik Frojdh
2019-01-24 11:12:24 +01:00
parent c3472f295b
commit a1c0d28ddb
16 changed files with 113 additions and 334 deletions

View File

@ -9,16 +9,21 @@ set(SOURCES
set(HEADERS
)
include_directories(
multiSlsDetector
sharedMemory
slsDetector
)
# include_directories(
# multiSlsDetector
# sharedMemory
# slsDetector
# )
add_library(slsDetectorShared SHARED
${SOURCES}
${HEADERS}
)
target_include_directories(slsDetectorShared PUBLIC
multiSlsDetector
sharedMemory
slsDetector
)
target_link_libraries(slsDetectorShared
slsSupportLib

View File

@ -482,24 +482,9 @@ void multiSlsDetector::addSlsDetector(const std::string &hostname) {
}
}
// check entire shared memory if it doesnt exist?? needed?
// could be that detectors not loaded completely cuz of crash in new
// slsdetector in initsharedmemory
// get type by connecting
detectorType type = slsDetector::getDetectorTypeAsEnum(hostname.c_str(), DEFAULT_PORTNO);
if (type == GENERIC) {
FILE_LOG(logERROR) << "Could not connect to Detector " << hostname
<< " to determine the type!";
setErrorMask(getErrorMask() | MULTI_DETECTORS_NOT_ADDED);
appendNotAddedList(hostname.c_str());
return;
}
int pos = (int)detectors.size();
detectors.push_back(sls::make_unique<slsDetector>(type, detId, pos, false));
detectors.push_back(sls::make_unique<slsDetector>(hostname, detId, pos, false));
thisMultiDetector->numberOfDetectors = detectors.size();
detectors[pos]->setHostname(hostname.c_str()); // also updates client
thisMultiDetector->dataBytes += detectors[pos]->getDataBytes();
thisMultiDetector->dataBytesInclGapPixels +=
detectors[pos]->getDataBytesInclGapPixels();

View File

@ -1,5 +1,5 @@
#include "slsDetector.h"
#include "ClientInterface.h"
#include "ServerInterface.h"
#include "ClientSocket.h"
#include "MySocketTCP.h"
#include "SharedMemory.h"
@ -24,7 +24,7 @@
#define DEFAULT_HOSTNAME "localhost"
slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
slsDetector::slsDetector(const std::string& hostname, int multiId, int id, bool verify)
: detId(id) {
/* called from put hostname command,
* so sls shared memory will be created */
@ -37,11 +37,17 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify)
<< shm.GetName() << ". Freeing it again";
freeSharedMemory(multiId, id);
}
auto type = getDetectorTypeAsEnum(hostname);
if (type == GENERIC) {
FILE_LOG(logERROR) << "Could not connect to Detector " << hostname
<< " to determine the type!";
throw std::runtime_error("Cannot connect");
}
initSharedMemory(true, type, multiId, verify);
initializeDetectorStructure(type);
initializeMembers();
initializeDetectorStructurePointers();
setHostname(hostname.c_str());
}
slsDetector::slsDetector(int multiId, int id, bool verify)
@ -225,15 +231,15 @@ void slsDetector::freeSharedMemory() {
thisDetector = nullptr;
}
void slsDetector::setHostname(const char *name) {
setTCPSocket(std::string(name));
void slsDetector::setHostname(const std::string& hostname) {
setTCPSocket(hostname);
if (thisDetector->onlineFlag == ONLINE_FLAG) {
updateDetector();
}
}
std::string slsDetector::getHostname() {
return std::string(thisDetector->hostname);
return thisDetector->hostname;
}
/*
@ -502,9 +508,9 @@ void slsDetector::initializeMembers() {
delete thisReceiver;
thisReceiver = nullptr;
}
thisDetectorControl = new ClientInterface(controlSocket, detId, "Detector (Control server)");
thisDetectorStop = new ClientInterface(stopSocket, detId, "Detector (Stop server)");
thisReceiver = new ClientInterface(dataSocket, detId, "Receiver");
thisDetectorControl = new ServerInterface(controlSocket, detId, "Detector (Control server)");
thisDetectorStop = new ServerInterface(stopSocket, detId, "Detector (Stop server)");
thisReceiver = new ServerInterface(dataSocket, detId, "Receiver");
}
void slsDetector::initializeDetectorStructurePointers() {

View File

@ -17,7 +17,7 @@
class multiSlsDetector;
class SharedMemory;
class ClientInterface;
class ServerInterface;
class MySocketTCP;
#define SLS_SHMVERSION 0x181005
@ -273,7 +273,10 @@ public:
* @param id sls detector id (position in detectors list)
* @param verify true to verify if shared memory version matches existing one
*/
explicit slsDetector(detectorType type, int multiId = 0, int id = 0, bool verify = true);
explicit slsDetector(const std::string& hostname,
int multiId = 0,
int id = 0,
bool verify = true);
/**
* Constructor called when opening existing shared memory
@ -326,7 +329,7 @@ public:
* Connects to them to set up online flag
* @param name hostname
*/
void setHostname(const char *name);
void setHostname(const std::string& hostname);
/**
* Gets the hostname of detector
@ -1774,13 +1777,13 @@ private:
sharedSlsDetector *thisDetector {nullptr};
/** control socket interface */
ClientInterface *thisDetectorControl {nullptr};
ServerInterface *thisDetectorControl {nullptr};
/** stop socket interface */
ClientInterface *thisDetectorStop {nullptr};
ServerInterface *thisDetectorStop {nullptr};
/** receiver interface */
ClientInterface *thisReceiver {nullptr};
ServerInterface *thisReceiver {nullptr};
/** socket for control commands */
MySocketTCP *controlSocket {nullptr};