From 048e4d89ab48e053315d21c6e5639bea5119e683 Mon Sep 17 00:00:00 2001 From: Jonathan Hollocombe Date: Wed, 27 Nov 2024 11:13:33 +0000 Subject: [PATCH] Fixing Linux build. --- source/bin/CMakeLists.txt | 3 ++- source/client/CMakeLists.txt | 3 ++- source/client2/CMakeLists.txt | 3 ++- source/clientserver/CMakeLists.txt | 2 +- source/clientserver/errorLog.cpp | 19 ++++++++++++++-- source/clientserver/errorLog.h | 14 +----------- source/clientserver/protocol.cpp | 35 ++++++++++++++++++++++++++++++ source/clientserver/protocol.h | 35 ++---------------------------- source/logging/logging.h | 20 +++++++++++++++++ source/server/CMakeLists.txt | 3 ++- source/server2/CMakeLists.txt | 3 ++- 11 files changed, 86 insertions(+), 54 deletions(-) diff --git a/source/bin/CMakeLists.txt b/source/bin/CMakeLists.txt index da5509c9..2e769b55 100644 --- a/source/bin/CMakeLists.txt +++ b/source/bin/CMakeLists.txt @@ -6,7 +6,7 @@ if ( UDA_CLI_BOOST_STATIC ) set( Boost_USE_STATIC_LIBS ON ) endif() -find_package( Boost COMPONENTS program_options REQUIRED ) +find_package( Boost COMPONENTS program_options regex REQUIRED ) target_include_directories( uda_cli PRIVATE ${CMAKE_SOURCE_DIR}/source @@ -17,6 +17,7 @@ target_include_directories( uda_cli PRIVATE target_link_libraries( uda_cli PRIVATE client-static uda_cpp-static ) target_link_libraries( uda_cli PRIVATE Boost::program_options ) +target_link_libraries( uda_cli PRIVATE Boost::regex ) if( ENABLE_CAPNP ) find_package( CapnProto REQUIRED ) diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index d74e9660..bde6e0b3 100755 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -4,8 +4,9 @@ find_package( OpenSSL REQUIRED ) find_package( fmt REQUIRED ) find_package( LibXml2 REQUIRED ) +find_package( Boost REQUIRED COMPONENTS regex ) -set( LIBS OpenSSL::SSL OpenSSL::Crypto fmt::fmt LibXml2::LibXml2 common-objects ) +set( LIBS OpenSSL::SSL OpenSSL::Crypto fmt::fmt LibXml2::LibXml2 common-objects Boost::regex ) if( WIN32 OR MINGW ) find_package( XDR REQUIRED ) diff --git a/source/client2/CMakeLists.txt b/source/client2/CMakeLists.txt index 59e03170..ac6d7412 100755 --- a/source/client2/CMakeLists.txt +++ b/source/client2/CMakeLists.txt @@ -4,8 +4,9 @@ find_package( OpenSSL REQUIRED ) find_package( LibXml2 REQUIRED ) find_package( fmt REQUIRED ) +find_package( Boost REQUIRED COMPONENTS regex ) -set( LIBS OpenSSL::SSL OpenSSL::Crypto LibXml2::LibXml2 fmt::fmt common-objects ) +set( LIBS OpenSSL::SSL OpenSSL::Crypto LibXml2::LibXml2 fmt::fmt common-objects Boost::regex ) if( WIN32 OR MINGW ) find_package( XDR REQUIRED ) diff --git a/source/clientserver/CMakeLists.txt b/source/clientserver/CMakeLists.txt index 98175c19..87f9f5bb 100755 --- a/source/clientserver/CMakeLists.txt +++ b/source/clientserver/CMakeLists.txt @@ -5,7 +5,7 @@ find_package( OpenSSL REQUIRED ) find_package( fmt REQUIRED ) find_package( Boost REQUIRED COMPONENTS regex ) -set( LIBS OpenSSL::SSL OpenSSL::Crypto fmt::fmt Boost::regex ) +set( LIBS OpenSSL::SSL OpenSSL::Crypto fmt::fmt Boost::boost ) if( NOT CLIENT_ONLY ) find_package( LibXml2 REQUIRED ) diff --git a/source/clientserver/errorLog.cpp b/source/clientserver/errorLog.cpp index 39f53d14..d527a8da 100644 --- a/source/clientserver/errorLog.cpp +++ b/source/clientserver/errorLog.cpp @@ -32,6 +32,21 @@ const char* udaGetErrorLocation(int err_num) return "no error found"; } +std::string uda::client_server::format_as(ErrorType error_type) +{ + switch (error_type) { + case ErrorType::None: + return "ErrorType::None"; + case ErrorType::System: + return "ErrorType::System"; + case ErrorType::Code: + return "ErrorType::Code"; + case ErrorType::Plugin: + return "ErrorType::Plugin"; + } + return ""; +} + void uda::client_server::error_log(ClientBlock client_block, RequestBlock request_block, ErrorStack* error_stack) { UdaError* errors = nullptr; @@ -76,7 +91,7 @@ void uda::client_server::error_log(ClientBlock client_block, RequestBlock reques for (unsigned int i = 0; i < nerrors; i++) { log(UDA_LOG_ERROR, __FILE__, __LINE__, - "1 {} [{}] {} {} [{}] [{}]", client_block.uid, access_date, errors[i].type, + "1 {} [{}] {} {} [{}] [{}]", client_block.uid, access_date, format_as(errors[i].type), errors[i].code, errors[i].location, errors[i].msg); } } @@ -106,7 +121,7 @@ void uda::client_server::print_error_stack() } int i = 1; for (const auto& error : uda_error_stack) { - UDA_LOG(UDA_LOG_DEBUG, "{} {} {} {} {}", i, error.type, error.code, error.location, error.msg); + UDA_LOG(UDA_LOG_DEBUG, "{} {} {} {} {}", i, format_as(error.type), error.code, error.location, error.msg); ++i; } } diff --git a/source/clientserver/errorLog.h b/source/clientserver/errorLog.h index 6d25e118..14822f1e 100644 --- a/source/clientserver/errorLog.h +++ b/source/clientserver/errorLog.h @@ -11,19 +11,7 @@ enum class ErrorType : int { Plugin = 3, }; -inline std::string format_as(ErrorType error_type) -{ - switch (error_type) { - case ErrorType::None: - return "ErrorType::None"; - case ErrorType::System: - return "ErrorType::System"; - case ErrorType::Code: - return "ErrorType::Code"; - case ErrorType::Plugin: - return "ErrorType::Plugin"; - } -} +std::string format_as(ErrorType error_type); void error_log(ClientBlock client_block, RequestBlock request_block, ErrorStack* error_stack); diff --git a/source/clientserver/protocol.cpp b/source/clientserver/protocol.cpp index 50753b39..90dd1113 100644 --- a/source/clientserver/protocol.cpp +++ b/source/clientserver/protocol.cpp @@ -49,6 +49,41 @@ constexpr int MaxBlockTime = 10000; } // anon namespace +std::string uda::client_server::format_as(ProtocolId protocol) +{ + switch (protocol) { + case ProtocolId::Start: return "ProtocolId::Start"; + case ProtocolId::RequestBlock: return "ProtocolId::RequestBlock"; + case ProtocolId::DataBlockList: return "ProtocolId::DataBlockList"; + case ProtocolId::NextProtocol: return "ProtocolId::NextProtocol"; + case ProtocolId::DataSystem: return "ProtocolId::DataSystem"; + case ProtocolId::SystemConfig: return "ProtocolId::SystemConfig"; + case ProtocolId::DataSource: return "ProtocolId::DataSource"; + case ProtocolId::Signal: return "ProtocolId::Signal"; + case ProtocolId::SignalDesc: return "ProtocolId::SignalDesc"; + case ProtocolId::Spare1: return "ProtocolId::Spare1"; + case ProtocolId::ClientBlock: return "ProtocolId::ClientBlock"; + case ProtocolId::ServerBlock: return "ProtocolId::ServerBlock"; + case ProtocolId::Spare2: return "ProtocolId::Spare2"; + case ProtocolId::CloseDown: return "ProtocolId::CloseDown"; + case ProtocolId::Sleep: return "ProtocolId::Sleep"; + case ProtocolId::WakeUp: return "ProtocolId::WakeUp"; + case ProtocolId::PutdataBlockList: return "ProtocolId::PutdataBlockList"; + case ProtocolId::SecurityBlock: return "ProtocolId::SecurityBlock"; + case ProtocolId::Object: return "ProtocolId::Object"; + case ProtocolId::SerialiseObject: return "ProtocolId::SerialiseObject"; + case ProtocolId::SerialiseFile: return "ProtocolId::SerialiseFile"; + case ProtocolId::DataObject: return "ProtocolId::DataObject"; + case ProtocolId::DataObjectFile: return "ProtocolId::DataObjectFile"; + case ProtocolId::RegularStop: return "ProtocolId::RegularStop"; + case ProtocolId::OpaqueStart: return "ProtocolId::OpaqueStart"; + case ProtocolId::Structures: return "ProtocolId::Structures"; + case ProtocolId::Meta: return "ProtocolId::Meta"; + case ProtocolId::OpaqueStop: return "ProtocolId::OpaqueStop"; + } + return ""; +} + void uda::client_server::set_select_params(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time) { FD_ZERO(rfds); // Initialise the File Descriptor set diff --git a/source/clientserver/protocol.h b/source/clientserver/protocol.h index f8a3f1c2..d9dfde9f 100644 --- a/source/clientserver/protocol.h +++ b/source/clientserver/protocol.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "structures/genStructs.h" #include "xdrlib.h" @@ -44,39 +45,7 @@ enum class ProtocolId : int { OpaqueStop = 200, }; -inline std::string format_as(ProtocolId protocol) -{ - switch (protocol) { - case ProtocolId::Start: return "ProtocolId::Start"; - case ProtocolId::RequestBlock: return "ProtocolId::RequestBlock"; - case ProtocolId::DataBlockList: return "ProtocolId::DataBlockList"; - case ProtocolId::NextProtocol: return "ProtocolId::NextProtocol"; - case ProtocolId::DataSystem: return "ProtocolId::DataSystem"; - case ProtocolId::SystemConfig: return "ProtocolId::SystemConfig"; - case ProtocolId::DataSource: return "ProtocolId::DataSource"; - case ProtocolId::Signal: return "ProtocolId::Signal"; - case ProtocolId::SignalDesc: return "ProtocolId::SignalDesc"; - case ProtocolId::Spare1: return "ProtocolId::Spare1"; - case ProtocolId::ClientBlock: return "ProtocolId::ClientBlock"; - case ProtocolId::ServerBlock: return "ProtocolId::ServerBlock"; - case ProtocolId::Spare2: return "ProtocolId::Spare2"; - case ProtocolId::CloseDown: return "ProtocolId::CloseDown"; - case ProtocolId::Sleep: return "ProtocolId::Sleep"; - case ProtocolId::WakeUp: return "ProtocolId::WakeUp"; - case ProtocolId::PutdataBlockList: return "ProtocolId::PutdataBlockList"; - case ProtocolId::SecurityBlock: return "ProtocolId::SecurityBlock"; - case ProtocolId::Object: return "ProtocolId::Object"; - case ProtocolId::SerialiseObject: return "ProtocolId::SerialiseObject"; - case ProtocolId::SerialiseFile: return "ProtocolId::SerialiseFile"; - case ProtocolId::DataObject: return "ProtocolId::DataObject"; - case ProtocolId::DataObjectFile: return "ProtocolId::DataObjectFile"; - case ProtocolId::RegularStop: return "ProtocolId::RegularStop"; - case ProtocolId::OpaqueStart: return "ProtocolId::OpaqueStart"; - case ProtocolId::Structures: return "ProtocolId::Structures"; - case ProtocolId::Meta: return "ProtocolId::Meta"; - case ProtocolId::OpaqueStop: return "ProtocolId::OpaqueStop"; - } -} +std::string format_as(ProtocolId protocol); } diff --git a/source/logging/logging.h b/source/logging/logging.h index e9dafb7d..b7ebca76 100644 --- a/source/logging/logging.h +++ b/source/logging/logging.h @@ -7,6 +7,26 @@ #define UDA_LOG(LEVEL, FMT, ...) uda::logging::log(LEVEL, __FILE__, __LINE__, FMT, ##__VA_ARGS__); +//template::value, bool>> +//inline auto format_as(T t) -> typename std::underlying_type::type { +// return static_cast::type>(t); +//} + +namespace uda::client_server { +enum class ProtocolId; +} + +template<> +struct fmt::formatter : fmt::formatter> +{ + // Forwards the formatting by casting the enum to it's underlying type + auto format(const uda::client_server::ProtocolId& enumValue, format_context& ctx) const + { + return fmt::formatter>::format( + static_cast>(enumValue), ctx); + } +}; + namespace uda::logging { diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index 2d337ea7..8d3ebcef 100755 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -4,8 +4,9 @@ find_package( LibXml2 REQUIRED ) find_package( OpenSSL REQUIRED ) find_package( fmt REQUIRED ) +find_package( Boost REQUIRED COMPONENTS regex ) -set( LIBS LibXml2::LibXml2 OpenSSL::SSL OpenSSL::Crypto fmt::fmt ) +set( LIBS LibXml2::LibXml2 OpenSSL::SSL OpenSSL::Crypto fmt::fmt Boost::regex ) if( WIN32 OR MINGW ) find_package( XDR REQUIRED ) diff --git a/source/server2/CMakeLists.txt b/source/server2/CMakeLists.txt index 99f0119d..43188f5e 100755 --- a/source/server2/CMakeLists.txt +++ b/source/server2/CMakeLists.txt @@ -5,8 +5,9 @@ find_package( LibXml2 REQUIRED ) find_package( OpenSSL REQUIRED ) find_package( spdlog REQUIRED ) find_package( fmt REQUIRED ) +find_package( Boost REQUIRED COMPONENTS regex ) -set( LIBS LibXml2::LibXml2 OpenSSL::SSL OpenSSL::Crypto spdlog::spdlog fmt::fmt ) +set( LIBS LibXml2::LibXml2 OpenSSL::SSL OpenSSL::Crypto spdlog::spdlog fmt::fmt Boost::regex ) if( WIN32 OR MINGW ) find_package( XDR REQUIRED )