From 447e83dac3b3c8440d10bdacd1b46ac345caca55 Mon Sep 17 00:00:00 2001 From: Alice Date: Wed, 8 Jul 2026 09:42:42 +0200 Subject: [PATCH] check if detector already set up --- .../src/BaseMatterhornServerImpl.hpp | 6 ++++-- .../include/DetectorServer.hpp | 13 +++++++++---- .../include/DetectorServerImpl.hpp | 9 ++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp b/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp index 6cf5474fc..612b40b12 100644 --- a/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp +++ b/slsDetectorServers/matterhornServer/src/BaseMatterhornServerImpl.hpp @@ -91,10 +91,12 @@ void BaseMatterhornServerImpl::setupDetector() { } catch (const std::exception &e) { LOG(logERROR) << "Failed to setup detector: " << e.what(); detectorSetupStatus.error_message = std::string(e.what()); - detectorSetupStatus.successful_setup = false; + detectorSetupStatus.setup_status = + detector_setup_status::SETUP_STATUS::FAILED_SETUP; } - detectorSetupStatus.successful_setup = true; + detectorSetupStatus.setup_status = + detector_setup_status::SETUP_STATUS::SUCCESSFUL_SETUP; } template diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp index 6bdbc22c5..44c2ebe22 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp +++ b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServer.hpp @@ -481,14 +481,19 @@ ProcessedResult DetectorServer::initial_checks( ServerInterface &socket) const { auto detectorsetupstatus = getDerivedImpl()->initial_checks(); - const bool setup_successful = detectorsetupstatus.successful_setup; - - if (!setup_successful) { + // TODO: should there be a time limit? + while (detectorsetupstatus.setup_status == + detector_setup_status::NOT_SETUP) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + detectorsetupstatus = getDerivedImpl()->initial_checks(); + } + if (detectorsetupstatus.setup_status == + detector_setup_status::FAILED_SETUP) { return return_fail("Initial checks failed: " + detectorsetupstatus.error_message); } else { return ProcessedResult{ - static_cast(socket.sendResult(setup_successful))}; + static_cast(socket.sendResult(true))}; } } diff --git a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp index 71b470f17..1287d4f91 100644 --- a/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp +++ b/slsDetectorServers/slsDetectorServer_cpp/include/DetectorServerImpl.hpp @@ -18,8 +18,15 @@ struct UDPInfo { /// @brief struct to store detector setup status struct detector_setup_status { + + enum SETUP_STATUS : uint8_t { + FAILED_SETUP = 0, + SUCCESSFUL_SETUP = 1, + NOT_SETUP = 2 + }; + /// @brief true if setupDetector() was successful, false otherwise - bool successful_setup{false}; + SETUP_STATUS setup_status{NOT_SETUP}; /// @brief error message if setupDetector() failed, empty otherwise std::string error_message{}; };