From 02f648ec7af00579fbde767f0e354c102bfdccf1 Mon Sep 17 00:00:00 2001 From: Alice Date: Tue, 14 Jul 2026 18:19:02 +0200 Subject: [PATCH] moved boolean stop server flag to DetectorImpl - moving template parameter up --- .../src/BaseMatterhornServer.hpp | 12 ++-- .../src/BaseMatterhornServerImpl.hpp | 18 +++--- .../src/utils/type_traits.hpp | 36 ------------ .../include/DetectorServer.hpp | 25 +++++--- .../include/DetectorServerImpl.hpp | 5 +- .../src/DetectorServerImpl.cpp | 57 ++++++++++++++----- 6 files changed, 77 insertions(+), 76 deletions(-) delete mode 100644 slsDetectorServers/matterhornServer/src/utils/type_traits.hpp diff --git a/slsDetectorServers/matterhornServer/src/BaseMatterhornServer.hpp b/slsDetectorServers/matterhornServer/src/BaseMatterhornServer.hpp index 8c2a26c05..684ce2224 100644 --- a/slsDetectorServers/matterhornServer/src/BaseMatterhornServer.hpp +++ b/slsDetectorServers/matterhornServer/src/BaseMatterhornServer.hpp @@ -2,10 +2,10 @@ #include "DetectorServer.hpp" #include "TCPInterface.hpp" #include "fmt/format.h" +#include "helpers/type_traits.hpp" #include "sls/logger.h" #include "sls/network_utils.h" #include "sls/sls_detector_defs.h" -#include "utils/type_traits.hpp" #include #include #include @@ -29,8 +29,11 @@ class BaseMatterhornServer * throws an exception in case of failure * @param port TCP/IP port number */ - explicit BaseMatterhornServer(std::unique_ptr impl, - uint16_t port = DEFAULT_TCP_CNTRL_PORTNO) + explicit BaseMatterhornServer( + std::unique_ptr< + DetectorServerImpl::value>> + impl, + uint16_t port = DEFAULT_TCP_CNTRL_PORTNO) : DetectorServer>(std::move(impl), port) {} @@ -49,9 +52,6 @@ class BaseMatterhornServer ProcessedResult processFunction(const detFuncs function_id, ServerInterface &socket); - using ImplType = - typename implementation_type_trait::ImplType; - private: DerivedServer *getDerived() { return static_cast(this); } diff --git a/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp b/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp index 34d89522f..9d0e45d22 100644 --- a/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp +++ b/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp @@ -5,9 +5,9 @@ #include "communication/SPICommunication.hpp" #include "defs/MatterhornDefs.hpp" #include "defs/RegisterDefs.hpp" +#include "helpers/type_traits.hpp" #include "sls/versionAPI.h" #include "utils/HelperFunctions.hpp" -#include "utils/type_traits.hpp" #include #include @@ -17,7 +17,9 @@ template class VirtualMatterhornServerImpl; // forward declare template -class BaseMatterhornServerImpl : public DetectorServerImpl { +class BaseMatterhornServerImpl + : public DetectorServerImpl< + is_stop_server::value> { public: BaseMatterhornServerImpl(); ~BaseMatterhornServerImpl() = default; @@ -73,10 +75,6 @@ class BaseMatterhornServerImpl : public DetectorServerImpl { private: static constexpr uint8_t numUDPInterfaces = 1; // only one udp per module for now - - /// @brief true if the derived server is a stop server, false otherwise - static constexpr bool isStopServer = - is_stop_server::value; }; template @@ -95,19 +93,19 @@ void BaseMatterhornServerImpl::setupDetector() { // TODO: extend try { // stop server does not talk to the board - if constexpr (!isStopServer) { + if constexpr (!this->stop_server) { set_num_frames(1); set_num_triggers(1); set_counter_mask(0xF); // enable counter all counters by default } } catch (const std::exception &e) { LOG(logERROR) << "Failed to setup detector: " << e.what(); - detectorSetupStatus.error_message = std::string(e.what()); - detectorSetupStatus.setup_status = + this->detectorSetupStatus.error_message = std::string(e.what()); + this->detectorSetupStatus.setup_status = detector_setup_status::SETUP_STATUS::FAILED_SETUP; } - detectorSetupStatus.setup_status = + this->detectorSetupStatus.setup_status = detector_setup_status::SETUP_STATUS::SUCCESSFUL_SETUP; } diff --git a/slsDetectorServers/matterhornServer/src/utils/type_traits.hpp b/slsDetectorServers/matterhornServer/src/utils/type_traits.hpp deleted file mode 100644 index 13c2c3884..000000000 --- a/slsDetectorServers/matterhornServer/src/utils/type_traits.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include - -namespace sls { - -// forward declares -template class MatterhornServer; - -template class VirtualMatterhornServer; - -template class MatterhornServerImpl; - -template class VirtualMatterhornServerImpl; - -template struct implementation_type_trait; - -template -struct implementation_type_trait> { - using ImplType = MatterhornServerImpl; -}; - -template -struct implementation_type_trait> { - using ImplType = VirtualMatterhornServerImpl; -}; - -template -struct is_stop_server : std::false_type {}; - -template <> -struct is_stop_server> : std::true_type {}; - -template <> -struct is_stop_server> : std::true_type {}; - -} // namespace sls diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp index 1b0c673ee..bafbdbb3e 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp +++ b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp @@ -2,6 +2,7 @@ #include "DetectorServerImpl.hpp" #include "TCPInterface.hpp" #include "helpers/Helpers.hpp" +#include "helpers/type_traits.hpp" #include "sls/logger.h" #include "sls/network_utils.h" #include "sls/sls_detector_defs.h" @@ -27,8 +28,11 @@ template class DetectorServer { * throws an exception in case of failure * @param port TCP/IP port number */ - explicit DetectorServer(std::unique_ptr impl_, - uint16_t port = DEFAULT_TCP_CNTRL_PORTNO); + explicit DetectorServer( + std::unique_ptr< + DetectorServerImpl::value>> + impl_, + uint16_t port = DEFAULT_TCP_CNTRL_PORTNO); ~DetectorServer() = default; @@ -36,16 +40,18 @@ template class DetectorServer { /// @brief TCP/IP interface for communication with the client std::unique_ptr tcpInterface; - std::unique_ptr impl; + std::unique_ptr< + DetectorServerImpl::value>> + impl; auto *getImpl() { - return static_cast( - impl.get()); + return static_cast::ImplType *>(impl.get()); } const auto *getImpl() const { - return static_cast( - impl.get()); + return static_cast::ImplType *>(impl.get()); } private: @@ -112,7 +118,10 @@ template class DetectorServer { template DetectorServer::DetectorServer( - std::unique_ptr impl_, uint16_t port) + std::unique_ptr< + DetectorServerImpl::value>> + impl_, + uint16_t port) : impl(std::move(impl_)) { validatePortNumber(port); diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp index 98054cf3d..8c4c29adf 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp +++ b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp @@ -50,7 +50,7 @@ struct acquisitionStatus { std::atomic stop{false}; }; -class DetectorServerImpl { +template class DetectorServerImpl { public: DetectorServerImpl(); @@ -98,6 +98,9 @@ class DetectorServerImpl { /// @brief true if setupDetector() was successful, false otherwise detector_setup_status detectorSetupStatus{}; + /// @brief true if the derived server is a stop server, false otherwise + static constexpr bool stop_server = isStopServer; + private: /// @brief creates and maps shared memory void createSharedMemory(); diff --git a/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp b/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp index 8804d9cd2..959fa2080 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp +++ b/slsDetectorServers/slsDetectorServer_cpp/src/DetectorServerImpl.cpp @@ -5,16 +5,24 @@ namespace sls { -DetectorServerImpl::DetectorServerImpl() { +template class DetectorServerImpl; // forward declare +template class DetectorServerImpl; // forward declare + +template +DetectorServerImpl::DetectorServerImpl() { udpDetails[0].srcport = DEFAULT_UDP_SRC_PORTNO; udpDetails[0].dstport = DEFAULT_UDP_DST_PORTNO; createSharedMemory(); } -DetectorServerImpl::~DetectorServerImpl() { shm.removeSharedMemory(); } +template +DetectorServerImpl::~DetectorServerImpl() { + shm.removeSharedMemory(); +} -void DetectorServerImpl::createSharedMemory() { +template +void DetectorServerImpl::createSharedMemory() { shm = SharedMemory(0, -1, "server"); if (shm.exists()) { @@ -30,7 +38,9 @@ void DetectorServerImpl::createSharedMemory() { } } -void DetectorServerImpl::updateSrcMacAddress(const uint64_t srcmac) { +template +void DetectorServerImpl::updateSrcMacAddress( + const uint64_t srcmac) { LOG(logINFO) << "Updating source MAC address to: " << fmt::format("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", (srcmac >> 40) & 0xff, (srcmac >> 32) & 0xff, @@ -44,46 +54,63 @@ void DetectorServerImpl::updateSrcMacAddress(const uint64_t srcmac) { // TODO: do i need to keep track of the configured member ? } -bool DetectorServerImpl::get_update_mode() const { return updateMode; } +template +bool DetectorServerImpl::get_update_mode() const { + return updateMode; +} -uint64_t DetectorServerImpl::get_source_udp_mac() const { +template +uint64_t DetectorServerImpl::get_source_udp_mac() const { return udpDetails[0].srcmac; } -void DetectorServerImpl::set_source_udp_ip(const uint32_t srcip) { +template +void DetectorServerImpl::set_source_udp_ip(const uint32_t srcip) { udpDetails[0].srcip = srcip; } -uint32_t DetectorServerImpl::get_source_udp_ip() const { +template +uint32_t DetectorServerImpl::get_source_udp_ip() const { return udpDetails[0].srcip; } -void DetectorServerImpl::set_destination_udp_ip(const uint32_t dstip) { +template +void DetectorServerImpl::set_destination_udp_ip( + const uint32_t dstip) { udpDetails[0].dstip = dstip; } -uint32_t DetectorServerImpl::get_destination_udp_ip() const { +template +uint32_t DetectorServerImpl::get_destination_udp_ip() const { return udpDetails[0].dstip; } -void DetectorServerImpl::set_destination_udp_mac(const uint64_t dstmac) { +template +void DetectorServerImpl::set_destination_udp_mac( + const uint64_t dstmac) { // TODO: configuremac, check unicast address udpDetails[0].dstmac = dstmac; } -uint64_t DetectorServerImpl::get_destination_udp_mac() const { +template +uint64_t DetectorServerImpl::get_destination_udp_mac() const { return udpDetails[0].dstmac; } -void DetectorServerImpl::set_destination_udp_port(const uint16_t dstport) { +template +void DetectorServerImpl::set_destination_udp_port( + const uint16_t dstport) { udpDetails[0].dstport = dstport; } -uint16_t DetectorServerImpl::get_destination_udp_port() const { +template +uint16_t DetectorServerImpl::get_destination_udp_port() const { return udpDetails[0].dstport; } -detector_setup_status DetectorServerImpl::get_detector_setup_status() const { +template +detector_setup_status +DetectorServerImpl::get_detector_setup_status() const { return detectorSetupStatus; }