From 1fefc001f9ca364287bb34333099136a99e3e124 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 24 Jul 2020 11:17:45 +0200 Subject: [PATCH] added const methods for detector --- slsDetectorSoftware/src/Module.cpp | 95 ++++++++++++++++++++++-------- slsDetectorSoftware/src/Module.h | 23 +++++++- 2 files changed, 92 insertions(+), 26 deletions(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index ed0684244..ba1b99b38 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -2410,79 +2410,117 @@ void Module::preSendArgsCheck(const void *args, size_t args_size, void *retval, static_assert(!std::is_same::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(*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(*this).sendToDetector(fnum, args, args_size, + retval, retval_size); +} + template -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(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 +void Module::sendToDetector(int fnum, const Arg &args, Ret &retval) { + static_cast(*this).sendToDetector(fnum, args, retval); +} + template -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(fnum)) << ", " << typeid(Arg).name() << ", " << sizeof(Arg) << ", nullptr, 0 ]"; + STATIC_ASSERT_ARG(Arg, "sendToDetector") sendToDetector(fnum, &args, sizeof(args), nullptr, 0); } +template +void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t) { + static_cast(*this).sendToDetector(fnum, args, nullptr); +} + template -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(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 +void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) { + static_cast(*this).sendToDetector(fnum, nullptr, retval); +} + +void Module::sendToDetector(int fnum) const { LOG(logDEBUG1) << "Sending: [" << getFunctionNameFromEnum(static_cast(fnum)) << "]"; sendToDetector(fnum, nullptr, 0, nullptr, 0); } -template Ret Module::sendToDetector(int fnum) { +void Module::sendToDetector(int fnum) { + static_cast(*this).sendToDetector(fnum); +} + +template Ret Module::sendToDetector(int fnum) const { LOG(logDEBUG1) << "Sending: [" << getFunctionNameFromEnum(static_cast(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 Ret Module::sendToDetector(int fnum) { + return static_cast(*this).sendToDetector(fnum); +} + template -Ret Module::sendToDetector(int fnum, const Arg &args) { +Ret Module::sendToDetector(int fnum, const Arg &args) const { LOG(logDEBUG1) << "Sending: [" << getFunctionNameFromEnum(static_cast(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 +Ret Module::sendToDetector(int fnum, const Arg &args) { + return static_cast(*this).sendToDetector(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(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(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(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 void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) { - static_cast(*this).sendToDetectorStop(fnum, nullptr, retval); + static_cast(*this).sendToDetectorStop(fnum, nullptr, + retval); } void Module::sendToDetectorStop(int fnum) const { @@ -2558,40 +2601,42 @@ void Module::sendToDetectorStop(int fnum) { static_cast(*this).sendToDetectorStop(fnum); } -template Ret Module::sendToDetectorStop(int fnum) { - LOG(logDEBUG1) << "Sending to Stop: [" - << getFunctionNameFromEnum(static_cast(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 Ret Module::sendToDetectorStop(int fnum) const { LOG(logDEBUG1) << "Sending to Stop: [" << getFunctionNameFromEnum(static_cast(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 Ret Module::sendToDetectorStop(int fnum) { + return static_cast(*this).sendToDetectorStop(fnum); +} + template -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(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 +Ret Module::sendToDetectorStop(int fnum, const Arg &args) { + return static_cast(*this).sendToDetectorStop(fnum, + args); +} + //-------------------------------------------------------------- sendToReceiver void Module::sendToReceiver(int fnum, const void *args, size_t args_size, diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index fcae5f7ef..03af74c11 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -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 void sendToDetector(int fnum, const Arg &args, Ret &retval); + + template + void sendToDetector(int fnum, const Arg &args, Ret &retval) const; + template void sendToDetector(int fnum, const Arg &args, std::nullptr_t); + + template + void sendToDetector(int fnum, const Arg &args, std::nullptr_t) const; + template void sendToDetector(int fnum, std::nullptr_t, Ret &retval); + + template + void sendToDetector(int fnum, std::nullptr_t, Ret &retval) const; + void sendToDetector(int fnum); + void sendToDetector(int fnum) const; template Ret sendToDetector(int fnum); + template Ret sendToDetector(int fnum) const; template Ret sendToDetector(int fnum, const Arg &args); + template + 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 Ret sendToDetectorStop(int fnum, const Arg &args); + template + 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);