Skip to content

Commit

Permalink
Fixing Linux build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholloc committed Nov 27, 2024
1 parent be0c858 commit 048e4d8
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 54 deletions.
3 changes: 2 additions & 1 deletion source/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion source/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion source/client2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion source/clientserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
19 changes: 17 additions & 2 deletions source/clientserver/errorLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
14 changes: 1 addition & 13 deletions source/clientserver/errorLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
35 changes: 35 additions & 0 deletions source/clientserver/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 2 additions & 33 deletions source/clientserver/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <string>
#include <fmt/format.h>

#include "structures/genStructs.h"
#include "xdrlib.h"
Expand Down Expand Up @@ -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);

}

Expand Down
20 changes: 20 additions & 0 deletions source/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@

#define UDA_LOG(LEVEL, FMT, ...) uda::logging::log(LEVEL, __FILE__, __LINE__, FMT, ##__VA_ARGS__);

//template<typename T, typename = std::enable_if<std::is_enum<T>::value, bool>>
//inline auto format_as(T t) -> typename std::underlying_type<T>::type {
// return static_cast<typename std::underlying_type<T>::type>(t);
//}

namespace uda::client_server {
enum class ProtocolId;
}

template<>
struct fmt::formatter<uda::client_server::ProtocolId> : fmt::formatter<std::underlying_type_t<uda::client_server::ProtocolId>>
{
// 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<std::underlying_type_t<uda::client_server::ProtocolId>>::format(
static_cast<std::underlying_type_t<uda::client_server::ProtocolId>>(enumValue), ctx);
}
};

namespace uda::logging
{

Expand Down
3 changes: 2 additions & 1 deletion source/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion source/server2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit 048e4d8

Please sign in to comment.