added const methods for detector

This commit is contained in:
Erik Frojdh 2020-07-24 11:17:45 +02:00
parent e8556abbe7
commit 1fefc001f9
2 changed files with 92 additions and 26 deletions

View File

@ -2410,79 +2410,117 @@ void Module::preSendArgsCheck(const void *args, size_t args_size, void *retval,
static_assert(!std::is_same<ARG, std::nullptr_t>::value, \
"nullptr_t type is incompatible with templated " DST);
void Module::sendToDetector(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) {
static_cast<const Module &>(*this).sendToDetector(fnum, args, args_size,
retval, retval_size);
}
void Module::sendToDetector(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const {
// This is the only function that actually sends data to the detector
// the other versions use templates to deduce sizes and create
// the return type
preSendArgsCheck(args, args_size, retval, retval_size);
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
client.close();
}
void Module::sendToDetector(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) {
static_cast<const Module &>(*this).sendToDetector(fnum, args, args_size,
retval, retval_size);
}
template <typename Arg, typename Ret>
void Module::sendToDetector(int fnum, const Arg &args, Ret &retval) {
void Module::sendToDetector(int fnum, const Arg &args, Ret &retval) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
<< sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Arg, "sendToDetector")
STATIC_ASSERT_ARG(Ret, "sendToDetector")
sendToDetector(fnum, &args, sizeof(args), &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << ToString(retval);
}
template <typename Arg, typename Ret>
void Module::sendToDetector(int fnum, const Arg &args, Ret &retval) {
static_cast<const Module &>(*this).sendToDetector(fnum, args, retval);
}
template <typename Arg>
void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t) {
void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << typeid(Arg).name() << ", " << sizeof(Arg)
<< ", nullptr, 0 ]";
STATIC_ASSERT_ARG(Arg, "sendToDetector")
sendToDetector(fnum, &args, sizeof(args), nullptr, 0);
}
template <typename Arg>
void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t) {
static_cast<const Module &>(*this).sendToDetector(fnum, args, nullptr);
}
template <typename Ret>
void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) {
void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
<< sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Ret, "sendToDetector")
sendToDetector(fnum, nullptr, 0, &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << ToString(retval);
}
void Module::sendToDetector(int fnum) {
template <typename Ret>
void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) {
static_cast<const Module &>(*this).sendToDetector(fnum, nullptr, retval);
}
void Module::sendToDetector(int fnum) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< "]";
sendToDetector(fnum, nullptr, 0, nullptr, 0);
}
template <typename Ret> Ret Module::sendToDetector(int fnum) {
void Module::sendToDetector(int fnum) {
static_cast<const Module &>(*this).sendToDetector(fnum);
}
template <typename Ret> Ret Module::sendToDetector(int fnum) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
<< sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Ret, "sendToDetector")
Ret retval{};
sendToDetector(fnum, nullptr, 0, &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << ToString(retval);
return retval;
}
template <typename Ret> Ret Module::sendToDetector(int fnum) {
return static_cast<const Module &>(*this).sendToDetector<Ret>(fnum);
}
template <typename Ret, typename Arg>
Ret Module::sendToDetector(int fnum, const Arg &args) {
Ret Module::sendToDetector(int fnum, const Arg &args) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << args << ", " << sizeof(args) << ", "
<< typeid(Ret).name() << ", " << sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Arg, "sendToDetector")
STATIC_ASSERT_ARG(Ret, "sendToDetector")
Ret retval{};
sendToDetector(fnum, &args, sizeof(args), &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << ToString(retval);
return retval;
}
template <typename Ret, typename Arg>
Ret Module::sendToDetector(int fnum, const Arg &args) {
return static_cast<const Module &>(*this).sendToDetector<Ret>(fnum, args);
}
//---------------------------------------------------------- sendToDetectorStop
void Module::sendToDetectorStop(int fnum, const void *args, size_t args_size,
@ -2508,6 +2546,8 @@ void Module::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) const {
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << args << ", " << sizeof(args) << ", "
<< typeid(Ret).name() << ", " << sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Arg, "sendToDetectorStop")
STATIC_ASSERT_ARG(Ret, "sendToDetectorStop")
sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << ToString(retval);
}
@ -2524,6 +2564,7 @@ void Module::sendToDetectorStop(int fnum, const Arg &args,
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << typeid(Arg).name() << ", " << sizeof(Arg)
<< ", nullptr, 0 ]";
STATIC_ASSERT_ARG(Arg, "sendToDetectorStop")
sendToDetectorStop(fnum, &args, sizeof(args), nullptr, 0);
}
@ -2538,13 +2579,15 @@ void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) const {
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
<< sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Ret, "sendToDetectorStop")
sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << retval;
}
template <typename Ret>
void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) {
static_cast<const Module &>(*this).sendToDetectorStop(fnum, nullptr, retval);
static_cast<const Module &>(*this).sendToDetectorStop(fnum, nullptr,
retval);
}
void Module::sendToDetectorStop(int fnum) const {
@ -2558,40 +2601,42 @@ void Module::sendToDetectorStop(int fnum) {
static_cast<const Module &>(*this).sendToDetectorStop(fnum);
}
template <typename Ret> Ret Module::sendToDetectorStop(int fnum) {
LOG(logDEBUG1) << "Sending to Stop: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
<< sizeof(Ret) << "]";
Ret retval{};
sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << retval;
return retval;
}
template <typename Ret> Ret Module::sendToDetectorStop(int fnum) const {
LOG(logDEBUG1) << "Sending to Stop: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
<< sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Ret, "sendToDetectorStop")
Ret retval{};
sendToDetectorStop(fnum, nullptr, 0, &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << retval;
return retval;
}
template <typename Ret> Ret Module::sendToDetectorStop(int fnum) {
return static_cast<const Module &>(*this).sendToDetectorStop<Ret>(fnum);
}
template <typename Ret, typename Arg>
Ret Module::sendToDetectorStop(int fnum, const Arg &args) {
Ret Module::sendToDetectorStop(int fnum, const Arg &args) const {
LOG(logDEBUG1) << "Sending to Stop: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << args << ", " << sizeof(args) << ", "
<< typeid(Ret).name() << ", " << sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Arg, "sendToDetectorStop")
STATIC_ASSERT_ARG(Ret, "sendToDetectorStop")
Ret retval{};
sendToDetectorStop(fnum, &args, sizeof(args), &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << ToString(retval);
return retval;
}
template <typename Ret, typename Arg>
Ret Module::sendToDetectorStop(int fnum, const Arg &args) {
return static_cast<const Module &>(*this).sendToDetectorStop<Ret>(fnum,
args);
}
//-------------------------------------------------------------- sendToReceiver
void Module::sendToReceiver(int fnum, const void *args, size_t args_size,

View File

@ -518,7 +518,8 @@ class Module : public virtual slsDetectorDefs {
uint64_t getReceiverCurrentFrameIndex() const;
private:
void preSendArgsCheck(const void * args, size_t args_size, void * retval, size_t retval_size) const;
void preSendArgsCheck(const void *args, size_t args_size, void *retval,
size_t retval_size) const;
/**
* Send function parameters to detector (control server)
@ -536,17 +537,34 @@ class Module : public virtual slsDetectorDefs {
template <typename Arg, typename Ret>
void sendToDetector(int fnum, const Arg &args, Ret &retval);
template <typename Arg, typename Ret>
void sendToDetector(int fnum, const Arg &args, Ret &retval) const;
template <typename Arg>
void sendToDetector(int fnum, const Arg &args, std::nullptr_t);
template <typename Arg>
void sendToDetector(int fnum, const Arg &args, std::nullptr_t) const;
template <typename Ret>
void sendToDetector(int fnum, std::nullptr_t, Ret &retval);
template <typename Ret>
void sendToDetector(int fnum, std::nullptr_t, Ret &retval) const;
void sendToDetector(int fnum);
void sendToDetector(int fnum) const;
template <typename Ret> Ret sendToDetector(int fnum);
template <typename Ret> Ret sendToDetector(int fnum) const;
template <typename Ret, typename Arg>
Ret sendToDetector(int fnum, const Arg &args);
template <typename Ret, typename Arg>
Ret sendToDetector(int fnum, const Arg &args) const;
/** Send function parameters to detector (stop server) */
void sendToDetectorStop(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
@ -583,6 +601,9 @@ class Module : public virtual slsDetectorDefs {
template <typename Ret, typename Arg>
Ret sendToDetectorStop(int fnum, const Arg &args);
template <typename Ret, typename Arg>
Ret sendToDetectorStop(int fnum, const Arg &args) const;
/** Send function parameters to receiver */
void sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);