mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-16 23:07:13 +02:00
multiSlsDetectorClient.cpp added .h cleaned
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/multiSlsDetector.cpp
|
src/multiSlsDetector.cpp
|
||||||
|
src/multiSlsDetectorClient.cpp
|
||||||
src/slsDetectorUsers.cpp
|
src/slsDetectorUsers.cpp
|
||||||
src/slsDetectorCommand.cpp
|
src/slsDetectorCommand.cpp
|
||||||
src/slsDetector.cpp
|
src/slsDetector.cpp
|
||||||
|
@ -1,46 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "CmdLineParser.h"
|
#include "CmdLineParser.h"
|
||||||
#include "CmdProxy.h"
|
|
||||||
#include "Detector.h"
|
|
||||||
#include "container_utils.h"
|
|
||||||
#include "multiSlsDetector.h"
|
|
||||||
#include "slsDetectorCommand.h"
|
|
||||||
#include "sls_detector_exceptions.h"
|
|
||||||
#include "string_utils.h"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
class multiSlsDetector;
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
using sls::RuntimeError;
|
|
||||||
|
|
||||||
inline int dummyCallback(detectorData *d, int p, void *) {
|
|
||||||
std::cout << "got data " << p << std::endl;
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class multiSlsDetectorClient {
|
class multiSlsDetectorClient {
|
||||||
public:
|
public:
|
||||||
multiSlsDetectorClient(int argc, char *argv[], int action,
|
multiSlsDetectorClient(int argc, char *argv[], int action,
|
||||||
multiSlsDetector *myDetector = nullptr,
|
multiSlsDetector *myDetector = nullptr,
|
||||||
std::ostream &output = std::cout)
|
std::ostream &output = std::cout);
|
||||||
: action_(action), detPtr(myDetector), os(output) {
|
|
||||||
parser.Parse(argc, argv);
|
|
||||||
if (parser.isHelp())
|
|
||||||
action_ = slsDetectorDefs::HELP_ACTION;
|
|
||||||
runCommand();
|
|
||||||
}
|
|
||||||
multiSlsDetectorClient(const std::string &args, int action,
|
multiSlsDetectorClient(const std::string &args, int action,
|
||||||
multiSlsDetector *myDetector = nullptr,
|
multiSlsDetector *myDetector = nullptr,
|
||||||
std::ostream &output = std::cout)
|
std::ostream &output = std::cout);
|
||||||
: action_(action), detPtr(myDetector), os(output) {
|
|
||||||
parser.Parse(args);
|
|
||||||
if (parser.isHelp())
|
|
||||||
action_ = slsDetectorDefs::HELP_ACTION;
|
|
||||||
runCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int action_;
|
int action_;
|
||||||
@ -48,97 +19,5 @@ class multiSlsDetectorClient {
|
|||||||
multiSlsDetector *detPtr = nullptr;
|
multiSlsDetector *detPtr = nullptr;
|
||||||
std::ostream &os;
|
std::ostream &os;
|
||||||
|
|
||||||
void runCommand() {
|
void runCommand();
|
||||||
bool verify = true;
|
|
||||||
bool update = true;
|
|
||||||
if (action_ == slsDetectorDefs::PUT_ACTION &&
|
|
||||||
parser.n_arguments() == 0) {
|
|
||||||
os << "Wrong usage - should be: " << parser.executable()
|
|
||||||
<< "[id-][pos:]channel arg" << std::endl;
|
|
||||||
os << std::endl;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
if (action_ == slsDetectorDefs::GET_ACTION &&
|
|
||||||
parser.command().empty()) {
|
|
||||||
os << "Wrong usage - should be: " << parser.executable()
|
|
||||||
<< "[id-][pos:]channel arg" << std::endl;
|
|
||||||
os << std::endl;
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (action_ == slsDetectorDefs::READOUT_ACTION &&
|
|
||||||
parser.detector_id() != -1) {
|
|
||||||
os << "detector_id: " << parser.detector_id()
|
|
||||||
<< " ,readout of individual detectors is not allowed!"
|
|
||||||
<< std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// special commands
|
|
||||||
if (parser.command() == "free") {
|
|
||||||
multiSlsDetector::freeSharedMemory(parser.multi_id(),
|
|
||||||
parser.detector_id());
|
|
||||||
return;
|
|
||||||
} // get user details without verify sharedMultiSlsDetector version
|
|
||||||
else if ((parser.command() == "user") &&
|
|
||||||
(action_ == slsDetectorDefs::GET_ACTION)) {
|
|
||||||
verify = false;
|
|
||||||
update = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create multiSlsDetector class if required
|
|
||||||
std::unique_ptr<multiSlsDetector> localDet;
|
|
||||||
if (detPtr == nullptr) {
|
|
||||||
try {
|
|
||||||
localDet = sls::make_unique<multiSlsDetector>(parser.multi_id(),
|
|
||||||
verify, update);
|
|
||||||
detPtr = localDet.get();
|
|
||||||
} catch (const RuntimeError &e) {
|
|
||||||
/*os << e.GetMessage() << std::endl;*/
|
|
||||||
return;
|
|
||||||
} catch (...) {
|
|
||||||
os << " caught exception\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (parser.detector_id() >= static_cast<int>(detPtr->size())) {
|
|
||||||
os << "position is out of bounds.\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call CmdProxy which execute the command if it exists, on success
|
|
||||||
// returns an empty string If the command is not in CmdProxy but
|
|
||||||
// deprecated the new command is returned
|
|
||||||
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
|
||||||
int multi_id = 0;
|
|
||||||
if (detPtr != nullptr)
|
|
||||||
multi_id = detPtr->getMultiId();
|
|
||||||
sls::Detector d(multi_id);
|
|
||||||
sls::CmdProxy<sls::Detector> proxy(&d);
|
|
||||||
// sls::CmdProxy<multiSlsDetector> proxy(detPtr);
|
|
||||||
auto cmd = proxy.Call(parser.command(), parser.arguments(),
|
|
||||||
parser.detector_id(), action_);
|
|
||||||
if (cmd.empty()) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
parser.setCommand(cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// call multi detector command line
|
|
||||||
slsDetectorCommand myCmd(detPtr);
|
|
||||||
std::string answer =
|
|
||||||
myCmd.executeLine(parser.n_arguments() + 1, parser.argv().data(),
|
|
||||||
action_, parser.detector_id());
|
|
||||||
|
|
||||||
if (parser.multi_id() != 0)
|
|
||||||
os << parser.multi_id() << '-';
|
|
||||||
if (parser.detector_id() != -1)
|
|
||||||
os << parser.detector_id() << ':';
|
|
||||||
|
|
||||||
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
|
||||||
os << parser.command() << " ";
|
|
||||||
}
|
|
||||||
os << answer << std::endl;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
119
slsDetectorSoftware/src/multiSlsDetectorClient.cpp
Normal file
119
slsDetectorSoftware/src/multiSlsDetectorClient.cpp
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
#include "multiSlsDetectorClient.h"
|
||||||
|
#include "CmdProxy.h"
|
||||||
|
#include "Detector.h"
|
||||||
|
#include "multiSlsDetector.h"
|
||||||
|
#include "slsDetectorCommand.h"
|
||||||
|
#include "sls_detector_exceptions.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
multiSlsDetectorClient::multiSlsDetectorClient(int argc, char *argv[],
|
||||||
|
int action,
|
||||||
|
multiSlsDetector *myDetector,
|
||||||
|
std::ostream &output)
|
||||||
|
: action_(action), detPtr(myDetector), os(output) {
|
||||||
|
parser.Parse(argc, argv);
|
||||||
|
runCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
multiSlsDetectorClient::multiSlsDetectorClient(const std::string &args,
|
||||||
|
int action,
|
||||||
|
multiSlsDetector *myDetector,
|
||||||
|
std::ostream &output)
|
||||||
|
: action_(action), detPtr(myDetector), os(output) {
|
||||||
|
parser.Parse(args);
|
||||||
|
runCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
void multiSlsDetectorClient::runCommand() {
|
||||||
|
if (parser.isHelp())
|
||||||
|
action_ = slsDetectorDefs::HELP_ACTION;
|
||||||
|
bool verify = true;
|
||||||
|
bool update = true;
|
||||||
|
if (action_ == slsDetectorDefs::PUT_ACTION && parser.n_arguments() == 0) {
|
||||||
|
os << "Wrong usage - should be: " << parser.executable()
|
||||||
|
<< "[id-][pos:]channel arg" << std::endl;
|
||||||
|
os << std::endl;
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if (action_ == slsDetectorDefs::GET_ACTION && parser.command().empty()) {
|
||||||
|
os << "Wrong usage - should be: " << parser.executable()
|
||||||
|
<< "[id-][pos:]channel arg" << std::endl;
|
||||||
|
os << std::endl;
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (action_ == slsDetectorDefs::READOUT_ACTION &&
|
||||||
|
parser.detector_id() != -1) {
|
||||||
|
os << "detector_id: " << parser.detector_id()
|
||||||
|
<< " ,readout of individual detectors is not allowed!" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// special commands
|
||||||
|
if (parser.command() == "free") {
|
||||||
|
multiSlsDetector::freeSharedMemory(parser.multi_id(),
|
||||||
|
parser.detector_id());
|
||||||
|
return;
|
||||||
|
} // get user details without verify sharedMultiSlsDetector version
|
||||||
|
else if ((parser.command() == "user") &&
|
||||||
|
(action_ == slsDetectorDefs::GET_ACTION)) {
|
||||||
|
verify = false;
|
||||||
|
update = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create multiSlsDetector class if required
|
||||||
|
std::unique_ptr<multiSlsDetector> localDet;
|
||||||
|
if (detPtr == nullptr) {
|
||||||
|
try {
|
||||||
|
localDet = sls::make_unique<multiSlsDetector>(parser.multi_id(),
|
||||||
|
verify, update);
|
||||||
|
detPtr = localDet.get();
|
||||||
|
} catch (const sls::RuntimeError &e) {
|
||||||
|
/*os << e.GetMessage() << std::endl;*/
|
||||||
|
return;
|
||||||
|
} catch (...) {
|
||||||
|
os << " caught exception\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parser.detector_id() >= static_cast<int>(detPtr->size())) {
|
||||||
|
os << "position is out of bounds.\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call CmdProxy which execute the command if it exists, on success
|
||||||
|
// returns an empty string If the command is not in CmdProxy but
|
||||||
|
// deprecated the new command is returned
|
||||||
|
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
||||||
|
int multi_id = 0;
|
||||||
|
if (detPtr != nullptr)
|
||||||
|
multi_id = detPtr->getMultiId();
|
||||||
|
sls::Detector d(multi_id);
|
||||||
|
sls::CmdProxy<sls::Detector> proxy(&d);
|
||||||
|
// sls::CmdProxy<multiSlsDetector> proxy(detPtr);
|
||||||
|
auto cmd = proxy.Call(parser.command(), parser.arguments(),
|
||||||
|
parser.detector_id(), action_);
|
||||||
|
if (cmd.empty()) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
parser.setCommand(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// call multi detector command line
|
||||||
|
slsDetectorCommand myCmd(detPtr);
|
||||||
|
std::string answer =
|
||||||
|
myCmd.executeLine(parser.n_arguments() + 1, parser.argv().data(),
|
||||||
|
action_, parser.detector_id());
|
||||||
|
|
||||||
|
if (parser.multi_id() != 0)
|
||||||
|
os << parser.multi_id() << '-';
|
||||||
|
if (parser.detector_id() != -1)
|
||||||
|
os << parser.detector_id() << ':';
|
||||||
|
|
||||||
|
if (action_ != slsDetectorDefs::READOUT_ACTION) {
|
||||||
|
os << parser.command() << " ";
|
||||||
|
}
|
||||||
|
os << answer << std::endl;
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
#include "multiSlsDetectorClient.h"
|
#include "multiSlsDetectorClient.h"
|
||||||
|
#include "sls_detector_defs.h"
|
||||||
#include "versionAPI.h"
|
#include "versionAPI.h"
|
||||||
#include <cstdlib>
|
|
||||||
|
#include <cstring> //strcmp
|
||||||
|
|
||||||
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) {
|
||||||
|
Reference in New Issue
Block a user