mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
virtual servers using command virtual numdet port
This commit is contained in:
parent
c6dddaba97
commit
d10d9462a3
Binary file not shown.
@ -306,6 +306,13 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
||||
*/
|
||||
std::string getUserDetails(); // part of multi
|
||||
|
||||
/**
|
||||
* Connect to Virtual Detector Servers at local host
|
||||
* @param ndet number of detectors
|
||||
* @param port starting port number
|
||||
*/
|
||||
void setVirtualDetectorServers(const int numdet, const int port);
|
||||
|
||||
/**
|
||||
* Sets the hostname of all sls detectors in shared memory and updates local
|
||||
* cache
|
||||
|
@ -351,6 +351,15 @@ std::string multiSlsDetector::exec(const char *cmd) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void multiSlsDetector::setVirtualDetectorServers(const int numdet, const int port) {
|
||||
std::vector <std::string> hostnames;
|
||||
for (int i = 0; i < numdet; ++i) {
|
||||
// * 2 is for control and stop port
|
||||
hostnames.push_back(std::string("localhost:") + std::to_string(port + i * 2));
|
||||
}
|
||||
setHostname(hostnames);
|
||||
}
|
||||
|
||||
void multiSlsDetector::setHostname(const std::vector<std::string> &name) {
|
||||
// this check is there only to allow the previous detsizechan command
|
||||
if (multi_shm()->numberOfDetectors != 0) {
|
||||
@ -363,6 +372,7 @@ void multiSlsDetector::setHostname(const std::vector<std::string> &name) {
|
||||
for (const auto &hostname : name) {
|
||||
addSlsDetector(hostname);
|
||||
}
|
||||
updateDetectorSize();
|
||||
}
|
||||
|
||||
void multiSlsDetector::setHostname(const char *name, int detPos) {
|
||||
@ -392,7 +402,7 @@ std::string multiSlsDetector::getHostname(int detPos) const {
|
||||
|
||||
// multi
|
||||
auto r = serialCall(&slsDetector::getHostname);
|
||||
return sls::concatenateIfDifferent(r);
|
||||
return sls::concatenateNonEmptyStrings(r);
|
||||
}
|
||||
|
||||
void multiSlsDetector::addMultipleDetectors(const char *name) {
|
||||
|
@ -268,6 +268,14 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdHostname;
|
||||
++i;
|
||||
|
||||
/*! \page config
|
||||
- <b>virtual [n] [p]</b> \c connects to n virtual detector servers at local host starting at port p \c Returns the list of the hostnames of the multi-detector structure. \c (string)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "virtual";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdHostname;
|
||||
++i;
|
||||
|
||||
|
||||
/*! \page config
|
||||
- <b>user</b> \c Returns user details from shared memory. Only allowed at multi detector level. Cannot put. \c (string)
|
||||
*/
|
||||
@ -2345,7 +2353,7 @@ std::string slsDetectorCommand::cmdHostname(int narg, const char * const args[],
|
||||
|
||||
if (action == PUT_ACTION) {
|
||||
if (detPos >= 0) {
|
||||
return std::string("Wrong usage - setting hostname/add only from "
|
||||
return std::string("Wrong usage - setting hostname/virtual only from "
|
||||
"multiDetector level");
|
||||
}
|
||||
|
||||
@ -2357,10 +2365,23 @@ std::string slsDetectorCommand::cmdHostname(int narg, const char * const args[],
|
||||
if (narg > 2)
|
||||
strcat(hostname, "+");
|
||||
}
|
||||
|
||||
myDet->setHostname(hostname, detPos);
|
||||
if (cmd == "hostname") {
|
||||
myDet->setHostname(hostname, detPos);
|
||||
}
|
||||
else if (cmd == "virtual") {
|
||||
int port = -1;
|
||||
int numDetectors = 0;
|
||||
if (!sscanf(args[1], "%d", &numDetectors)) {
|
||||
throw sls::RuntimeError("Cannot scan number of detector servers from virtual command\n");
|
||||
}
|
||||
if (!sscanf(args[2], "%d", &port)) {
|
||||
throw sls::RuntimeError("Cannot scan port from virtual command\n");
|
||||
}
|
||||
myDet->setVirtualDetectorServers(numDetectors, port);
|
||||
} else {
|
||||
throw sls::RuntimeError("unknown command\n");
|
||||
}
|
||||
}
|
||||
|
||||
return myDet->getHostname(detPos);
|
||||
}
|
||||
|
||||
@ -2372,6 +2393,7 @@ std::string slsDetectorCommand::helpHostname(int action) {
|
||||
if (action == PUT_ACTION || action == HELP_ACTION) {
|
||||
os << std::string("hostname name [name name]\t frees shared memory and "
|
||||
"sets the hostname (or IP adress). Only allowed at multi detector level.\n");
|
||||
os << std::string("virtual [n] [p]\t connects to n virtual detector servers at local host starting at port p \n");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user