From 3962714b486cea047d4c160783b08be0eabbe01c Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 13 May 2020 14:48:52 +0200 Subject: [PATCH] format + exception.cpp --- slsDetectorSoftware/src/Module.cpp | 14 ++++++---- slsDetectorSoftware/tests/test-Module.cpp | 2 +- slsReceiverSoftware/src/MultiReceiverApp.cpp | 1 + slsSupportLib/CMakeLists.txt | 3 +-- slsSupportLib/include/ToString.h | 7 ++--- .../include/sls_detector_exceptions.h | 27 +++++++------------ slsSupportLib/include/versionAPI.h | 2 +- slsSupportLib/src/ServerInterface.cpp | 1 + slsSupportLib/src/ToString.cpp | 4 +-- slsSupportLib/src/UdpRxSocket.cpp | 1 + slsSupportLib/src/ZmqSocket.cpp | 1 + slsSupportLib/src/sls_detector_exceptions.cpp | 23 ++++++++++++++++ slsSupportLib/tests/test-ToString.cpp | 15 +++++------ slsSupportLib/tests/test-network_utils.cpp | 1 + 14 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 slsSupportLib/src/sls_detector_exceptions.cpp diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 909e92927..a2ae089a7 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1282,7 +1282,8 @@ int Module::getADC(dacIndex index) { slsDetectorDefs::externalSignalFlag Module::setExternalSignalFlags(externalSignalFlag pol) { LOG(logDEBUG1) << "Setting signal flag to " << pol; - return sendToDetector(F_SET_EXTERNAL_SIGNAL_FLAG, pol); + return sendToDetector( + F_SET_EXTERNAL_SIGNAL_FLAG, pol); } void Module::setParallelMode(const bool enable) { @@ -1835,7 +1836,8 @@ std::string Module::getAdditionalJsonParameter(const std::string &key) { } int64_t Module::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize) { - return sendToReceiver(F_RECEIVER_UDP_SOCK_BUF_SIZE, udpsockbufsize); + return sendToReceiver(F_RECEIVER_UDP_SOCK_BUF_SIZE, + udpsockbufsize); } int64_t Module::getReceiverUDPSocketBufferSize() { @@ -2216,7 +2218,8 @@ bool Module::getDeactivatedRxrPaddingMode() { } void Module::setDeactivatedRxrPaddingMode(bool padding) { - sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING, static_cast(padding), nullptr); + sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING, + static_cast(padding), nullptr); } bool Module::getFlippedDataX() { @@ -2656,7 +2659,7 @@ int64_t Module::getFramesCaughtByReceiver() const { } std::vector Module::getNumMissingPackets() const { - //TODO!(Erik) Refactor + // TODO!(Erik) Refactor LOG(logDEBUG1) << "Getting num missing packets"; if (shm()->useReceiverFlag) { int fnum = F_GET_NUM_MISSING_PACKETS; @@ -2701,7 +2704,8 @@ bool Module::getFileWrite() { } void Module::setMasterFileWrite(bool value) { - sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, static_cast(value), nullptr); + sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, static_cast(value), + nullptr); } bool Module::getMasterFileWrite() { diff --git a/slsDetectorSoftware/tests/test-Module.cpp b/slsDetectorSoftware/tests/test-Module.cpp index c871823df..47d11e395 100644 --- a/slsDetectorSoftware/tests/test-Module.cpp +++ b/slsDetectorSoftware/tests/test-Module.cpp @@ -2,7 +2,7 @@ #include "catch.hpp" using dt = slsDetectorDefs::detectorType; -TEST_CASE("Construction with a defined detector type") { +TEST_CASE("Construction with a defined detector type") { sls::Module m(dt::EIGER); REQUIRE(m.getDetectorType() == dt::EIGER); } \ No newline at end of file diff --git a/slsReceiverSoftware/src/MultiReceiverApp.cpp b/slsReceiverSoftware/src/MultiReceiverApp.cpp index f7a514741..0fa827b22 100644 --- a/slsReceiverSoftware/src/MultiReceiverApp.cpp +++ b/slsReceiverSoftware/src/MultiReceiverApp.cpp @@ -2,6 +2,7 @@ * binary */ #include "Receiver.h" #include "container_utils.h" +#include "logger.h" #include "sls_detector_defs.h" #include //SIGINT diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt index 6e3dee6b4..d75ef8034 100755 --- a/slsSupportLib/CMakeLists.txt +++ b/slsSupportLib/CMakeLists.txt @@ -9,13 +9,13 @@ set(SOURCES src/network_utils.cpp src/ZmqSocket.cpp src/UdpRxSocket.cpp + src/sls_detector_exceptions.cpp ) set(HEADERS ) set(PUBLICHEADERS - include/ansi.h include/sls_detector_defs.h include/sls_detector_funcs.h include/versionAPI.h @@ -23,7 +23,6 @@ set(PUBLICHEADERS include/file_utils.h include/container_utils.h include/string_utils.h - include/logger.h include/ClientSocket.h include/DataSocket.h include/ServerSocket.h diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 04532e825..fdd0db241 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -7,12 +7,12 @@ * */ +#include "FixedCapacityContainer.h" #include "TimeHelper.h" #include "TypeTraits.h" #include "sls_detector_defs.h" #include "sls_detector_exceptions.h" #include "string_utils.h" -#include "FixedCapacityContainer.h" #include #include #include @@ -40,8 +40,9 @@ std::string ToString(const defs::timingSourceType s); std::string ToString(const slsDetectorDefs::ROI &roi); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi); -template -std::ostream &operator<<(std::ostream &os, const sls::FixedCapacityContainer& c){ +template +std::ostream &operator<<(std::ostream &os, + const sls::FixedCapacityContainer &c) { return os << ToString(c); } diff --git a/slsSupportLib/include/sls_detector_exceptions.h b/slsSupportLib/include/sls_detector_exceptions.h index 75dfe09d4..4f1407c13 100644 --- a/slsSupportLib/include/sls_detector_exceptions.h +++ b/slsSupportLib/include/sls_detector_exceptions.h @@ -1,55 +1,48 @@ #pragma once - -#include "logger.h" -#include #include namespace sls { struct RuntimeError : public std::runtime_error { public: - RuntimeError() : runtime_error("SLS Detector Package Failed") { - LOG(logERROR) << "SLS Detector Package Failed"; - } - RuntimeError(const std::string &msg) : runtime_error(msg) { - LOG(logERROR) << msg; - } - RuntimeError(const char *msg) : runtime_error(msg) { LOG(logERROR) << msg; } + RuntimeError(); + RuntimeError(const std::string &msg); + RuntimeError(const char *msg); }; struct SharedMemoryError : public RuntimeError { public: - SharedMemoryError(const std::string &msg) : RuntimeError(msg) {} + SharedMemoryError(const std::string &msg); }; struct SocketError : public RuntimeError { public: - SocketError(const std::string &msg) : RuntimeError(msg) {} + SocketError(const std::string &msg); }; struct ZmqSocketError : public RuntimeError { public: - ZmqSocketError(const std::string &msg) : RuntimeError(msg) {} + ZmqSocketError(const std::string &msg); }; struct NotImplementedError : public RuntimeError { public: - NotImplementedError(const std::string &msg) : RuntimeError(msg) {} + NotImplementedError(const std::string &msg); }; struct DetectorError : public RuntimeError { public: - DetectorError(const std::string &msg) : RuntimeError(msg) {} + DetectorError(const std::string &msg); }; struct ReceiverError : public RuntimeError { public: - ReceiverError(const std::string &msg) : RuntimeError(msg) {} + ReceiverError(const std::string &msg); }; struct GuiError : public RuntimeError { public: - GuiError(const std::string &msg) : RuntimeError(msg) {} + GuiError(const std::string &msg); }; } // namespace sls diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 0c70a2b72..21c378a88 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -10,4 +10,4 @@ #define APIJUNGFRAU 0x200508 #define APIMYTHEN3 0x200508 #define APIMOENCH 0x200508 -#define APIEIGER 0x200513 +#define APIEIGER 0x200513 diff --git a/slsSupportLib/src/ServerInterface.cpp b/slsSupportLib/src/ServerInterface.cpp index 75e97fea9..9ea66e473 100644 --- a/slsSupportLib/src/ServerInterface.cpp +++ b/slsSupportLib/src/ServerInterface.cpp @@ -1,4 +1,5 @@ #include "ServerInterface.h" +#include "logger.h" #include #include #include diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 2c2a05efc..934ecc944 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -2,13 +2,13 @@ namespace sls { -std::string ToString(const slsDetectorDefs::ROI& roi){ +std::string ToString(const slsDetectorDefs::ROI &roi) { std::ostringstream oss; oss << '[' << roi.xmin << ", " << roi.xmax << ']'; return oss.str(); } -std::ostream&operator<<(std::ostream &os, const slsDetectorDefs::ROI& roi){ +std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi) { return os << ToString(roi); } diff --git a/slsSupportLib/src/UdpRxSocket.cpp b/slsSupportLib/src/UdpRxSocket.cpp index e342d24e3..8f4b0afa5 100644 --- a/slsSupportLib/src/UdpRxSocket.cpp +++ b/slsSupportLib/src/UdpRxSocket.cpp @@ -1,4 +1,5 @@ #include "UdpRxSocket.h" +#include "logger.h" #include "network_utils.h" #include "sls_detector_exceptions.h" #include diff --git a/slsSupportLib/src/ZmqSocket.cpp b/slsSupportLib/src/ZmqSocket.cpp index ffef36bd5..fc58ed1ff 100644 --- a/slsSupportLib/src/ZmqSocket.cpp +++ b/slsSupportLib/src/ZmqSocket.cpp @@ -1,4 +1,5 @@ #include "ZmqSocket.h" +#include "logger.h" #include //inet_ntoa #include #include diff --git a/slsSupportLib/src/sls_detector_exceptions.cpp b/slsSupportLib/src/sls_detector_exceptions.cpp new file mode 100644 index 000000000..23ca4b9fb --- /dev/null +++ b/slsSupportLib/src/sls_detector_exceptions.cpp @@ -0,0 +1,23 @@ +#include "sls_detector_exceptions.h" +#include "logger.h" +namespace sls { +RuntimeError::RuntimeError() : runtime_error("SLS Detector Package Failed") { + LOG(logERROR) << "SLS Detector Package Failed"; +} +RuntimeError::RuntimeError(const std::string &msg) : runtime_error(msg) { + LOG(logERROR) << msg; +} +RuntimeError::RuntimeError(const char *msg) : runtime_error(msg) { + LOG(logERROR) << msg; +} +SharedMemoryError::SharedMemoryError(const std::string &msg) + : RuntimeError(msg) {} +SocketError::SocketError(const std::string &msg) : RuntimeError(msg) {} +ZmqSocketError::ZmqSocketError(const std::string &msg) : RuntimeError(msg) {} +NotImplementedError::NotImplementedError(const std::string &msg) + : RuntimeError(msg) {} +DetectorError::DetectorError(const std::string &msg) : RuntimeError(msg) {} +ReceiverError::ReceiverError(const std::string &msg) : RuntimeError(msg) {} +GuiError::GuiError(const std::string &msg) : RuntimeError(msg) {} + +} // namespace sls diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index e6716482f..f08216b4d 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -5,8 +5,8 @@ #include "sls_detector_defs.h" #include #include -#include #include +#include // using namespace sls; using sls::defs; @@ -219,28 +219,27 @@ TEST_CASE("Detector type") { REQUIRE(StringTo("Eiger") == dt); } - -TEST_CASE("Formatting slsDetectorDefs::ROI"){ - slsDetectorDefs::ROI roi{5,159}; +TEST_CASE("Formatting slsDetectorDefs::ROI") { + slsDetectorDefs::ROI roi{5, 159}; REQUIRE(ToString(roi) == "[5, 159]"); } -TEST_CASE("Streaming of slsDetectorDefs::ROI"){ +TEST_CASE("Streaming of slsDetectorDefs::ROI") { using namespace sls; - slsDetectorDefs::ROI roi{-10,1}; + slsDetectorDefs::ROI roi{-10, 1}; std::ostringstream oss; oss << roi; REQUIRE(oss.str() == "[-10, 1]"); } -TEST_CASE("sls::FixedCapacityContainer"){ +TEST_CASE("sls::FixedCapacityContainer") { sls::FixedCapacityContainer vec; vec.push_back(3); vec.push_back(8); REQUIRE(ToString(vec) == "[3, 8]"); } -TEST_CASE("sls::FixedCapacityContainer stream"){ +TEST_CASE("sls::FixedCapacityContainer stream") { sls::FixedCapacityContainer vec; vec.push_back(33); vec.push_back(85667); diff --git a/slsSupportLib/tests/test-network_utils.cpp b/slsSupportLib/tests/test-network_utils.cpp index 39afd6cfb..c516c6f92 100644 --- a/slsSupportLib/tests/test-network_utils.cpp +++ b/slsSupportLib/tests/test-network_utils.cpp @@ -2,6 +2,7 @@ #include "catch.hpp" #include "network_utils.h" #include +#include #include #include "sls_detector_exceptions.h"