mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-10 21:30:29 +02:00
moved boolean stop server flag to DetectorImpl - moving template parameter up
This commit is contained in:
@@ -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 <array>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
@@ -29,8 +29,11 @@ class BaseMatterhornServer
|
||||
* throws an exception in case of failure
|
||||
* @param port TCP/IP port number
|
||||
*/
|
||||
explicit BaseMatterhornServer(std::unique_ptr<DetectorServerImpl> impl,
|
||||
uint16_t port = DEFAULT_TCP_CNTRL_PORTNO)
|
||||
explicit BaseMatterhornServer(
|
||||
std::unique_ptr<
|
||||
DetectorServerImpl<is_stop_server<DerivedServer>::value>>
|
||||
impl,
|
||||
uint16_t port = DEFAULT_TCP_CNTRL_PORTNO)
|
||||
: DetectorServer<BaseMatterhornServer<DerivedServer>>(std::move(impl),
|
||||
port) {}
|
||||
|
||||
@@ -49,9 +52,6 @@ class BaseMatterhornServer
|
||||
ProcessedResult processFunction(const detFuncs function_id,
|
||||
ServerInterface &socket);
|
||||
|
||||
using ImplType =
|
||||
typename implementation_type_trait<DerivedServer>::ImplType;
|
||||
|
||||
private:
|
||||
DerivedServer *getDerived() { return static_cast<DerivedServer *>(this); }
|
||||
|
||||
|
||||
@@ -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 <cstdint>
|
||||
#include <string>
|
||||
|
||||
@@ -17,7 +17,9 @@ template <bool isStopServer>
|
||||
class VirtualMatterhornServerImpl; // forward declare
|
||||
|
||||
template <typename DerivedMatterhornServerImpl>
|
||||
class BaseMatterhornServerImpl : public DetectorServerImpl {
|
||||
class BaseMatterhornServerImpl
|
||||
: public DetectorServerImpl<
|
||||
is_stop_server<DerivedMatterhornServerImpl>::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<DerivedMatterhornServerImpl>::value;
|
||||
};
|
||||
|
||||
template <typename DerivedMatterhornServerImpl>
|
||||
@@ -95,19 +93,19 @@ void BaseMatterhornServerImpl<DerivedMatterhornServerImpl>::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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
namespace sls {
|
||||
|
||||
// forward declares
|
||||
template <bool isStopServer> class MatterhornServer;
|
||||
|
||||
template <bool isStopServer> class VirtualMatterhornServer;
|
||||
|
||||
template <bool isStopServer> class MatterhornServerImpl;
|
||||
|
||||
template <bool isStopServer> class VirtualMatterhornServerImpl;
|
||||
|
||||
template <typename DetectorServer> struct implementation_type_trait;
|
||||
|
||||
template <bool isStopServer>
|
||||
struct implementation_type_trait<MatterhornServer<isStopServer>> {
|
||||
using ImplType = MatterhornServerImpl<isStopServer>;
|
||||
};
|
||||
|
||||
template <bool isStopServer>
|
||||
struct implementation_type_trait<VirtualMatterhornServer<isStopServer>> {
|
||||
using ImplType = VirtualMatterhornServerImpl<isStopServer>;
|
||||
};
|
||||
|
||||
template <typename DetectorServerImpl>
|
||||
struct is_stop_server : std::false_type {};
|
||||
|
||||
template <>
|
||||
struct is_stop_server<VirtualMatterhornServerImpl<true>> : std::true_type {};
|
||||
|
||||
template <>
|
||||
struct is_stop_server<MatterhornServerImpl<true>> : std::true_type {};
|
||||
|
||||
} // namespace sls
|
||||
@@ -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 <typename DerivedDetectorServer> class DetectorServer {
|
||||
* throws an exception in case of failure
|
||||
* @param port TCP/IP port number
|
||||
*/
|
||||
explicit DetectorServer(std::unique_ptr<DetectorServerImpl> impl_,
|
||||
uint16_t port = DEFAULT_TCP_CNTRL_PORTNO);
|
||||
explicit DetectorServer(
|
||||
std::unique_ptr<
|
||||
DetectorServerImpl<is_stop_server<DerivedDetectorServer>::value>>
|
||||
impl_,
|
||||
uint16_t port = DEFAULT_TCP_CNTRL_PORTNO);
|
||||
|
||||
~DetectorServer() = default;
|
||||
|
||||
@@ -36,16 +40,18 @@ template <typename DerivedDetectorServer> class DetectorServer {
|
||||
/// @brief TCP/IP interface for communication with the client
|
||||
std::unique_ptr<TCPInterface> tcpInterface;
|
||||
|
||||
std::unique_ptr<DetectorServerImpl> impl;
|
||||
std::unique_ptr<
|
||||
DetectorServerImpl<is_stop_server<DerivedDetectorServer>::value>>
|
||||
impl;
|
||||
|
||||
auto *getImpl() {
|
||||
return static_cast<typename DerivedDetectorServer::ImplType *>(
|
||||
impl.get());
|
||||
return static_cast<typename implementation_type_trait<
|
||||
DerivedDetectorServer>::ImplType *>(impl.get());
|
||||
}
|
||||
|
||||
const auto *getImpl() const {
|
||||
return static_cast<const typename DerivedDetectorServer::ImplType *>(
|
||||
impl.get());
|
||||
return static_cast<const typename implementation_type_trait<
|
||||
DerivedDetectorServer>::ImplType *>(impl.get());
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -112,7 +118,10 @@ template <typename DerivedDetectorServer> class DetectorServer {
|
||||
|
||||
template <typename DerivedDetectorServer>
|
||||
DetectorServer<DerivedDetectorServer>::DetectorServer(
|
||||
std::unique_ptr<DetectorServerImpl> impl_, uint16_t port)
|
||||
std::unique_ptr<
|
||||
DetectorServerImpl<is_stop_server<DerivedDetectorServer>::value>>
|
||||
impl_,
|
||||
uint16_t port)
|
||||
: impl(std::move(impl_)) {
|
||||
validatePortNumber(port);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ struct acquisitionStatus {
|
||||
std::atomic<bool> stop{false};
|
||||
};
|
||||
|
||||
class DetectorServerImpl {
|
||||
template <bool isStopServer> 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();
|
||||
|
||||
@@ -5,16 +5,24 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
DetectorServerImpl::DetectorServerImpl() {
|
||||
template class DetectorServerImpl<true>; // forward declare
|
||||
template class DetectorServerImpl<false>; // forward declare
|
||||
|
||||
template <bool isStopServer>
|
||||
DetectorServerImpl<isStopServer>::DetectorServerImpl() {
|
||||
udpDetails[0].srcport = DEFAULT_UDP_SRC_PORTNO;
|
||||
udpDetails[0].dstport = DEFAULT_UDP_DST_PORTNO;
|
||||
|
||||
createSharedMemory();
|
||||
}
|
||||
|
||||
DetectorServerImpl::~DetectorServerImpl() { shm.removeSharedMemory(); }
|
||||
template <bool isStopServer>
|
||||
DetectorServerImpl<isStopServer>::~DetectorServerImpl() {
|
||||
shm.removeSharedMemory();
|
||||
}
|
||||
|
||||
void DetectorServerImpl::createSharedMemory() {
|
||||
template <bool isStopServer>
|
||||
void DetectorServerImpl<isStopServer>::createSharedMemory() {
|
||||
shm = SharedMemory<acquisitionStatus>(0, -1, "server");
|
||||
|
||||
if (shm.exists()) {
|
||||
@@ -30,7 +38,9 @@ void DetectorServerImpl::createSharedMemory() {
|
||||
}
|
||||
}
|
||||
|
||||
void DetectorServerImpl::updateSrcMacAddress(const uint64_t srcmac) {
|
||||
template <bool isStopServer>
|
||||
void DetectorServerImpl<isStopServer>::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 isStopServer>
|
||||
bool DetectorServerImpl<isStopServer>::get_update_mode() const {
|
||||
return updateMode;
|
||||
}
|
||||
|
||||
uint64_t DetectorServerImpl::get_source_udp_mac() const {
|
||||
template <bool isStopServer>
|
||||
uint64_t DetectorServerImpl<isStopServer>::get_source_udp_mac() const {
|
||||
return udpDetails[0].srcmac;
|
||||
}
|
||||
|
||||
void DetectorServerImpl::set_source_udp_ip(const uint32_t srcip) {
|
||||
template <bool isStopServer>
|
||||
void DetectorServerImpl<isStopServer>::set_source_udp_ip(const uint32_t srcip) {
|
||||
udpDetails[0].srcip = srcip;
|
||||
}
|
||||
|
||||
uint32_t DetectorServerImpl::get_source_udp_ip() const {
|
||||
template <bool isStopServer>
|
||||
uint32_t DetectorServerImpl<isStopServer>::get_source_udp_ip() const {
|
||||
return udpDetails[0].srcip;
|
||||
}
|
||||
|
||||
void DetectorServerImpl::set_destination_udp_ip(const uint32_t dstip) {
|
||||
template <bool isStopServer>
|
||||
void DetectorServerImpl<isStopServer>::set_destination_udp_ip(
|
||||
const uint32_t dstip) {
|
||||
udpDetails[0].dstip = dstip;
|
||||
}
|
||||
|
||||
uint32_t DetectorServerImpl::get_destination_udp_ip() const {
|
||||
template <bool isStopServer>
|
||||
uint32_t DetectorServerImpl<isStopServer>::get_destination_udp_ip() const {
|
||||
return udpDetails[0].dstip;
|
||||
}
|
||||
|
||||
void DetectorServerImpl::set_destination_udp_mac(const uint64_t dstmac) {
|
||||
template <bool isStopServer>
|
||||
void DetectorServerImpl<isStopServer>::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 <bool isStopServer>
|
||||
uint64_t DetectorServerImpl<isStopServer>::get_destination_udp_mac() const {
|
||||
return udpDetails[0].dstmac;
|
||||
}
|
||||
|
||||
void DetectorServerImpl::set_destination_udp_port(const uint16_t dstport) {
|
||||
template <bool isStopServer>
|
||||
void DetectorServerImpl<isStopServer>::set_destination_udp_port(
|
||||
const uint16_t dstport) {
|
||||
udpDetails[0].dstport = dstport;
|
||||
}
|
||||
|
||||
uint16_t DetectorServerImpl::get_destination_udp_port() const {
|
||||
template <bool isStopServer>
|
||||
uint16_t DetectorServerImpl<isStopServer>::get_destination_udp_port() const {
|
||||
return udpDetails[0].dstport;
|
||||
}
|
||||
|
||||
detector_setup_status DetectorServerImpl::get_detector_setup_status() const {
|
||||
template <bool isStopServer>
|
||||
detector_setup_status
|
||||
DetectorServerImpl<isStopServer>::get_detector_setup_status() const {
|
||||
return detectorSetupStatus;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user