mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Compare commits
106 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ebcbe2dde6 | ||
|
fda8126a43 | ||
|
8796ce5b20 | ||
|
b8503bfbd5 | ||
|
7329cb4428 | ||
|
e84a16da88 | ||
|
1a5d0eddbe | ||
|
5fe2f53c7b | ||
|
d7fb01908c | ||
|
1449166d44 | ||
|
55a2cfcc37 | ||
|
36600dce2c | ||
|
153dcfab94 | ||
|
ad824b4de1 | ||
|
597d88277b | ||
|
9590b5be40 | ||
|
cf9b45cd75 | ||
|
1ee9d2d222 | ||
|
310204a89d | ||
|
f33c597f34 | ||
|
42a7e298c0 | ||
|
efca8e0ad4 | ||
|
1ac30b51b1 | ||
|
2934016586 | ||
|
e484bf4578 | ||
|
b442483dc3 | ||
|
727a709aff | ||
|
bce380d871 | ||
|
c57410b820 | ||
|
815b2f1d76 | ||
|
4e8f247a0d | ||
|
0bf765e6ba | ||
|
24fbf94946 | ||
|
d392f60c09 | ||
|
dff2b4b7d1 | ||
|
9cbaf7e0fd | ||
|
db727092c5 | ||
|
8e6c50e7cc | ||
|
db0500fb2d | ||
|
479d6e0712 | ||
|
170557ace9 | ||
|
8859c563ac | ||
|
e3d3be888f | ||
|
0c4921d650 | ||
|
1007de8e49 | ||
|
9585c20b7f | ||
|
03ba9eb558 | ||
|
a6193a380d | ||
|
38f9870893 | ||
|
08d72d492a | ||
|
787a0a8748 | ||
|
e2452fa7e4 | ||
|
b374c235f0 | ||
|
1df338b262 | ||
|
81b1ba1f20 | ||
|
3702d3bfca | ||
|
0046bb38aa | ||
|
ea452e3bf7 | ||
|
a18ce7a435 | ||
|
e2de214a19 | ||
|
09d2574105 | ||
|
2ebf67d727 | ||
|
f413aa1979 | ||
|
df98b193ec | ||
|
8533a44418 | ||
|
42606f9f17 | ||
|
8bf9e1d0a6 | ||
|
9a2af84b7e | ||
|
b99e8ed1e2 | ||
|
c5e40fd180 | ||
|
ac3293fcc6 | ||
|
4fdf9d340b | ||
|
5c9ba5e5b4 | ||
|
4dbb5535c3 | ||
|
a8bdb91165 | ||
|
37c059177f | ||
|
28a887a457 | ||
|
ab54668aee | ||
|
2e655823e4 | ||
|
3c4158addb | ||
|
882edbbdb8 | ||
|
c847a7ca02 | ||
|
f25cca2073 | ||
|
6aeac265ec | ||
|
9444de5868 | ||
|
acf63d3c1b | ||
|
e1b229522c | ||
|
ccbd622130 | ||
|
904771e9fa | ||
|
2b438452a0 | ||
|
20200f02a3 | ||
|
2e9a088b4d | ||
|
9c3478252a | ||
|
e6c7c6b0f0 | ||
|
ff3281cc80 | ||
|
415232b56a | ||
|
947c4a73ad | ||
|
7616b0b0aa | ||
|
575054a11f | ||
|
f2d7bbeb21 | ||
|
14227aeb6d | ||
|
5efa50929d | ||
|
ed78ccd29c | ||
|
d15bc17b12 | ||
|
ce0a052252 | ||
|
bac5b90d82 |
@@ -1,3 +1,3 @@
|
||||
---
|
||||
Checks: 'cppcoreguidelines-*,misc-unused-alias-decls,misc-unused-parameters,modernize-deprecated-headers,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-using,performance-faster-string-find,performance-for-range-copy,performance-unnecessary-copy-initialization,readability-avoid-const-params-in-decls,readability-braces-around-statements,readability-container-size-empty,readability-delete-null-pointer,readability-redundant-member-init,readability-redundant-string-init,readability-static-accessed-through-instance,readability-string-compare'
|
||||
Checks: 'cppcoreguidelines-*,misc-unused-alias-decls,misc-unused-parameters,modernize-pass-by-value,modernize-deprecated-headers,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-using,performance-faster-string-find,performance-for-range-copy,performance-unnecessary-copy-initialization,readability-avoid-const-params-in-decls,readability-braces-around-statements,readability-container-size-empty,readability-delete-null-pointer,readability-redundant-member-init,readability-redundant-string-init,readability-static-accessed-through-instance,readability-string-compare'
|
||||
HeaderFilterRegex: '/(fairmq/)'
|
||||
|
@@ -1,3 +0,0 @@
|
||||
comment:
|
||||
layout: "diff, files"
|
||||
behavior: once
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
build
|
||||
|
||||
install
|
||||
.DS_Store
|
||||
|
||||
.vscode
|
||||
/compile_commands.json
|
||||
.cache
|
||||
|
14
.gitlint
Normal file
14
.gitlint
Normal file
@@ -0,0 +1,14 @@
|
||||
[general]
|
||||
ignore=body-is-missing
|
||||
contrib=contrib-title-conventional-commits
|
||||
|
||||
ignore-merge-commits=false
|
||||
ignore-revert-commits=false
|
||||
ignore-fixup-commits=false
|
||||
ignore-squash-commits=false
|
||||
|
||||
[title-max-length]
|
||||
line-length=75
|
||||
|
||||
[contrib-title-conventional-commits]
|
||||
types=fix,feat,build,ci,docs,style,refactor,perf,test
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -1,9 +1,9 @@
|
||||
[submodule "extern/googletest"]
|
||||
path = extern/googletest
|
||||
url = https://github.com/google/googletest
|
||||
[submodule "extern/asio"]
|
||||
path = extern/asio
|
||||
url = https://github.com/chriskohlhoff/asio
|
||||
[submodule "extern/PicoSHA2"]
|
||||
path = extern/PicoSHA2
|
||||
url = https://github.com/okdshin/PicoSHA2
|
||||
[submodule "extern/FairCMakeModules"]
|
||||
path = extern/FairCMakeModules
|
||||
url = https://github.com/FairRootGroup/FairCMakeModules
|
||||
|
349
CMakeLists.txt
349
CMakeLists.txt
@@ -1,32 +1,28 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
|
||||
cmake_policy(VERSION 3.12...3.15)
|
||||
|
||||
# Project ######################################################################
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||
include(FairMQLib)
|
||||
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
|
||||
cmake_policy(VERSION 3.15...3.20)
|
||||
|
||||
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||
include(GitHelper)
|
||||
get_git_version()
|
||||
|
||||
project(FairMQ VERSION ${PROJECT_VERSION} LANGUAGES CXX)
|
||||
message(STATUS "${BWhite}${PROJECT_NAME}${CR} ${PROJECT_GIT_VERSION} from ${PROJECT_DATE}")
|
||||
|
||||
set(PROJECT_MIN_CXX_STANDARD 17)
|
||||
|
||||
set_fairmq_defaults()
|
||||
|
||||
include(CTest)
|
||||
include(FairMQProjectSettings)
|
||||
################################################################################
|
||||
|
||||
|
||||
# Build options ################################################################
|
||||
include(FairMQBuildOption)
|
||||
|
||||
fairmq_build_option(BUILD_FAIRMQ "Build FairMQ library and devices."
|
||||
DEFAULT ON)
|
||||
fairmq_build_option(BUILD_TESTING "Build tests."
|
||||
@@ -43,9 +39,9 @@ fairmq_build_option(BUILD_EXAMPLES "Build FairMQ examples."
|
||||
DEFAULT ON REQUIRES "BUILD_FAIRMQ")
|
||||
fairmq_build_option(BUILD_SDK "Build the FairMQ controller SDK."
|
||||
DEFAULT OFF REQUIRES "BUILD_DDS_PLUGIN;BUILD_SDK_COMMANDS")
|
||||
fairmq_build_option(BUILD_DOCS "Build FairMQ documentation."
|
||||
fairmq_build_option(BUILD_TIDY_TOOL "Build the fairmq-tidy tool."
|
||||
DEFAULT OFF)
|
||||
fairmq_build_option(FAST_BUILD "Fast production build. Not recommended for development."
|
||||
fairmq_build_option(BUILD_DOCS "Build FairMQ documentation."
|
||||
DEFAULT OFF)
|
||||
fairmq_build_option(USE_EXTERNAL_GTEST "Do not use bundled GTest. Not recommended."
|
||||
DEFAULT OFF)
|
||||
@@ -55,116 +51,8 @@ fairmq_build_option(FAIRMQ_DEBUG_MODE "Compile in debug mode (may decrease per
|
||||
|
||||
|
||||
# Dependencies #################################################################
|
||||
if(FAST_BUILD)
|
||||
include(cotire)
|
||||
endif()
|
||||
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
find_package2(PRIVATE asiofi REQUIRED
|
||||
VERSION 0.3.1
|
||||
)
|
||||
find_package2(PRIVATE OFI REQUIRED
|
||||
ADD_REQUIREMENTS_OF asiofi
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_SDK_COMMANDS)
|
||||
find_package2(PRIVATE Flatbuffers REQUIRED)
|
||||
endif()
|
||||
|
||||
if(BUILD_DDS_PLUGIN OR BUILD_SDK)
|
||||
find_package2(PRIVATE DDS REQUIRED
|
||||
VERSION 3.5.3
|
||||
)
|
||||
set(DDS_Boost_COMPONENTS system log log_setup regex filesystem thread)
|
||||
set(DDS_Boost_VERSION 1.67)
|
||||
endif()
|
||||
|
||||
if(BUILD_PMIX_PLUGIN)
|
||||
find_package2(PRIVATE PMIx REQUIRED
|
||||
VERSION 2.1.4
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
find_package2(PUBLIC FairLogger REQUIRED
|
||||
VERSION 1.6.0
|
||||
)
|
||||
|
||||
foreach(dep IN LISTS FairLogger_PACKAGE_DEPENDENCIES)
|
||||
if(NOT dep STREQUAL "Boost")
|
||||
find_package2(PUBLIC ${dep} REQUIRED VERSION ${FairLogger_${dep}_VERSION})
|
||||
set(PROJECT_${dep}_VERSION ${FairLogger_${dep}_VERSION})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT DEFINED Boost_NO_BOOST_CMAKE AND CMAKE_VERSION VERSION_LESS 3.15)
|
||||
# Since Boost 1.70 a CMake package is shipped by default. Unfortunately, it has a number
|
||||
# of problems that are only fixed in Boost 1.71 or CMake 3.15. By default we skip the
|
||||
# BoostConfig lookup. This can be overridden on the command line via -DBoost_NO_BOOST_CMAKE=OFF
|
||||
set(Boost_NO_BOOST_CMAKE ON)
|
||||
endif()
|
||||
find_package2(PUBLIC Boost REQUIRED
|
||||
VERSION 1.66
|
||||
|
||||
COMPONENTS
|
||||
container
|
||||
program_options
|
||||
filesystem
|
||||
date_time
|
||||
regex
|
||||
|
||||
ADD_REQUIREMENTS_OF
|
||||
asiofi
|
||||
DDS
|
||||
FairLogger
|
||||
)
|
||||
|
||||
# Normalize Boost version
|
||||
if(CMAKE_VERSION VERSION_LESS 3.15)
|
||||
set(Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_SDK)
|
||||
find_package2(BUNDLED asio
|
||||
VERSION 1.18.0
|
||||
)
|
||||
if(NOT asio_FOUND)
|
||||
build_bundled(asio extern/asio)
|
||||
find_package2(PRIVATE asio REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_FAIRMQ)
|
||||
find_package2(PRIVATE ZeroMQ REQUIRED
|
||||
VERSION 4.1.4
|
||||
)
|
||||
build_bundled(PicoSHA2 extern/PicoSHA2)
|
||||
find_package2(PRIVATE PicoSHA2 REQUIRED)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
if(USE_EXTERNAL_GTEST)
|
||||
find_package2(PRIVATE GTest VERSION 1.7.0)
|
||||
endif()
|
||||
if(NOT GTest_FOUND)
|
||||
build_bundled(GTest extern/googletest)
|
||||
find_package2(PRIVATE GTest REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_DOCS)
|
||||
find_package2(PRIVATE Doxygen REQUIRED
|
||||
VERSION 1.8.8
|
||||
COMPONENTS dot
|
||||
OPTIONAL_COMPONENTS mscgen dia
|
||||
)
|
||||
endif()
|
||||
include(CTest)
|
||||
include(FairMQDependencies)
|
||||
################################################################################
|
||||
|
||||
|
||||
@@ -190,6 +78,10 @@ if(BUILD_DOCS)
|
||||
doxygen_add_docs(doxygen README.md fairmq)
|
||||
add_custom_target(docs ALL DEPENDS doxygen)
|
||||
endif()
|
||||
|
||||
if(BUILD_TIDY_TOOL)
|
||||
add_subdirectory(fairmq/tidy)
|
||||
endif()
|
||||
################################################################################
|
||||
|
||||
|
||||
@@ -221,6 +113,9 @@ endif()
|
||||
if(BUILD_SDK_COMMANDS)
|
||||
list(APPEND PROJECT_PACKAGE_COMPONENTS sdk_commands)
|
||||
endif()
|
||||
if(BUILD_TIDY_TOOL)
|
||||
list(APPEND PROJECT_PACKAGE_COMPONENTS tidy_tool)
|
||||
endif()
|
||||
################################################################################
|
||||
|
||||
|
||||
@@ -230,207 +125,37 @@ if(BUILD_FAIRMQ)
|
||||
DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR}
|
||||
)
|
||||
endif()
|
||||
if(BUILD_SDK OR BUILD_DDS_PLUGIN)
|
||||
install(FILES cmake/Findasio.cmake
|
||||
DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR}
|
||||
)
|
||||
endif()
|
||||
if(BUILD_DOCS)
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/doxygen/html
|
||||
DESTINATION ${PROJECT_INSTALL_DATADIR}/docs
|
||||
)
|
||||
endif()
|
||||
if(BUILD_SDK)
|
||||
install(FILES cmake/Findasio.cmake
|
||||
if(BUILD_TIDY_TOOL)
|
||||
install(FILES cmake/FairMQTidy.cmake
|
||||
DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR}
|
||||
)
|
||||
if(asio_BUNDLED)
|
||||
install(TARGETS bundled_asio_headers EXPORT ${PROJECT_EXPORT_SET})
|
||||
install(DIRECTORY "${asio_BUILD_INCLUDE_DIR}/asio"
|
||||
DESTINATION ${asio_INSTALL_INCLUDE_DIR}
|
||||
PATTERN "Makefile.am" EXCLUDE
|
||||
PATTERN ".gitignore" EXCLUDE
|
||||
)
|
||||
install(FILES "${asio_BUILD_INCLUDE_DIR}/asio.hpp"
|
||||
DESTINATION ${asio_INSTALL_INCLUDE_DIR}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FairMQPackage)
|
||||
install_cmake_package()
|
||||
################################################################################
|
||||
|
||||
|
||||
# Summary ######################################################################
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}CXX STANDARD${CR} ${BGreen}C++${CMAKE_CXX_STANDARD}${CR} (>= C++${PROJECT_MIN_CXX_STANDARD}, change with ${BMagenta}-DCMAKE_CXX_STANDARD=20${CR})")
|
||||
if(CMAKE_CXX_FLAGS)
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}GLOBAL CXX FLAGS${CR} ${BGreen}${CMAKE_CXX_FLAGS}${CR}")
|
||||
endif()
|
||||
if(CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}BUILD TYPE CXX FLAGS${CR}")
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" selected_type)
|
||||
foreach(type IN LISTS CMAKE_CONFIGURATION_TYPES)
|
||||
string(TOUPPER "${type}" type_upper)
|
||||
if(type_upper STREQUAL selected_type)
|
||||
pad("${type}" 18 " " type_padded)
|
||||
message(STATUS "${BGreen}* ${type_padded}${CMAKE_CXX_FLAGS_${type_upper}}${CR}")
|
||||
else()
|
||||
pad("${type}" 18 " " type_padded)
|
||||
message(STATUS " ${BWhite}${type_padded}${CR}${CMAKE_CXX_FLAGS_${type_upper}}")
|
||||
endif()
|
||||
unset(type_padded)
|
||||
unset(type_upper)
|
||||
endforeach()
|
||||
message(STATUS " ")
|
||||
message(STATUS " (Change the build type with ${BMagenta}-DCMAKE_BUILD_TYPE=...${CR})")
|
||||
endif()
|
||||
if(PROJECT_PACKAGE_DEPENDENCIES)
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}DEPENDENCY FOUND VERSION PREFIX${CR}")
|
||||
foreach(dep IN LISTS PROJECT_PACKAGE_DEPENDENCIES)
|
||||
if(${dep}_VERSION AND NOT ${dep}_VERSION STREQUAL "..")
|
||||
set(version_str "${BGreen}${${dep}_VERSION}${CR}")
|
||||
else()
|
||||
set(version_str "${BYellow}unknown${CR}")
|
||||
endif()
|
||||
if(PROJECT_${dep}_VERSION)
|
||||
set(version_req_str " (>= ${PROJECT_${dep}_VERSION})")
|
||||
endif()
|
||||
pad(${dep} 20 " " dep_padded)
|
||||
if(DISABLE_COLOR)
|
||||
pad("${version_str}${version_req_str}" 25 " " version_padded)
|
||||
else()
|
||||
pad("${version_str}${version_req_str}" 25 " " version_padded COLOR 1)
|
||||
endif()
|
||||
if(${dep} STREQUAL FairLogger)
|
||||
if(FairLogger_PREFIX)
|
||||
set(prefix ${FairLogger_PREFIX})
|
||||
else()
|
||||
set(prefix ${FairLogger_ROOT})
|
||||
endif()
|
||||
elseif(${dep} STREQUAL GTest)
|
||||
get_filename_component(prefix ${GTEST_INCLUDE_DIRS}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL asiofi)
|
||||
set(prefix ${asiofi_ROOT})
|
||||
elseif(${dep} STREQUAL OFI)
|
||||
get_filename_component(prefix ${${dep}_INCLUDE_DIRS}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL DDS)
|
||||
set(prefix "${DDS_INSTALL_PREFIX}")
|
||||
elseif(${dep} STREQUAL Boost)
|
||||
if(TARGET Boost::headers)
|
||||
get_target_property(boost_include Boost::headers INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
get_target_property(boost_include Boost::boost INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif()
|
||||
get_filename_component(prefix ${boost_include}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL Doxygen)
|
||||
get_target_property(doxygen_bin Doxygen::doxygen INTERFACE_LOCATION)
|
||||
get_filename_component(prefix ${doxygen_bin} DIRECTORY)
|
||||
get_filename_component(prefix ${prefix}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL fmt)
|
||||
get_target_property(fmt_include fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_filename_component(prefix ${fmt_include}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL Flatbuffers)
|
||||
if(TARGET flatbuffers::flatbuffers)
|
||||
get_target_property(flatbuffers_include flatbuffers::flatbuffers INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
get_target_property(flatbuffers_include flatbuffers::flatbuffers_shared INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif()
|
||||
get_filename_component(prefix ${flatbuffers_include}/.. ABSOLUTE)
|
||||
else()
|
||||
get_filename_component(prefix ${${dep}_INCLUDE_DIR}/.. ABSOLUTE)
|
||||
endif()
|
||||
if(NOT ${dep}_BUNDLED)
|
||||
message(STATUS " ${BWhite}${dep_padded}${CR}${version_padded}${prefix}")
|
||||
endif()
|
||||
unset(version_str)
|
||||
unset(version_padded)
|
||||
unset(version_req_str)
|
||||
endforeach()
|
||||
endif()
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}COMPONENT BUILT? INFO${CR}")
|
||||
if(BUILD_FAIRMQ)
|
||||
set(fairmq_summary "${BGreen}YES${CR} (default, disable with ${BMagenta}-DBUILD_FAIRMQ=OFF${CR})")
|
||||
else()
|
||||
set(fairmq_summary "${BRed} NO${CR} (enable with ${BMagenta}-DBUILD_FAIRMQ=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}fairmq${CR} ${fairmq_summary}")
|
||||
if(BUILD_TESTING)
|
||||
set(tests_summary "${BGreen}YES${CR} (default, disable with ${BMagenta}-DBUILD_TESTING=OFF${CR})")
|
||||
else()
|
||||
set(tests_summary "${BRed} NO${CR} (enable with ${BMagenta}-DBUILD_TESTING=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}tests${CR} ${tests_summary}")
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(ofi_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_OFI_TRANSPORT=OFF${CR})")
|
||||
else()
|
||||
set(ofi_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_OFI_TRANSPORT=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}ofi_transport${CR} ${ofi_summary}")
|
||||
if(BUILD_DDS_PLUGIN)
|
||||
set(dds_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_DDS_PLUGIN=OFF${CR})")
|
||||
else()
|
||||
set(dds_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_DDS_PLUGIN=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}dds_plugin${CR} ${dds_summary}")
|
||||
if(BUILD_PMIX_PLUGIN)
|
||||
set(pmix_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_PMIX_PLUGIN=OFF${CR})")
|
||||
else()
|
||||
set(pmix_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_PMIX_PLUGIN=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}pmix_plugin${CR} ${pmix_summary}")
|
||||
if(BUILD_EXAMPLES)
|
||||
set(examples_summary "${BGreen}YES${CR} (default, disable with ${BMagenta}-DBUILD_EXAMPLES=OFF${CR})")
|
||||
else()
|
||||
set(examples_summary "${BRed} NO${CR} (enable with ${BMagenta}-DBUILD_EXAMPLES=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}examples${CR} ${examples_summary}")
|
||||
if(BUILD_DOCS)
|
||||
set(docs_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_DOCS=OFF${CR})")
|
||||
else()
|
||||
set(docs_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_DOCS=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}docs${CR} ${docs_summary}")
|
||||
if(BUILD_SDK)
|
||||
set(sdk_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_SDK=OFF${CR})")
|
||||
else()
|
||||
set(sdk_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_SDK=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}sdk${CR} ${sdk_summary}")
|
||||
if(BUILD_SDK_COMMANDS)
|
||||
set(sdk_commands_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_SDK_COMMANDS=OFF${CR})")
|
||||
else()
|
||||
set(sdk_commands_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_SDK_COMMANDS=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}sdk_commands${CR} ${sdk_commands_summary}")
|
||||
message(STATUS " ")
|
||||
if(RUN_STATIC_ANALYSIS)
|
||||
list(LENGTH PROJECT_STATIC_ANALYSERS size)
|
||||
unset(analyser_list)
|
||||
set(count 0)
|
||||
foreach(analyser IN LISTS PROJECT_STATIC_ANALYSERS)
|
||||
if(${analyser}_FOUND)
|
||||
set(${analyser}_status "${analyser} ${BGreen}YES${CR}")
|
||||
else()
|
||||
set(${analyser}_status "${analyser} ${BRed}NO${CR}")
|
||||
endif()
|
||||
math(EXPR count "${count} + 1")
|
||||
string(APPEND analyser_list "${${analyser}_status}")
|
||||
if(count LESS size)
|
||||
string(APPEND analyser_list "${BWhite},${CR} ")
|
||||
endif()
|
||||
endforeach()
|
||||
set(static_ana_summary "${BWhite}(${CR}${analyser_list}${BWhite})${CR} (disable with ${BMagenta}-DRUN_STATIC_ANALYSIS=OFF${CR})")
|
||||
else()
|
||||
set(static_ana_summary "${BRed}OFF${CR} (default, enable with ${BMagenta}-DRUN_STATIC_ANALYSIS=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${Cyan}INSTALL PREFIX${CR} ${BGreen}${CMAKE_INSTALL_PREFIX}${CR} (change with ${BMagenta}-DCMAKE_INSTALL_PREFIX=...${CR})")
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}RUN STATIC ANALYSIS ${static_ana_summary}")
|
||||
message(STATUS " ")
|
||||
if(FAIRMQ_DEBUG_MODE)
|
||||
message(STATUS " ${Cyan}DEBUG MODE${CR} ${BGreen}${FAIRMQ_DEBUG_MODE}${CR} (disable with ${BMagenta}-DFAIRMQ_DEBUG_MODE=OFF${CR})")
|
||||
else()
|
||||
message(STATUS " ${Cyan}DEBUG MODE${CR} ${BRed}${FAIRMQ_DEBUG_MODE}${CR} (enable with ${BMagenta}-DFAIRMQ_DEBUG_MODE=ON${CR})")
|
||||
endif()
|
||||
include(FairMQSummary)
|
||||
|
||||
message(STATUS "${BWhite}${PROJECT_NAME}${CR} ${PROJECT_GIT_VERSION} from ${PROJECT_DATE}")
|
||||
fair_summary_global_cxx_flags_standard()
|
||||
fair_summary_build_types()
|
||||
fair_summary_package_dependencies()
|
||||
fairmq_summary_components()
|
||||
fairmq_summary_static_analysis()
|
||||
fairmq_summary_install_prefix()
|
||||
fairmq_summary_debug_mode()
|
||||
message(STATUS " ")
|
||||
################################################################################
|
||||
|
36
COPYRIGHT
36
COPYRIGHT
@@ -4,23 +4,19 @@ Upstream-Contact: Mohammad Al-Turany <m.al-turany@gsi.de>
|
||||
Source: https://github.com/FairRootGroup/FairMQ
|
||||
|
||||
Files: *
|
||||
Copyright: 2012-2019, GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
|
||||
Copyright: 2012-2019, [see AUTHORS file]
|
||||
Copyright: 2012-2019, [see CONTRIBUTORS file]
|
||||
Copyright: 2012-2021, GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
|
||||
Copyright: 2012-2021, [see AUTHORS file]
|
||||
Copyright: 2012-2021, [see CONTRIBUTORS file]
|
||||
Comment: The copyright of individual contributors is documented in the
|
||||
Git history.
|
||||
License: LGPL-3.0-only
|
||||
|
||||
Files: cmake/cotire.cmake
|
||||
Copyright: 2012-2018 Sascha Kratky
|
||||
License: COTIRE
|
||||
|
||||
Files: extern/googletest
|
||||
Copyright: 2008, Google Inc.
|
||||
Copyright: 2008-2021, Google Inc.
|
||||
License: GOOGLE
|
||||
|
||||
Files: extern/asio
|
||||
Copyright: 2003-2019, Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
Copyright: 2003-2021, Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
License: BSL-1.0
|
||||
|
||||
Files: extern/PicoSHA2
|
||||
@@ -30,28 +26,6 @@ License: MIT
|
||||
License: LGPL-3.0-only
|
||||
[see LICENSE file]
|
||||
|
||||
License: COTIRE
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
License: GOOGLE
|
||||
Copyright 2008, Google Inc.
|
||||
All rights reserved.
|
||||
|
@@ -1,9 +1,3 @@
|
||||
set(CTEST_PROJECT_NAME "FairMQ")
|
||||
set(CTEST_NIGHTLY_START_TIME "00:00:00 CEST")
|
||||
|
||||
set(CTEST_DROP_METHOD "https")
|
||||
set(CTEST_DROP_SITE "cdash.gsi.de")
|
||||
set(CTEST_DROP_LOCATION "/submit.php?project=FairMQ")
|
||||
set(CTEST_DROP_SITE_CDASH TRUE)
|
||||
|
||||
set(CTEST_TESTING_TIMEOUT 60)
|
||||
set(CTEST_SUBMIT_URL "https://cdash.gsi.de/submit.php?project=FairMQ")
|
||||
|
145
Dart.sh
145
Dart.sh
@@ -1,145 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
function print_example(){
|
||||
echo "##################################################################"
|
||||
echo "# To set the required parameters as source and the build #"
|
||||
echo "# directory for ctest, the linux flavour and the SIMPATH #"
|
||||
echo "# put the export commands below to a separate file which is read #"
|
||||
echo "# during execution and which is defined on the command line. #"
|
||||
echo "# Set all parameters according to your needs. #"
|
||||
echo "# LINUX_FLAVOUR should be set to the distribution you are using #"
|
||||
echo "# eg Debian, SuSe etc. #"
|
||||
echo "# An additional varibale NCPU can overwrite the default number #"
|
||||
echo "# of parallel processes used to compile the project. #"
|
||||
echo "# This can be usefull if one can use a distributed build system #"
|
||||
echo "# like icecream. #"
|
||||
echo "# For example #"
|
||||
echo "#!/bin/bash #"
|
||||
echo "export LINUX_FLAVOUR=<your linux flavour> #"
|
||||
echo "export FAIRSOFT_VERSION=<version of FairSoft> #"
|
||||
echo "export SIMPATH=<path to your FairSoft version> #"
|
||||
echo "export GIT_BRANCH=< master or dev> #"
|
||||
echo "export BUILDDIR=<dir where the build files go> #"
|
||||
echo "export SOURCEDIR=<location of the FairRoot sources> #"
|
||||
echo "#export NCPU=100 #"
|
||||
echo "##################################################################"
|
||||
}
|
||||
|
||||
if [ "$#" -lt "2" ]; then
|
||||
echo ""
|
||||
echo "-- Error -- Please start script with two parameters"
|
||||
echo "-- Error -- The first parameter is the ctest model."
|
||||
echo "-- Error -- Possible arguments are Nightly, Experimental, "
|
||||
echo "-- Error -- Continuous or Profile."
|
||||
echo "-- Error -- The second parameter is the file containg the"
|
||||
echo "-- Error -- Information about the setup at the client"
|
||||
echo "-- Error -- installation (see example below)."
|
||||
echo ""
|
||||
print_example
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# test if a valid ctest model is defined
|
||||
case "$1" in
|
||||
Experimental|Nightly|Continuous|Profile|alfa_ci|codecov)
|
||||
;;
|
||||
*)
|
||||
echo "-- Error -- This ctest model is not supported."
|
||||
echo "-- Error -- Possible arguments are Nightly, Experimental, Continuous or Profile."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# test if the input file exists and execute it
|
||||
if [ -e "$2" ];then
|
||||
source $2
|
||||
else
|
||||
echo "-- Error -- Input file does not exist."
|
||||
echo "-- Error -- Please choose existing input file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# set the ctest model to command line parameter
|
||||
if [ "$1" == "alfa_ci" ]; then
|
||||
export ctest_model=Experimental
|
||||
elif [ "$1" == "codecov" ]; then
|
||||
export ctest_model=Profile
|
||||
export do_codecov_upload=0
|
||||
else
|
||||
export ctest_model=$1
|
||||
fi
|
||||
|
||||
|
||||
# test for architecture
|
||||
arch=$(uname -s | tr '[A-Z]' '[a-z]')
|
||||
chip=$(uname -m | tr '[A-Z]' '[a-z]')
|
||||
|
||||
# extract information about the system and the machine and set
|
||||
# environment variables used by ctest
|
||||
SYSTEM=$arch-$chip
|
||||
if test -z $CXX ; then
|
||||
if [ "$arch" == "darwin" ]; then
|
||||
COMPILER=$(clang --version | head -n 1 | cut -d' ' -f1,2,4 | tr -d ' ')
|
||||
else
|
||||
COMPILER=gcc$(gcc -dumpversion)
|
||||
fi
|
||||
else
|
||||
COMPILER=$CXX$($CXX -dumpversion)
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
alfa_ci)
|
||||
export LABEL1=alfa_ci-$COMPILER-FairMQ_$GIT_BRANCH
|
||||
export LABEL=$(echo $LABEL1 | sed -e 's#/#_#g')
|
||||
;;
|
||||
codecov)
|
||||
export LABEL1=codecov-$COMPILER-FairMQ_$GIT_BRANCH
|
||||
export LABEL=$(echo $LABEL1 | sed -e 's#/#_#g')
|
||||
;;
|
||||
*)
|
||||
export LABEL1=${LINUX_FLAVOUR}-$chip-$COMPILER-FairMQ_$GIT_BRANCH
|
||||
export LABEL=$(echo $LABEL1 | sed -e 's#/#_#g')
|
||||
;;
|
||||
esac
|
||||
|
||||
# get the number of processors
|
||||
# and information about the host
|
||||
if [ "$arch" = "linux" ];
|
||||
then
|
||||
if [ "$NCPU" != "" ];
|
||||
then
|
||||
export number_of_processors=$NCPU
|
||||
else
|
||||
export number_of_processors=$(cat /proc/cpuinfo | grep processor | wc -l)
|
||||
fi
|
||||
if [ -z "$SITE" ]; then
|
||||
export SITE=$(hostname -f)
|
||||
if [ -z "$SITE" ]; then
|
||||
export SITE=$(uname -n)
|
||||
fi
|
||||
fi
|
||||
elif [ "$arch" = "darwin" ];
|
||||
then
|
||||
if [ "$NCPU" != "" ];
|
||||
then
|
||||
export number_of_processors=$NCPU
|
||||
else
|
||||
export number_of_processors=$(sysctl -n hw.ncpu)
|
||||
fi
|
||||
if [ -z "$SITE" ]; then
|
||||
export SITE=$(hostname -s)
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "************************"
|
||||
date
|
||||
echo "LABEL: " $LABEL
|
||||
echo "SITE: " $SITE
|
||||
echo "Model: " ${ctest_model}
|
||||
echo "Nr. of processes: " $number_of_processors
|
||||
echo "************************"
|
||||
|
||||
cd $SOURCEDIR
|
||||
|
||||
ctest -S FairMQTest.cmake -V --VV
|
@@ -13,6 +13,7 @@ set(CTEST_BINARY_DIRECTORY build)
|
||||
set(CTEST_CMAKE_GENERATOR "Ninja")
|
||||
set(CTEST_USE_LAUNCHERS ON)
|
||||
set(CTEST_CONFIGURATION_TYPE "RelWithDebInfo")
|
||||
set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 102400)
|
||||
|
||||
if(NOT NCPUS)
|
||||
if(ENV{SLURM_CPUS_PER_TASK})
|
||||
@@ -40,14 +41,41 @@ endif()
|
||||
|
||||
ctest_start(Continuous)
|
||||
|
||||
list(APPEND options
|
||||
"-DDISABLE_COLOR=ON"
|
||||
"-DBUILD_SDK_COMMANDS=ON"
|
||||
"-DBUILD_SDK=ON"
|
||||
"-DBUILD_DDS_PLUGIN=ON")
|
||||
list(APPEND options "-DDISABLE_COLOR=ON" "-DBUILD_EXAMPLES=ON" "-DBUILD_TESTING=ON")
|
||||
if(HAS_ASIO AND HAS_DDS)
|
||||
list(APPEND options "-DBUILD_SDK_COMMANDS=ON" "-DBUILD_SDK=ON" "-DBUILD_DDS_PLUGIN=ON")
|
||||
endif()
|
||||
if(HAS_PMIX)
|
||||
list(APPEND options "-DBUILD_SDK_COMMANDS=ON" "-DBUILD_PMIX_PLUGIN=ON")
|
||||
endif()
|
||||
if(HAS_ASIO AND HAS_ASIOFI)
|
||||
list(APPEND options "-DBUILD_OFI_TRANSPORT=ON")
|
||||
endif()
|
||||
if(RUN_STATIC_ANALYSIS)
|
||||
list(APPEND options "-DRUN_STATIC_ANALYSIS=ON")
|
||||
endif()
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
set(CTEST_CONFIGURATION_TYPE ${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
if(ENABLE_SANITIZER_ADDRESS)
|
||||
list(APPEND options "-DENABLE_SANITIZER_ADDRESS=ON")
|
||||
endif()
|
||||
if(ENABLE_SANITIZER_LEAK)
|
||||
list(APPEND options "-DENABLE_SANITIZER_LEAK=ON")
|
||||
endif()
|
||||
if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR)
|
||||
list(APPEND options "-DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON")
|
||||
endif()
|
||||
if(ENABLE_SANITIZER_MEMORY)
|
||||
list(APPEND options "-DENABLE_SANITIZER_MEMORY=ON")
|
||||
endif()
|
||||
if(ENABLE_SANITIZER_THREAD)
|
||||
list(APPEND options "-DENABLE_SANITIZER_THREAD=ON")
|
||||
endif()
|
||||
if(CMAKE_CXX_FLAGS)
|
||||
list(APPEND options "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
list(REMOVE_DUPLICATES options)
|
||||
list(JOIN options ";" optionsstr)
|
||||
ctest_configure(OPTIONS "${optionsstr}")
|
||||
|
||||
@@ -57,12 +85,14 @@ ctest_build(FLAGS "-j${NCPUS}")
|
||||
|
||||
ctest_submit()
|
||||
|
||||
ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}"
|
||||
PARALLEL_LEVEL 1
|
||||
SCHEDULE_RANDOM ON
|
||||
RETURN_VALUE _ctest_test_ret_val)
|
||||
if(NOT RUN_STATIC_ANALYSIS)
|
||||
ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}"
|
||||
PARALLEL_LEVEL 1
|
||||
SCHEDULE_RANDOM ON
|
||||
RETURN_VALUE _ctest_test_ret_val)
|
||||
|
||||
ctest_submit()
|
||||
ctest_submit()
|
||||
endif()
|
||||
|
||||
if(_ctest_test_ret_val)
|
||||
Message(FATAL_ERROR "Some tests failed.")
|
||||
|
76
Jenkinsfile
vendored
76
Jenkinsfile
vendored
@@ -3,12 +3,25 @@
|
||||
def jobMatrix(String type, List specs) {
|
||||
def nodes = [:]
|
||||
for (spec in specs) {
|
||||
job = "${spec.os}-${spec.ver}-${spec.arch}-${spec.compiler}"
|
||||
def label = "${type}/${job}"
|
||||
def selector = "${spec.os}-${spec.ver}-${spec.arch}"
|
||||
def os = spec.os
|
||||
def ver = spec.ver
|
||||
def check = spec.check
|
||||
def job = ""
|
||||
def selector = ""
|
||||
def os = ""
|
||||
def ver = ""
|
||||
|
||||
if (type == 'build') {
|
||||
job = "${spec.os}-${spec.ver}-${spec.arch}-${spec.compiler}"
|
||||
selector = "${spec.os}-${spec.ver}-${spec.arch}"
|
||||
os = spec.os
|
||||
ver = spec.ver
|
||||
} else { // == 'check'
|
||||
job = "${spec.name}"
|
||||
selector = 'fedora-34-x86_64'
|
||||
os = 'fedora'
|
||||
ver = '34'
|
||||
}
|
||||
|
||||
def label = "${job}"
|
||||
def extra = spec.extra
|
||||
|
||||
nodes[label] = {
|
||||
node(selector) {
|
||||
@@ -18,22 +31,19 @@ def jobMatrix(String type, List specs) {
|
||||
checkout scm
|
||||
|
||||
def jobscript = 'job.sh'
|
||||
def ctestcmd = "ctest -S FairMQTest.cmake -V --output-on-failure"
|
||||
def ctestcmd = "ctest ${extra} -S FairMQTest.cmake -V --output-on-failure"
|
||||
sh "echo \"set -e\" >> ${jobscript}"
|
||||
sh "echo \"export LABEL=\\\"\${JOB_BASE_NAME} ${label}\\\"\" >> ${jobscript}"
|
||||
if (selector =~ /^macos/) {
|
||||
sh """\
|
||||
echo \"export DDS_ROOT=\\\"\\\$(brew --prefix dds)\\\"\" >> ${jobscript}
|
||||
echo \"export PATH=\\\"\\\$(brew --prefix dds)/bin:\\\$PATH\\\"\" >> ${jobscript}
|
||||
echo \"${ctestcmd}\" >> ${jobscript}
|
||||
"""
|
||||
sh "cat ${jobscript}"
|
||||
sh "bash ${jobscript}"
|
||||
} else {
|
||||
def static_analysis = "OFF"
|
||||
if (selector =~ /^fedora/) {
|
||||
static_analysis = "ON"
|
||||
}
|
||||
def containercmd = "singularity exec -B/shared ${env.SINGULARITY_CONTAINER_ROOT}/fairmq/${os}.${ver}.sif bash -l -c \\\"${ctestcmd} -DRUN_STATIC_ANALYSIS=${static_analysis}\\\""
|
||||
def containercmd = "singularity exec --net --ipc --uts --pid -B/shared ${env.SINGULARITY_CONTAINER_ROOT}/fairmq/${os}.${ver}.sif bash -l -c \\\"${ctestcmd} ${extra}\\\""
|
||||
sh """\
|
||||
echo \"echo \\\"*** Job started at .......: \\\$(date -R)\\\"\" >> ${jobscript}
|
||||
echo \"echo \\\"*** Job ID ...............: \\\${SLURM_JOB_ID}\\\"\" >> ${jobscript}
|
||||
@@ -45,22 +55,23 @@ def jobMatrix(String type, List specs) {
|
||||
sh "cat ${jobscript}"
|
||||
sh "test/ci/slurm-submit.sh \"FairMQ \${JOB_BASE_NAME} ${label}\" ${jobscript}"
|
||||
|
||||
withChecks('Static Analysis') {
|
||||
if (static_analysis == "ON") {
|
||||
recordIssues(enabledForFailure: true,
|
||||
tools: [gcc(pattern: 'build/Testing/Temporary/*.log')],
|
||||
filters: [excludeFile('extern/*'), excludeFile('usr/*')],
|
||||
skipBlames: true)
|
||||
}
|
||||
if (job == "static-analyzers") {
|
||||
recordIssues(enabledForFailure: true,
|
||||
tools: [gcc(pattern: 'build/Testing/Temporary/*.log')],
|
||||
filters: [excludeFile('extern/*'), excludeFile('usr/*')],
|
||||
skipBlames: true,
|
||||
skipPublishingChecks: true)
|
||||
}
|
||||
}
|
||||
|
||||
deleteDir()
|
||||
githubNotify(context: "${label}", description: 'Success', status: 'SUCCESS')
|
||||
} catch (e) {
|
||||
def tarball = "${prefix}_${label}_dds_logs.tar.gz"
|
||||
sh "tar czvf ${tarball} -C \${WORKSPACE}/build/test .DDS/"
|
||||
archiveArtifacts tarball
|
||||
def tarball = "${type}_${job}_dds_logs.tar.gz"
|
||||
if (fileExists("build/test/.DDS")) {
|
||||
sh "tar czvf ${tarball} -C \${WORKSPACE}/build/test .DDS/"
|
||||
archiveArtifacts tarball
|
||||
}
|
||||
|
||||
deleteDir()
|
||||
githubNotify(context: "${label}", description: 'Error', status: 'ERROR')
|
||||
@@ -78,13 +89,26 @@ pipeline{
|
||||
stage("CI") {
|
||||
steps{
|
||||
script {
|
||||
def all = '-DHAS_ASIO=ON -DHAS_ASIOFI=ON -DHAS_PMIX=ON'
|
||||
|
||||
def builds = jobMatrix('build', [
|
||||
[os: 'alice-centos', ver: '7', arch: 'x86_64', compiler: 'gcc-7'],
|
||||
[os: 'fedora', ver: '32', arch: 'x86_64', compiler: 'gcc-10'],
|
||||
[os: 'macos', ver: '11', arch: 'x86_64', compiler: 'apple-clang-12'],
|
||||
[os: 'ubuntu', ver: '20.04', arch: 'x86_64', compiler: 'gcc-9', extra: all],
|
||||
[os: 'fedora', ver: '32', arch: 'x86_64', compiler: 'gcc-10', extra: all],
|
||||
[os: 'fedora', ver: '33', arch: 'x86_64', compiler: 'gcc-10', extra: all],
|
||||
[os: 'fedora', ver: '34', arch: 'x86_64', compiler: 'gcc-11', extra: all],
|
||||
[os: 'macos', ver: '11', arch: 'x86_64', compiler: 'apple-clang-12', extra: '-DHAS_ASIO=ON'],
|
||||
[os: 'macos', ver: '11', arch: 'arm64', compiler: 'apple-clang-13', extra: '-DHAS_ASIO=ON'],
|
||||
])
|
||||
|
||||
parallel(builds)
|
||||
def all_debug = "${all} -DCMAKE_BUILD_TYPE=Debug"
|
||||
|
||||
def checks = jobMatrix('check', [
|
||||
[name: 'static-analyzers', extra: "${all_debug} -DRUN_STATIC_ANALYSIS=ON"],
|
||||
[name: '{address,leak,ub}-sanitizers',
|
||||
extra: "${all_debug} -DENABLE_SANITIZER_ADDRESS=ON -DENABLE_SANITIZER_LEAK=ON -DENABLE_SANITIZER_UNDEFINED_BEHAVIOUR=ON -DCMAKE_CXX_FLAGS='-O1 -fno-omit-frame-pointer'"],
|
||||
])
|
||||
|
||||
parallel(builds + checks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
README.md
45
README.md
@@ -41,7 +41,7 @@ Recommended:
|
||||
git clone https://github.com/FairRootGroup/FairMQ fairmq_source
|
||||
cmake -S fairmq_source -B fairmq_build -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=fairmq_install
|
||||
cmake --build fairmq_build
|
||||
cd fairmq_build; ctest -j4; cd ..
|
||||
cmake --build fairmq_build --target test
|
||||
cmake --build fairmq_build --target install
|
||||
```
|
||||
|
||||
@@ -54,39 +54,24 @@ If dependencies are not installed in standard system directories, you can hint t
|
||||
FairMQ ships as a CMake package, so in your `CMakeLists.txt` you can discover it like this:
|
||||
|
||||
```cmake
|
||||
find_package(FairMQ)
|
||||
find_package(FairCMakeModules 0.2 REQUIRED)
|
||||
include(FairFindPackage2)
|
||||
find_package2(FairMQ)
|
||||
find_package2_implicit_dependencies()
|
||||
```
|
||||
|
||||
The [`FairFindPackage2` module](https://fairrootgroup.github.io/FairCMakeModules/latest/module/FairFindPackage2.html) is part of the [`FairCMakeModules` package](https://fairrootgroup.github.io/FairCMakeModules).
|
||||
|
||||
If FairMQ is not installed in system directories, you can hint the installation:
|
||||
|
||||
```cmake
|
||||
set(CMAKE_PREFIX_PATH /path/to/FairMQ_install_prefix ${CMAKE_PREFIX_PATH})
|
||||
find_package(FairMQ)
|
||||
list(PREPEND CMAKE_PREFIX_PATH /path/to/fairmq_install)
|
||||
```
|
||||
|
||||
`find_package(FairMQ)` will define an imported target `FairMQ::FairMQ`.
|
||||
|
||||
In order to succesfully compile and link against the `FairMQ::FairMQ` target, you need to discover its public package dependencies:
|
||||
|
||||
```cmake
|
||||
find_package(FairMQ)
|
||||
if(FairMQ_FOUND)
|
||||
foreach(dep IN LISTS FairMQ_PACKAGE_DEPENDENCIES)
|
||||
if(FairMQ_${dep}_COMPONENTS)
|
||||
find_package(${dep} ${FairMQ_${dep}_VERSION} COMPONENTS ${FairMQ_${dep}_COMPONENTS})
|
||||
else()
|
||||
find_package(${dep} ${FairMQ_${dep}_VERSION})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
```
|
||||
|
||||
If your project shares a dependency with FairMQ or if you want to omit a certain dependency, you may want to customize the above example code to your needs.
|
||||
|
||||
Optionally, you can require certain FairMQ package components and a minimum version:
|
||||
|
||||
```cmake
|
||||
find_package(FairMQ 1.1.0 COMPONENTS dds_plugin)
|
||||
find_package(FairMQ 1.4.0 COMPONENTS dds_plugin)
|
||||
```
|
||||
|
||||
When building FairMQ, CMake will print a summary table of all available package components.
|
||||
@@ -99,6 +84,7 @@ When building FairMQ, CMake will print a summary table of all available package
|
||||
* [CMake](https://cmake.org/)
|
||||
* [DDS](http://dds.gsi.de)
|
||||
* [Doxygen](http://www.doxygen.org/)
|
||||
* [FairCMakeModules](https://github.com/FairRootGroup/FairCMakeModules) (optionally bundled)
|
||||
* [FairLogger](https://github.com/FairRootGroup/FairLogger)
|
||||
* [GTest](https://github.com/google/googletest) (optionally bundled)
|
||||
* [PMIx](https://pmix.org/)
|
||||
@@ -126,9 +112,8 @@ After the `find_package(FairMQ)` call the following CMake variables are defined:
|
||||
| Variable | Info |
|
||||
| --- | --- |
|
||||
| `${FairMQ_PACKAGE_DEPENDENCIES}` | the list of public package dependencies |
|
||||
| `${FairMQ_Boost_VERSION}` | the minimum Boost version FairMQ requires |
|
||||
| `${FairMQ_Boost_COMPONENTS}` | the list of Boost components FairMQ depends on |
|
||||
| `${FairMQ_FairLogger_VERSION}` | the minimum FairLogger version FairMQ requires |
|
||||
| `${FairMQ_<dep>_VERSION}` | the minimum `<dep>` version FairMQ requires |
|
||||
| `${FairMQ_<dep>_COMPONENTS}` | the list of `<dep>` components FairMQ depends on |
|
||||
| `${FairMQ_PACKAGE_COMPONENTS}` | the list of components FairMQ consists of |
|
||||
| `${FairMQ_#COMPONENT#_FOUND}` | `TRUE` if this component was built |
|
||||
| `${FairMQ_VERSION}` | the version in format `MAJOR.MINOR.PATCH` |
|
||||
@@ -139,9 +124,6 @@ After the `find_package(FairMQ)` call the following CMake variables are defined:
|
||||
| `${FairMQ_LIBDIR}` | the installation lib directory |
|
||||
| `${FairMQ_DATADIR}` | the installation data directory (`../share/fairmq`) |
|
||||
| `${FairMQ_CMAKEMODDIR}` | the installation directory of shipped CMake find modules |
|
||||
| `${FairMQ_CXX_STANDARD_REQUIRED}` | the value of `CMAKE_CXX_STANDARD_REQUIRED` at build-time |
|
||||
| `${FairMQ_CXX_STANDARD}` | the value of `CMAKE_CXX_STANDARD` at build-time |
|
||||
| `${FairMQ_CXX_EXTENSIONS}` | the values of `CMAKE_CXX_EXTENSIONS` at build-time |
|
||||
| `${FairMQ_BUILD_TYPE}` | the value of `CMAKE_BUILD_TYPE` at build-time |
|
||||
| `${FairMQ_CXX_FLAGS}` | the values of `CMAKE_CXX_FLAGS` and `CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}` at build-time |
|
||||
|
||||
@@ -165,6 +147,9 @@ After the `find_package(FairMQ)` call the following CMake variables are defined:
|
||||
3. [Introspection](docs/Configuration.md#33-introspection)
|
||||
4. [Development](docs/Development.md#4-development)
|
||||
1. [Testing](docs/Development.md#41-testing)
|
||||
2. [Static Analysis](docs/Development.md#42-static-analysis)
|
||||
1. [CMake Integration](docs/Development.md#421-cmake-integration)
|
||||
2. [Extra Compiler Arguments](docs/Development.md#422-extra-compiler-arguments)
|
||||
5. [Logging](docs/Logging.md#5-logging)
|
||||
1. [Log severity](docs/Logging.md#51-log-severity)
|
||||
2. [Log verbosity](docs/Logging.md#52-log-verbosity)
|
||||
|
19
cmake/FairCMakeModules.cmake
Normal file
19
cmake/FairCMakeModules.cmake
Normal file
@@ -0,0 +1,19 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(FairMQBundlePackageHelper)
|
||||
|
||||
set(PROJECT_FairCMakeModules_VERSION 0.2)
|
||||
find_package(FairCMakeModules ${PROJECT_FairCMakeModules_VERSION} QUIET)
|
||||
|
||||
if(NOT FairCMakeModules_FOUND AND NOT FairCMakeModules_BUNDLED)
|
||||
build_bundled(FairCMakeModules extern/FairCMakeModules)
|
||||
find_package(FairCMakeModules REQUIRED)
|
||||
endif()
|
50
cmake/FairMQBuildOption.cmake
Normal file
50
cmake/FairMQBuildOption.cmake
Normal file
@@ -0,0 +1,50 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(CMakeDependentOption)
|
||||
|
||||
macro(fairmq_build_option option description)
|
||||
cmake_parse_arguments(ARGS "" "DEFAULT" "REQUIRES" ${ARGN})
|
||||
|
||||
if(ARGS_DEFAULT)
|
||||
set(__default__ ON)
|
||||
else()
|
||||
set(__default__ OFF)
|
||||
endif()
|
||||
|
||||
if(ARGS_REQUIRES)
|
||||
set(__requires__ ${ARGS_REQUIRES})
|
||||
foreach(d ${__requires__})
|
||||
string(REGEX REPLACE " +" ";" __requires_condition__ "${d}")
|
||||
if(${__requires_condition__})
|
||||
else()
|
||||
if(${option})
|
||||
message(FATAL_ERROR "Cannot enable build option ${option}, depending option is not set: ${__requires_condition__}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
set(__requires__)
|
||||
endif()
|
||||
|
||||
if(__requires__)
|
||||
cmake_dependent_option(${option} ${description} ${__default__} "${__requires__}" OFF)
|
||||
else()
|
||||
option(${option} ${description} ${__default__})
|
||||
endif()
|
||||
|
||||
set(__default__)
|
||||
set(__requires__)
|
||||
set(__requires_condition__)
|
||||
set(ARGS_DEFAULT)
|
||||
set(ARGS_REQUIRES)
|
||||
set(option)
|
||||
set(description)
|
||||
endmacro()
|
92
cmake/FairMQBundlePackageHelper.cmake
Normal file
92
cmake/FairMQBundlePackageHelper.cmake
Normal file
@@ -0,0 +1,92 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
if(NOT DEFINED ${GIT_EXECUTABLE})
|
||||
find_program(GIT_EXECUTABLE NAMES git)
|
||||
endif()
|
||||
|
||||
# TODO Deduplicate code
|
||||
|
||||
macro(exec cmd)
|
||||
list(JOIN ARGN " " args)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ">>> ${cmd} ${args}\n")
|
||||
|
||||
execute_process(COMMAND ${cmd} ${ARGN}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
OUTPUT_VARIABLE log
|
||||
ERROR_VARIABLE log
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ${log})
|
||||
|
||||
if(res)
|
||||
message(FATAL_ERROR "${res} \nSee also \"${${package}_BUILD_LOGFILE}\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(exec_source cmd)
|
||||
list(JOIN ARGN " " args)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ">>> ${cmd} ${args}\n")
|
||||
|
||||
execute_process(COMMAND ${cmd} ${ARGN}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE log
|
||||
ERROR_VARIABLE log
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ${log})
|
||||
|
||||
if(res)
|
||||
message(FATAL_ERROR "${res} \nSee also \"${${package}_BUILD_LOGFILE}\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(build_bundled package bundle)
|
||||
message(STATUS "Building bundled ${package}")
|
||||
|
||||
set(${package}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${bundle})
|
||||
set(${package}_BINARY_DIR ${CMAKE_BINARY_DIR}/${bundle})
|
||||
file(MAKE_DIRECTORY ${${package}_BINARY_DIR})
|
||||
set(${package}_BUILD_LOGFILE ${${package}_BINARY_DIR}/build.log)
|
||||
file(REMOVE ${${package}_BUILD_LOGFILE})
|
||||
|
||||
if(GIT_EXECUTABLE)
|
||||
exec_source(${GIT_EXECUTABLE} submodule update --init -- ${${package}_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
if(${package} STREQUAL GTest)
|
||||
set(${package}_INSTALL_DIR ${CMAKE_BINARY_DIR}/${bundle}_install)
|
||||
file(MAKE_DIRECTORY ${${package}_INSTALL_DIR})
|
||||
set(${package}_PREFIX ${${package}_INSTALL_DIR})
|
||||
|
||||
exec(${CMAKE_COMMAND} -S ${${package}_SOURCE_DIR} -B ${${package}_BINARY_DIR} -G ${CMAKE_GENERATOR}
|
||||
-DCMAKE_INSTALL_PREFIX=${${package}_INSTALL_DIR} -DBUILD_GMOCK=OFF
|
||||
)
|
||||
exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR})
|
||||
exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR} --target install)
|
||||
elseif(${package} STREQUAL FairCMakeModules)
|
||||
set(${package}_INSTALL_DIR ${CMAKE_BINARY_DIR}/${bundle}_install)
|
||||
file(MAKE_DIRECTORY ${${package}_INSTALL_DIR})
|
||||
set(${package}_PREFIX ${${package}_INSTALL_DIR})
|
||||
|
||||
exec(${CMAKE_COMMAND} -S ${${package}_SOURCE_DIR} -B ${${package}_BINARY_DIR} -G ${CMAKE_GENERATOR}
|
||||
-DCMAKE_INSTALL_PREFIX=${${package}_INSTALL_DIR}
|
||||
)
|
||||
exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR})
|
||||
exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR} --target install)
|
||||
elseif(${package} STREQUAL PicoSHA2)
|
||||
set(${package}_PREFIX ${${package}_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
set(${package}_ROOT ${${package}_PREFIX} CACHE PATH "Location of bundle package ${package}")
|
||||
set(${package}_BUNDLED ON CACHE BOOL "Whether bundled ${package} was used")
|
||||
|
||||
message(STATUS "Building bundled ${package} - done")
|
||||
endfunction()
|
@@ -1,5 +1,5 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -20,9 +20,6 @@ set(@PROJECT_NAME@_LIBDIR @PACKAGE_CMAKE_INSTALL_PREFIX@/@PROJECT_INSTALL_LIBDIR
|
||||
set(@PROJECT_NAME@_DATADIR @PACKAGE_CMAKE_INSTALL_PREFIX@/@PROJECT_INSTALL_DATADIR@)
|
||||
set(@PROJECT_NAME@_CMAKEMODDIR @PACKAGE_CMAKE_INSTALL_PREFIX@/@PROJECT_INSTALL_CMAKEMODDIR@)
|
||||
|
||||
set(@PROJECT_NAME@_CXX_STANDARD_REQUIRED @CMAKE_CXX_STANDARD_REQUIRED@)
|
||||
set(@PROJECT_NAME@_CXX_STANDARD @CMAKE_CXX_STANDARD@)
|
||||
set(@PROJECT_NAME@_CXX_EXTENSIONS @CMAKE_CXX_EXTENSIONS@)
|
||||
set(@PROJECT_NAME@_VERSION_HOTFIX @PROJECT_VERSION_HOTFIX@)
|
||||
set(@PROJECT_NAME@_BUILD_TYPE @CMAKE_BUILD_TYPE@)
|
||||
set(@PROJECT_NAME@_BUILD_TYPE_UPPER @PROJECT_BUILD_TYPE_UPPER@)
|
||||
@@ -36,6 +33,4 @@ set(CMAKE_MODULE_PATH ${@PROJECT_NAME@_CMAKEMODDIR} ${CMAKE_MODULE_PATH})
|
||||
### Import targets
|
||||
include(@PACKAGE_CMAKE_INSTALL_PREFIX@/@PACKAGE_INSTALL_DESTINATION@/@PROJECT_EXPORT_SET@.cmake)
|
||||
|
||||
@BUNDLED_PACKAGES@
|
||||
|
||||
@PACKAGE_COMPONENTS@
|
||||
|
148
cmake/FairMQDependencies.cmake
Normal file
148
cmake/FairMQDependencies.cmake
Normal file
@@ -0,0 +1,148 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(FairCMakeModules)
|
||||
include(FairFindPackage2)
|
||||
include(FairMQBundlePackageHelper)
|
||||
|
||||
if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package2(PUBLIC Threads REQUIRED)
|
||||
set(Threads_PREFIX "<system>")
|
||||
endif()
|
||||
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
find_package2(PRIVATE asiofi REQUIRED VERSION 0.5)
|
||||
find_package2(PRIVATE OFI REQUIRED)
|
||||
endif()
|
||||
|
||||
if(BUILD_SDK_COMMANDS)
|
||||
find_package2(PRIVATE Flatbuffers REQUIRED)
|
||||
endif()
|
||||
|
||||
if(BUILD_DDS_PLUGIN OR BUILD_SDK)
|
||||
find_package2(PRIVATE DDS REQUIRED VERSION 3.5.13.7)
|
||||
set(DDS_Boost_COMPONENTS system log log_setup regex filesystem thread)
|
||||
set(DDS_Boost_VERSION 1.67)
|
||||
endif()
|
||||
|
||||
if(BUILD_PMIX_PLUGIN)
|
||||
find_package2(PRIVATE PMIx REQUIRED VERSION 2.1.4)
|
||||
endif()
|
||||
|
||||
if(BUILD_FAIRMQ OR BUILD_SDK OR BUILD_TIDY_TOOL)
|
||||
find_package2(PUBLIC FairLogger REQUIRED VERSION 1.6.0)
|
||||
find_package2(PUBLIC Boost REQUIRED VERSION 1.66
|
||||
COMPONENTS container program_options filesystem date_time regex
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_OFI_TRANSPORT OR BUILD_SDK OR BUILD_DDS_PLUGIN)
|
||||
set(__old ${CMAKE_FIND_PACKAGE_PREFER_CONFIG})
|
||||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
|
||||
find_package2(PUBLIC asio REQUIRED VERSION 1.18)
|
||||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${__old})
|
||||
unset(__old)
|
||||
endif()
|
||||
|
||||
if(BUILD_FAIRMQ)
|
||||
find_package2(PRIVATE ZeroMQ REQUIRED VERSION 4.1.4)
|
||||
if(NOT PicoSHA2_BUNDLED)
|
||||
build_bundled(PicoSHA2 extern/PicoSHA2)
|
||||
endif()
|
||||
find_package2(BUNDLED PicoSHA2 REQUIRED)
|
||||
set(PicoSHA2_VERSION "1.0.0")
|
||||
set(PicoSHA2_PREFIX "<bundled>")
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
if(NOT GTest_FOUND AND NOT GTest_BUNDLED AND NOT USE_EXTERNAL_GTEST)
|
||||
build_bundled(GTest extern/googletest)
|
||||
endif()
|
||||
find_package2(BUNDLED GTest REQUIRED)
|
||||
if(GTest_BUNDLED)
|
||||
set(GTest_VERSION "Apr 28 2021 @f5e592d8")
|
||||
set(GTest_PREFIX "<bundled>")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_DOCS)
|
||||
find_package2(PRIVATE Doxygen REQUIRED VERSION 1.8.8
|
||||
COMPONENTS dot
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_TIDY_TOOL)
|
||||
find_package2(PRIVATE LLVM REQUIRED)
|
||||
find_package2(PRIVATE Clang REQUIRED)
|
||||
set(Clang_VERSION ${LLVM_VERSION})
|
||||
find_package2(PRIVATE CLI11 REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package2_implicit_dependencies() # Always call last after latest find_package2
|
||||
|
||||
if(PROJECT_PACKAGE_DEPENDENCIES)
|
||||
foreach(dep IN LISTS PROJECT_PACKAGE_DEPENDENCIES)
|
||||
string(TOUPPER ${dep} dep_upper)
|
||||
if(${dep}_BUNDLED)
|
||||
set(${dep}_PREFIX "<bundled>")
|
||||
elseif(${dep} STREQUAL FairLogger)
|
||||
if(NOT FairLogger_PREFIX AND FairLogger_ROOT)
|
||||
set(FairLogger_PREFIX ${FairLogger_ROOT})
|
||||
endif()
|
||||
elseif(${dep} STREQUAL asiofi)
|
||||
if(NOT asiofi_PREFIX AND asiofi_ROOT)
|
||||
set(asiofi_PREFIX ${asiofi_ROOT})
|
||||
endif()
|
||||
elseif(${dep} STREQUAL DDS)
|
||||
set(DDS_PREFIX "${DDS_INSTALL_PREFIX}")
|
||||
elseif(${dep} STREQUAL Boost)
|
||||
if(TARGET Boost::headers)
|
||||
get_target_property(boost_include Boost::headers INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
get_target_property(boost_include Boost::boost INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif()
|
||||
get_filename_component(Boost_PREFIX ${boost_include}/.. ABSOLUTE)
|
||||
unset(boost_include)
|
||||
elseif(${dep} STREQUAL Doxygen)
|
||||
get_target_property(doxygen_bin Doxygen::doxygen INTERFACE_LOCATION)
|
||||
get_filename_component(Doxygen_PREFIX ${doxygen_bin} DIRECTORY)
|
||||
get_filename_component(Doxygen_PREFIX ${Doxygen_PREFIX}/.. ABSOLUTE)
|
||||
unset(doxygen_bin)
|
||||
elseif(${dep} STREQUAL Flatbuffers)
|
||||
if(TARGET flatbuffers::flatbuffers)
|
||||
get_target_property(flatbuffers_include flatbuffers::flatbuffers INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
get_target_property(flatbuffers_include flatbuffers::flatbuffers_shared INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif()
|
||||
get_filename_component(Flatbuffers_PREFIX ${flatbuffers_include}/.. ABSOLUTE)
|
||||
unset(flatbuffers_include)
|
||||
elseif(NOT ${dep}_PREFIX)
|
||||
# try to guess
|
||||
if(TARGET ${dep}::${dep})
|
||||
get_target_property(${dep}_include ${dep}::${dep} INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_filename_component(${dep}_PREFIX ${${dep}_include}/.. ABSOLUTE)
|
||||
unset(${dep}_include)
|
||||
elseif(${dep}_INCLUDE_DIR)
|
||||
get_filename_component(${dep}_PREFIX ${${dep}_INCLUDE_DIR}/.. ABSOLUTE)
|
||||
elseif(${dep_upper}_INCLUDE_DIR)
|
||||
get_filename_component(${dep}_PREFIX ${${dep_upper}_INCLUDE_DIR}/.. ABSOLUTE)
|
||||
elseif(${dep}_INCLUDE_DIRS)
|
||||
list(GET ${dep}_INCLUDE_DIRS 0 ${dep}_include)
|
||||
get_filename_component(${dep}_PREFIX ${${dep}_include}/.. ABSOLUTE)
|
||||
unset(${dep}_include)
|
||||
elseif(${dep_upper}_INCLUDE_DIRS)
|
||||
list(GET ${dep_upper}_INCLUDE_DIRS 0 ${dep}_include)
|
||||
get_filename_component(${dep}_PREFIX ${${dep}_include}/.. ABSOLUTE)
|
||||
unset(${dep}_include)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
@@ -1,557 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
### PUBLIC
|
||||
|
||||
# Defines some variables with console color escape sequences
|
||||
if(NOT WIN32 AND NOT DISABLE_COLOR)
|
||||
string(ASCII 27 Esc)
|
||||
set(CR "${Esc}[m")
|
||||
set(CB "${Esc}[1m")
|
||||
set(Red "${Esc}[31m")
|
||||
set(Green "${Esc}[32m")
|
||||
set(Yellow "${Esc}[33m")
|
||||
set(Blue "${Esc}[34m")
|
||||
set(Magenta "${Esc}[35m")
|
||||
set(Cyan "${Esc}[36m")
|
||||
set(White "${Esc}[37m")
|
||||
set(BRed "${Esc}[1;31m")
|
||||
set(BGreen "${Esc}[1;32m")
|
||||
set(BYellow "${Esc}[1;33m")
|
||||
set(BBlue "${Esc}[1;34m")
|
||||
set(BMagenta "${Esc}[1;35m")
|
||||
set(BCyan "${Esc}[1;36m")
|
||||
set(BWhite "${Esc}[1;37m")
|
||||
endif()
|
||||
|
||||
find_package(Git)
|
||||
# get_git_version([DEFAULT_VERSION version] [DEFAULT_DATE date] [OUTVAR_PREFIX prefix])
|
||||
#
|
||||
# Sets variables #prefix#_VERSION, #prefix#_GIT_VERSION, #prefix#_DATE, #prefix#_GIT_DATE
|
||||
function(get_git_version)
|
||||
cmake_parse_arguments(ARGS "" "DEFAULT_VERSION;DEFAULT_DATE;OUTVAR_PREFIX" "" ${ARGN})
|
||||
|
||||
if(NOT ARGS_OUTVAR_PREFIX)
|
||||
set(ARGS_OUTVAR_PREFIX PROJECT)
|
||||
endif()
|
||||
|
||||
if(GIT_FOUND AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
|
||||
OUTPUT_VARIABLE ${ARGS_OUTVAR_PREFIX}_GIT_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
if(${ARGS_OUTVAR_PREFIX}_GIT_VERSION)
|
||||
# cut first two characters "v-"
|
||||
string(SUBSTRING ${${ARGS_OUTVAR_PREFIX}_GIT_VERSION} 1 -1 ${ARGS_OUTVAR_PREFIX}_GIT_VERSION)
|
||||
endif()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%cd
|
||||
OUTPUT_VARIABLE ${ARGS_OUTVAR_PREFIX}_GIT_DATE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT ${ARGS_OUTVAR_PREFIX}_GIT_VERSION)
|
||||
if(ARGS_DEFAULT_VERSION)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_VERSION ${ARGS_DEFAULT_VERSION})
|
||||
else()
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_VERSION 0.0.0.0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT ${ARGS_OUTVAR_PREFIX}_GIT_DATE)
|
||||
if(ARGS_DEFAULT_DATE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_DATE ${ARGS_DEFAULT_DATE})
|
||||
else()
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_DATE "Thu Jan 1 00:00:00 1970 +0000")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "^([^-]*)" blubb ${${ARGS_OUTVAR_PREFIX}_GIT_VERSION})
|
||||
|
||||
# return values
|
||||
set(${ARGS_OUTVAR_PREFIX}_VERSION ${CMAKE_MATCH_0} PARENT_SCOPE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_DATE ${${ARGS_OUTVAR_PREFIX}_GIT_DATE} PARENT_SCOPE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_VERSION ${${ARGS_OUTVAR_PREFIX}_GIT_VERSION} PARENT_SCOPE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_DATE ${${ARGS_OUTVAR_PREFIX}_GIT_DATE} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
|
||||
# Set defaults
|
||||
macro(set_fairmq_defaults)
|
||||
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
|
||||
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
|
||||
|
||||
# Set a default build type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo)
|
||||
endif()
|
||||
|
||||
# Handle C++ standard level
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD ${PROJECT_MIN_CXX_STANDARD})
|
||||
elseif(${CMAKE_CXX_STANDARD} LESS ${PROJECT_MIN_CXX_STANDARD})
|
||||
message(FATAL_ERROR "A minimum CMAKE_CXX_STANDARD of ${PROJECT_MIN_CXX_STANDARD} is required.")
|
||||
endif()
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "Whether to build shared libraries or static archives")
|
||||
endif()
|
||||
|
||||
# Set -fPIC as default for all library types
|
||||
if(NOT CMAKE_POSITION_INDEPENDENT_CODE)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
# Generate compile_commands.json file (https://clang.llvm.org/docs/JSONCompilationDatabase.html)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# Define CMAKE_INSTALL_*DIR family of variables
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Define install dirs
|
||||
set(PROJECT_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
|
||||
set(PROJECT_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
||||
set(PROJECT_INSTALL_INCDIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME_LOWER})
|
||||
set(PROJECT_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME_LOWER})
|
||||
set(PROJECT_INSTALL_CMAKEMODDIR ${PROJECT_INSTALL_DATADIR}/cmake)
|
||||
|
||||
# https://cmake.org/Wiki/CMake_RPATH_handling
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_LIBDIR}" isSystemDir)
|
||||
if("${isSystemDir}" STREQUAL "-1")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-Wl,--enable-new-dtags")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--enable-new-dtags")
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${PROJECT_INSTALL_LIBDIR}")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
set(CMAKE_INSTALL_RPATH "@loader_path/../${PROJECT_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Define export set, only one for now
|
||||
set(PROJECT_EXPORT_SET ${PROJECT_NAME}Targets)
|
||||
|
||||
# Configure build types
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "RelWithDebInfo" "Nightly" "Profile" "Experimental" "AddressSan" "ThreadSan")
|
||||
set(_warnings "-Wshadow -Wall -Wextra -Wpedantic")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g ${_warnings}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g ${_warnings} -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_NIGHTLY "-O2 -g ${_warnings}")
|
||||
set(CMAKE_CXX_FLAGS_PROFILE "-g3 ${_warnings} -fno-inline -ftest-coverage -fprofile-arcs")
|
||||
set(CMAKE_CXX_FLAGS_EXPERIMENTAL "-O2 -g ${_warnings} -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_ADDRESSSAN "-O2 -g ${_warnings} -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_THREADSAN "-O2 -g ${_warnings} -fsanitize=thread")
|
||||
unset(_warnings)
|
||||
|
||||
if(CMAKE_GENERATOR STREQUAL "Ninja" AND
|
||||
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR
|
||||
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)))
|
||||
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
|
||||
# Rationale in https://github.com/ninja-build/ninja/issues/814
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
||||
endif()
|
||||
|
||||
if(NOT PROJECT_VERSION_TWEAK)
|
||||
set(PROJECT_VERSION_HOTFIX 0)
|
||||
else()
|
||||
set(PROJECT_VERSION_HOTFIX ${PROJECT_VERSION_TWEAK})
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED RUN_STATIC_ANALYSIS)
|
||||
set(RUN_STATIC_ANALYSIS OFF)
|
||||
endif()
|
||||
|
||||
unset(PROJECT_STATIC_ANALYSERS)
|
||||
if(RUN_STATIC_ANALYSIS)
|
||||
set(analyser "clang-tidy")
|
||||
find_program(${analyser}_FOUND "${analyser}")
|
||||
if(${analyser}_FOUND)
|
||||
set(CMAKE_CXX_CLANG_TIDY "${${analyser}_FOUND}")
|
||||
endif()
|
||||
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
|
||||
|
||||
set(analyser "iwyu")
|
||||
find_program(${analyser}_FOUND "${analyser}")
|
||||
if(${analyser}_FOUND)
|
||||
set(CMAKE_CXX_IWYU "${${analyser}_FOUND}")
|
||||
endif()
|
||||
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
|
||||
|
||||
set(analyser "cpplint")
|
||||
find_program(${analyser}_FOUND "${analyser}")
|
||||
if(${analyser}_FOUND)
|
||||
set(CMAKE_CXX_CPPLINT "${${analyser}_FOUND}")
|
||||
endif()
|
||||
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
|
||||
endif()
|
||||
|
||||
if(CMAKE_GENERATOR STREQUAL Ninja AND ENABLE_CCACHE)
|
||||
find_program(CCACHE ccache)
|
||||
if(CCACHE)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
||||
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
|
||||
set(FAIRMQ_HAS_STD_FILESYSTEM 0)
|
||||
else()
|
||||
set(FAIRMQ_HAS_STD_FILESYSTEM 1)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(join VALUES GLUE OUTPUT)
|
||||
string(REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
|
||||
string(REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
|
||||
set(${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(pad str width char out)
|
||||
cmake_parse_arguments(ARGS "" "COLOR" "" ${ARGN})
|
||||
string(LENGTH ${str} length)
|
||||
if(ARGS_COLOR)
|
||||
math(EXPR padding "${width}-(${length}-10*${ARGS_COLOR})")
|
||||
else()
|
||||
math(EXPR padding "${width}-${length}")
|
||||
endif()
|
||||
if(padding GREATER 0)
|
||||
foreach(i RANGE ${padding})
|
||||
set(str "${str}${char}")
|
||||
endforeach()
|
||||
endif()
|
||||
set(${out} ${str} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(generate_package_dependencies)
|
||||
join("${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES}" " " DEPS)
|
||||
set(PACKAGE_DEPENDENCIES "\
|
||||
####### Expanded from @PACKAGE_DEPENDENCIES@ by configure_package_config_file() #######
|
||||
|
||||
set(${PROJECT_NAME}_PACKAGE_DEPENDENCIES ${DEPS})
|
||||
|
||||
")
|
||||
foreach(dep IN LISTS PROJECT_INTERFACE_PACKAGE_DEPENDENCIES)
|
||||
join("${PROJECT_INTERFACE_${dep}_COMPONENTS}" " " COMPS)
|
||||
if(COMPS)
|
||||
string(CONCAT PACKAGE_DEPENDENCIES ${PACKAGE_DEPENDENCIES} "\
|
||||
set(${PROJECT_NAME}_${dep}_COMPONENTS ${COMPS})
|
||||
")
|
||||
endif()
|
||||
if(PROJECT_INTERFACE_${dep}_VERSION)
|
||||
string(CONCAT PACKAGE_DEPENDENCIES ${PACKAGE_DEPENDENCIES} "\
|
||||
set(${PROJECT_NAME}_${dep}_VERSION ${PROJECT_INTERFACE_${dep}_VERSION})
|
||||
")
|
||||
endif()
|
||||
endforeach()
|
||||
string(CONCAT PACKAGE_DEPENDENCIES ${PACKAGE_DEPENDENCIES} "\
|
||||
|
||||
#######################################################################################
|
||||
")
|
||||
set(PACKAGE_DEPENDENCIES ${PACKAGE_DEPENDENCIES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(generate_package_components)
|
||||
join("${PROJECT_PACKAGE_COMPONENTS}" " " COMPS)
|
||||
set(PACKAGE_COMPONENTS "\
|
||||
####### Expanded from @PACKAGE_COMPONENTS@ by configure_package_config_file() #########
|
||||
|
||||
set(${PROJECT_NAME}_PACKAGE_COMPONENTS ${COMPS})
|
||||
|
||||
")
|
||||
foreach(comp IN LISTS PROJECT_PACKAGE_COMPONENTS)
|
||||
string(CONCAT PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} "\
|
||||
set(${PROJECT_NAME}_${comp}_FOUND TRUE)
|
||||
")
|
||||
endforeach()
|
||||
string(CONCAT PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} "\
|
||||
|
||||
check_required_components(${PROJECT_NAME})
|
||||
")
|
||||
set(PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(generate_bundled_packages)
|
||||
if(asio_BUNDLED)
|
||||
set(BUNDLED_PACKAGES "\
|
||||
####### Expanded from @BUNDLED_PACKAGES@ by configure_package_config_file() #########
|
||||
|
||||
if(\"\${CMAKE_MAJOR_VERSION}.\${CMAKE_MINOR_VERSION}\" VERSION_LESS 3.11)
|
||||
message(FATAL_ERROR \"CMake >= 3.11 required\")
|
||||
endif()
|
||||
set_target_properties(${PROJECT_NAME}::bundled_asio_headers PROPERTIES IMPORTED_GLOBAL TRUE)
|
||||
add_library(asio::headers ALIAS ${PROJECT_NAME}::bundled_asio_headers)
|
||||
set(asio_VERSION ${asio_VERSION})
|
||||
|
||||
")
|
||||
endif()
|
||||
set(BUNDLED_PACKAGES ${BUNDLED_PACKAGES} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Configure/Install CMake package
|
||||
macro(install_cmake_package)
|
||||
list(SORT PROJECT_PACKAGE_DEPENDENCIES)
|
||||
list(SORT PROJECT_INTERFACE_PACKAGE_DEPENDENCIES)
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(PACKAGE_INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||
)
|
||||
if(BUILD_FAIRMQ)
|
||||
install(EXPORT ${PROJECT_EXPORT_SET}
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${PACKAGE_INSTALL_DESTINATION}
|
||||
EXPORT_LINK_INTERFACE_LIBRARIES
|
||||
)
|
||||
endif()
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
generate_package_dependencies() # fills ${PACKAGE_DEPENDENCIES}
|
||||
generate_package_components() # fills ${PACKAGE_COMPONENTS}
|
||||
generate_bundled_packages() # fills ${BUNDLED_PACKAGES}
|
||||
string(TOUPPER ${CMAKE_BUILD_TYPE} PROJECT_BUILD_TYPE_UPPER)
|
||||
set(PROJECT_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${PROJECT_BUILD_TYPE_UPPER}})
|
||||
configure_package_config_file(
|
||||
${CMAKE_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${PACKAGE_INSTALL_DESTINATION}
|
||||
PATH_VARS CMAKE_INSTALL_PREFIX
|
||||
)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION ${PACKAGE_INSTALL_DESTINATION}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# find_package2(PRIVATE|PUBLIC|INTERFACE <pkgname>
|
||||
# [VERSION <version>]
|
||||
# [COMPONENTS <list of components>]
|
||||
# [ADD_REQUIREMENTS_OF <list of dep_pgkname>]
|
||||
# [any other option the native find_package supports]...)
|
||||
#
|
||||
# Wrapper around CMake's native find_package command to add some features and bookkeeping.
|
||||
#
|
||||
# The qualifier (PRIVATE|PUBLIC|INTERFACE|BUNDLED) to the package to populate
|
||||
# the variables PROJECT_[INTERFACE]_<pkgname>_([VERSION]|[COMPONENTS]|PACKAGE_DEPENDENCIES)
|
||||
# accordingly. This bookkeeping information is used to print our dependency found summary
|
||||
# table and to generate a part of our CMake package. BUNDLED decays to PUBLIC if the variable
|
||||
# <pkgname>_BUNDLED is false and to PRIVATE otherwise.
|
||||
#
|
||||
# When a dependending package is listed with ADD_REQUIREMENTS_OF the variables
|
||||
# <dep_pkgname>_<pkgname>_VERSION|COMPONENTS are looked up to and added to the native
|
||||
# VERSION (selected highest version) and COMPONENTS (deduplicated) args.
|
||||
#
|
||||
# COMPONENTS and VERSION args are then just passed to the native find_package.
|
||||
#
|
||||
macro(find_package2 qualifier pkgname)
|
||||
cmake_parse_arguments(ARGS "" "VERSION" "COMPONENTS;ADD_REQUIREMENTS_OF" ${ARGN})
|
||||
|
||||
string(TOUPPER ${pkgname} pkgname_upper)
|
||||
set(__old_cpp__ ${CMAKE_PREFIX_PATH})
|
||||
set(CMAKE_PREFIX_PATH ${${pkgname_upper}_ROOT} $ENV{${pkgname_upper}_ROOT} ${CMAKE_PREFIX_PATH})
|
||||
|
||||
# build lists of required versions and components
|
||||
unset(__required_versions__)
|
||||
unset(__components__)
|
||||
if(ARGS_VERSION)
|
||||
list(APPEND __required_versions__ ${ARGS_VERSION})
|
||||
endif()
|
||||
if(ARGS_COMPONENTS)
|
||||
list(APPEND __components__ ${ARGS_COMPONENTS})
|
||||
endif()
|
||||
if(ARGS_ADD_REQUIREMENTS_OF)
|
||||
foreach(dep_pkgname IN LISTS ARGS_ADD_REQUIREMENTS_OF)
|
||||
if(${dep_pkgname}_${pkgname}_VERSION)
|
||||
list(APPEND __required_versions__ ${${dep_pkgname}_${pkgname}_VERSION})
|
||||
endif()
|
||||
if(${dep_pkgname}_${pkgname}_COMPONENTS)
|
||||
list(APPEND __components__ ${${dep_pkgname}_${pkgname}_COMPONENTS})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# select highest required version
|
||||
unset(__version__)
|
||||
if(__required_versions__)
|
||||
list(GET __required_versions__ 0 __version__)
|
||||
foreach(v IN LISTS __required_versions__)
|
||||
if(${v} VERSION_GREATER ${__version__})
|
||||
set(__version__ ${v})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
# deduplicate required component list
|
||||
if(__components__)
|
||||
list(REMOVE_DUPLICATES __components__)
|
||||
endif()
|
||||
|
||||
# call native find_package
|
||||
if(__components__)
|
||||
find_package(${pkgname} ${__version__} QUIET COMPONENTS ${__components__} ${ARGS_UNPARSED_ARGUMENTS})
|
||||
else()
|
||||
find_package(${pkgname} ${__version__} QUIET ${ARGS_UNPARSED_ARGUMENTS})
|
||||
endif()
|
||||
|
||||
if(${qualifier} STREQUAL BUNDLED)
|
||||
if(${pkgname}_BUNDLED)
|
||||
set(__qualifier__ PRIVATE)
|
||||
else()
|
||||
set(__qualifier__ PUBLIC)
|
||||
endif()
|
||||
else()
|
||||
set(__qualifier__ ${qualifier})
|
||||
endif()
|
||||
|
||||
if(${pkgname}_FOUND)
|
||||
if(${__qualifier__} STREQUAL PRIVATE)
|
||||
set(PROJECT_${pkgname}_VERSION ${__version__})
|
||||
set(PROJECT_${pkgname}_COMPONENTS ${__components__})
|
||||
set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname})
|
||||
elseif(${__qualifier__} STREQUAL PUBLIC)
|
||||
set(PROJECT_${pkgname}_VERSION ${__version__})
|
||||
set(PROJECT_${pkgname}_COMPONENTS ${__components__})
|
||||
set(PROJECT_PACKAGE_DEPENDENCIES ${PROJECT_PACKAGE_DEPENDENCIES} ${pkgname})
|
||||
set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__})
|
||||
set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__})
|
||||
set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname})
|
||||
elseif(${__qualifier__} STREQUAL INTERFACE)
|
||||
set(PROJECT_INTERFACE_${pkgname}_VERSION ${__version__})
|
||||
set(PROJECT_INTERFACE_${pkgname}_COMPONENTS ${__components__})
|
||||
set(PROJECT_INTERFACE_PACKAGE_DEPENDENCIES ${PROJECT_INTERFACE_PACKAGE_DEPENDENCIES} ${pkgname})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
unset(__qualifier__)
|
||||
unset(__version__)
|
||||
unset(__components__)
|
||||
unset(__required_versions__)
|
||||
set(CMAKE_PREFIX_PATH ${__old_cpp__})
|
||||
unset(__old_cpp__)
|
||||
endmacro()
|
||||
|
||||
macro(exec cmd)
|
||||
join("${ARGN}" " " args)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ">>> ${cmd} ${args}\n")
|
||||
|
||||
execute_process(COMMAND ${cmd} ${ARGN}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
OUTPUT_VARIABLE log
|
||||
ERROR_VARIABLE log
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ${log})
|
||||
|
||||
if(res)
|
||||
message(FATAL_ERROR "${res} \nSee also \"${${package}_BUILD_LOGFILE}\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(exec_source cmd)
|
||||
join("${ARGN}" " " args)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ">>> ${cmd} ${args}\n")
|
||||
|
||||
execute_process(COMMAND ${cmd} ${ARGN}
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE log
|
||||
ERROR_VARIABLE log
|
||||
RESULT_VARIABLE res
|
||||
)
|
||||
file(APPEND ${${package}_BUILD_LOGFILE} ${log})
|
||||
|
||||
if(res)
|
||||
message(FATAL_ERROR "${res} \nSee also \"${${package}_BUILD_LOGFILE}\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(build_bundled package bundle)
|
||||
message(STATUS "Building bundled ${package}")
|
||||
|
||||
set(${package}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${bundle})
|
||||
set(${package}_BINARY_DIR ${CMAKE_BINARY_DIR}/${bundle})
|
||||
file(MAKE_DIRECTORY ${${package}_BINARY_DIR})
|
||||
set(${package}_BUILD_LOGFILE ${${package}_BINARY_DIR}/build.log)
|
||||
file(REMOVE ${${package}_BUILD_LOGFILE})
|
||||
|
||||
if(Git_FOUND)
|
||||
exec_source(${GIT_EXECUTABLE} submodule update --init -- ${${package}_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
if(${package} STREQUAL GTest)
|
||||
set(${package}_INSTALL_DIR ${CMAKE_BINARY_DIR}/${bundle}_install)
|
||||
file(MAKE_DIRECTORY ${${package}_INSTALL_DIR})
|
||||
set(${package}_ROOT ${${package}_INSTALL_DIR})
|
||||
|
||||
exec(${CMAKE_COMMAND} -S ${${package}_SOURCE_DIR} -B ${${package}_BINARY_DIR} -G ${CMAKE_GENERATOR}
|
||||
-DCMAKE_INSTALL_PREFIX=${${package}_INSTALL_DIR} -DBUILD_GMOCK=OFF
|
||||
)
|
||||
exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR})
|
||||
exec(${CMAKE_COMMAND} --build ${${package}_BINARY_DIR} --target install)
|
||||
elseif(${package} STREQUAL asio)
|
||||
set(${package}_BUILD_INCLUDE_DIR ${${package}_SOURCE_DIR}/asio/include CACHE PATH "Bundled ${package} build-interface include dir")
|
||||
set(${package}_INSTALL_INCLUDE_DIR ${PROJECT_INSTALL_INCDIR}/bundled CACHE PATH "Bundled ${package} install-interface include dir")
|
||||
set(${package}_ROOT ${${package}_SOURCE_DIR}/asio)
|
||||
elseif(${package} STREQUAL PicoSHA2)
|
||||
set(${package}_ROOT ${${package}_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
string(TOUPPER ${package} package_upper)
|
||||
set(${package_upper}_ROOT "${${package}_ROOT}" CACHE PATH "Bundled ${package} install prefix search hint")
|
||||
set(${package}_BUNDLED ON CACHE BOOL "Whether bundled ${package} was used")
|
||||
|
||||
message(STATUS "Building bundled ${package} - done")
|
||||
endfunction()
|
||||
|
||||
macro(fairmq_build_option option description)
|
||||
cmake_parse_arguments(ARGS "" "DEFAULT" "REQUIRES" ${ARGN})
|
||||
|
||||
if(ARGS_DEFAULT)
|
||||
set(__default__ ON)
|
||||
else()
|
||||
set(__default__ OFF)
|
||||
endif()
|
||||
|
||||
if(ARGS_REQUIRES)
|
||||
include(CMakeDependentOption)
|
||||
set(__requires__ ${ARGS_REQUIRES})
|
||||
foreach(d ${__requires__})
|
||||
string(REGEX REPLACE " +" ";" __requires_condition__ "${d}")
|
||||
if(${__requires_condition__})
|
||||
else()
|
||||
if(${option})
|
||||
message(FATAL_ERROR "Cannot enable build option ${option}, depending option is not set: ${__requires_condition__}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
set(__requires__)
|
||||
endif()
|
||||
|
||||
if(__requires__)
|
||||
cmake_dependent_option(${option} ${description} ${__default__} "${__requires__}" OFF)
|
||||
else()
|
||||
option(${option} ${description} ${__default__})
|
||||
endif()
|
||||
|
||||
set(__default__)
|
||||
set(__requires__)
|
||||
set(__requires_condition__)
|
||||
set(ARGS_DEFAULT)
|
||||
set(ARGS_REQUIRES)
|
||||
set(option)
|
||||
set(description)
|
||||
endmacro()
|
70
cmake/FairMQPackage.cmake
Normal file
70
cmake/FairMQPackage.cmake
Normal file
@@ -0,0 +1,70 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(FairCMakeModules)
|
||||
include(FairFindPackage2)
|
||||
include(FairMQBundlePackageHelper)
|
||||
|
||||
function(generate_package_components)
|
||||
list(JOIN PROJECT_PACKAGE_COMPONENTS} " " COMPS)
|
||||
set(PACKAGE_COMPONENTS "\
|
||||
####### Expanded from @PACKAGE_COMPONENTS@ by configure_package_config_file() #########
|
||||
|
||||
set(${PROJECT_NAME}_PACKAGE_COMPONENTS ${COMPS})
|
||||
|
||||
")
|
||||
foreach(comp IN LISTS PROJECT_PACKAGE_COMPONENTS)
|
||||
string(CONCAT PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} "\
|
||||
set(${PROJECT_NAME}_${comp}_FOUND TRUE)
|
||||
")
|
||||
endforeach()
|
||||
string(CONCAT PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} "\
|
||||
|
||||
check_required_components(${PROJECT_NAME})
|
||||
")
|
||||
set(PACKAGE_COMPONENTS ${PACKAGE_COMPONENTS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Configure/Install CMake package
|
||||
macro(install_cmake_package)
|
||||
list(SORT PROJECT_PACKAGE_DEPENDENCIES)
|
||||
list(SORT PROJECT_INTERFACE_PACKAGE_DEPENDENCIES)
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(PACKAGE_INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||
)
|
||||
if(BUILD_FAIRMQ)
|
||||
install(EXPORT ${PROJECT_EXPORT_SET}
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${PACKAGE_INSTALL_DESTINATION}
|
||||
EXPORT_LINK_INTERFACE_LIBRARIES
|
||||
)
|
||||
endif()
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
fair_generate_package_dependencies() # fills ${PACKAGE_DEPENDENCIES}
|
||||
generate_package_components() # fills ${PACKAGE_COMPONENTS}
|
||||
string(TOUPPER ${CMAKE_BUILD_TYPE} PROJECT_BUILD_TYPE_UPPER)
|
||||
set(PROJECT_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${PROJECT_BUILD_TYPE_UPPER}})
|
||||
configure_package_config_file(
|
||||
${CMAKE_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${PACKAGE_INSTALL_DESTINATION}
|
||||
PATH_VARS CMAKE_INSTALL_PREFIX
|
||||
)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
||||
DESTINATION ${PACKAGE_INSTALL_DESTINATION}
|
||||
)
|
||||
endmacro()
|
176
cmake/FairMQProjectSettings.cmake
Normal file
176
cmake/FairMQProjectSettings.cmake
Normal file
@@ -0,0 +1,176 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
|
||||
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
|
||||
|
||||
# Set a default build type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo)
|
||||
endif()
|
||||
|
||||
set(PROJECT_MIN_CXX_STANDARD 17)
|
||||
|
||||
# Handle C++ standard level
|
||||
if(CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD VERSION_LESS PROJECT_MIN_CXX_STANDARD)
|
||||
message(FATAL_ERROR "A minimum CMAKE_CXX_STANDARD of ${PROJECT_MIN_CXX_STANDARD} is required.")
|
||||
endif()
|
||||
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "Whether to build shared libraries or static archives")
|
||||
endif()
|
||||
|
||||
# Set -fPIC as default for all library types
|
||||
if(NOT CMAKE_POSITION_INDEPENDENT_CODE)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
# Generate compile_commands.json file (https://clang.llvm.org/docs/JSONCompilationDatabase.html)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
|
||||
|
||||
# Define install dirs
|
||||
set(PROJECT_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
|
||||
set(PROJECT_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
|
||||
set(PROJECT_INSTALL_INCDIR ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME_LOWER})
|
||||
set(PROJECT_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME_LOWER})
|
||||
set(PROJECT_INSTALL_CMAKEMODDIR ${PROJECT_INSTALL_DATADIR}/cmake)
|
||||
|
||||
# https://cmake.org/Wiki/CMake_RPATH_handling
|
||||
if(NOT DEFINED CMAKE_INSTALL_RPATH_USE_LINK_PATH)
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
|
||||
endif()
|
||||
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_LIBDIR}" isSystemDir)
|
||||
if("${isSystemDir}" STREQUAL "-1")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
list(APPEND CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
|
||||
list(APPEND CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-new-dtags")
|
||||
list(PREPEND CMAKE_INSTALL_RPATH "$ORIGIN/../${PROJECT_INSTALL_LIBDIR}")
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
list(PREPEND CMAKE_INSTALL_RPATH "@loader_path/../${PROJECT_INSTALL_LIBDIR}")
|
||||
else()
|
||||
list(PREPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Define export set, only one for now
|
||||
set(PROJECT_EXPORT_SET ${PROJECT_NAME}Targets)
|
||||
|
||||
# Sanitizers
|
||||
set(_sanitizers "")
|
||||
|
||||
option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" FALSE)
|
||||
if(ENABLE_SANITIZER_ADDRESS)
|
||||
list(APPEND _sanitizers "address")
|
||||
endif()
|
||||
|
||||
option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" FALSE)
|
||||
if(ENABLE_SANITIZER_LEAK)
|
||||
list(APPEND _sanitizers "leak")
|
||||
endif()
|
||||
|
||||
option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" FALSE)
|
||||
if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR)
|
||||
list(APPEND _sanitizers "undefined")
|
||||
endif()
|
||||
|
||||
option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" FALSE)
|
||||
if(ENABLE_SANITIZER_THREAD)
|
||||
if("address" IN_LIST _sanitizers OR "leak" IN_LIST _sanitizers)
|
||||
message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled")
|
||||
else()
|
||||
list(APPEND _sanitizers "thread")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" FALSE)
|
||||
if(ENABLE_SANITIZER_MEMORY AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||
if("address" IN_LIST _sanitizers
|
||||
OR "thread" IN_LIST _sanitizers
|
||||
OR "leak" IN_LIST _sanitizers)
|
||||
message(WARNING "Memory sanitizer does not work with Address, Thread and Leak sanitizer enabled")
|
||||
else()
|
||||
list(APPEND _sanitizers "memory")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
list(JOIN _sanitizers "," _sanitizers)
|
||||
if(_sanitizers)
|
||||
set(_sanitizers "-fsanitize=${_sanitizers}")
|
||||
endif()
|
||||
|
||||
# Configure build types
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "RelWithDebInfo")
|
||||
set(_warnings "-Wshadow -Wall -Wextra -Wpedantic")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g ${_warnings} ${_sanitizers}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g ${_warnings} -DNDEBUG ${_sanitizers}")
|
||||
unset(_warnings)
|
||||
unset(_sanitizers)
|
||||
|
||||
if(DISABLE_COLOR)
|
||||
set(CMAKE_COLOR_MAKEFILE OFF)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=never")
|
||||
else()
|
||||
set(CMAKE_COLOR_MAKEFILE ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED PROJECT_VERSION_TWEAK)
|
||||
set(PROJECT_VERSION_HOTFIX 0)
|
||||
else()
|
||||
set(PROJECT_VERSION_HOTFIX ${PROJECT_VERSION_TWEAK})
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED RUN_STATIC_ANALYSIS)
|
||||
set(RUN_STATIC_ANALYSIS OFF)
|
||||
endif()
|
||||
|
||||
unset(PROJECT_STATIC_ANALYSERS)
|
||||
if(RUN_STATIC_ANALYSIS)
|
||||
set(analyser "clang-tidy")
|
||||
find_program(${analyser}_FOUND "${analyser}")
|
||||
if(${analyser}_FOUND)
|
||||
set(CMAKE_CXX_CLANG_TIDY ${analyser} "--extra-arg=-std=c++17")
|
||||
endif()
|
||||
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
|
||||
|
||||
set(analyser "iwyu")
|
||||
find_program(${analyser}_FOUND "${analyser}")
|
||||
if(${analyser}_FOUND)
|
||||
set(CMAKE_CXX_IWYU "${${analyser}_FOUND}")
|
||||
endif()
|
||||
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
|
||||
|
||||
set(analyser "cpplint")
|
||||
find_program(${analyser}_FOUND "${analyser}")
|
||||
if(${analyser}_FOUND)
|
||||
set(CMAKE_CXX_CPPLINT "${${analyser}_FOUND}")
|
||||
endif()
|
||||
list(APPEND PROJECT_STATIC_ANALYSERS "${analyser}")
|
||||
endif()
|
||||
|
||||
if(CMAKE_GENERATOR STREQUAL Ninja AND ENABLE_CCACHE)
|
||||
find_program(CCACHE ccache)
|
||||
if(CCACHE)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
||||
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
|
||||
set(FAIRMQ_HAS_STD_FILESYSTEM 0)
|
||||
else()
|
||||
set(FAIRMQ_HAS_STD_FILESYSTEM 1)
|
||||
endif()
|
125
cmake/FairMQSummary.cmake
Normal file
125
cmake/FairMQSummary.cmake
Normal file
@@ -0,0 +1,125 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(FairCMakeModules)
|
||||
include(FairFormattedOutput)
|
||||
include(FairSummary)
|
||||
|
||||
macro(fairmq_summary_components)
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}COMPONENT BUILT? INFO${CR}")
|
||||
if(BUILD_FAIRMQ)
|
||||
set(fairmq_summary "${BGreen}YES${CR} (default, disable with ${BMagenta}-DBUILD_FAIRMQ=OFF${CR})")
|
||||
else()
|
||||
set(fairmq_summary "${BRed} NO${CR} (enable with ${BMagenta}-DBUILD_FAIRMQ=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}fairmq${CR} ${fairmq_summary}")
|
||||
if(BUILD_TESTING)
|
||||
set(tests_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_TESTING=OFF${CR})")
|
||||
else()
|
||||
set(tests_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_TESTING=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}tests${CR} ${tests_summary}")
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(ofi_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_OFI_TRANSPORT=OFF${CR})")
|
||||
else()
|
||||
set(ofi_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_OFI_TRANSPORT=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}ofi_transport${CR} ${ofi_summary}")
|
||||
if(BUILD_DDS_PLUGIN)
|
||||
set(dds_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_DDS_PLUGIN=OFF${CR})")
|
||||
else()
|
||||
set(dds_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_DDS_PLUGIN=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}dds_plugin${CR} ${dds_summary}")
|
||||
if(BUILD_PMIX_PLUGIN)
|
||||
set(pmix_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_PMIX_PLUGIN=OFF${CR})")
|
||||
else()
|
||||
set(pmix_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_PMIX_PLUGIN=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}pmix_plugin${CR} ${pmix_summary}")
|
||||
if(BUILD_EXAMPLES)
|
||||
set(examples_summary "${BGreen}YES${CR} (default, disable with ${BMagenta}-DBUILD_EXAMPLES=OFF${CR})")
|
||||
else()
|
||||
set(examples_summary "${BRed} NO${CR} (enable with ${BMagenta}-DBUILD_EXAMPLES=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}examples${CR} ${examples_summary}")
|
||||
if(BUILD_DOCS)
|
||||
set(docs_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_DOCS=OFF${CR})")
|
||||
else()
|
||||
set(docs_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_DOCS=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}docs${CR} ${docs_summary}")
|
||||
if(BUILD_SDK)
|
||||
set(sdk_summary "${BGreen}YES${CR} EXPERIMENTAL (disable with ${BMagenta}-DBUILD_SDK=OFF${CR})")
|
||||
else()
|
||||
set(sdk_summary "${BRed} NO${CR} EXPERIMENTAL (default, enable with ${BMagenta}-DBUILD_SDK=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}sdk${CR} ${sdk_summary}")
|
||||
if(BUILD_SDK_COMMANDS)
|
||||
set(sdk_commands_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_SDK_COMMANDS=OFF${CR})")
|
||||
else()
|
||||
set(sdk_commands_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_SDK_COMMANDS=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}sdk_commands${CR} ${sdk_commands_summary}")
|
||||
if(BUILD_TIDY_TOOL)
|
||||
set(sdk_tidy_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DBUILD_TIDY_TOOL=OFF${CR})")
|
||||
else()
|
||||
set(sdk_tidy_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DBUILD_TIDY_TOOL=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${BWhite}tidy_tool${CR} ${sdk_tidy_summary}")
|
||||
endmacro()
|
||||
|
||||
macro(fairmq_summary_static_analysis)
|
||||
message(STATUS " ")
|
||||
if(RUN_STATIC_ANALYSIS)
|
||||
list(LENGTH PROJECT_STATIC_ANALYSERS size)
|
||||
unset(analyser_list)
|
||||
set(count 0)
|
||||
foreach(analyser IN LISTS PROJECT_STATIC_ANALYSERS)
|
||||
if(${analyser}_FOUND)
|
||||
set(${analyser}_status "${analyser} ${BGreen}YES${CR}")
|
||||
else()
|
||||
set(${analyser}_status "${analyser} ${BRed}NO${CR}")
|
||||
endif()
|
||||
math(EXPR count "${count} + 1")
|
||||
string(APPEND analyser_list "${${analyser}_status}")
|
||||
if(count LESS size)
|
||||
string(APPEND analyser_list "${BWhite},${CR} ")
|
||||
endif()
|
||||
endforeach()
|
||||
set(static_ana_summary "${BWhite}(${CR}${analyser_list}${BWhite})${CR} (disable with ${BMagenta}-DRUN_STATIC_ANALYSIS=OFF${CR})")
|
||||
else()
|
||||
set(static_ana_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DRUN_STATIC_ANALYSIS=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${Cyan}RUN STATIC ANALYSIS ${static_ana_summary}")
|
||||
if(BUILD_TIDY_TOOL)
|
||||
if(RUN_FAIRMQ_TIDY)
|
||||
set(tidy_summary "${BGreen}YES${CR} (disable with ${BMagenta}-DRUN_FAIRMQ_TIDY=OFF${CR})")
|
||||
else()
|
||||
set(tidy_summary "${BRed} NO${CR} (default, enable with ${BMagenta}-DRUN_FAIRMQ_TIDY=ON${CR})")
|
||||
endif()
|
||||
message(STATUS " ${Cyan}RUN fairmq-tidy ${tidy_summary}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(fairmq_summary_install_prefix)
|
||||
message(STATUS " ")
|
||||
message(STATUS " ${Cyan}INSTALL PREFIX${CR} ${BGreen}${CMAKE_INSTALL_PREFIX}${CR} (change with ${BMagenta}-DCMAKE_INSTALL_PREFIX=...${CR})")
|
||||
endmacro()
|
||||
|
||||
macro(fairmq_summary_debug_mode)
|
||||
message(STATUS " ")
|
||||
if(FAIRMQ_DEBUG_MODE)
|
||||
message(STATUS " ${Cyan}DEBUG MODE${CR} ${BGreen}${FAIRMQ_DEBUG_MODE}${CR} (disable with ${BMagenta}-DFAIRMQ_DEBUG_MODE=OFF${CR})")
|
||||
else()
|
||||
message(STATUS " ${Cyan}DEBUG MODE${CR} ${BRed}${FAIRMQ_DEBUG_MODE}${CR} (enable with ${BMagenta}-DFAIRMQ_DEBUG_MODE=ON${CR})")
|
||||
endif()
|
||||
endmacro()
|
103
cmake/FairMQTidy.cmake
Normal file
103
cmake/FairMQTidy.cmake
Normal file
@@ -0,0 +1,103 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
|
||||
``fairmq_target_tidy()``
|
||||
========================
|
||||
|
||||
Runs the FairMQ static analyzer ``fairmq-tidy`` on source files in given
|
||||
target.
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
fairmq_target_tidy(TARGET <target> [EXTRA_ARGS <args>]
|
||||
[CLANG_EXECUTABLE <clang>])
|
||||
|
||||
Registers a custom command that depends on ``<target>`` which runs ``fairmq-tidy``
|
||||
on the source files that belong to ``<target>``. Optional extra arguments
|
||||
``<args>`` are passed to the ``fairmq-tidy`` command-line.
|
||||
|
||||
Requires ``CMAKE_EXPORT_COMPILE_COMMANDS`` to be enabled.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
function(fairmq_target_tidy)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "TARGET;EXTRA_ARGS;CLANG_EXECUTABLE" "")
|
||||
|
||||
if(NOT CMAKE_EXPORT_COMPILE_COMMANDS)
|
||||
message(AUTHOR_WARNING "CMAKE_EXPORT_COMPILE_COMMANDS is not enabled. Skipping.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT ARG_TARGET)
|
||||
message(AUTHOR_WARNING "TARGET argument is required. Skipping.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT TARGET ${ARG_TARGET})
|
||||
message(AUTHOR_WARNING "Given TARGET argument `${ARG_TARGET}` is not a target. Skipping.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if(NOT fairmq_tidy_clang_resource_dir)
|
||||
if(ARG_CLANG_EXECUTABLE)
|
||||
set(clang_exe ${ARG_CLANG_EXECUTABLE})
|
||||
else()
|
||||
if(TARGET clang)
|
||||
get_property(clang_exe TARGET clang PROPERTY LOCATION)
|
||||
else()
|
||||
set(clang_exe "clang")
|
||||
endif()
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${clang_exe} -print-resource-dir
|
||||
OUTPUT_VARIABLE clang_resource_dir
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
set(fairmq_tidy_clang_resource_dir ${clang_resource_dir}
|
||||
CACHE PATH "fairmq_target_tidy() internal state" FORCE)
|
||||
endif()
|
||||
list(APPEND ARG_EXTRA_ARGS
|
||||
"--extra-arg-before=-I${fairmq_tidy_clang_resource_dir}/include")
|
||||
endif()
|
||||
|
||||
if(ARG_EXTRA_ARGS)
|
||||
set(extra 1)
|
||||
else()
|
||||
set(extra 0)
|
||||
endif()
|
||||
|
||||
get_target_property(sources ${ARG_TARGET} SOURCES)
|
||||
list(FILTER sources INCLUDE REGEX "\.(cpp|cxx)$")
|
||||
string(REPLACE ":" "-" target_nocolon "${ARG_TARGET}")
|
||||
|
||||
set(src_deps)
|
||||
foreach(source IN LISTS sources)
|
||||
string(REPLACE "\/" "-" source_noslash "${source}")
|
||||
set(src_stamp "${CMAKE_CURRENT_BINARY_DIR}/${target_nocolon}-${source_noslash}.fairmq-tidy")
|
||||
add_custom_command(
|
||||
OUTPUT ${src_stamp}
|
||||
COMMAND $<TARGET_FILE:FairMQ::fairmq-tidy> -p=${CMAKE_BINARY_DIR}
|
||||
$<${extra}:${ARG_EXTRA_ARGS}> ${source}
|
||||
COMMAND ${CMAKE_COMMAND} -E touch ${src_stamp}
|
||||
COMMENT "fairmq-tidy: Analyzing source file '${source}' of target '${ARG_TARGET}'"
|
||||
DEPENDS ${ARG_TARGET}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND_EXPAND_LISTS VERBATIM
|
||||
)
|
||||
list(APPEND src_deps ${src_stamp})
|
||||
endforeach()
|
||||
|
||||
if(src_deps)
|
||||
add_custom_target("fairmq-tidy-${target_nocolon}" ALL DEPENDS ${src_deps})
|
||||
endif()
|
||||
endfunction()
|
@@ -1,5 +1,5 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -36,17 +36,10 @@ find_package_handle_standard_args(asio
|
||||
HANDLE_COMPONENTS
|
||||
)
|
||||
|
||||
if(asio_FOUND AND asio_BUNDLED)
|
||||
add_library(bundled_asio_headers INTERFACE)
|
||||
target_include_directories(bundled_asio_headers INTERFACE
|
||||
$<BUILD_INTERFACE:${asio_BUILD_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${asio_INSTALL_INCLUDE_DIR}>
|
||||
)
|
||||
add_library(asio::headers ALIAS bundled_asio_headers)
|
||||
endif()
|
||||
if(asio_FOUND AND NOT TARGET asio::headers)
|
||||
add_library(asio::headers INTERFACE IMPORTED)
|
||||
set_target_properties(asio::headers PROPERTIES
|
||||
if(asio_FOUND AND NOT TARGET asio::asio)
|
||||
add_library(asio::asio INTERFACE IMPORTED)
|
||||
set_target_properties(asio::asio PROPERTIES
|
||||
INTERFACE_COMPILE_DEFINITIONS "ASIO_STANDALONE"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${asio_INCLUDE_DIR}"
|
||||
)
|
||||
endif()
|
||||
|
@@ -48,6 +48,9 @@
|
||||
#
|
||||
|
||||
include(GoogleTest)
|
||||
if(BUILD_TIDY_TOOL)
|
||||
include(FairMQTidy)
|
||||
endif()
|
||||
|
||||
function(add_testsuite suitename)
|
||||
cmake_parse_arguments(testsuite
|
||||
@@ -74,6 +77,9 @@ function(add_testsuite suitename)
|
||||
if(testsuite_DEFINITIONS)
|
||||
target_compile_definitions("${target}" PUBLIC ${testsuite_DEFINITIONS})
|
||||
endif()
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET ${target})
|
||||
endif()
|
||||
|
||||
# add_test(NAME "${suitename}" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${target})
|
||||
if(testsuite_TIMEOUT)
|
||||
@@ -120,6 +126,9 @@ function(add_testhelper helpername)
|
||||
if(testhelper_DEFINITIONS)
|
||||
target_compile_definitions(${target} PUBLIC ${testhelper_DEFINITIONS})
|
||||
endif()
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET ${target})
|
||||
endif()
|
||||
|
||||
list(APPEND ALL_TEST_TARGETS ${target})
|
||||
set(ALL_TEST_TARGETS ${ALL_TEST_TARGETS} PARENT_SCOPE)
|
||||
@@ -154,6 +163,9 @@ function(add_testlib libname)
|
||||
if(testlib_DEFINITIONS)
|
||||
target_compile_definitions(${target} PUBLIC ${testlib_DEFINITIONS})
|
||||
endif()
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET ${target})
|
||||
endif()
|
||||
|
||||
list(APPEND ALL_TEST_TARGETS ${target})
|
||||
set(ALL_TEST_TARGETS ${ALL_TEST_TARGETS} PARENT_SCOPE)
|
||||
|
65
cmake/GitHelper.cmake
Normal file
65
cmake/GitHelper.cmake
Normal file
@@ -0,0 +1,65 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
if(NOT DEFINED ${GIT_EXECUTABLE})
|
||||
find_program(GIT_EXECUTABLE NAMES git)
|
||||
endif()
|
||||
|
||||
# get_git_version([DEFAULT_VERSION version] [DEFAULT_DATE date] [OUTVAR_PREFIX prefix])
|
||||
#
|
||||
# Sets variables #prefix#_VERSION, #prefix#_GIT_VERSION, #prefix#_DATE, #prefix#_GIT_DATE
|
||||
function(get_git_version)
|
||||
cmake_parse_arguments(ARGS "" "DEFAULT_VERSION;DEFAULT_DATE;OUTVAR_PREFIX" "" ${ARGN})
|
||||
|
||||
if(NOT ARGS_OUTVAR_PREFIX)
|
||||
set(ARGS_OUTVAR_PREFIX PROJECT)
|
||||
endif()
|
||||
|
||||
if(GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
|
||||
OUTPUT_VARIABLE ${ARGS_OUTVAR_PREFIX}_GIT_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
if(${ARGS_OUTVAR_PREFIX}_GIT_VERSION)
|
||||
# cut first two characters "v-"
|
||||
string(SUBSTRING ${${ARGS_OUTVAR_PREFIX}_GIT_VERSION} 1 -1 ${ARGS_OUTVAR_PREFIX}_GIT_VERSION)
|
||||
endif()
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%cd
|
||||
OUTPUT_VARIABLE ${ARGS_OUTVAR_PREFIX}_GIT_DATE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT ${ARGS_OUTVAR_PREFIX}_GIT_VERSION)
|
||||
if(ARGS_DEFAULT_VERSION)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_VERSION ${ARGS_DEFAULT_VERSION})
|
||||
else()
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_VERSION 0.0.0.0)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT ${ARGS_OUTVAR_PREFIX}_GIT_DATE)
|
||||
if(ARGS_DEFAULT_DATE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_DATE ${ARGS_DEFAULT_DATE})
|
||||
else()
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_DATE "Thu Jan 1 00:00:00 1970 +0000")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "^([^-]*)" blubb ${${ARGS_OUTVAR_PREFIX}_GIT_VERSION})
|
||||
|
||||
# return values
|
||||
set(${ARGS_OUTVAR_PREFIX}_VERSION ${CMAKE_MATCH_0} PARENT_SCOPE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_DATE ${${ARGS_OUTVAR_PREFIX}_GIT_DATE} PARENT_SCOPE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_VERSION ${${ARGS_OUTVAR_PREFIX}_GIT_VERSION} PARENT_SCOPE)
|
||||
set(${ARGS_OUTVAR_PREFIX}_GIT_DATE ${${ARGS_OUTVAR_PREFIX}_GIT_DATE} PARENT_SCOPE)
|
||||
endfunction()
|
4190
cmake/cotire.cmake
4190
cmake/cotire.cmake
File diff suppressed because it is too large
Load Diff
108
codemeta.json
Normal file
108
codemeta.json
Normal file
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
|
||||
"@type": "SoftwareSourceCode",
|
||||
"name": "FairMQ",
|
||||
"description": "C++ Message Queuing Library and Framework",
|
||||
"license": "./COPYRIGHT",
|
||||
"datePublished": "2018-04-15",
|
||||
"developmentStatus": "active",
|
||||
"codeRepository": "https://github.com/FairRootGroup/FairMQ/",
|
||||
"issueTracker": "https://github.com/FairRootGroup/FairMQ/issues",
|
||||
"identifier": "https://doi.org/10.5281/zenodo.1689985",
|
||||
"author": [
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Mohammad",
|
||||
"familyName": "Al-Turany"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Dennis",
|
||||
"familyName": "Klein"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Thorsten",
|
||||
"familyName": "Kollegger"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Alexey",
|
||||
"familyName": "Rybalchenko"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Nicolas",
|
||||
"familyName": "Winckler"
|
||||
}
|
||||
],
|
||||
"contributor": [
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Laurent",
|
||||
"familyName": "Aphecetche"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Sebastien",
|
||||
"familyName": "Binet"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Giulio",
|
||||
"familyName": "Eulisse"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Radoslaw",
|
||||
"familyName": "Karabowicz"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Matthias",
|
||||
"familyName": "Kretz",
|
||||
"email": "kretz@kde.org"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Mikolaj",
|
||||
"familyName": "Krzewicki"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Andrey",
|
||||
"familyName": "Lebedev"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Teo",
|
||||
"familyName": "Mrnjavac",
|
||||
"email": "teo.m@cern.ch"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Gvozden",
|
||||
"familyName": "Neskovic"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Matthias",
|
||||
"familyName": "Richter"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Christian",
|
||||
"familyName": "Tacke"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Florian",
|
||||
"familyName": "Uhlig"
|
||||
},
|
||||
{
|
||||
"@type": "Person",
|
||||
"givenName": "Sandro",
|
||||
"familyName": "Wenzel"
|
||||
}
|
||||
]
|
||||
}
|
83
codemeta_update.py
Executable file
83
codemeta_update.py
Executable file
@@ -0,0 +1,83 @@
|
||||
#! /usr/bin/env python3
|
||||
# Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
|
||||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
class CodeMetaManipulator(object):
|
||||
def load(self, filename='codemeta.json'):
|
||||
with open(filename, 'rb') as fp:
|
||||
self.data = json.load(fp, object_pairs_hook=OrderedDict)
|
||||
|
||||
@staticmethod
|
||||
def _dict_entry_cmp(dict1, dict2, field):
|
||||
if (field in dict1) and (field in dict2):
|
||||
return dict1[field] == dict2[field]
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def find_person_entry(cls, person_list, matchdict):
|
||||
for entry in person_list:
|
||||
if cls._dict_entry_cmp(entry, matchdict, 'email'):
|
||||
return entry
|
||||
if cls._dict_entry_cmp(entry, matchdict, 'familyName') \
|
||||
and cls._dict_entry_cmp(entry, matchdict, 'givenName'):
|
||||
return entry
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def update_person_entry(entry, matchdict):
|
||||
if entry is None:
|
||||
entry = OrderedDict()
|
||||
entry['@type'] = 'Person'
|
||||
for field in ('givenName', 'familyName', 'email'):
|
||||
val = matchdict.get(field, None)
|
||||
if val is not None:
|
||||
entry[field] = val
|
||||
return entry
|
||||
|
||||
def handle_person_list_file(self, filename, cm_field_name):
|
||||
fp = open(filename, 'r', encoding='utf8')
|
||||
findregex = re.compile(r'^(?P<familyName>[-\w\s]*[-\w]),\s*'
|
||||
r'(?P<givenName>[-\w\s]*[-\w])\s*'
|
||||
r'(?:<(?P<email>\S+@\S+)>)?$')
|
||||
person_list = self.data.setdefault(cm_field_name, [])
|
||||
for line in fp:
|
||||
line = line.strip()
|
||||
m = findregex.match(line)
|
||||
if m is None:
|
||||
raise RuntimeError("Could not analyze line %r" % line)
|
||||
found_entry = self.find_person_entry(person_list, m.groupdict())
|
||||
entry = self.update_person_entry(found_entry, m.groupdict())
|
||||
if found_entry is None:
|
||||
person_list.append(entry)
|
||||
|
||||
def save(self, filename='codemeta.json'):
|
||||
with open('codemeta.json', 'w', encoding='utf8') as fp:
|
||||
json.dump(self.data, fp, indent=2)
|
||||
fp.write('\n')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Update codemeta.json')
|
||||
parser.add_argument('--set-version', dest='newversion')
|
||||
args = parser.parse_args()
|
||||
|
||||
cm = CodeMetaManipulator()
|
||||
cm.load()
|
||||
if args.newversion is not None:
|
||||
cm.data['softwareVersion'] = args.newversion
|
||||
cm.handle_person_list_file('AUTHORS', 'author')
|
||||
cm.handle_person_list_file('CONTRIBUTORS', 'contributor')
|
||||
cm.save()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -8,6 +8,51 @@ For unit testing it is often not feasible to boot up a full-blown distributed sy
|
||||
|
||||
In some scenarios it is useful to not even instantiate a `FairMQDevice` at all. Please see [this example](../test/protocols/_push_pull_multipart.cxx) for single and multi threaded unit test without a device instance. If you store your transport factories and channels on the heap, pls make sure, you destroy the channels before you destroy the related transport factory for proper shutdown. Channels provide all the `Send/Receive` and `New*Message/New*Poller` APIs provided by the device too.
|
||||
|
||||
TODO Multiple devices in one process.
|
||||
## 4.2 Static Analysis
|
||||
|
||||
With `-DBUILD_TIDY_TOOL=ON` you can build the `fairmq-tidy` tool that implements static checks on your source code. To use it, enable the generation of a [compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) in your project via `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` (generates a file `<builddir>/compile_commands.json`):
|
||||
|
||||
```
|
||||
fairmq-tidy -p <builddir> mysourcefile.cpp
|
||||
```
|
||||
|
||||
If you find any issue (e.g. false positives) with this tool, please tell us by opening an issue on github.
|
||||
|
||||
### 4.2.1 CMake Integration
|
||||
|
||||
When discovering a FairMQ installation in your project, explicitely state, that you want one with the `fairmq-tidy` tool included:
|
||||
|
||||
```
|
||||
find_package(FairMQ COMPONENTS tidy_tool)
|
||||
```
|
||||
|
||||
Now the CMake module [`FairMQTidy.cmake`](../cmake/FairMQTidy.cmake) is available for inclusion:
|
||||
|
||||
```
|
||||
include(FairMQTidy)
|
||||
```
|
||||
|
||||
It provides the CMake function `fairmq_target_tidy()` which attaches appropriate `fairmq-tidy` build rules to each source file contained in the passed library or executable target, e.g. if you have an executable that uses FairMQ:
|
||||
|
||||
```
|
||||
add_executable(myexe mysource1.cpp mysource2.cpp)
|
||||
target_link_libraries(myexe PRIVATE FairMQ::FairMQ)
|
||||
fairmq_target_tidy(TARGET myexe)
|
||||
```
|
||||
|
||||
### 4.2.2 Extra Compiler Arguments
|
||||
|
||||
On most Linux distros you are likely to use GCC to compile your projects, so the resulting `compile_commands.json` contains the command-line tuned for GCC which might be missing options needed to successfully invoke the Clang frontend which is used internally by `fairmq-tidy`. In general, you can pass extra `clang` options via the following options:
|
||||
|
||||
```
|
||||
--extra-arg=<string> - Additional argument to append to the compiler command line
|
||||
--extra-arg-before=<string> - Additional argument to prepend to the compiler command line
|
||||
```
|
||||
|
||||
E.g. if standard headers are not found, you can hint the location like this:
|
||||
|
||||
```
|
||||
fairmq-top -p <builddir> --extra-arg-before=-I$(clang -print-resource-dir)/include mysourcefile.cpp
|
||||
```
|
||||
|
||||
← [Back](../README.md)
|
||||
|
@@ -27,34 +27,34 @@ The next table shows the supported address types for each transport implementati
|
||||
|
||||
## 2.1 Message
|
||||
|
||||
Devices transport data between each other in form of `FairMQMessage`s. These can be filled with arbitrary content. Message can be initialized in three different ways by calling `NewMessage()`:
|
||||
Devices transport data between each other in form of `fair::mq::Message`s. These can be filled with arbitrary content. Message can be initialized in three different ways by calling `NewMessage()`:
|
||||
|
||||
```cpp
|
||||
FairMQMessagePtr NewMessage() const;
|
||||
fair::mq::MessagePtr NewMessage() const;
|
||||
```
|
||||
**with no parameters**: Initializes an empty message (typically used for receiving).
|
||||
|
||||
```cpp
|
||||
FairMQMessagePtr NewMessage(const size_t size) const;
|
||||
fair::mq::MessagePtr NewMessage(const size_t size) const;
|
||||
```
|
||||
**given message size**: Initializes message body with a given size. Fill the created contents via buffer pointer.
|
||||
|
||||
```cpp
|
||||
using fairmq_free_fn = void(void* data, void* hint);
|
||||
FairMQMessagePtr NewMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const;
|
||||
fair::mq::MessagePtr NewMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const;
|
||||
```
|
||||
**given existing buffer and a size**: Initialize the message from an existing buffer. In case of ZeroMQ this is a zero-copy operation.
|
||||
|
||||
Additionally, FairMQ provides two more message factories for convenience:
|
||||
```cpp
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data) const
|
||||
fair::mq::MessagePtr NewSimpleMessage(const T& data) const
|
||||
```
|
||||
**copy and own**: Copy the `data` argument into the returned message and take ownership (free memory after message is sent). This interface is useful for small, [trivially copyable](http://en.cppreference.com/w/cpp/concept/TriviallyCopyable) data.
|
||||
|
||||
```cpp
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data) const
|
||||
fair::mq::MessagePtr NewStaticMessage(const T& data) const
|
||||
```
|
||||
**point to existing memory**: The returned message will point to the `data` argument, but not take ownership (someone else must destruct this variable). Make sure that `data` lives long enough to be successfully sent. This interface is most useful for third party managed, contiguous memory (Be aware of shallow types with internal pointer references! These will not be sent.)
|
||||
|
||||
@@ -65,19 +65,19 @@ The component of a program, that is reponsible for the allocation or destruction
|
||||
After queuing a message for sending in FairMQ, the transport takes ownership over the message body and will free it with `free()` after it is no longer used. A callback can be passed to the message object, to be called instead of the destruction with `free()` (for initialization via buffer+size).
|
||||
|
||||
```cpp
|
||||
static void FairMQNoCleanup(void* /*data*/, void* /*obj*/) {}
|
||||
static void fair::mq::NoCleanup(void* /*data*/, void* /*obj*/) {}
|
||||
|
||||
template<typename T>
|
||||
static void FairMQSimpleMsgCleanup(void* /*data*/, void* obj) { delete static_cast<T*>(obj); }
|
||||
static void fair::mq::SimpleMsgCleanup(void* /*data*/, void* obj) { delete static_cast<T*>(obj); }
|
||||
```
|
||||
For convenience, two common deleter callbacks are already defined in the `FairMQTransportFactory` class to aid the user in controlling ownership of the data.
|
||||
For convenience, two common deleter callbacks are already defined in the `fair::mq::TransportFactory` class to aid the user in controlling ownership of the data.
|
||||
|
||||
## 2.2 Channel
|
||||
|
||||
A channel represents a communication endpoint in FairMQ. Usage is similar to a traditional Unix network socket. A device usually contains a number of channels that can either listen for incoming connections from channels of other devices or they can connect to other listening channels. Channels are organized by a channel name and a subchannel index.
|
||||
|
||||
```cpp
|
||||
const FairMQChannel& GetChannel(const std::string& channelName, const int index = 0) const;
|
||||
const fair::mq::Channel& GetChannel(const std::string& channelName, const int index = 0) const;
|
||||
```
|
||||
|
||||
All subchannels with a common channel name need to be of the same transport type.
|
||||
@@ -87,7 +87,7 @@ All subchannels with a common channel name need to be of the same transport type
|
||||
A poller allows to wait on multiple channels either to receive or send a message.
|
||||
|
||||
```cpp
|
||||
FairMQPollerPtr NewPoller(const std::vector<const FairMQChannel*>& channels)
|
||||
fair::mq::PollerPtr NewPoller(const std::vector<const fair::mq::Channel*>& channels)
|
||||
```
|
||||
**list channels**: This poller waits on all supplied channels. Currently, it is limited to channels of the same transport type only.
|
||||
|
||||
|
@@ -13,19 +13,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fText and fMaxIterations values from the command line options (via fConfig)
|
||||
@@ -60,6 +49,11 @@ class Sampler : public FairMQDevice
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,18 +13,14 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
// register a handler for data arriving on "data" channel
|
||||
OnData("data", &Sink::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
@@ -46,8 +42,8 @@ class Sink : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,15 +13,13 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Processor : public FairMQDevice
|
||||
struct Processor : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Processor()
|
||||
{
|
||||
OnData("data1", &Processor::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQMessagePtr& msg, int)
|
||||
{
|
||||
LOG(info) << "Received data, processing...";
|
||||
|
@@ -15,19 +15,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fText and fMaxIterations values from the command line options (via fConfig)
|
||||
@@ -56,6 +45,11 @@ class Sampler : public FairMQDevice
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,19 +13,15 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
// register a handler for data arriving on "data2" channel
|
||||
OnData("data2", &Sink::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void InitTask() override
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
fMaxIterations = fConfig->GetProperty<uint64_t>("max-iterations");
|
||||
@@ -45,8 +41,8 @@ class Sink : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -15,17 +15,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fNumDataChannels(0)
|
||||
, fCounter(0)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fNumDataChannels = fChannels.at("data").size();
|
||||
@@ -55,11 +46,11 @@ class Sampler : public FairMQDevice
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int fNumDataChannels;
|
||||
uint64_t fCounter;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
private:
|
||||
int fNumDataChannels = 0;
|
||||
uint64_t fCounter = 0;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,12 +13,9 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
OnData("data", &Sink::HandleData);
|
||||
}
|
||||
@@ -44,8 +41,8 @@ class Sink : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -27,14 +27,13 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-ex-dds-env.sh ${CMAKE_CURRENT_
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-dds.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-dds.sh @ONLY)
|
||||
|
||||
# test
|
||||
if(DDS_FOUND)
|
||||
add_test(NAME Example.DDS.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-dds.sh localhost)
|
||||
set_tests_properties(Example.DDS.localhost PROPERTIES
|
||||
TIMEOUT 15
|
||||
RUN_SERIAL true
|
||||
PASS_REGULAR_EXPRESSION "Example successful"
|
||||
)
|
||||
endif()
|
||||
# if(DDS_FOUND)
|
||||
# add_test(NAME Example.DDS.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-dds.sh localhost)
|
||||
# set_tests_properties(Example.DDS.localhost PROPERTIES
|
||||
# TIMEOUT 15
|
||||
# PASS_REGULAR_EXPRESSION "Example successful"
|
||||
# )
|
||||
# endif()
|
||||
|
||||
# install
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<declrequirement name="SinkWorker" type="wnname" value="sink"/>
|
||||
|
||||
<decltask name="Sampler">
|
||||
<exe>fairmq-ex-dds-sampler --color false --channel-config name=data1,type=push,method=bind --rate 100 -P dds</exe>
|
||||
<exe>fairmq-ex-dds-sampler --color false --channel-config name=data1,type=push,method=bind --rate 100 --iterations 0 -P dds</exe>
|
||||
<env reachable="false">fairmq-ex-dds-env.sh</env>
|
||||
<requirements>
|
||||
<name>SamplerWorker</name>
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<declrequirement name="SinkWorker" type="wnname" value="sink"/>
|
||||
|
||||
<decltask name="Sampler">
|
||||
<exe>fairmq-ex-dds-sampler --color false --channel-config name=data1,type=push,method=bind -P dds --iterations 10</exe>
|
||||
<exe>fairmq-ex-dds-sampler --color false --channel-config name=data1,type=push,method=bind -P dds --iterations 10 --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-dds-env.sh</env>
|
||||
<requirements>
|
||||
<name>SamplerWorker</name>
|
||||
@@ -19,7 +19,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Processor">
|
||||
<exe>fairmq-ex-dds-processor --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect -P dds</exe>
|
||||
<exe>fairmq-ex-dds-processor --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect -P dds --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-dds-env.sh</env>
|
||||
<requirements>
|
||||
<name>ProcessorWorker</name>
|
||||
@@ -31,7 +31,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Sink">
|
||||
<exe>fairmq-ex-dds-sink --color false --channel-config name=data2,type=pull,method=bind -P dds --iterations 10</exe>
|
||||
<exe>fairmq-ex-dds-sink --color false --channel-config name=data2,type=pull,method=bind -P dds --iterations 10 --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-dds-env.sh</env>
|
||||
<requirements>
|
||||
<name>SinkWorker</name>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -18,7 +18,6 @@ cleanup() {
|
||||
echo "CLEANUP PERFORMED"
|
||||
}
|
||||
|
||||
source @DDS_INSTALL_PREFIX@/DDS_env.sh
|
||||
export PATH=@BIN_DIR@:$PATH
|
||||
|
||||
plugin=${1:-localhost}
|
||||
@@ -51,7 +50,6 @@ dds-info --executing-count --wait ${requiredNofSlots}
|
||||
|
||||
echo "------------------------"
|
||||
echo "...waiting for Topology to finish..."
|
||||
# TODO Retrieve number of devices from DDS topology API instead of having the user pass it explicitely
|
||||
fairmq-dds-command-ui -w "IDLE"
|
||||
fairmq-dds-command-ui -c i
|
||||
fairmq-dds-command-ui -c k
|
||||
@@ -74,12 +72,13 @@ dds-info --active-topology
|
||||
dds-topology --stop
|
||||
dds-info --active-topology
|
||||
|
||||
dds-agent-cmd getlog -a
|
||||
logDir="${wrkDir}/logs"
|
||||
for file in $(find "${logDir}" -name "*.tar.gz"); do tar -xf ${file} -C "${logDir}" ; done
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
# TODO Simplify, see https://github.com/FairRootGroup/DDS/issues/369
|
||||
if dds-agent-cmd getlog -a; then
|
||||
logDir=$(eval "echo $(dds-user-defaults --key server.sandbox_dir)/log/agents")
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
fi
|
||||
|
||||
# This string is used by ctest to detect success
|
||||
echo "Example successful :)"
|
||||
echo "Example successful"
|
||||
|
||||
# Cleanup function is called by EXIT trap
|
||||
|
@@ -13,15 +13,13 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Processor : public FairMQDevice
|
||||
struct Processor : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Processor()
|
||||
{
|
||||
OnData("data1", &Processor::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQMessagePtr& msg, int)
|
||||
{
|
||||
LOG(info) << "Received data, processing...";
|
||||
|
@@ -13,20 +13,13 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fIterations(0)
|
||||
, fCounter(0)
|
||||
{}
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
fIterations = fConfig->GetValue<uint64_t>("iterations");
|
||||
}
|
||||
|
||||
protected:
|
||||
bool ConditionalRun() override
|
||||
{
|
||||
// NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
|
||||
@@ -53,8 +46,8 @@ class Sampler : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fIterations;
|
||||
uint64_t fCounter;
|
||||
uint64_t fIterations = 0;
|
||||
uint64_t fCounter = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,12 +13,9 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fIterations(0)
|
||||
, fCounter(0)
|
||||
{
|
||||
OnData("data2", &Sink::HandleData);
|
||||
}
|
||||
@@ -28,7 +25,6 @@ class Sink : public FairMQDevice
|
||||
fIterations = fConfig->GetValue<uint64_t>("iterations");
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQMessagePtr& msg, int)
|
||||
{
|
||||
LOG(info) << "Received: \"" << std::string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
@@ -45,8 +41,8 @@ class Sink : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fIterations;
|
||||
uint64_t fCounter;
|
||||
uint64_t fIterations = 0;
|
||||
uint64_t fCounter = 0;
|
||||
};
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
|
@@ -17,15 +17,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fMaxIterations(5)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fMaxIterations = fConfig->GetProperty<uint64_t>("max-iterations");
|
||||
@@ -81,8 +74,8 @@ class Sampler : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 5;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,15 +13,13 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
{
|
||||
OnData("data", &Sink::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQParts& parts, int)
|
||||
{
|
||||
LOG(info) << "Received message with " << parts.Size() << " parts";
|
||||
|
@@ -14,12 +14,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Broadcaster : public FairMQDevice
|
||||
struct Broadcaster : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Broadcaster() {}
|
||||
|
||||
protected:
|
||||
bool ConditionalRun() override
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
@@ -16,14 +16,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
fText = fConfig->GetProperty<std::string>("text");
|
||||
@@ -62,10 +56,10 @@ class Sampler : public FairMQDevice
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -14,14 +14,9 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fReceivedData(false)
|
||||
, fReceivedBroadcast(false)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
OnData("broadcast", &Sink::HandleBroadcast);
|
||||
OnData("data", &Sink::HandleData);
|
||||
@@ -61,10 +56,10 @@ class Sink : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
bool fReceivedData;
|
||||
bool fReceivedBroadcast;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
bool fReceivedData = false;
|
||||
bool fReceivedBroadcast = false;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,16 +13,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler1 : public FairMQDevice
|
||||
struct Sampler1 : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler1()
|
||||
: fAckListener()
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fMaxIterations = fConfig->GetProperty<uint64_t>("max-iterations");
|
||||
@@ -72,9 +64,10 @@ class Sampler1 : public FairMQDevice
|
||||
LOG(info) << "Acknowledged " << numAcks << " messages";
|
||||
}
|
||||
|
||||
private:
|
||||
std::thread fAckListener;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,15 +13,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler2 : public FairMQDevice
|
||||
struct Sampler2 : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler2()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fMaxIterations = fConfig->GetProperty<uint64_t>("max-iterations");
|
||||
@@ -45,10 +38,9 @@ class Sampler2 : public FairMQDevice
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -11,20 +11,15 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations1(0)
|
||||
, fNumIterations2(0)
|
||||
{
|
||||
// register a handler for data arriving on "data" channel
|
||||
OnData("data1", &Sink::HandleData1);
|
||||
OnData("data2", &Sink::HandleData2);
|
||||
}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fMaxIterations = fConfig->GetProperty<uint64_t>("max-iterations");
|
||||
@@ -65,9 +60,9 @@ class Sink : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations1;
|
||||
uint64_t fNumIterations2;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations1 = 0;
|
||||
uint64_t fNumIterations2 = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -29,12 +29,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-n-m-dds.sh.in ${
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-n-m-pair-dds.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-n-m-pair-dds.sh @ONLY)
|
||||
|
||||
# test
|
||||
if(DDS_FOUND)
|
||||
add_test(NAME Example.N-M.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-n-m-dds.sh localhost)
|
||||
set_tests_properties(Example.N-M.localhost PROPERTIES TIMEOUT 15 RUN_SERIAL true PASS_REGULAR_EXPRESSION "Example successful")
|
||||
add_test(NAME Example.N-M-pair.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-n-m-pair-dds.sh localhost)
|
||||
set_tests_properties(Example.N-M-pair.localhost PROPERTIES TIMEOUT 15 RUN_SERIAL true PASS_REGULAR_EXPRESSION "Example successful")
|
||||
endif()
|
||||
# if(DDS_FOUND)
|
||||
# add_test(NAME Example.N-M.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-n-m-dds.sh localhost)
|
||||
# set_tests_properties(Example.N-M.localhost PROPERTIES TIMEOUT 15 PASS_REGULAR_EXPRESSION "Example successful")
|
||||
# add_test(NAME Example.N-M-pair.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-n-m-pair-dds.sh localhost)
|
||||
# set_tests_properties(Example.N-M-pair.localhost PROPERTIES TIMEOUT 15 PASS_REGULAR_EXPRESSION "Example successful")
|
||||
# endif()
|
||||
|
||||
# install
|
||||
install(
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<property name="fmqchan_data" />
|
||||
|
||||
<decltask name="Synchronizer">
|
||||
<exe reachable="true">fairmq-ex-n-m-synchronizer --id sync --rate 100 --color false -P dds --channel-config name=sync,type=pub,method=bind</exe>
|
||||
<exe reachable="true">fairmq-ex-n-m-synchronizer --id sync --rate 100 --color false -P dds --channel-config name=sync,type=pub,method=bind --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-n-m-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_sync</name>
|
||||
@@ -15,7 +15,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Sender">
|
||||
<exe reachable="true">fairmq-ex-n-m-sender --id sender%taskIndex% --timeframe-size 100000 --num-receivers ${numReceivers} --color false -P dds --channel-config name=sync,type=sub,method=connect name=data,type=pair,method=connect,numSockets=${numReceivers} --dds-i data:%taskIndex%</exe>
|
||||
<exe reachable="true">fairmq-ex-n-m-sender --id sender%taskIndex% --timeframe-size 100000 --num-receivers ${numReceivers} --color false -P dds --channel-config name=sync,type=sub,method=connect name=data,type=pair,method=connect,numSockets=${numReceivers} --dds-i data:%taskIndex% --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-n-m-env.sh</env>
|
||||
<properties>
|
||||
<name access="read">fmqchan_sync</name>
|
||||
@@ -24,7 +24,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Receiver">
|
||||
<exe reachable="true">fairmq-ex-n-m-receiver --id receiver%taskIndex% --num-senders ${numSenders} --color false -P dds --max-timeframes 10 --channel-config name=data,type=pair,method=bind,numSockets=${numSenders}</exe>
|
||||
<exe reachable="true">fairmq-ex-n-m-receiver --id receiver%taskIndex% --num-senders ${numSenders} --color false -P dds --max-timeframes 10 --channel-config name=data,type=pair,method=bind,numSockets=${numSenders} --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-n-m-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_data</name>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
<property name="fmqchan_data" />
|
||||
|
||||
<decltask name="Synchronizer">
|
||||
<exe reachable="true">fairmq-ex-n-m-synchronizer --id sync --rate 100 --color false -P dds --channel-config name=sync,type=pub,method=bind</exe>
|
||||
<exe reachable="true">fairmq-ex-n-m-synchronizer --id sync --rate 100 --color false -P dds --channel-config name=sync,type=pub,method=bind --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-n-m-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_sync</name>
|
||||
@@ -15,7 +15,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Sender">
|
||||
<exe reachable="true">fairmq-ex-n-m-sender --id sender%taskIndex% --timeframe-size 100000 --num-receivers ${numReceivers} --color false -P dds --channel-config name=sync,type=sub,method=connect name=data,type=push,method=connect,numSockets=${numReceivers}</exe>
|
||||
<exe reachable="true">fairmq-ex-n-m-sender --id sender%taskIndex% --timeframe-size 100000 --num-receivers ${numReceivers} --color false -P dds --channel-config name=sync,type=sub,method=connect name=data,type=push,method=connect,numSockets=${numReceivers} --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-n-m-env.sh</env>
|
||||
<properties>
|
||||
<name access="read">fmqchan_sync</name>
|
||||
@@ -24,7 +24,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Receiver">
|
||||
<exe reachable="true">fairmq-ex-n-m-receiver --id receiver%taskIndex% --num-senders ${numSenders} --color false -P dds --max-timeframes 10 --channel-config name=data,type=pull,method=bind</exe>
|
||||
<exe reachable="true">fairmq-ex-n-m-receiver --id receiver%taskIndex% --num-senders ${numSenders} --color false -P dds --max-timeframes 10 --channel-config name=data,type=pull,method=bind --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-n-m-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_data</name>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -15,7 +15,6 @@ cleanup() {
|
||||
echo "CLEANUP PERFORMED"
|
||||
}
|
||||
|
||||
source @DDS_INSTALL_PREFIX@/DDS_env.sh
|
||||
export PATH=@BIN_DIR@:$PATH
|
||||
|
||||
exec 5>&1
|
||||
@@ -42,7 +41,6 @@ dds-info --executing-count --wait ${requiredNofSlots}
|
||||
|
||||
echo "------------------------"
|
||||
echo "...waiting for Topology to finish..."
|
||||
# TODO Retrieve number of devices from DDS topology API instead of having the user pass it explicitely
|
||||
fairmq-dds-command-ui -w "IDLE"
|
||||
fairmq-dds-command-ui -c i
|
||||
fairmq-dds-command-ui -c k
|
||||
@@ -65,10 +63,11 @@ dds-info --active-topology
|
||||
dds-topology --stop
|
||||
dds-info --active-topology
|
||||
|
||||
dds-agent-cmd getlog -a
|
||||
logDir="${wrkDir}/logs"
|
||||
for file in $(find "${logDir}" -name "*.tar.gz"); do tar -xf ${file} -C "${logDir}" ; done
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
# TODO Simplify, see https://github.com/FairRootGroup/DDS/issues/369
|
||||
if dds-agent-cmd getlog -a; then
|
||||
logDir=$(eval "echo $(dds-user-defaults --key server.sandbox_dir)/log/agents")
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
fi
|
||||
|
||||
# This string is used by ctest to detect success
|
||||
echo "Example successful :)"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -15,7 +15,6 @@ cleanup() {
|
||||
echo "CLEANUP PERFORMED"
|
||||
}
|
||||
|
||||
source @DDS_INSTALL_PREFIX@/DDS_env.sh
|
||||
export PATH=@BIN_DIR@:$PATH
|
||||
|
||||
exec 5>&1
|
||||
@@ -42,7 +41,6 @@ dds-info --executing-count --wait ${requiredNofSlots}
|
||||
|
||||
echo "------------------------"
|
||||
echo "...waiting for Topology to finish..."
|
||||
# TODO Retrieve number of devices from DDS topology API instead of having the user pass it explicitely
|
||||
fairmq-dds-command-ui -w "IDLE"
|
||||
fairmq-dds-command-ui -c i
|
||||
fairmq-dds-command-ui -c k
|
||||
@@ -65,10 +63,11 @@ dds-info --active-topology
|
||||
dds-topology --stop
|
||||
dds-info --active-topology
|
||||
|
||||
dds-agent-cmd getlog -a
|
||||
logDir="${wrkDir}/logs"
|
||||
for file in $(find "${logDir}" -name "*.tar.gz"); do tar -xf ${file} -C "${logDir}" ; done
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
# TODO Simplify, see https://github.com/FairRootGroup/DDS/issues/369
|
||||
if dds-agent-cmd getlog -a; then
|
||||
logDir=$(eval "echo $(dds-user-defaults --key server.sandbox_dir)/log/agents")
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
fi
|
||||
|
||||
# This string is used by ctest to detect success
|
||||
echo "Example successful :)"
|
||||
|
@@ -29,22 +29,13 @@ struct TFBuffer
|
||||
chrono::steady_clock::time_point end;
|
||||
};
|
||||
|
||||
class Receiver : public FairMQDevice
|
||||
struct Receiver : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Receiver()
|
||||
: fBuffer()
|
||||
, fDiscardedSet()
|
||||
, fNumSenders(0)
|
||||
, fBufferTimeoutInMs(5000)
|
||||
, fMaxTimeframes(0)
|
||||
, fTimeframeCounter(0)
|
||||
{
|
||||
OnData("data", &Receiver::HandleData);
|
||||
}
|
||||
|
||||
~Receiver() = default;
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
fNumSenders = GetConfig()->GetValue<int>("num-senders");
|
||||
@@ -52,7 +43,6 @@ class Receiver : public FairMQDevice
|
||||
fMaxTimeframes = GetConfig()->GetValue<int>("max-timeframes");
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQParts& parts, int /* index */)
|
||||
{
|
||||
Header& h = *(static_cast<Header*>(parts.At(0)->GetData()));
|
||||
@@ -99,13 +89,14 @@ class Receiver : public FairMQDevice
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
unordered_map<uint16_t, TFBuffer> fBuffer;
|
||||
unordered_set<uint16_t> fDiscardedSet;
|
||||
|
||||
int fNumSenders;
|
||||
int fBufferTimeoutInMs;
|
||||
int fMaxTimeframes;
|
||||
int fTimeframeCounter;
|
||||
int fNumSenders = 0;
|
||||
int fBufferTimeoutInMs = 5000;
|
||||
int fMaxTimeframes = 0;
|
||||
int fTimeframeCounter = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -17,18 +17,8 @@ using namespace std;
|
||||
using namespace example_n_m;
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sender : public FairMQDevice
|
||||
struct Sender : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sender()
|
||||
: fNumReceivers(0)
|
||||
, fIndex(0)
|
||||
, fSubtimeframeSize(10000)
|
||||
{}
|
||||
|
||||
~Sender() = default;
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fIndex = GetConfig()->GetProperty<int>("sender-index");
|
||||
@@ -64,9 +54,9 @@ class Sender : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
int fNumReceivers;
|
||||
unsigned int fIndex;
|
||||
int fSubtimeframeSize;
|
||||
int fNumReceivers = 0;
|
||||
unsigned int fIndex = 0;
|
||||
int fSubtimeframeSize = 10000;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -15,15 +15,8 @@
|
||||
using namespace std;
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Synchronizer : public FairMQDevice
|
||||
struct Synchronizer : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Synchronizer()
|
||||
: fTimeframeId(0)
|
||||
{}
|
||||
~Synchronizer() = default;
|
||||
|
||||
protected:
|
||||
bool ConditionalRun() override
|
||||
{
|
||||
FairMQMessagePtr msg(NewSimpleMessage(fTimeframeId));
|
||||
@@ -39,7 +32,8 @@ class Synchronizer : public FairMQDevice
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t fTimeframeId;
|
||||
private:
|
||||
uint16_t fTimeframeId = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& /* options */) {}
|
||||
|
@@ -28,10 +28,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-ex-qc-env.sh ${CMAKE_CURRENT_B
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-qc.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-qc.sh @ONLY)
|
||||
|
||||
# test
|
||||
if(DDS_FOUND)
|
||||
add_test(NAME Example.QC.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-qc.sh localhost)
|
||||
set_tests_properties(Example.QC.localhost PROPERTIES TIMEOUT 15 RUN_SERIAL true PASS_REGULAR_EXPRESSION "Example successful")
|
||||
endif()
|
||||
# if(DDS_FOUND)
|
||||
# add_test(NAME Example.QC.localhost COMMAND ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-qc.sh localhost)
|
||||
# set_tests_properties(Example.QC.localhost PROPERTIES TIMEOUT 15 PASS_REGULAR_EXPRESSION "Example successful")
|
||||
# endif()
|
||||
|
||||
# install
|
||||
install(
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<property name="fmqchan_qc" />
|
||||
|
||||
<decltask name="Sampler">
|
||||
<exe>fairmq-ex-qc-sampler --color false --channel-config name=data1,type=push,method=bind -P dds --max-iterations 1000</exe>
|
||||
<exe>fairmq-ex-qc-sampler --color false --channel-config name=data1,type=push,method=bind -P dds --max-iterations 1000 --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-qc-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_data1</name>
|
||||
@@ -13,7 +13,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="QCDispatcher">
|
||||
<exe>fairmq-ex-qc-dispatcher --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect name=qc,type=push,method=connect -P dds</exe>
|
||||
<exe>fairmq-ex-qc-dispatcher --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect name=qc,type=push,method=connect -P dds --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-qc-env.sh</env>
|
||||
<properties>
|
||||
<name access="read">fmqchan_data1</name>
|
||||
@@ -23,7 +23,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="QCTask">
|
||||
<exe>fairmq-ex-qc-task --color false --channel-config name=qc,type=pull,method=bind -P dds</exe>
|
||||
<exe>fairmq-ex-qc-task --color false --channel-config name=qc,type=pull,method=bind -P dds --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-qc-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_qc</name>
|
||||
@@ -31,7 +31,7 @@
|
||||
</decltask>
|
||||
|
||||
<decltask name="Sink">
|
||||
<exe>fairmq-ex-qc-sink --color false --channel-config name=data2,type=pull,method=bind -P dds --max-iterations 1000</exe>
|
||||
<exe>fairmq-ex-qc-sink --color false --channel-config name=data2,type=pull,method=bind -P dds --max-iterations 1000 --severity trace --verbosity veryhigh</exe>
|
||||
<env reachable="false">fairmq-ex-qc-env.sh</env>
|
||||
<properties>
|
||||
<name access="write">fmqchan_data2</name>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
@@ -17,7 +17,6 @@ cleanup() {
|
||||
echo "CLEANUP PERFORMED"
|
||||
}
|
||||
|
||||
source @DDS_INSTALL_PREFIX@/DDS_env.sh
|
||||
export PATH=@BIN_DIR@:$PATH
|
||||
|
||||
exec 5>&1
|
||||
@@ -44,7 +43,6 @@ dds-info --executing-count --wait ${requiredNofSlots}
|
||||
|
||||
echo "------------------------"
|
||||
echo "...waiting for Topology to finish..."
|
||||
# TODO Retrieve number of devices from DDS topology API instead of having the user pass it explicitely
|
||||
fairmq-dds-command-ui -w "IDLE"
|
||||
fairmq-dds-command-ui -c i
|
||||
fairmq-dds-command-ui -c k
|
||||
@@ -71,10 +69,11 @@ dds-info --active-topology
|
||||
dds-topology --stop
|
||||
dds-info --active-topology
|
||||
|
||||
dds-agent-cmd getlog -a
|
||||
logDir="${wrkDir}/logs"
|
||||
for file in $(find "${logDir}" -name "*.tar.gz"); do tar -xf ${file} -C "${logDir}" ; done
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
# TODO Simplify, see https://github.com/FairRootGroup/DDS/issues/369
|
||||
if dds-agent-cmd getlog -a; then
|
||||
logDir=$(eval "echo $(dds-user-defaults --key server.sandbox_dir)/log/agents")
|
||||
echo "AGENT LOG FILES IN: ${logDir}"
|
||||
fi
|
||||
|
||||
# This string is used by ctest to detect success
|
||||
echo "Example successful :)"
|
||||
|
@@ -9,9 +9,8 @@
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairmq/runDevice.h>
|
||||
|
||||
class QCDispatcher : public FairMQDevice
|
||||
struct QCDispatcher : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
QCDispatcher()
|
||||
: fDoQC(false)
|
||||
{
|
||||
@@ -31,7 +30,6 @@ class QCDispatcher : public FairMQDevice
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQMessagePtr& msg, int)
|
||||
{
|
||||
if (fDoQC.load() == true) {
|
||||
|
@@ -12,13 +12,9 @@
|
||||
#include <thread> // this_thread::sleep_for
|
||||
#include <chrono>
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler() {}
|
||||
|
||||
protected:
|
||||
virtual bool ConditionalRun()
|
||||
bool ConditionalRun() override
|
||||
{
|
||||
FairMQMessagePtr msg(NewMessage(1000));
|
||||
|
||||
|
@@ -11,12 +11,9 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
struct Sink : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sink() { OnData("data2", &Sink::HandleData); }
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQMessagePtr& /*msg*/, int /*index*/) { return true; }
|
||||
};
|
||||
|
||||
|
@@ -16,9 +16,7 @@ namespace bpo = boost::program_options;
|
||||
class Builder : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
Builder()
|
||||
: fOutputChannelName()
|
||||
{}
|
||||
Builder() = default;
|
||||
|
||||
void Init() override
|
||||
{
|
||||
|
@@ -11,14 +11,13 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Processor : public FairMQDevice
|
||||
struct Processor : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Processor() {
|
||||
Processor()
|
||||
{
|
||||
OnData("bp", &Processor::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool HandleData(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
FairMQMessagePtr msg2(NewMessageFor("ps", 0, msg->GetSize()));
|
||||
|
@@ -15,18 +15,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Readout : public FairMQDevice
|
||||
struct Readout : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Readout()
|
||||
: fMsgSize(10000)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
, fRegion(nullptr)
|
||||
, fNumUnackedMsgs(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fMsgSize = fConfig->GetProperty<int>("msg-size");
|
||||
@@ -65,6 +55,7 @@ class Readout : public FairMQDevice
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResetTask() override
|
||||
{
|
||||
// if not all messages acknowledged, wait for a bit. But only once, since receiver could be already dead.
|
||||
@@ -77,11 +68,11 @@ class Readout : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
int fMsgSize;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
FairMQUnmanagedRegionPtr fRegion;
|
||||
std::atomic<uint64_t> fNumUnackedMsgs;
|
||||
int fMsgSize = 10000;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
FairMQUnmanagedRegionPtr fRegion = nullptr;
|
||||
std::atomic<uint64_t> fNumUnackedMsgs = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -8,18 +8,16 @@
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairmq/runDevice.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Receiver : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
Receiver()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
namespace {
|
||||
|
||||
protected:
|
||||
struct Receiver : Device
|
||||
{
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
@@ -28,32 +26,32 @@ class Receiver : public FairMQDevice
|
||||
|
||||
void Run() override
|
||||
{
|
||||
FairMQChannel& dataInChannel = fChannels.at("sr").at(0);
|
||||
Channel& dataInChannel = fChannels.at("sr").at(0);
|
||||
|
||||
while (!NewStatePending()) {
|
||||
FairMQMessagePtr msg(dataInChannel.Transport()->CreateMessage());
|
||||
auto msg(dataInChannel.NewMessage());
|
||||
dataInChannel.Receive(msg);
|
||||
// void* ptr = msg->GetData();
|
||||
|
||||
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations) {
|
||||
LOG(info) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
|
||||
LOG(info) << "Configured max number of iterations reached. Leaving RUNNING state.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
options.add_options()
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
|
||||
options.add_options()(
|
||||
"max-iterations",
|
||||
bpo::value<uint64_t>()->default_value(0),
|
||||
"Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
|
||||
}
|
||||
|
||||
std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions& /*config*/)
|
||||
{
|
||||
return std::make_unique<Receiver>();
|
||||
}
|
||||
unique_ptr<Device> getDevice(ProgOptions& /*config*/) { return make_unique<Receiver>(); }
|
||||
|
@@ -13,13 +13,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sender : public FairMQDevice
|
||||
struct Sender : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sender()
|
||||
: fInputChannelName()
|
||||
{}
|
||||
|
||||
void Init() override
|
||||
{
|
||||
fInputChannelName = fConfig->GetProperty<std::string>("input-name");
|
||||
|
@@ -15,19 +15,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Sampler : public FairMQDevice
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Sampler()
|
||||
: fMsgSize(10000)
|
||||
, fLinger(100)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
, fRegion(nullptr)
|
||||
, fNumUnackedMsgs(0)
|
||||
{}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
fMsgSize = fConfig->GetProperty<int>("msg-size");
|
||||
@@ -102,13 +91,13 @@ class Sampler : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
int fMsgSize;
|
||||
uint32_t fLinger;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
FairMQUnmanagedRegionPtr fRegion;
|
||||
int fMsgSize = 10000;
|
||||
uint32_t fLinger = 100;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
FairMQUnmanagedRegionPtr fRegion = nullptr;
|
||||
std::mutex fMtx;
|
||||
uint64_t fNumUnackedMsgs;
|
||||
uint64_t fNumUnackedMsgs = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -8,36 +8,34 @@
|
||||
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairmq/runDevice.h>
|
||||
#include <memory>
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
class Sink : public FairMQDevice
|
||||
namespace {
|
||||
|
||||
struct Sink : Device
|
||||
{
|
||||
public:
|
||||
Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
fMaxIterations = fConfig->GetProperty<uint64_t>("max-iterations");
|
||||
fChannels.at("data").at(0).Transport()->SubscribeToRegionEvents([](FairMQRegionInfo info) {
|
||||
fChannels.at("data").at(0).Transport()->SubscribeToRegionEvents([](RegionInfo info) {
|
||||
LOG(info) << "Region event: " << info.event << ": "
|
||||
<< (info.managed ? "managed" : "unmanaged")
|
||||
<< ", id: " << info.id
|
||||
<< ", ptr: " << info.ptr
|
||||
<< ", size: " << info.size
|
||||
<< ", flags: " << info.flags;
|
||||
<< (info.managed ? "managed" : "unmanaged") << ", id: " << info.id
|
||||
<< ", ptr: " << info.ptr << ", size: " << info.size
|
||||
<< ", flags: " << info.flags;
|
||||
});
|
||||
}
|
||||
|
||||
void Run() override
|
||||
{
|
||||
FairMQChannel& dataInChannel = fChannels.at("data").at(0);
|
||||
Channel& dataInChannel = fChannels.at("data").at(0);
|
||||
|
||||
while (!NewStatePending()) {
|
||||
FairMQMessagePtr msg(dataInChannel.Transport()->CreateMessage());
|
||||
auto msg(dataInChannel.Transport()->CreateMessage());
|
||||
dataInChannel.Receive(msg);
|
||||
|
||||
// void* ptr = msg->GetData();
|
||||
@@ -45,29 +43,30 @@ class Sink : public FairMQDevice
|
||||
// LOG(info) << "check: " << cptr[3];
|
||||
|
||||
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations) {
|
||||
LOG(info) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
|
||||
LOG(info) << "Configured max number of iterations reached. Leaving RUNNING state.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResetTask() override
|
||||
{
|
||||
fChannels.at("data").at(0).Transport()->UnsubscribeFromRegionEvents();
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
options.add_options()
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
|
||||
options.add_options()(
|
||||
"max-iterations",
|
||||
bpo::value<uint64_t>()->default_value(0),
|
||||
"Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)");
|
||||
}
|
||||
|
||||
std::unique_ptr<fair::mq::Device> getDevice(fair::mq::ProgOptions& /*config*/)
|
||||
{
|
||||
return std::make_unique<Sink>();
|
||||
}
|
||||
unique_ptr<Device> getDevice(ProgOptions& /*config*/) { return make_unique<Sink>(); }
|
||||
|
@@ -15,14 +15,8 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Client : public FairMQDevice
|
||||
struct Client : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Client()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{}
|
||||
|
||||
void InitTask() override
|
||||
{
|
||||
fText = fConfig->GetProperty<std::string>("text");
|
||||
@@ -66,8 +60,8 @@ class Client : public FairMQDevice
|
||||
|
||||
private:
|
||||
std::string fText;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
@@ -13,17 +13,13 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
class Server : public FairMQDevice
|
||||
struct Server : fair::mq::Device
|
||||
{
|
||||
public:
|
||||
Server()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
OnData("data", &Server::HandleData);
|
||||
}
|
||||
|
||||
protected:
|
||||
void InitTask() override
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
@@ -56,8 +52,8 @@ class Server : public FairMQDevice
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations = 0;
|
||||
uint64_t fNumIterations = 0;
|
||||
};
|
||||
|
||||
void addCustomOptions(bpo::options_description& options)
|
||||
|
1
extern/FairCMakeModules
vendored
Submodule
1
extern/FairCMakeModules
vendored
Submodule
Submodule extern/FairCMakeModules added at ceecfbad90
1
extern/asio
vendored
1
extern/asio
vendored
Submodule extern/asio deleted from be7badc31a
2
extern/googletest
vendored
2
extern/googletest
vendored
Submodule extern/googletest updated: 90a443f9c2...f5e592d8ee
@@ -7,6 +7,11 @@
|
||||
################################################################################
|
||||
|
||||
if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
|
||||
if(BUILD_TIDY_TOOL)
|
||||
include(FairMQTidy)
|
||||
endif()
|
||||
|
||||
###########
|
||||
# Version #
|
||||
###########
|
||||
@@ -26,6 +31,7 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
set(TOOLS_PUBLIC_HEADER_FILES
|
||||
tools/CppSTL.h
|
||||
tools/InstanceLimit.h
|
||||
tools/IO.h
|
||||
tools/Network.h
|
||||
tools/Process.h
|
||||
tools/RateLimit.h
|
||||
@@ -33,10 +39,12 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
tools/Strings.h
|
||||
tools/Unique.h
|
||||
tools/Version.h
|
||||
Error.h
|
||||
Tools.h
|
||||
)
|
||||
|
||||
set(TOOLS_SOURCE_FILES
|
||||
Error.cxx
|
||||
tools/Network.cxx
|
||||
tools/Process.cxx
|
||||
tools/Semaphore.cxx
|
||||
@@ -47,23 +55,17 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
${TOOLS_SOURCE_FILES}
|
||||
${TOOLS_PUBLIC_HEADER_FILES}
|
||||
)
|
||||
target_compile_features(${target} PUBLIC cxx_std_17)
|
||||
target_compile_definitions(${target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
# workaround https://github.com/boostorg/asio/commit/43874d5497414c67655d901e48c939ef01337edb
|
||||
if( Boost_VERSION VERSION_LESS 1.69
|
||||
AND CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
|
||||
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0.1)
|
||||
target_compile_definitions(${target} PUBLIC BOOST_ASIO_HAS_STD_STRING_VIEW)
|
||||
endif()
|
||||
target_include_directories(${target}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
target_link_libraries(${target}
|
||||
PRIVATE
|
||||
FairLogger::FairLogger
|
||||
Threads::Threads
|
||||
PUBLIC
|
||||
Boost::boost
|
||||
)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
@@ -71,6 +73,9 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
|
||||
OUTPUT_NAME FairMQ${target}
|
||||
)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET ${target})
|
||||
endif()
|
||||
install(
|
||||
TARGETS ${target}
|
||||
EXPORT ${PROJECT_EXPORT_SET}
|
||||
@@ -106,11 +111,12 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
${FSM_SOURCE_FILES}
|
||||
${FSM_PUBLIC_HEADER_FILES}
|
||||
)
|
||||
target_compile_features(${target} PUBLIC cxx_std_17)
|
||||
target_compile_definitions(${target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
target_include_directories(${target}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
target_link_libraries(${target}
|
||||
PUBLIC
|
||||
@@ -125,6 +131,9 @@ if(BUILD_FAIRMQ OR BUILD_SDK)
|
||||
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
|
||||
OUTPUT_NAME FairMQ${target}
|
||||
)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET ${target})
|
||||
endif()
|
||||
install(
|
||||
TARGETS ${target}
|
||||
EXPORT ${PROJECT_EXPORT_SET}
|
||||
@@ -146,6 +155,7 @@ if(BUILD_FAIRMQ)
|
||||
# libFairMQ header files #
|
||||
##########################
|
||||
set(FAIRMQ_PUBLIC_HEADER_FILES
|
||||
Channel.h
|
||||
Device.h
|
||||
DeviceRunner.h
|
||||
EventManager.h
|
||||
@@ -155,22 +165,29 @@ if(BUILD_FAIRMQ)
|
||||
FairMQMessage.h
|
||||
FairMQParts.h
|
||||
FairMQPoller.h
|
||||
FairMQUnmanagedRegion.h
|
||||
FairMQSocket.h
|
||||
FairMQTransportFactory.h
|
||||
MemoryResources.h
|
||||
MemoryResourceTools.h
|
||||
Transports.h
|
||||
options/FairMQProgOptions.h
|
||||
FairMQUnmanagedRegion.h
|
||||
FwdDecls.h
|
||||
JSONParser.h
|
||||
ProgOptionsFwd.h
|
||||
ProgOptions.h
|
||||
Properties.h
|
||||
PropertyOutput.h
|
||||
SuboptParser.h
|
||||
MemoryResourceTools.h
|
||||
MemoryResources.h
|
||||
Message.h
|
||||
Parts.h
|
||||
Plugin.h
|
||||
PluginManager.h
|
||||
PluginServices.h
|
||||
Poller.h
|
||||
ProgOptions.h
|
||||
ProgOptionsFwd.h
|
||||
Properties.h
|
||||
PropertyOutput.h
|
||||
Socket.h
|
||||
SuboptParser.h
|
||||
TransportFactory.h
|
||||
Transports.h
|
||||
UnmanagedRegion.h
|
||||
options/FairMQProgOptions.h
|
||||
runDevice.h
|
||||
runFairMQDevice.h
|
||||
shmem/Monitor.h
|
||||
@@ -194,6 +211,7 @@ if(BUILD_FAIRMQ)
|
||||
shmem/Common.h
|
||||
shmem/Manager.h
|
||||
shmem/Region.h
|
||||
zeromq/Common.h
|
||||
zeromq/Context.h
|
||||
zeromq/Message.h
|
||||
zeromq/Poller.h
|
||||
@@ -205,8 +223,8 @@ if(BUILD_FAIRMQ)
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(FAIRMQ_PRIVATE_HEADER_FILES ${FAIRMQ_PRIVATE_HEADER_FILES}
|
||||
ofi/Context.h
|
||||
ofi/ControlMessages.h
|
||||
ofi/Message.h
|
||||
ofi/Poller.h
|
||||
ofi/Socket.h
|
||||
ofi/TransportFactory.h
|
||||
)
|
||||
@@ -216,24 +234,21 @@ if(BUILD_FAIRMQ)
|
||||
# libFairMQ source files #
|
||||
##########################
|
||||
set(FAIRMQ_SOURCE_FILES
|
||||
Channel.cxx
|
||||
Device.cxx
|
||||
DeviceRunner.cxx
|
||||
FairMQChannel.cxx
|
||||
FairMQDevice.cxx
|
||||
FairMQLogger.cxx
|
||||
FairMQMessage.cxx
|
||||
FairMQPoller.cxx
|
||||
FairMQSocket.cxx
|
||||
FairMQTransportFactory.cxx
|
||||
JSONParser.cxx
|
||||
MemoryResources.cxx
|
||||
Plugin.cxx
|
||||
PluginManager.cxx
|
||||
PluginServices.cxx
|
||||
ProgOptions.cxx
|
||||
JSONParser.cxx
|
||||
Properties.cxx
|
||||
SuboptParser.cxx
|
||||
TransportFactory.cxx
|
||||
plugins/config/Config.cxx
|
||||
plugins/control/Control.cxx
|
||||
MemoryResources.cxx
|
||||
shmem/Manager.cxx
|
||||
shmem/Monitor.cxx
|
||||
)
|
||||
|
||||
@@ -241,9 +256,7 @@ if(BUILD_FAIRMQ)
|
||||
set(FAIRMQ_SOURCE_FILES ${FAIRMQ_SOURCE_FILES}
|
||||
ofi/Context.cxx
|
||||
ofi/Message.cxx
|
||||
ofi/Poller.cxx
|
||||
ofi/Socket.cxx
|
||||
ofi/TransportFactory.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -257,45 +270,39 @@ if(BUILD_FAIRMQ)
|
||||
#################################
|
||||
# define libFairMQ build target #
|
||||
#################################
|
||||
if(FAST_BUILD)
|
||||
set(_target FairMQ_)
|
||||
else()
|
||||
set(_target FairMQ)
|
||||
endif()
|
||||
add_library(${_target}
|
||||
set(target FairMQ)
|
||||
add_library(${target}
|
||||
${FAIRMQ_SOURCE_FILES}
|
||||
${FAIRMQ_PUBLIC_HEADER_FILES} # for IDE integration
|
||||
${FAIRMQ_PRIVATE_HEADER_FILES} # for IDE integration
|
||||
)
|
||||
set_target_properties(${_target} PROPERTIES LABELS coverage)
|
||||
if(FAST_BUILD)
|
||||
set_target_properties(${_target} PROPERTIES OUTPUT_NAME FairMQ)
|
||||
endif()
|
||||
target_compile_features(${target} PUBLIC cxx_std_17)
|
||||
set_target_properties(${target} PROPERTIES LABELS coverage)
|
||||
|
||||
|
||||
############################
|
||||
# preprocessor definitions #
|
||||
############################
|
||||
target_compile_definitions(${_target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
target_compile_definitions(${target} PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
if(FAIRMQ_DEBUG_MODE)
|
||||
target_compile_definitions(${_target} PUBLIC FAIRMQ_DEBUG_MODE)
|
||||
target_compile_definitions(${target} PUBLIC FAIRMQ_DEBUG_MODE)
|
||||
endif()
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
target_compile_definitions(${_target} PRIVATE BUILD_OFI_TRANSPORT)
|
||||
target_compile_definitions(${target} PRIVATE BUILD_OFI_TRANSPORT)
|
||||
endif()
|
||||
target_compile_definitions(${_target} PUBLIC FAIRMQ_HAS_STD_FILESYSTEM=${FAIRMQ_HAS_STD_FILESYSTEM})
|
||||
target_compile_definitions(${target} PUBLIC FAIRMQ_HAS_STD_FILESYSTEM=${FAIRMQ_HAS_STD_FILESYSTEM})
|
||||
|
||||
|
||||
#######################
|
||||
# include directories #
|
||||
#######################
|
||||
target_include_directories(${_target}
|
||||
target_include_directories(${target}
|
||||
PUBLIC # consumers inherit public include directories
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:include/fairmq>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
$<INSTALL_INTERFACE:${PROJECT_INSTALL_INCDIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
##################
|
||||
@@ -303,16 +310,12 @@ if(BUILD_FAIRMQ)
|
||||
##################
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(OFI_DEPS
|
||||
asio::asio
|
||||
asiofi::asiofi
|
||||
Boost::container
|
||||
)
|
||||
endif()
|
||||
set(optional_deps ${OFI_DEPS})
|
||||
if(optional_deps)
|
||||
list(REMOVE_DUPLICATES optional_deps)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${_target}
|
||||
target_link_libraries(${target}
|
||||
INTERFACE # only consumers link against interface dependencies
|
||||
Boost::container
|
||||
|
||||
@@ -333,24 +336,12 @@ if(BUILD_FAIRMQ)
|
||||
PicoSHA2
|
||||
${OFI_DEPS}
|
||||
)
|
||||
set_target_properties(${_target} PROPERTIES
|
||||
set_target_properties(${target} PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
|
||||
)
|
||||
|
||||
|
||||
##############
|
||||
# fast build #
|
||||
##############
|
||||
if(FAST_BUILD)
|
||||
set_target_properties(${_target} PROPERTIES
|
||||
COTIRE_UNITY_TARGET_NAME "FairMQ"
|
||||
# COTIRE_ENABLE_PRECOMPILED_HEADER FALSE
|
||||
EXCLUDE_FROM_ALL TRUE
|
||||
)
|
||||
cotire(${_target})
|
||||
set_target_properties(FairMQ PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
||||
set_target_properties(FairMQ PROPERTIES LABELS coverage)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET ${target})
|
||||
endif()
|
||||
|
||||
|
||||
@@ -359,23 +350,42 @@ if(BUILD_FAIRMQ)
|
||||
###############
|
||||
add_executable(fairmq-bsampler devices/runBenchmarkSampler.cxx)
|
||||
target_link_libraries(fairmq-bsampler FairMQ)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-bsampler)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-merger devices/runMerger.cxx)
|
||||
target_link_libraries(fairmq-merger FairMQ)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-merger)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-multiplier devices/runMultiplier.cxx)
|
||||
target_link_libraries(fairmq-multiplier FairMQ)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-multiplier)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-proxy devices/runProxy.cxx)
|
||||
target_link_libraries(fairmq-proxy FairMQ)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-proxy)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-sink devices/runSink.cxx)
|
||||
target_link_libraries(fairmq-sink FairMQ)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-sink)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-splitter devices/runSplitter.cxx)
|
||||
target_link_libraries(fairmq-splitter FairMQ)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-splitter)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-shmmonitor shmem/Monitor.cxx shmem/Monitor.h shmem/runMonitor.cxx)
|
||||
target_compile_features(fairmq-shmmonitor PUBLIC cxx_std_17)
|
||||
target_compile_definitions(fairmq-shmmonitor PUBLIC BOOST_ERROR_CODE_HEADER_ONLY)
|
||||
if(FAIRMQ_DEBUG_MODE)
|
||||
target_compile_definitions(fairmq-shmmonitor PUBLIC FAIRMQ_DEBUG_MODE)
|
||||
@@ -394,12 +404,18 @@ if(BUILD_FAIRMQ)
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||
)
|
||||
target_compile_definitions(fairmq-shmmonitor PUBLIC FAIRMQ_HAS_STD_FILESYSTEM=${FAIRMQ_HAS_STD_FILESYSTEM})
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-shmmonitor)
|
||||
endif()
|
||||
|
||||
add_executable(fairmq-uuid-gen tools/runUuidGenerator.cxx)
|
||||
target_link_libraries(fairmq-uuid-gen PUBLIC
|
||||
Boost::program_options
|
||||
Tools
|
||||
)
|
||||
if(BUILD_TIDY_TOOL AND RUN_FAIRMQ_TIDY)
|
||||
fairmq_target_tidy(TARGET fairmq-uuid-gen)
|
||||
endif()
|
||||
|
||||
|
||||
###########
|
||||
|
@@ -1,30 +1,27 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <fairmq/Properties.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
#include <cstddef> // size_t
|
||||
#include <fairlogger/Logger.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
|
||||
#include <cstddef> // size_t
|
||||
#include <fairmq/Channel.h>
|
||||
#include <fairmq/Properties.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <random>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <random>
|
||||
|
||||
namespace fair::mq {
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
template<typename T>
|
||||
T GetPropertyOrDefault(const fair::mq::Properties& m, const string& k, const T& ifNotFound)
|
||||
T GetPropertyOrDefault(const Properties& m, const string& k, const T& ifNotFound)
|
||||
{
|
||||
if (m.count(k)) {
|
||||
return boost::any_cast<T>(m.at(k));
|
||||
@@ -32,46 +29,46 @@ T GetPropertyOrDefault(const fair::mq::Properties& m, const string& k, const T&
|
||||
return ifNotFound;
|
||||
}
|
||||
|
||||
constexpr fair::mq::Transport FairMQChannel::DefaultTransportType;
|
||||
constexpr const char* FairMQChannel::DefaultTransportName;
|
||||
constexpr const char* FairMQChannel::DefaultName;
|
||||
constexpr const char* FairMQChannel::DefaultType;
|
||||
constexpr const char* FairMQChannel::DefaultMethod;
|
||||
constexpr const char* FairMQChannel::DefaultAddress;
|
||||
constexpr int FairMQChannel::DefaultSndBufSize;
|
||||
constexpr int FairMQChannel::DefaultRcvBufSize;
|
||||
constexpr int FairMQChannel::DefaultSndKernelSize;
|
||||
constexpr int FairMQChannel::DefaultRcvKernelSize;
|
||||
constexpr int FairMQChannel::DefaultLinger;
|
||||
constexpr int FairMQChannel::DefaultRateLogging;
|
||||
constexpr int FairMQChannel::DefaultPortRangeMin;
|
||||
constexpr int FairMQChannel::DefaultPortRangeMax;
|
||||
constexpr bool FairMQChannel::DefaultAutoBind;
|
||||
constexpr Transport Channel::DefaultTransportType;
|
||||
constexpr const char* Channel::DefaultTransportName;
|
||||
constexpr const char* Channel::DefaultName;
|
||||
constexpr const char* Channel::DefaultType;
|
||||
constexpr const char* Channel::DefaultMethod;
|
||||
constexpr const char* Channel::DefaultAddress;
|
||||
constexpr int Channel::DefaultSndBufSize;
|
||||
constexpr int Channel::DefaultRcvBufSize;
|
||||
constexpr int Channel::DefaultSndKernelSize;
|
||||
constexpr int Channel::DefaultRcvKernelSize;
|
||||
constexpr int Channel::DefaultLinger;
|
||||
constexpr int Channel::DefaultRateLogging;
|
||||
constexpr int Channel::DefaultPortRangeMin;
|
||||
constexpr int Channel::DefaultPortRangeMax;
|
||||
constexpr bool Channel::DefaultAutoBind;
|
||||
|
||||
FairMQChannel::FairMQChannel()
|
||||
: FairMQChannel(DefaultName, DefaultType, DefaultMethod, DefaultAddress, nullptr)
|
||||
Channel::Channel()
|
||||
: Channel(DefaultName, DefaultType, DefaultMethod, DefaultAddress, nullptr)
|
||||
{}
|
||||
|
||||
FairMQChannel::FairMQChannel(const string& name)
|
||||
: FairMQChannel(name, DefaultType, DefaultMethod, DefaultAddress, nullptr)
|
||||
Channel::Channel(const string& name)
|
||||
: Channel(name, DefaultType, DefaultMethod, DefaultAddress, nullptr)
|
||||
{}
|
||||
|
||||
FairMQChannel::FairMQChannel(const string& type, const string& method, const string& address)
|
||||
: FairMQChannel(DefaultName, type, method, address, nullptr)
|
||||
Channel::Channel(const string& type, const string& method, const string& address)
|
||||
: Channel(DefaultName, type, method, address, nullptr)
|
||||
{}
|
||||
|
||||
FairMQChannel::FairMQChannel(const string& name, const string& type, shared_ptr<FairMQTransportFactory> factory)
|
||||
: FairMQChannel(name, type, DefaultMethod, DefaultAddress, factory)
|
||||
Channel::Channel(const string& name, const string& type, shared_ptr<TransportFactory> factory)
|
||||
: Channel(name, type, DefaultMethod, DefaultAddress, factory)
|
||||
{}
|
||||
|
||||
FairMQChannel::FairMQChannel(const string& name, const string& type, const string& method, const string& address, shared_ptr<FairMQTransportFactory> factory)
|
||||
Channel::Channel(string name, string type, string method, string address, shared_ptr<TransportFactory> factory)
|
||||
: fTransportFactory(factory)
|
||||
, fTransportType(factory ? factory->GetType() : DefaultTransportType)
|
||||
, fSocket(factory ? factory->CreateSocket(type, name) : nullptr)
|
||||
, fName(name)
|
||||
, fType(type)
|
||||
, fMethod(method)
|
||||
, fAddress(address)
|
||||
, fName(std::move(name))
|
||||
, fType(std::move(type))
|
||||
, fMethod(std::move(method))
|
||||
, fAddress(std::move(address))
|
||||
, fSndBufSize(DefaultSndBufSize)
|
||||
, fRcvBufSize(DefaultRcvBufSize)
|
||||
, fSndKernelSize(DefaultSndKernelSize)
|
||||
@@ -87,8 +84,8 @@ FairMQChannel::FairMQChannel(const string& name, const string& type, const strin
|
||||
// LOG(warn) << "Constructing channel '" << fName << "'";
|
||||
}
|
||||
|
||||
FairMQChannel::FairMQChannel(const string& name, int index, const fair::mq::Properties& properties)
|
||||
: FairMQChannel(tools::ToString(name, "[", index, "]"), "unspecified", "unspecified", "unspecified", nullptr)
|
||||
Channel::Channel(const string& name, int index, const Properties& properties)
|
||||
: Channel(tools::ToString(name, "[", index, "]"), "unspecified", "unspecified", "unspecified", nullptr)
|
||||
{
|
||||
string prefix(tools::ToString("chans.", name, ".", index, "."));
|
||||
|
||||
@@ -107,15 +104,15 @@ FairMQChannel::FairMQChannel(const string& name, int index, const fair::mq::Prop
|
||||
fAutoBind = GetPropertyOrDefault(properties, string(prefix + "autoBind"), DefaultAutoBind);
|
||||
}
|
||||
|
||||
FairMQChannel::FairMQChannel(const FairMQChannel& chan)
|
||||
: FairMQChannel(chan, chan.fName)
|
||||
Channel::Channel(const Channel& chan)
|
||||
: Channel(chan, chan.fName)
|
||||
{}
|
||||
|
||||
FairMQChannel::FairMQChannel(const FairMQChannel& chan, const string& newName)
|
||||
Channel::Channel(const Channel& chan, string newName)
|
||||
: fTransportFactory(nullptr)
|
||||
, fTransportType(chan.fTransportType)
|
||||
, fSocket(nullptr)
|
||||
, fName(newName)
|
||||
, fName(std::move(newName))
|
||||
, fType(chan.fType)
|
||||
, fMethod(chan.fMethod)
|
||||
, fAddress(chan.fAddress)
|
||||
@@ -132,7 +129,7 @@ FairMQChannel::FairMQChannel(const FairMQChannel& chan, const string& newName)
|
||||
, fMultipart(chan.fMultipart)
|
||||
{}
|
||||
|
||||
FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan)
|
||||
Channel& Channel::operator=(const Channel& chan)
|
||||
{
|
||||
if (this == &chan) {
|
||||
return *this;
|
||||
@@ -160,7 +157,7 @@ FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool FairMQChannel::Validate()
|
||||
bool Channel::Validate()
|
||||
try {
|
||||
stringstream ss;
|
||||
ss << "Validating channel '" << fName << "'... ";
|
||||
@@ -190,7 +187,7 @@ try {
|
||||
}
|
||||
|
||||
// validate socket address
|
||||
if (fAddress == "unspecified" || fAddress == "") {
|
||||
if (fAddress == "unspecified" || fAddress.empty()) {
|
||||
ss << "INVALID";
|
||||
LOG(debug) << ss.str();
|
||||
LOG(debug) << "invalid channel address: '" << fAddress << "'";
|
||||
@@ -226,7 +223,7 @@ try {
|
||||
} else if (address.compare(0, 6, "ipc://") == 0) {
|
||||
// check if IPC address is not empty
|
||||
string addressString = address.substr(6);
|
||||
if (addressString == "") {
|
||||
if (addressString.empty()) {
|
||||
ss << "INVALID";
|
||||
LOG(debug) << ss.str();
|
||||
LOG(error) << "invalid channel address: '" << address << "' (empty IPC address?)";
|
||||
@@ -235,7 +232,7 @@ try {
|
||||
} else if (address.compare(0, 9, "inproc://") == 0) {
|
||||
// check if IPC address is not empty
|
||||
string addressString = address.substr(9);
|
||||
if (addressString == "") {
|
||||
if (addressString.empty()) {
|
||||
ss << "INVALID";
|
||||
LOG(debug) << ss.str();
|
||||
LOG(error) << "invalid channel address: '" << address << "' (empty inproc address?)";
|
||||
@@ -244,7 +241,7 @@ try {
|
||||
} else if (address.compare(0, 8, "verbs://") == 0) {
|
||||
// check if IPC address is not empty
|
||||
string addressString = address.substr(8);
|
||||
if (addressString == "") {
|
||||
if (addressString.empty()) {
|
||||
ss << "INVALID";
|
||||
LOG(debug) << ss.str();
|
||||
LOG(error) << "invalid channel address: '" << address << "' (empty verbs address?)";
|
||||
@@ -305,11 +302,11 @@ try {
|
||||
LOG(debug) << ss.str();
|
||||
return true;
|
||||
} catch (exception& e) {
|
||||
LOG(error) << "Exception caught in FairMQChannel::ValidateChannel: " << e.what();
|
||||
LOG(error) << "Exception caught in Channel::ValidateChannel: " << e.what();
|
||||
throw ChannelConfigurationError(tools::ToString(e.what()));
|
||||
}
|
||||
|
||||
void FairMQChannel::Init()
|
||||
void Channel::Init()
|
||||
{
|
||||
fSocket = fTransportFactory->CreateSocket(fType, fName);
|
||||
|
||||
@@ -329,12 +326,12 @@ void FairMQChannel::Init()
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQChannel::ConnectEndpoint(const string& endpoint)
|
||||
bool Channel::ConnectEndpoint(const string& endpoint)
|
||||
{
|
||||
return fSocket->Connect(endpoint);
|
||||
}
|
||||
|
||||
bool FairMQChannel::BindEndpoint(string& endpoint)
|
||||
bool Channel::BindEndpoint(string& endpoint)
|
||||
{
|
||||
// try to bind to the configured port. If it fails, try random one (if AutoBind is on).
|
||||
if (fSocket->Bind(endpoint)) {
|
||||
@@ -374,5 +371,6 @@ bool FairMQChannel::BindEndpoint(string& endpoint)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace fair::mq
|
469
fairmq/Channel.h
Normal file
469
fairmq/Channel.h
Normal file
@@ -0,0 +1,469 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_CHANNEL_H
|
||||
#define FAIR_MQ_CHANNEL_H
|
||||
|
||||
#include <fairmq/Message.h>
|
||||
#include <fairmq/Parts.h>
|
||||
#include <fairmq/Properties.h>
|
||||
#include <fairmq/Socket.h>
|
||||
#include <fairmq/TransportFactory.h>
|
||||
#include <fairmq/Transports.h>
|
||||
#include <fairmq/UnmanagedRegion.h>
|
||||
|
||||
#include <cstdint> // int64_t
|
||||
#include <memory> // unique_ptr, shared_ptr
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility> // std::move
|
||||
#include <vector>
|
||||
|
||||
namespace fair::mq {
|
||||
|
||||
/**
|
||||
* @class Channel Channel.h <fairmq/Channel.h>
|
||||
* @brief Wrapper class for Socket and related methods
|
||||
*
|
||||
* The class is not thread-safe.
|
||||
*/
|
||||
class Channel
|
||||
{
|
||||
friend class Device;
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
Channel();
|
||||
|
||||
/// Constructor
|
||||
/// @param name Channel name
|
||||
Channel(const std::string& name);
|
||||
|
||||
/// Constructor
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
/// @param method Socket method (bind/connect)
|
||||
/// @param address Network address to bind/connect to (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
Channel(const std::string& type, const std::string& method, const std::string& address);
|
||||
|
||||
/// Constructor
|
||||
/// @param name Channel name
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
/// @param factory TransportFactory
|
||||
Channel(const std::string& name, const std::string& type, std::shared_ptr<TransportFactory> factory);
|
||||
|
||||
/// Constructor
|
||||
/// @param name Channel name
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
/// @param method Socket method (bind/connect)
|
||||
/// @param address Network address to bind/connect to (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
/// @param factory TransportFactory
|
||||
Channel(std::string name, std::string type, std::string method, std::string address, std::shared_ptr<TransportFactory> factory);
|
||||
|
||||
Channel(const std::string& name, int index, const Properties& properties);
|
||||
|
||||
/// Copy Constructor
|
||||
Channel(const Channel&);
|
||||
|
||||
/// Copy Constructor (with new name)
|
||||
Channel(const Channel&, std::string name);
|
||||
|
||||
/// Move constructor
|
||||
Channel(Channel&&) = default;
|
||||
|
||||
/// Assignment operator
|
||||
Channel& operator=(const Channel&);
|
||||
|
||||
/// Move assignment operator
|
||||
Channel& operator=(Channel&&) = default;
|
||||
|
||||
/// Destructor
|
||||
~Channel() = default;
|
||||
// { LOG(warn) << "Destroying channel '" << fName << "'"; }
|
||||
|
||||
struct ChannelConfigurationError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
Socket& GetSocket() const
|
||||
{
|
||||
assert(fSocket); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
|
||||
return *fSocket;
|
||||
}
|
||||
|
||||
bool Bind(const std::string& address)
|
||||
{
|
||||
fMethod = "bind";
|
||||
fAddress = address;
|
||||
return fSocket->Bind(address);
|
||||
}
|
||||
|
||||
bool Connect(const std::string& address)
|
||||
{
|
||||
fMethod = "connect";
|
||||
fAddress = address;
|
||||
return fSocket->Connect(address);
|
||||
}
|
||||
|
||||
/// Get channel name
|
||||
/// @return Returns full channel name (e.g. "data[0]")
|
||||
std::string GetName() const { return fName; }
|
||||
|
||||
/// Get channel prefix
|
||||
/// @return Returns channel prefix (e.g. "data" in "data[0]")
|
||||
std::string GetPrefix() const
|
||||
{
|
||||
std::string prefix = fName;
|
||||
prefix = prefix.erase(fName.rfind('['));
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/// Get channel index
|
||||
/// @return Returns channel index (e.g. 0 in "data[0]")
|
||||
std::string GetIndex() const
|
||||
{
|
||||
std::string indexStr = fName;
|
||||
indexStr.erase(indexStr.rfind(']'));
|
||||
indexStr.erase(0, indexStr.rfind('[') + 1);
|
||||
return indexStr;
|
||||
}
|
||||
|
||||
/// Get socket type
|
||||
/// @return Returns socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
std::string GetType() const { return fType; }
|
||||
|
||||
/// Get socket method
|
||||
/// @return Returns socket method (bind/connect)
|
||||
std::string GetMethod() const { return fMethod; }
|
||||
|
||||
/// Get socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
/// @return Returns socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
std::string GetAddress() const { return fAddress; }
|
||||
|
||||
/// Get channel transport name ("default", "zeromq" or "shmem")
|
||||
/// @return Returns channel transport name (e.g. "default", "zeromq" or "shmem")
|
||||
std::string GetTransportName() const { return TransportName(fTransportType); }
|
||||
|
||||
/// Get channel transport type
|
||||
/// @return Returns channel transport type
|
||||
mq::Transport GetTransportType() const { return fTransportType; }
|
||||
|
||||
/// Get socket send buffer size (in number of messages)
|
||||
/// @return Returns socket send buffer size (in number of messages)
|
||||
int GetSndBufSize() const { return fSndBufSize; }
|
||||
|
||||
/// Get socket receive buffer size (in number of messages)
|
||||
/// @return Returns socket receive buffer size (in number of messages)
|
||||
int GetRcvBufSize() const { return fRcvBufSize; }
|
||||
|
||||
/// Get socket kernel transmit send buffer size (in bytes)
|
||||
/// @return Returns socket kernel transmit send buffer size (in bytes)
|
||||
int GetSndKernelSize() const { return fSndKernelSize; }
|
||||
|
||||
/// Get socket kernel transmit receive buffer size (in bytes)
|
||||
/// @return Returns socket kernel transmit receive buffer size (in bytes)
|
||||
int GetRcvKernelSize() const { return fRcvKernelSize; }
|
||||
|
||||
/// Get linger duration (in milliseconds)
|
||||
/// @return Returns linger duration (in milliseconds)
|
||||
int GetLinger() const { return fLinger; }
|
||||
|
||||
/// Get socket rate logging interval (in seconds)
|
||||
/// @return Returns socket rate logging interval (in seconds)
|
||||
int GetRateLogging() const { return fRateLogging; }
|
||||
|
||||
/// Get start of the port range for automatic binding
|
||||
/// @return start of the port range
|
||||
int GetPortRangeMin() const { return fPortRangeMin; }
|
||||
|
||||
/// Get end of the port range for automatic binding
|
||||
/// @return end of the port range
|
||||
int GetPortRangeMax() const { return fPortRangeMax; }
|
||||
|
||||
/// Set automatic binding (pick random port if bind fails)
|
||||
/// @return true/false, true if automatic binding is enabled
|
||||
bool GetAutoBind() const { return fAutoBind; }
|
||||
|
||||
/// @par Thread Safety
|
||||
/// * @e Distinct @e objects: Safe.@n
|
||||
/// * @e Shared @e objects: Unsafe.
|
||||
auto GetNumberOfConnectedPeers() const
|
||||
{
|
||||
return fSocket ? fSocket->GetNumberOfConnectedPeers() : 0;
|
||||
}
|
||||
|
||||
/// Set channel name
|
||||
/// @param name Arbitrary channel name
|
||||
void UpdateName(const std::string& name) { fName = name; Invalidate(); }
|
||||
|
||||
/// Set socket type
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
void UpdateType(const std::string& type) { fType = type; Invalidate(); }
|
||||
|
||||
/// Set socket method
|
||||
/// @param method Socket method (bind/connect)
|
||||
void UpdateMethod(const std::string& method) { fMethod = method; Invalidate(); }
|
||||
|
||||
/// Set socket address
|
||||
/// @param Socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
void UpdateAddress(const std::string& address) { fAddress = address; Invalidate(); }
|
||||
|
||||
/// Set channel transport
|
||||
/// @param transport transport string ("default", "zeromq" or "shmem")
|
||||
void UpdateTransport(const std::string& transport) { fTransportType = TransportType(transport); Invalidate(); }
|
||||
|
||||
/// Set socket send buffer size
|
||||
/// @param sndBufSize Socket send buffer size (in number of messages)
|
||||
void UpdateSndBufSize(int sndBufSize) { fSndBufSize = sndBufSize; Invalidate(); }
|
||||
|
||||
/// Set socket receive buffer size
|
||||
/// @param rcvBufSize Socket receive buffer size (in number of messages)
|
||||
void UpdateRcvBufSize(int rcvBufSize) { fRcvBufSize = rcvBufSize; Invalidate(); }
|
||||
|
||||
/// Set socket kernel transmit send buffer size (in bytes)
|
||||
/// @param sndKernelSize Socket send buffer size (in bytes)
|
||||
void UpdateSndKernelSize(int sndKernelSize) { fSndKernelSize = sndKernelSize; Invalidate(); }
|
||||
|
||||
/// Set socket kernel transmit receive buffer size (in bytes)
|
||||
/// @param rcvKernelSize Socket receive buffer size (in bytes)
|
||||
void UpdateRcvKernelSize(int rcvKernelSize) { fRcvKernelSize = rcvKernelSize; Invalidate(); }
|
||||
|
||||
/// Set linger duration (in milliseconds)
|
||||
/// @param duration linger duration (in milliseconds)
|
||||
void UpdateLinger(int duration) { fLinger = duration; Invalidate(); }
|
||||
|
||||
/// Set socket rate logging interval (in seconds)
|
||||
/// @param rateLogging Socket rate logging interval (in seconds)
|
||||
void UpdateRateLogging(int rateLogging) { fRateLogging = rateLogging; Invalidate(); }
|
||||
|
||||
/// Set start of the port range for automatic binding
|
||||
/// @param minPort start of the port range
|
||||
void UpdatePortRangeMin(int minPort) { fPortRangeMin = minPort; Invalidate(); }
|
||||
|
||||
/// Set end of the port range for automatic binding
|
||||
/// @param maxPort end of the port range
|
||||
void UpdatePortRangeMax(int maxPort) { fPortRangeMax = maxPort; Invalidate(); }
|
||||
|
||||
/// Set automatic binding (pick random port if bind fails)
|
||||
/// @param autobind true/false, true to enable automatic binding
|
||||
void UpdateAutoBind(bool autobind) { fAutoBind = autobind; Invalidate(); }
|
||||
|
||||
/// Checks if the configured channel settings are valid (checks the validity parameter, without running full validation (as oposed to ValidateChannel()))
|
||||
/// @return true if channel settings are valid, false otherwise.
|
||||
bool IsValid() const { return fValid; }
|
||||
|
||||
/// Validates channel configuration
|
||||
/// @return true if channel settings are valid, false otherwise.
|
||||
bool Validate();
|
||||
|
||||
void Init();
|
||||
|
||||
bool ConnectEndpoint(const std::string& endpoint);
|
||||
|
||||
bool BindEndpoint(std::string& endpoint);
|
||||
|
||||
/// invalidates the channel (requires validation to be used again).
|
||||
void Invalidate() { fValid = false; }
|
||||
|
||||
/// Sends a message to the socket queue.
|
||||
/// @param msg Constant reference of unique_ptr to a Message
|
||||
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(MessagePtr& msg, int sndTimeoutInMs = -1)
|
||||
{
|
||||
CheckSendCompatibility(msg);
|
||||
return fSocket->Send(msg, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Receives a message from the socket queue.
|
||||
/// @param msg Constant reference of unique_ptr to a Message
|
||||
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(MessagePtr& msg, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
CheckReceiveCompatibility(msg);
|
||||
return fSocket->Receive(msg, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Send a vector of messages
|
||||
/// @param msgVec message vector reference
|
||||
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(std::vector<MessagePtr>& msgVec, int sndTimeoutInMs = -1)
|
||||
{
|
||||
CheckSendCompatibility(msgVec);
|
||||
return fSocket->Send(msgVec, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Receive a vector of messages
|
||||
/// @param msgVec message vector reference
|
||||
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(std::vector<MessagePtr>& msgVec, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
CheckReceiveCompatibility(msgVec);
|
||||
return fSocket->Receive(msgVec, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Send Parts
|
||||
/// @param parts Parts reference
|
||||
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(Parts& parts, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return Send(parts.fParts, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Receive Parts
|
||||
/// @param parts Parts reference
|
||||
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(Parts& parts, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return Receive(parts.fParts, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
unsigned long GetBytesTx() const { return fSocket->GetBytesTx(); }
|
||||
unsigned long GetBytesRx() const { return fSocket->GetBytesRx(); }
|
||||
unsigned long GetMessagesTx() const { return fSocket->GetMessagesTx(); }
|
||||
unsigned long GetMessagesRx() const { return fSocket->GetMessagesRx(); }
|
||||
|
||||
auto Transport() -> TransportFactory* { return fTransportFactory.get(); };
|
||||
|
||||
template<typename... Args>
|
||||
MessagePtr NewMessage(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
MessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
MessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewStaticMessage(data);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
UnmanagedRegionPtr NewUnmanagedRegion(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateUnmanagedRegion(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static constexpr mq::Transport DefaultTransportType = mq::Transport::DEFAULT;
|
||||
static constexpr const char* DefaultTransportName = "default";
|
||||
static constexpr const char* DefaultName = "";
|
||||
static constexpr const char* DefaultType = "unspecified";
|
||||
static constexpr const char* DefaultMethod = "unspecified";
|
||||
static constexpr const char* DefaultAddress = "unspecified";
|
||||
static constexpr int DefaultSndBufSize = 1000;
|
||||
static constexpr int DefaultRcvBufSize = 1000;
|
||||
static constexpr int DefaultSndKernelSize = 0;
|
||||
static constexpr int DefaultRcvKernelSize = 0;
|
||||
static constexpr int DefaultLinger = 500;
|
||||
static constexpr int DefaultRateLogging = 1;
|
||||
static constexpr int DefaultPortRangeMin = 22000;
|
||||
static constexpr int DefaultPortRangeMax = 23000;
|
||||
static constexpr bool DefaultAutoBind = true;
|
||||
|
||||
private:
|
||||
std::shared_ptr<TransportFactory> fTransportFactory;
|
||||
mq::Transport fTransportType;
|
||||
std::unique_ptr<Socket> fSocket;
|
||||
|
||||
std::string fName;
|
||||
std::string fType;
|
||||
std::string fMethod;
|
||||
std::string fAddress;
|
||||
int fSndBufSize;
|
||||
int fRcvBufSize;
|
||||
int fSndKernelSize;
|
||||
int fRcvKernelSize;
|
||||
int fLinger;
|
||||
int fRateLogging;
|
||||
int fPortRangeMin;
|
||||
int fPortRangeMax;
|
||||
bool fAutoBind;
|
||||
|
||||
bool fValid;
|
||||
|
||||
bool fMultipart;
|
||||
|
||||
void CheckSendCompatibility(MessagePtr& msg)
|
||||
{
|
||||
if (fTransportType != msg->GetType()) {
|
||||
if (msg->GetSize() > 0) {
|
||||
MessagePtr msgWrapper(NewMessage(
|
||||
msg->GetData(),
|
||||
msg->GetSize(),
|
||||
[](void* /*data*/, void* _msg) { delete static_cast<Message*>(_msg); },
|
||||
msg.get()
|
||||
));
|
||||
msg.release();
|
||||
msg = move(msgWrapper);
|
||||
} else {
|
||||
MessagePtr newMsg(NewMessage());
|
||||
msg = move(newMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckSendCompatibility(std::vector<MessagePtr>& msgVec)
|
||||
{
|
||||
for (auto& msg : msgVec) {
|
||||
if (fTransportType != msg->GetType()) {
|
||||
if (msg->GetSize() > 0) {
|
||||
MessagePtr msgWrapper(NewMessage(
|
||||
msg->GetData(),
|
||||
msg->GetSize(),
|
||||
[](void* /*data*/, void* _msg) { delete static_cast<Message*>(_msg); },
|
||||
msg.get()
|
||||
));
|
||||
msg.release();
|
||||
msg = move(msgWrapper);
|
||||
} else {
|
||||
MessagePtr newMsg(NewMessage());
|
||||
msg = move(newMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckReceiveCompatibility(MessagePtr& msg)
|
||||
{
|
||||
if (fTransportType != msg->GetType()) {
|
||||
MessagePtr newMsg(NewMessage());
|
||||
msg = move(newMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckReceiveCompatibility(std::vector<MessagePtr>& msgVec)
|
||||
{
|
||||
for (auto& msg : msgVec) {
|
||||
if (fTransportType != msg->GetType()) {
|
||||
|
||||
MessagePtr newMsg(NewMessage());
|
||||
msg = move(newMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitTransport(std::shared_ptr<TransportFactory> factory)
|
||||
{
|
||||
fTransportFactory = factory;
|
||||
fTransportType = factory->GetType();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fair::mq
|
||||
|
||||
// using FairMQChannel [[deprecated("Use fair::mq::Channel")]] = fair::mq::Channel;
|
||||
using FairMQChannel = fair::mq::Channel;
|
||||
|
||||
#endif // FAIR_MQ_CHANNEL_H
|
@@ -1,101 +1,90 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2012-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2012-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
|
||||
#include <fairmq/tools/RateLimit.h>
|
||||
#include <fairmq/tools/Network.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
|
||||
#include <list>
|
||||
#include <algorithm> // std::max
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
#include <chrono>
|
||||
#include <fairmq/Device.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <future>
|
||||
#include <iomanip>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <iomanip>
|
||||
#include <future>
|
||||
#include <algorithm> // std::max
|
||||
|
||||
namespace fair::mq {
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
constexpr const char* FairMQDevice::DefaultId;
|
||||
constexpr int FairMQDevice::DefaultIOThreads;
|
||||
constexpr const char* FairMQDevice::DefaultTransportName;
|
||||
constexpr fair::mq::Transport FairMQDevice::DefaultTransportType;
|
||||
constexpr const char* FairMQDevice::DefaultNetworkInterface;
|
||||
constexpr int FairMQDevice::DefaultInitTimeout;
|
||||
constexpr uint64_t FairMQDevice::DefaultMaxRunTime;
|
||||
constexpr float FairMQDevice::DefaultRate;
|
||||
constexpr const char* FairMQDevice::DefaultSession;
|
||||
constexpr const char* Device::DefaultId;
|
||||
constexpr int Device::DefaultIOThreads;
|
||||
constexpr const char* Device::DefaultTransportName;
|
||||
constexpr mq::Transport Device::DefaultTransportType;
|
||||
constexpr const char* Device::DefaultNetworkInterface;
|
||||
constexpr int Device::DefaultInitTimeout;
|
||||
constexpr uint64_t Device::DefaultMaxRunTime;
|
||||
constexpr float Device::DefaultRate;
|
||||
constexpr const char* Device::DefaultSession;
|
||||
|
||||
struct StateSubscription
|
||||
{
|
||||
fair::mq::StateMachine& fStateMachine;
|
||||
fair::mq::StateQueue& fStateQueue;
|
||||
StateMachine& fStateMachine;
|
||||
StateQueue& fStateQueue;
|
||||
string fId;
|
||||
|
||||
explicit StateSubscription(const string& id, fair::mq::StateMachine& stateMachine, fair::mq::StateQueue& stateQueue)
|
||||
explicit StateSubscription(string id, StateMachine& stateMachine, StateQueue& stateQueue)
|
||||
: fStateMachine(stateMachine)
|
||||
, fStateQueue(stateQueue)
|
||||
, fId(id)
|
||||
, fId(std::move(id))
|
||||
{
|
||||
fStateMachine.SubscribeToStateChange(fId, [&](fair::mq::State state) {
|
||||
fStateMachine.SubscribeToStateChange(fId, [&](State state) {
|
||||
fStateQueue.Push(state);
|
||||
});
|
||||
}
|
||||
|
||||
StateSubscription(const StateSubscription&) = delete;
|
||||
StateSubscription(StateSubscription&&) = delete;
|
||||
StateSubscription& operator=(const StateSubscription&) = delete;
|
||||
StateSubscription& operator=(StateSubscription&&) = delete;
|
||||
|
||||
~StateSubscription() {
|
||||
fStateMachine.UnsubscribeFromStateChange(fId);
|
||||
}
|
||||
};
|
||||
|
||||
FairMQDevice::FairMQDevice()
|
||||
: FairMQDevice(nullptr, {0, 0, 0})
|
||||
Device::Device()
|
||||
: Device(nullptr, {0, 0, 0})
|
||||
{}
|
||||
|
||||
FairMQDevice::FairMQDevice(ProgOptions& config)
|
||||
: FairMQDevice(&config, {0, 0, 0})
|
||||
Device::Device(ProgOptions& config)
|
||||
: Device(&config, {0, 0, 0})
|
||||
{}
|
||||
|
||||
FairMQDevice::FairMQDevice(const tools::Version version)
|
||||
: FairMQDevice(nullptr, version)
|
||||
Device::Device(tools::Version version)
|
||||
: Device(nullptr, version)
|
||||
{}
|
||||
|
||||
FairMQDevice::FairMQDevice(ProgOptions& config, const tools::Version version)
|
||||
: FairMQDevice(&config, version)
|
||||
Device::Device(ProgOptions& config, tools::Version version)
|
||||
: Device(&config, version)
|
||||
{}
|
||||
|
||||
FairMQDevice::FairMQDevice(ProgOptions* config, const tools::Version version)
|
||||
Device::Device(ProgOptions* config, tools::Version version)
|
||||
: fTransportFactory(nullptr)
|
||||
, fTransports()
|
||||
, fChannels()
|
||||
, fInternalConfig(config ? nullptr : make_unique<ProgOptions>())
|
||||
, fConfig(config ? config : fInternalConfig.get())
|
||||
, fId(DefaultId)
|
||||
, fDefaultTransportType(DefaultTransportType)
|
||||
, fStateMachine()
|
||||
, fUninitializedBindingChannels()
|
||||
, fUninitializedConnectingChannels()
|
||||
, fDataCallbacks(false)
|
||||
, fMsgInputs()
|
||||
, fMultipartInputs()
|
||||
, fMultitransportInputs()
|
||||
, fChannelRegistry()
|
||||
, fInputChannelKeys()
|
||||
, fMultitransportMutex()
|
||||
, fMultitransportProceed(false)
|
||||
, fVersion(version)
|
||||
, fRate(DefaultRate)
|
||||
, fMaxRunRuntimeInS(DefaultMaxRunTime)
|
||||
, fInitializationTimeoutInS(DefaultInitTimeout)
|
||||
, fRawCmdLineArgs()
|
||||
, fTransitionMtx()
|
||||
, fTransitioning(false)
|
||||
{
|
||||
SubscribeToNewTransition("device", [&](Transition transition) {
|
||||
@@ -110,34 +99,34 @@ FairMQDevice::FairMQDevice(ProgOptions* config, const tools::Version version)
|
||||
}
|
||||
});
|
||||
|
||||
fStateMachine.HandleStates([&](fair::mq::State state) {
|
||||
fStateMachine.HandleStates([&](State state) {
|
||||
LOG(trace) << "device notified on new state: " << state;
|
||||
|
||||
fStateQueue.Push(state);
|
||||
|
||||
switch (state) {
|
||||
case fair::mq::State::InitializingDevice:
|
||||
case State::InitializingDevice:
|
||||
InitWrapper();
|
||||
break;
|
||||
case fair::mq::State::Binding:
|
||||
case State::Binding:
|
||||
BindWrapper();
|
||||
break;
|
||||
case fair::mq::State::Connecting:
|
||||
case State::Connecting:
|
||||
ConnectWrapper();
|
||||
break;
|
||||
case fair::mq::State::InitializingTask:
|
||||
case State::InitializingTask:
|
||||
InitTaskWrapper();
|
||||
break;
|
||||
case fair::mq::State::Running:
|
||||
case State::Running:
|
||||
RunWrapper();
|
||||
break;
|
||||
case fair::mq::State::ResettingTask:
|
||||
case State::ResettingTask:
|
||||
ResetTaskWrapper();
|
||||
break;
|
||||
case fair::mq::State::ResettingDevice:
|
||||
case State::ResettingDevice:
|
||||
ResetWrapper();
|
||||
break;
|
||||
case fair::mq::State::Exiting:
|
||||
case State::Exiting:
|
||||
Exit();
|
||||
break;
|
||||
default:
|
||||
@@ -149,7 +138,7 @@ FairMQDevice::FairMQDevice(ProgOptions* config, const tools::Version version)
|
||||
fStateMachine.Start();
|
||||
}
|
||||
|
||||
void FairMQDevice::TransitionTo(const fair::mq::State s)
|
||||
void Device::TransitionTo(State s)
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock(fTransitionMtx);
|
||||
@@ -160,7 +149,7 @@ void FairMQDevice::TransitionTo(const fair::mq::State s)
|
||||
fTransitioning = true;
|
||||
}
|
||||
|
||||
using fair::mq::State;
|
||||
using mq::State;
|
||||
|
||||
StateQueue sq;
|
||||
StateSubscription ss(tools::ToString(fId, ".TransitionTo"), fStateMachine, sq);
|
||||
@@ -216,7 +205,7 @@ void FairMQDevice::TransitionTo(const fair::mq::State s)
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::InitWrapper()
|
||||
void Device::InitWrapper()
|
||||
{
|
||||
// run initialization once CompleteInit transition is requested
|
||||
fStateMachine.WaitForPendingState();
|
||||
@@ -230,7 +219,7 @@ void FairMQDevice::InitWrapper()
|
||||
fInitializationTimeoutInS = fConfig->GetProperty<int>("init-timeout", DefaultInitTimeout);
|
||||
|
||||
try {
|
||||
fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetProperty<string>("transport", DefaultTransportName));
|
||||
fDefaultTransportType = TransportTypes.at(fConfig->GetProperty<string>("transport", DefaultTransportName));
|
||||
} catch (const exception& e) {
|
||||
LOG(error) << "exception: " << e.what();
|
||||
LOG(error) << "invalid transport type provided: " << fConfig->GetProperty<string>("transport", "not provided");
|
||||
@@ -244,7 +233,7 @@ void FairMQDevice::InitWrapper()
|
||||
}
|
||||
}
|
||||
|
||||
LOG(debug) << "Setting '" << fair::mq::TransportNames.at(fDefaultTransportType) << "' as default transport for the device";
|
||||
LOG(debug) << "Setting '" << TransportNames.at(fDefaultTransportType) << "' as default transport for the device";
|
||||
fTransportFactory = AddTransport(fDefaultTransportType);
|
||||
|
||||
string networkInterface = fConfig->GetProperty<string>("network-interface", DefaultNetworkInterface);
|
||||
@@ -254,12 +243,12 @@ void FairMQDevice::InitWrapper()
|
||||
int subChannelIndex = 0;
|
||||
for (auto& subChannel : channel.second) {
|
||||
// set channel transport
|
||||
LOG(debug) << "Initializing transport for channel " << subChannel.fName << ": " << fair::mq::TransportNames.at(subChannel.fTransportType);
|
||||
LOG(debug) << "Initializing transport for channel " << subChannel.fName << ": " << TransportNames.at(subChannel.fTransportType);
|
||||
subChannel.InitTransport(AddTransport(subChannel.fTransportType));
|
||||
|
||||
if (subChannel.fMethod == "bind") {
|
||||
// if binding address is not specified, try getting it from the configured network interface
|
||||
if (subChannel.fAddress == "unspecified" || subChannel.fAddress == "") {
|
||||
if (subChannel.fAddress == "unspecified" || subChannel.fAddress.empty()) {
|
||||
// if the configured network interface is default, get its name from the default route
|
||||
try {
|
||||
if (networkInterface == "default") {
|
||||
@@ -291,7 +280,7 @@ void FairMQDevice::InitWrapper()
|
||||
// ChangeState(Transition::Auto);
|
||||
}
|
||||
|
||||
void FairMQDevice::BindWrapper()
|
||||
void Device::BindWrapper()
|
||||
{
|
||||
// Bind channels. Here one run is enough, because bind settings should be available locally
|
||||
// If necessary this could be handled in the same way as the connecting channels
|
||||
@@ -307,7 +296,7 @@ void FairMQDevice::BindWrapper()
|
||||
ChangeState(Transition::Auto);
|
||||
}
|
||||
|
||||
void FairMQDevice::ConnectWrapper()
|
||||
void Device::ConnectWrapper()
|
||||
{
|
||||
// go over the list of channels until all are initialized (and removed from the uninitialized list)
|
||||
int numAttempts = 1;
|
||||
@@ -344,7 +333,7 @@ void FairMQDevice::ConnectWrapper()
|
||||
ChangeState(Transition::Auto);
|
||||
}
|
||||
|
||||
void FairMQDevice::AttachChannels(vector<FairMQChannel*>& chans)
|
||||
void Device::AttachChannels(vector<Channel*>& chans)
|
||||
{
|
||||
auto itr = chans.begin();
|
||||
|
||||
@@ -364,7 +353,7 @@ void FairMQDevice::AttachChannels(vector<FairMQChannel*>& chans)
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQDevice::AttachChannel(FairMQChannel& chan)
|
||||
bool Device::AttachChannel(Channel& chan)
|
||||
{
|
||||
vector<string> endpoints;
|
||||
string chanAddress = chan.GetAddress();
|
||||
@@ -394,7 +383,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& chan)
|
||||
if (!(bind && hostPart == "*")) {
|
||||
string portPart = addressString.substr(pos + 1);
|
||||
string resolvedHost = tools::getIpFromHostname(hostPart);
|
||||
if (resolvedHost == "") {
|
||||
if (resolvedHost.empty()) {
|
||||
return false;
|
||||
}
|
||||
address.assign("tcp://" + resolvedHost + ":" + portPart);
|
||||
@@ -437,19 +426,19 @@ bool FairMQDevice::AttachChannel(FairMQChannel& chan)
|
||||
return true;
|
||||
}
|
||||
|
||||
void FairMQDevice::InitTaskWrapper()
|
||||
void Device::InitTaskWrapper()
|
||||
{
|
||||
InitTask();
|
||||
|
||||
ChangeState(Transition::Auto);
|
||||
}
|
||||
|
||||
void FairMQDevice::RunWrapper()
|
||||
void Device::RunWrapper()
|
||||
{
|
||||
LOG(info) << "DEVICE: Running...";
|
||||
|
||||
// start the rate logger thread
|
||||
future<void> rateLogger = async(launch::async, &FairMQDevice::LogSocketRates, this);
|
||||
future<void> rateLogger = async(launch::async, &Device::LogSocketRates, this);
|
||||
|
||||
// notify transports to resume transfers
|
||||
for (auto& t : fTransports) {
|
||||
@@ -499,29 +488,29 @@ void FairMQDevice::RunWrapper()
|
||||
rateLogger.get();
|
||||
}
|
||||
|
||||
void FairMQDevice::HandleSingleChannelInput()
|
||||
void Device::HandleSingleChannelInput()
|
||||
{
|
||||
bool proceed = true;
|
||||
|
||||
if (fMsgInputs.size() > 0) {
|
||||
if (!fMsgInputs.empty()) {
|
||||
while (!NewStatePending() && proceed) {
|
||||
proceed = HandleMsgInput(fInputChannelKeys.at(0), fMsgInputs.begin()->second, 0);
|
||||
}
|
||||
} else if (fMultipartInputs.size() > 0) {
|
||||
} else if (!fMultipartInputs.empty()) {
|
||||
while (!NewStatePending() && proceed) {
|
||||
proceed = HandleMultipartInput(fInputChannelKeys.at(0), fMultipartInputs.begin()->second, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::HandleMultipleChannelInput()
|
||||
void Device::HandleMultipleChannelInput()
|
||||
{
|
||||
// check if more than one transport is used
|
||||
fMultitransportInputs.clear();
|
||||
for (const auto& k : fInputChannelKeys) {
|
||||
fair::mq::Transport t = fChannels.at(k).at(0).fTransportType;
|
||||
mq::Transport t = fChannels.at(k).at(0).fTransportType;
|
||||
if (fMultitransportInputs.find(t) == fMultitransportInputs.end()) {
|
||||
fMultitransportInputs.insert(pair<fair::mq::Transport, vector<string>>(t, vector<string>()));
|
||||
fMultitransportInputs.insert(pair<mq::Transport, vector<string>>(t, vector<string>()));
|
||||
fMultitransportInputs.at(t).push_back(k);
|
||||
} else {
|
||||
fMultitransportInputs.at(t).push_back(k);
|
||||
@@ -546,7 +535,7 @@ void FairMQDevice::HandleMultipleChannelInput()
|
||||
} else { // otherwise poll directly
|
||||
bool proceed = true;
|
||||
|
||||
FairMQPollerPtr poller(fChannels.at(fInputChannelKeys.at(0)).at(0).fTransportFactory->CreatePoller(fChannels, fInputChannelKeys));
|
||||
PollerPtr poller(fChannels.at(fInputChannelKeys.at(0)).at(0).fTransportFactory->CreatePoller(fChannels, fInputChannelKeys));
|
||||
|
||||
while (!NewStatePending() && proceed) {
|
||||
poller->Poll(200);
|
||||
@@ -574,14 +563,14 @@ void FairMQDevice::HandleMultipleChannelInput()
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::HandleMultipleTransportInput()
|
||||
void Device::HandleMultipleTransportInput()
|
||||
{
|
||||
vector<thread> threads;
|
||||
|
||||
fMultitransportProceed = true;
|
||||
|
||||
for (const auto& i : fMultitransportInputs) {
|
||||
threads.emplace_back(thread(&FairMQDevice::PollForTransport, this, fTransports.at(i.first).get(), i.second));
|
||||
threads.emplace_back(thread(&Device::PollForTransport, this, fTransports.at(i.first).get(), i.second));
|
||||
}
|
||||
|
||||
for (thread& t : threads) {
|
||||
@@ -589,10 +578,10 @@ void FairMQDevice::HandleMultipleTransportInput()
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::PollForTransport(const FairMQTransportFactory* factory, const vector<string>& channelKeys)
|
||||
void Device::PollForTransport(const TransportFactory* factory, const vector<string>& channelKeys)
|
||||
{
|
||||
try {
|
||||
FairMQPollerPtr poller(factory->CreatePoller(fChannels, channelKeys));
|
||||
PollerPtr poller(factory->CreatePoller(fChannels, channelKeys));
|
||||
|
||||
while (!NewStatePending() && fMultitransportProceed) {
|
||||
poller->Poll(500);
|
||||
@@ -623,14 +612,14 @@ void FairMQDevice::PollForTransport(const FairMQTransportFactory* factory, const
|
||||
}
|
||||
}
|
||||
} catch (exception& e) {
|
||||
LOG(error) << "FairMQDevice::PollForTransport() failed: " << e.what() << ", going to ERROR state.";
|
||||
throw runtime_error(tools::ToString("FairMQDevice::PollForTransport() failed: ", e.what(), ", going to ERROR state."));
|
||||
LOG(error) << "fair::mq::Device::PollForTransport() failed: " << e.what() << ", going to ERROR state.";
|
||||
throw runtime_error(tools::ToString("fair::mq::Device::PollForTransport() failed: ", e.what(), ", going to ERROR state."));
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback& callback, int i)
|
||||
bool Device::HandleMsgInput(const string& chName, const InputMsgCallback& callback, int i)
|
||||
{
|
||||
unique_ptr<FairMQMessage> input(fChannels.at(chName).at(i).fTransportFactory->CreateMessage());
|
||||
unique_ptr<Message> input(fChannels.at(chName).at(i).fTransportFactory->CreateMessage());
|
||||
|
||||
if (Receive(input, chName, i) >= 0) {
|
||||
return callback(input, i);
|
||||
@@ -639,9 +628,9 @@ bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback&
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQDevice::HandleMultipartInput(const string& chName, const InputMultipartCallback& callback, int i)
|
||||
bool Device::HandleMultipartInput(const string& chName, const InputMultipartCallback& callback, int i)
|
||||
{
|
||||
FairMQParts input;
|
||||
Parts input;
|
||||
|
||||
if (Receive(input, chName, i) >= 0) {
|
||||
return callback(input, i);
|
||||
@@ -650,34 +639,34 @@ bool FairMQDevice::HandleMultipartInput(const string& chName, const InputMultipa
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<FairMQTransportFactory> FairMQDevice::AddTransport(fair::mq::Transport transport)
|
||||
shared_ptr<TransportFactory> Device::AddTransport(mq::Transport transport)
|
||||
{
|
||||
if (transport == fair::mq::Transport::DEFAULT) {
|
||||
if (transport == mq::Transport::DEFAULT) {
|
||||
transport = fDefaultTransportType;
|
||||
}
|
||||
|
||||
auto i = fTransports.find(transport);
|
||||
|
||||
if (i == fTransports.end()) {
|
||||
LOG(debug) << "Adding '" << fair::mq::TransportNames.at(transport) << "' transport";
|
||||
auto tr = FairMQTransportFactory::CreateTransportFactory(fair::mq::TransportNames.at(transport), fId, fConfig);
|
||||
LOG(debug) << "Adding '" << TransportNames.at(transport) << "' transport";
|
||||
auto tr = TransportFactory::CreateTransportFactory(TransportNames.at(transport), fId, fConfig);
|
||||
fTransports.insert({transport, tr});
|
||||
return tr;
|
||||
} else {
|
||||
LOG(debug) << "Reusing existing '" << fair::mq::TransportNames.at(transport) << "' transport";
|
||||
LOG(debug) << "Reusing existing '" << TransportNames.at(transport) << "' transport";
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::SetConfig(ProgOptions& config)
|
||||
void Device::SetConfig(ProgOptions& config)
|
||||
{
|
||||
fInternalConfig.reset();
|
||||
fConfig = &config;
|
||||
}
|
||||
|
||||
void FairMQDevice::LogSocketRates()
|
||||
void Device::LogSocketRates()
|
||||
{
|
||||
vector<FairMQChannel*> filteredChannels;
|
||||
vector<Channel*> filteredChannels;
|
||||
vector<string> filteredChannelNames;
|
||||
vector<int> logIntervals;
|
||||
vector<int> intervalCounters;
|
||||
@@ -773,21 +762,21 @@ void FairMQDevice::LogSocketRates()
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::UnblockTransports()
|
||||
void Device::UnblockTransports()
|
||||
{
|
||||
for (auto& transport : fTransports) {
|
||||
transport.second->Interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::ResetTaskWrapper()
|
||||
void Device::ResetTaskWrapper()
|
||||
{
|
||||
ResetTask();
|
||||
|
||||
ChangeState(Transition::Auto);
|
||||
}
|
||||
|
||||
void FairMQDevice::ResetWrapper()
|
||||
void Device::ResetWrapper()
|
||||
{
|
||||
for (auto& transport : fTransports) {
|
||||
transport.second->Reset();
|
||||
@@ -801,9 +790,11 @@ void FairMQDevice::ResetWrapper()
|
||||
ChangeState(Transition::Auto);
|
||||
}
|
||||
|
||||
FairMQDevice::~FairMQDevice()
|
||||
Device::~Device()
|
||||
{
|
||||
UnsubscribeFromNewTransition("device");
|
||||
fStateMachine.StopHandlingStates();
|
||||
LOG(debug) << "Shutting down device " << fId;
|
||||
}
|
||||
|
||||
} // namespace fair::mq
|
634
fairmq/Device.h
634
fairmq/Device.h
@@ -9,13 +9,639 @@
|
||||
#ifndef FAIR_MQ_DEVICE_H
|
||||
#define FAIR_MQ_DEVICE_H
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <algorithm> // find
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <fairmq/Channel.h>
|
||||
#include <fairmq/Message.h>
|
||||
#include <fairmq/Parts.h>
|
||||
#include <fairmq/ProgOptions.h>
|
||||
#include <fairmq/StateMachine.h>
|
||||
#include <fairmq/StateQueue.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <fairmq/TransportFactory.h>
|
||||
#include <fairmq/Transports.h>
|
||||
#include <fairmq/UnmanagedRegion.h>
|
||||
#include <functional>
|
||||
#include <memory> // unique_ptr
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility> // pair
|
||||
#include <vector>
|
||||
|
||||
namespace fair::mq
|
||||
namespace fair::mq {
|
||||
|
||||
using ChannelMap = std::unordered_map<std::string, std::vector<Channel>>;
|
||||
|
||||
struct OngoingTransition : std::runtime_error
|
||||
{
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
using Device = ::FairMQDevice;
|
||||
using InputMsgCallback = std::function<bool(MessagePtr&, int)>;
|
||||
|
||||
} // namespace fair::mq
|
||||
using InputMultipartCallback = std::function<bool(Parts&, int)>;
|
||||
|
||||
class Device
|
||||
{
|
||||
friend class Channel;
|
||||
|
||||
public:
|
||||
Device();
|
||||
Device(ProgOptions& config);
|
||||
Device(tools::Version version);
|
||||
Device(ProgOptions& config, tools::Version version);
|
||||
|
||||
private:
|
||||
Device(ProgOptions* config, tools::Version version);
|
||||
|
||||
public:
|
||||
Device(const Device&) = delete;
|
||||
Device(Device&&) = delete;
|
||||
Device& operator=(const Device&) = delete;
|
||||
Device& operator=(Device&&) = delete;
|
||||
virtual ~Device();
|
||||
|
||||
/// Outputs the socket transfer rates
|
||||
virtual void LogSocketRates();
|
||||
|
||||
template<typename Serializer, typename DataType, typename... Args>
|
||||
[[deprecated]] void Serialize(Message& msg, DataType&& data, Args&&... args) const
|
||||
{
|
||||
Serializer().Serialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename Deserializer, typename DataType, typename... Args>
|
||||
[[deprecated]] void Deserialize(Message& msg, DataType&& data, Args&&... args) const
|
||||
{
|
||||
Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/// Shorthand method to send `msg` on `chan` at index `i`
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via
|
||||
/// state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out,
|
||||
/// TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by
|
||||
/// requested state change)
|
||||
int64_t Send(MessagePtr& msg,
|
||||
const std::string& channel,
|
||||
const int index = 0,
|
||||
int sndTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Send(msg, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to receive `msg` on `chan` at index `i`
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g.
|
||||
/// via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out,
|
||||
/// TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by
|
||||
/// requested state change)
|
||||
int64_t Receive(MessagePtr& msg,
|
||||
const std::string& channel,
|
||||
const int index = 0,
|
||||
int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Receive(msg, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to send Parts on `chan` at index `i`
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via
|
||||
/// state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out,
|
||||
/// TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by
|
||||
/// requested state change)
|
||||
int64_t Send(Parts& parts,
|
||||
const std::string& channel,
|
||||
const int index = 0,
|
||||
int sndTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Send(parts.fParts, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to receive Parts on `chan` at index `i`
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g.
|
||||
/// via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out,
|
||||
/// TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by
|
||||
/// requested state change)
|
||||
int64_t Receive(Parts& parts,
|
||||
const std::string& channel,
|
||||
const int index = 0,
|
||||
int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Receive(parts.fParts, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// @brief Getter for default transport factory
|
||||
auto Transport() const -> TransportFactory* { return fTransportFactory.get(); }
|
||||
|
||||
// creates message with the default device transport
|
||||
template<typename... Args>
|
||||
MessagePtr NewMessage(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// creates message with the transport of the specified channel
|
||||
template<typename... Args>
|
||||
MessagePtr NewMessageFor(const std::string& channel, int index, Args&&... args)
|
||||
{
|
||||
return GetChannel(channel, index).NewMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// creates a message that will not be cleaned up after transfer, with the default device
|
||||
// transport
|
||||
template<typename T>
|
||||
MessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewStaticMessage(data);
|
||||
}
|
||||
|
||||
// creates a message that will not be cleaned up after transfer, with the transport of the
|
||||
// specified channel
|
||||
template<typename T>
|
||||
MessagePtr NewStaticMessageFor(const std::string& channel, int index, const T& data)
|
||||
{
|
||||
return GetChannel(channel, index).NewStaticMessage(data);
|
||||
}
|
||||
|
||||
// creates a message with a copy of the provided data, with the default device transport
|
||||
template<typename T>
|
||||
MessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
// creates a message with a copy of the provided data, with the transport of the specified
|
||||
// channel
|
||||
template<typename T>
|
||||
MessagePtr NewSimpleMessageFor(const std::string& channel, int index, const T& data)
|
||||
{
|
||||
return GetChannel(channel, index).NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
// creates unamanaged region with the default device transport
|
||||
template<typename... Args>
|
||||
UnmanagedRegionPtr NewUnmanagedRegion(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateUnmanagedRegion(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// creates unmanaged region with the transport of the specified channel
|
||||
template<typename... Args>
|
||||
UnmanagedRegionPtr NewUnmanagedRegionFor(const std::string& channel, int index, Args&&... args)
|
||||
{
|
||||
return GetChannel(channel, index).NewUnmanagedRegion(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Ts>
|
||||
PollerPtr NewPoller(const Ts&... inputs)
|
||||
{
|
||||
std::vector<std::string> chans{inputs...};
|
||||
|
||||
// if more than one channel provided, check compatibility
|
||||
if (chans.size() > 1) {
|
||||
mq::Transport type = GetChannel(chans.at(0), 0).Transport()->GetType();
|
||||
|
||||
for (unsigned int i = 1; i < chans.size(); ++i) {
|
||||
if (type != GetChannel(chans.at(i), 0).Transport()->GetType()) {
|
||||
LOG(error) << "poller failed: different transports within same poller are not "
|
||||
"yet supported. Going to ERROR state.";
|
||||
throw std::runtime_error("poller failed: different transports within same "
|
||||
"poller are not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GetChannel(chans.at(0), 0).Transport()->CreatePoller(fChannels, chans);
|
||||
}
|
||||
|
||||
PollerPtr NewPoller(const std::vector<Channel*>& channels)
|
||||
{
|
||||
// if more than one channel provided, check compatibility
|
||||
if (channels.size() > 1) {
|
||||
mq::Transport type = channels.at(0)->Transport()->GetType();
|
||||
|
||||
for (unsigned int i = 1; i < channels.size(); ++i) {
|
||||
if (type != channels.at(i)->Transport()->GetType()) {
|
||||
LOG(error) << "poller failed: different transports within same poller are not "
|
||||
"yet supported. Going to ERROR state.";
|
||||
throw std::runtime_error("poller failed: different transports within same "
|
||||
"poller are not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return channels.at(0)->Transport()->CreatePoller(channels);
|
||||
}
|
||||
|
||||
/// Adds a transport to the device if it doesn't exist
|
||||
/// @param transport Transport string ("zeromq"/"shmem")
|
||||
std::shared_ptr<TransportFactory> AddTransport(mq::Transport transport);
|
||||
|
||||
/// Assigns config to the device
|
||||
void SetConfig(ProgOptions& config);
|
||||
/// Get pointer to the config
|
||||
ProgOptions* GetConfig() const { return fConfig; }
|
||||
|
||||
// overload to easily bind member functions
|
||||
template<typename T>
|
||||
void OnData(const std::string& channelName,
|
||||
bool (T::*memberFunction)(MessagePtr& msg, int index))
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMsgInputs.insert(
|
||||
std::make_pair(channelName, [this, memberFunction](MessagePtr& msg, int index) {
|
||||
return (static_cast<T*>(this)->*memberFunction)(msg, index);
|
||||
}));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName)
|
||||
== fInputChannelKeys.end()) {
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
void OnData(const std::string& channelName, InputMsgCallback callback)
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMsgInputs.insert(make_pair(channelName, callback));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName)
|
||||
== fInputChannelKeys.end()) {
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
// overload to easily bind member functions
|
||||
template<typename T>
|
||||
void OnData(const std::string& channelName, bool (T::*memberFunction)(Parts& parts, int index))
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMultipartInputs.insert(
|
||||
std::make_pair(channelName, [this, memberFunction](Parts& parts, int index) {
|
||||
return (static_cast<T*>(this)->*memberFunction)(parts, index);
|
||||
}));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName)
|
||||
== fInputChannelKeys.end()) {
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
void OnData(const std::string& channelName, InputMultipartCallback callback)
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMultipartInputs.insert(make_pair(channelName, callback));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName)
|
||||
== fInputChannelKeys.end()) {
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
Channel& GetChannel(const std::string& channelName, const int index = 0)
|
||||
try {
|
||||
return fChannels.at(channelName).at(index);
|
||||
} catch (const std::out_of_range& oor) {
|
||||
LOG(error)
|
||||
<< "requested channel has not been configured? check channel names/configuration.";
|
||||
LOG(error) << "channel: " << channelName << ", index: " << index;
|
||||
LOG(error) << "out of range: " << oor.what();
|
||||
throw;
|
||||
}
|
||||
|
||||
/// @brief Get numbers of connected peers for the given channel
|
||||
/// @param name channel name
|
||||
/// @param index sub-channel
|
||||
unsigned long GetNumberOfConnectedPeers(const std::string& channelName, int index = 0)
|
||||
{
|
||||
return fChannels.at(channelName).at(index).GetNumberOfConnectedPeers();
|
||||
}
|
||||
|
||||
virtual void RegisterChannelEndpoints() {}
|
||||
|
||||
bool RegisterChannelEndpoint(const std::string& channelName,
|
||||
uint16_t minNumSubChannels = 1,
|
||||
uint16_t maxNumSubChannels = 1)
|
||||
{
|
||||
bool ok = fChannelRegistry
|
||||
.insert(std::make_pair(channelName,
|
||||
std::make_pair(minNumSubChannels, maxNumSubChannels)))
|
||||
.second;
|
||||
if (!ok) {
|
||||
LOG(warn) << "Registering channel: name already registered: \"" << channelName << "\"";
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void PrintRegisteredChannels()
|
||||
{
|
||||
if (fChannelRegistry.empty()) {
|
||||
LOGV(info, verylow) << "no channels registered.";
|
||||
} else {
|
||||
for (const auto& c : fChannelRegistry) {
|
||||
LOGV(info, verylow) << c.first << ":" << c.second.first << ":" << c.second.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetId(const std::string& id) { fId = id; }
|
||||
std::string GetId() { return fId; }
|
||||
|
||||
const tools::Version GetVersion() const { return fVersion; }
|
||||
|
||||
void SetNumIoThreads(int numIoThreads) { fConfig->SetProperty("io-threads", numIoThreads); }
|
||||
int GetNumIoThreads() const
|
||||
{
|
||||
return fConfig->GetProperty<int>("io-threads", DefaultIOThreads);
|
||||
}
|
||||
|
||||
void SetNetworkInterface(const std::string& networkInterface)
|
||||
{
|
||||
fConfig->SetProperty("network-interface", networkInterface);
|
||||
}
|
||||
std::string GetNetworkInterface() const
|
||||
{
|
||||
return fConfig->GetProperty<std::string>("network-interface", DefaultNetworkInterface);
|
||||
}
|
||||
|
||||
void SetDefaultTransport(const std::string& name) { fConfig->SetProperty("transport", name); }
|
||||
std::string GetDefaultTransport() const
|
||||
{
|
||||
return fConfig->GetProperty<std::string>("transport", DefaultTransportName);
|
||||
}
|
||||
|
||||
void SetInitTimeoutInS(int initTimeoutInS)
|
||||
{
|
||||
fConfig->SetProperty("init-timeout", initTimeoutInS);
|
||||
}
|
||||
int GetInitTimeoutInS() const
|
||||
{
|
||||
return fConfig->GetProperty<int>("init-timeout", DefaultInitTimeout);
|
||||
}
|
||||
|
||||
/// Sets the default transport for the device
|
||||
/// @param transport Transport string ("zeromq"/"shmem")
|
||||
void SetTransport(const std::string& transport)
|
||||
{
|
||||
fConfig->SetProperty("transport", transport);
|
||||
}
|
||||
/// Gets the default transport name
|
||||
std::string GetTransportName() const
|
||||
{
|
||||
return fConfig->GetProperty<std::string>("transport", DefaultTransportName);
|
||||
}
|
||||
|
||||
void SetRawCmdLineArgs(const std::vector<std::string>& args) { fRawCmdLineArgs = args; }
|
||||
std::vector<std::string> GetRawCmdLineArgs() const { return fRawCmdLineArgs; }
|
||||
|
||||
void RunStateMachine() { fStateMachine.ProcessWork(); };
|
||||
|
||||
/// Wait for the supplied amount of time or for interruption.
|
||||
/// If interrupted, returns false, otherwise true.
|
||||
/// @param duration wait duration
|
||||
template<typename Rep, typename Period>
|
||||
bool WaitFor(std::chrono::duration<Rep, Period> const& duration)
|
||||
{
|
||||
return !fStateMachine.WaitForPendingStateFor(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<TransportFactory> fTransportFactory; ///< Default transport factory
|
||||
std::unordered_map<mq::Transport, std::shared_ptr<TransportFactory>>
|
||||
fTransports; ///< Container for transports
|
||||
|
||||
public:
|
||||
std::unordered_map<std::string, std::vector<Channel>> fChannels; ///< Device channels
|
||||
std::unique_ptr<ProgOptions> fInternalConfig; ///< Internal program options configuration
|
||||
ProgOptions* fConfig; ///< Pointer to config (internal or external)
|
||||
|
||||
void AddChannel(const std::string& name, Channel&& channel)
|
||||
{
|
||||
fConfig->AddChannel(name, channel);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string fId; ///< Device ID
|
||||
|
||||
/// Additional user initialization (can be overloaded in child classes). Prefer to use
|
||||
/// InitTask().
|
||||
virtual void Init() {}
|
||||
|
||||
virtual void Bind() {}
|
||||
|
||||
virtual void Connect() {}
|
||||
|
||||
/// Task initialization (can be overloaded in child classes)
|
||||
virtual void InitTask() {}
|
||||
|
||||
/// Runs the device (to be overloaded in child classes)
|
||||
virtual void Run() {}
|
||||
|
||||
/// Called in the RUNNING state once before executing the Run()/ConditionalRun() method
|
||||
virtual void PreRun() {}
|
||||
|
||||
/// Called during RUNNING state repeatedly until it returns false or device state changes
|
||||
virtual bool ConditionalRun() { return false; }
|
||||
|
||||
/// Called in the RUNNING state once after executing the Run()/ConditionalRun() method
|
||||
virtual void PostRun() {}
|
||||
|
||||
/// Resets the user task (to be overloaded in child classes)
|
||||
virtual void ResetTask() {}
|
||||
|
||||
/// Resets the device (can be overloaded in child classes)
|
||||
virtual void Reset() {}
|
||||
|
||||
public:
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
///
|
||||
/// The state transition may not happen immediately, but when the current state evaluates the
|
||||
/// pending transition event and terminates. In other words, the device states are scheduled
|
||||
/// cooperatively.
|
||||
bool ChangeState(const Transition transition) { return fStateMachine.ChangeState(transition); }
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
///
|
||||
/// The state transition may not happen immediately, but when the current state evaluates the
|
||||
/// pending transition event and terminates. In other words, the device states are scheduled
|
||||
/// cooperatively.
|
||||
bool ChangeState(const std::string& transition)
|
||||
{
|
||||
return fStateMachine.ChangeState(GetTransition(transition));
|
||||
}
|
||||
|
||||
/// @brief waits for the next state (any) to occur
|
||||
State WaitForNextState() { return fStateQueue.WaitForNext(); }
|
||||
/// @brief waits for the specified state to occur
|
||||
/// @param state state to wait for
|
||||
void WaitForState(State state) { fStateQueue.WaitForState(state); }
|
||||
/// @brief waits for the specified state to occur
|
||||
/// @param state state to wait for
|
||||
void WaitForState(const std::string& state) { WaitForState(GetState(state)); }
|
||||
|
||||
void TransitionTo(State state);
|
||||
|
||||
/// @brief Subscribe with a callback to state changes
|
||||
/// @param key id to identify your subscription
|
||||
/// @param callback callback (called with the new state as the parameter)
|
||||
///
|
||||
/// The callback is called at the beginning of a new state.
|
||||
/// The callback is called from the thread the state is running in.
|
||||
void SubscribeToStateChange(const std::string& key, std::function<void(const State)> callback)
|
||||
{
|
||||
fStateMachine.SubscribeToStateChange(key, callback);
|
||||
}
|
||||
/// @brief Unsubscribe from state changes
|
||||
/// @param key id (that was used when subscribing)
|
||||
void UnsubscribeFromStateChange(const std::string& key)
|
||||
{
|
||||
fStateMachine.UnsubscribeFromStateChange(key);
|
||||
}
|
||||
|
||||
/// @brief Subscribe with a callback to incoming state transitions
|
||||
/// @param key id to identify your subscription
|
||||
/// @param callback callback (called with the incoming transition as the parameter)
|
||||
/// The callback is called when new transition is initiated.
|
||||
/// The callback is called from the thread that initiates the transition (via ChangeState).
|
||||
void SubscribeToNewTransition(const std::string& key,
|
||||
std::function<void(const Transition)> callback)
|
||||
{
|
||||
fStateMachine.SubscribeToNewTransition(key, callback);
|
||||
}
|
||||
/// @brief Unsubscribe from state transitions
|
||||
/// @param key id (that was used when subscribing)
|
||||
void UnsubscribeFromNewTransition(const std::string& key)
|
||||
{
|
||||
fStateMachine.UnsubscribeFromNewTransition(key);
|
||||
}
|
||||
|
||||
/// @brief Returns true if a new state has been requested, signaling the current handler to
|
||||
/// stop.
|
||||
bool NewStatePending() const { return fStateMachine.NewStatePending(); }
|
||||
|
||||
/// @brief Returns the current state
|
||||
State GetCurrentState() const { return fStateMachine.GetCurrentState(); }
|
||||
/// @brief Returns the name of the current state as a string
|
||||
std::string GetCurrentStateName() const { return fStateMachine.GetCurrentStateName(); }
|
||||
|
||||
/// @brief Returns name of the given state as a string
|
||||
/// @param state state
|
||||
[[deprecated("Use fair::mq::GetStateName from <fairmq/States.h> directly")]]
|
||||
static std::string GetStateName(State state) { return fair::mq::GetStateName(state); }
|
||||
/// @brief Returns name of the given transition as a string
|
||||
/// @param transition transition
|
||||
[[deprecated("Use fair::mq::GetTransitionName from <fairmq/States.h> directly")]]
|
||||
static std::string GetTransitionName(Transition transition)
|
||||
{
|
||||
return fair::mq::GetTransitionName(transition);
|
||||
}
|
||||
|
||||
static constexpr const char* DefaultId = "";
|
||||
static constexpr int DefaultIOThreads = 1;
|
||||
static constexpr const char* DefaultTransportName = "zeromq";
|
||||
static constexpr mq::Transport DefaultTransportType = mq::Transport::ZMQ;
|
||||
static constexpr const char* DefaultNetworkInterface = "default";
|
||||
static constexpr int DefaultInitTimeout = 120;
|
||||
static constexpr uint64_t DefaultMaxRunTime = 0;
|
||||
static constexpr float DefaultRate = 0.;
|
||||
static constexpr const char* DefaultSession = "default";
|
||||
|
||||
private:
|
||||
mq::Transport fDefaultTransportType; ///< Default transport for the device
|
||||
StateMachine fStateMachine;
|
||||
|
||||
/// Handles the initialization
|
||||
void InitWrapper();
|
||||
/// Initializes binding channels
|
||||
void BindWrapper();
|
||||
/// Initializes connecting channels
|
||||
void ConnectWrapper();
|
||||
/// Handles the InitTask() method
|
||||
void InitTaskWrapper();
|
||||
/// Handles the Run() method
|
||||
void RunWrapper();
|
||||
/// Handles the ResetTask() method
|
||||
void ResetTaskWrapper();
|
||||
/// Handles the Reset() method
|
||||
void ResetWrapper();
|
||||
|
||||
/// Notifies transports to cease any blocking activity
|
||||
void UnblockTransports();
|
||||
|
||||
/// Shuts down the transports and the device
|
||||
void Exit() {}
|
||||
|
||||
/// Attach (bind/connect) channels in the list
|
||||
void AttachChannels(std::vector<Channel*>& chans);
|
||||
bool AttachChannel(Channel& ch);
|
||||
|
||||
void HandleSingleChannelInput();
|
||||
void HandleMultipleChannelInput();
|
||||
void HandleMultipleTransportInput();
|
||||
void PollForTransport(const TransportFactory* factory,
|
||||
const std::vector<std::string>& channelKeys);
|
||||
|
||||
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i);
|
||||
bool HandleMultipartInput(const std::string& chName,
|
||||
const InputMultipartCallback& callback,
|
||||
int i);
|
||||
|
||||
std::vector<Channel*> fUninitializedBindingChannels;
|
||||
std::vector<Channel*> fUninitializedConnectingChannels;
|
||||
|
||||
bool fDataCallbacks;
|
||||
std::unordered_map<std::string, InputMsgCallback> fMsgInputs;
|
||||
std::unordered_map<std::string, InputMultipartCallback> fMultipartInputs;
|
||||
std::unordered_map<mq::Transport, std::vector<std::string>> fMultitransportInputs;
|
||||
std::unordered_map<std::string, std::pair<uint16_t, uint16_t>> fChannelRegistry;
|
||||
std::vector<std::string> fInputChannelKeys;
|
||||
std::mutex fMultitransportMutex;
|
||||
std::atomic<bool> fMultitransportProceed;
|
||||
|
||||
const tools::Version fVersion;
|
||||
float fRate; ///< Rate limiting for ConditionalRun
|
||||
uint64_t fMaxRunRuntimeInS; ///< Maximum runtime for the Running state handler, after which
|
||||
///< state will change to Ready (in seconds, 0 for no limit).
|
||||
int fInitializationTimeoutInS;
|
||||
std::vector<std::string> fRawCmdLineArgs;
|
||||
|
||||
StateQueue fStateQueue;
|
||||
|
||||
std::mutex fTransitionMtx;
|
||||
bool fTransitioning;
|
||||
};
|
||||
|
||||
} // namespace fair::mq
|
||||
|
||||
// using FairMQChannelMap [[deprecated("Use fair::mq::ChannelMap")]] = fair::mq::ChannelMap;
|
||||
// using InputMsgCallback [[deprecated("Use fair::mq::InputMsgCallback")]] =
|
||||
// fair::mq::InputMsgCallback;
|
||||
// using InputMultipartCallback [[deprecated("Use fair::mq::InputMultipartCallback")]] =
|
||||
// fair::mq::InputMultipartCallback;
|
||||
// using FairMQDevice [[deprecated("Use fair::mq::Device")]] = fair::mq::Device;
|
||||
using FairMQChannelMap = fair::mq::ChannelMap;
|
||||
using InputMsgCallback = fair::mq::InputMsgCallback;
|
||||
using InputMultipartCallback = fair::mq::InputMultipartCallback;
|
||||
using FairMQDevice = fair::mq::Device;
|
||||
|
||||
#endif /* FAIR_MQ_DEVICE_H */
|
||||
|
@@ -21,11 +21,9 @@ using namespace fair::mq;
|
||||
|
||||
DeviceRunner::DeviceRunner(int argc, char*const* argv, bool printLogo)
|
||||
: fRawCmdLineArgs(tools::ToStrVector(argc, argv, false))
|
||||
, fConfig()
|
||||
, fDevice(nullptr)
|
||||
, fPluginManager(fRawCmdLineArgs)
|
||||
, fPrintLogo(printLogo)
|
||||
, fEvents()
|
||||
{}
|
||||
|
||||
bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo)
|
||||
@@ -51,7 +49,7 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo
|
||||
string verbosity = config.GetProperty<string>("verbosity");
|
||||
fair::Logger::SetVerbosity(verbosity);
|
||||
|
||||
if (logFile != "") {
|
||||
if (!logFile.empty()) {
|
||||
fair::Logger::InitFileSink(logFileSeverity, logFile);
|
||||
fair::Logger::SetConsoleSeverity("nolog");
|
||||
} else {
|
||||
@@ -60,7 +58,7 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo
|
||||
if (envFairMQSeverity) {
|
||||
severity = envFairMQSeverity;
|
||||
}
|
||||
if (severity != "") {
|
||||
if (!severity.empty()) {
|
||||
fair::Logger::SetConsoleSeverity(severity);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +120,7 @@ auto DeviceRunner::Run() -> int
|
||||
fPluginManager.ForEachPluginProgOptions([&](boost::program_options::options_description options) {
|
||||
fConfig.AddToCmdLineOptions(options);
|
||||
});
|
||||
fConfig.AddToCmdLineOptions(fPluginManager.ProgramOptions());
|
||||
fConfig.AddToCmdLineOptions(PluginManager::ProgramOptions());
|
||||
|
||||
////// CALL HOOK ///////
|
||||
fEvents.Emit<hooks::ModifyRawCmdLineArgs>(*this);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2019-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -8,13 +8,9 @@
|
||||
|
||||
#include "Error.h"
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
namespace fair::mq {
|
||||
|
||||
const char* ErrorCategory::name() const noexcept
|
||||
{
|
||||
return "fairmq";
|
||||
}
|
||||
const char* ErrorCategory::name() const noexcept { return "fairmq"; }
|
||||
|
||||
std::string ErrorCategory::message(int ev) const
|
||||
{
|
||||
@@ -40,4 +36,4 @@ const ErrorCategory errorCategory{};
|
||||
|
||||
std::error_code MakeErrorCode(ErrorCode e) { return {static_cast<int>(e), errorCategory}; }
|
||||
|
||||
} // namespace fair::mq
|
||||
} // namespace fair::mq
|
59
fairmq/Error.h
Normal file
59
fairmq/Error.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_ERROR_H
|
||||
#define FAIR_MQ_ERROR_H
|
||||
|
||||
#include <cassert>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <stdexcept>
|
||||
#include <system_error>
|
||||
|
||||
// Macro copied from https://en.cppreference.com/w/cpp/error/assert
|
||||
// Use (void) to silent unused warnings.
|
||||
#define assertm(exp, msg) assert(((void)msg, exp))
|
||||
|
||||
namespace fair::mq {
|
||||
|
||||
struct RuntimeError : ::std::runtime_error
|
||||
{
|
||||
template<typename... T>
|
||||
explicit RuntimeError(T&&... t)
|
||||
: ::std::runtime_error::runtime_error(tools::ToString(std::forward<T>(t)...))
|
||||
{}
|
||||
};
|
||||
|
||||
enum class ErrorCode
|
||||
{
|
||||
OperationInProgress = 10,
|
||||
OperationTimeout,
|
||||
OperationCanceled,
|
||||
DeviceChangeStateFailed,
|
||||
DeviceGetPropertiesFailed,
|
||||
DeviceSetPropertiesFailed
|
||||
};
|
||||
|
||||
std::error_code MakeErrorCode(ErrorCode);
|
||||
|
||||
struct ErrorCategory : std::error_category
|
||||
{
|
||||
const char* name() const noexcept override;
|
||||
std::string message(int ev) const override;
|
||||
};
|
||||
|
||||
} // namespace fair::mq
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct is_error_code_enum<fair::mq::ErrorCode> : true_type
|
||||
{};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif /* FAIR_MQ_ERROR_H */
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,433 +9,12 @@
|
||||
#ifndef FAIRMQCHANNEL_H_
|
||||
#define FAIRMQCHANNEL_H_
|
||||
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <FairMQUnmanagedRegion.h>
|
||||
#include <FairMQSocket.h>
|
||||
#include <fairmq/Transports.h>
|
||||
#include <FairMQParts.h>
|
||||
#include <fairmq/Properties.h>
|
||||
#include <FairMQMessage.h>
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_CHANNEL_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/Channel.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <memory> // unique_ptr, shared_ptr
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <utility> // std::move
|
||||
#include <cstdint> // int64_t
|
||||
|
||||
/**
|
||||
* @class FairMQChannel FairMQChannel.h <FairMQChannel.h>
|
||||
* @brief Wrapper class for FairMQSocket and related methods
|
||||
*
|
||||
* The class is not thread-safe.
|
||||
*/
|
||||
class FairMQChannel
|
||||
{
|
||||
friend class FairMQDevice;
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
FairMQChannel();
|
||||
|
||||
/// Constructor
|
||||
/// @param name Channel name
|
||||
FairMQChannel(const std::string& name);
|
||||
|
||||
/// Constructor
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
/// @param method Socket method (bind/connect)
|
||||
/// @param address Network address to bind/connect to (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
FairMQChannel(const std::string& type, const std::string& method, const std::string& address);
|
||||
|
||||
/// Constructor
|
||||
/// @param name Channel name
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
/// @param factory TransportFactory
|
||||
FairMQChannel(const std::string& name, const std::string& type, std::shared_ptr<FairMQTransportFactory> factory);
|
||||
|
||||
/// Constructor
|
||||
/// @param name Channel name
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
/// @param method Socket method (bind/connect)
|
||||
/// @param address Network address to bind/connect to (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
/// @param factory TransportFactory
|
||||
FairMQChannel(const std::string& name, const std::string& type, const std::string& method, const std::string& address, std::shared_ptr<FairMQTransportFactory> factory);
|
||||
|
||||
FairMQChannel(const std::string& name, int index, const fair::mq::Properties& properties);
|
||||
|
||||
/// Copy Constructor
|
||||
FairMQChannel(const FairMQChannel&);
|
||||
|
||||
/// Copy Constructor (with new name)
|
||||
FairMQChannel(const FairMQChannel&, const std::string& name);
|
||||
|
||||
/// Move constructor
|
||||
// FairMQChannel(FairMQChannel&&) = delete;
|
||||
|
||||
/// Assignment operator
|
||||
FairMQChannel& operator=(const FairMQChannel&);
|
||||
|
||||
/// Move assignment operator
|
||||
// FairMQChannel& operator=(FairMQChannel&&) = delete;
|
||||
|
||||
/// Destructor
|
||||
virtual ~FairMQChannel() { /* LOG(warn) << "Destroying channel '" << fName << "'"; */ }
|
||||
|
||||
struct ChannelConfigurationError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
FairMQSocket& GetSocket() const { assert(fSocket); return *fSocket; }
|
||||
|
||||
bool Bind(const std::string& address)
|
||||
{
|
||||
fMethod = "bind";
|
||||
fAddress = address;
|
||||
return fSocket->Bind(address);
|
||||
}
|
||||
|
||||
bool Connect(const std::string& address)
|
||||
{
|
||||
fMethod = "connect";
|
||||
fAddress = address;
|
||||
return fSocket->Connect(address);
|
||||
}
|
||||
|
||||
/// Get channel name
|
||||
/// @return Returns full channel name (e.g. "data[0]")
|
||||
std::string GetName() const { return fName; }
|
||||
|
||||
/// Get channel prefix
|
||||
/// @return Returns channel prefix (e.g. "data" in "data[0]")
|
||||
std::string GetPrefix() const
|
||||
{
|
||||
std::string prefix = fName;
|
||||
prefix = prefix.erase(fName.rfind('['));
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/// Get channel index
|
||||
/// @return Returns channel index (e.g. 0 in "data[0]")
|
||||
std::string GetIndex() const
|
||||
{
|
||||
std::string indexStr = fName;
|
||||
indexStr.erase(indexStr.rfind(']'));
|
||||
indexStr.erase(0, indexStr.rfind('[') + 1);
|
||||
return indexStr;
|
||||
}
|
||||
|
||||
/// Get socket type
|
||||
/// @return Returns socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
std::string GetType() const { return fType; }
|
||||
|
||||
/// Get socket method
|
||||
/// @return Returns socket method (bind/connect)
|
||||
std::string GetMethod() const { return fMethod; }
|
||||
|
||||
/// Get socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
/// @return Returns socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
std::string GetAddress() const { return fAddress; }
|
||||
|
||||
/// Get channel transport name ("default", "zeromq" or "shmem")
|
||||
/// @return Returns channel transport name (e.g. "default", "zeromq" or "shmem")
|
||||
std::string GetTransportName() const { return fair::mq::TransportName(fTransportType); }
|
||||
|
||||
/// Get channel transport type
|
||||
/// @return Returns channel transport type
|
||||
fair::mq::Transport GetTransportType() const { return fTransportType; }
|
||||
|
||||
/// Get socket send buffer size (in number of messages)
|
||||
/// @return Returns socket send buffer size (in number of messages)
|
||||
int GetSndBufSize() const { return fSndBufSize; }
|
||||
|
||||
/// Get socket receive buffer size (in number of messages)
|
||||
/// @return Returns socket receive buffer size (in number of messages)
|
||||
int GetRcvBufSize() const { return fRcvBufSize; }
|
||||
|
||||
/// Get socket kernel transmit send buffer size (in bytes)
|
||||
/// @return Returns socket kernel transmit send buffer size (in bytes)
|
||||
int GetSndKernelSize() const { return fSndKernelSize; }
|
||||
|
||||
/// Get socket kernel transmit receive buffer size (in bytes)
|
||||
/// @return Returns socket kernel transmit receive buffer size (in bytes)
|
||||
int GetRcvKernelSize() const { return fRcvKernelSize; }
|
||||
|
||||
/// Get linger duration (in milliseconds)
|
||||
/// @return Returns linger duration (in milliseconds)
|
||||
int GetLinger() const { return fLinger; }
|
||||
|
||||
/// Get socket rate logging interval (in seconds)
|
||||
/// @return Returns socket rate logging interval (in seconds)
|
||||
int GetRateLogging() const { return fRateLogging; }
|
||||
|
||||
/// Get start of the port range for automatic binding
|
||||
/// @return start of the port range
|
||||
int GetPortRangeMin() const { return fPortRangeMin; }
|
||||
|
||||
/// Get end of the port range for automatic binding
|
||||
/// @return end of the port range
|
||||
int GetPortRangeMax() const { return fPortRangeMax; }
|
||||
|
||||
/// Set automatic binding (pick random port if bind fails)
|
||||
/// @return true/false, true if automatic binding is enabled
|
||||
bool GetAutoBind() const { return fAutoBind; }
|
||||
|
||||
/// Set channel name
|
||||
/// @param name Arbitrary channel name
|
||||
void UpdateName(const std::string& name) { fName = name; Invalidate(); }
|
||||
|
||||
/// Set socket type
|
||||
/// @param type Socket type (push/pull/pub/sub/spub/xsub/pair/req/rep/dealer/router/)
|
||||
void UpdateType(const std::string& type) { fType = type; Invalidate(); }
|
||||
|
||||
/// Set socket method
|
||||
/// @param method Socket method (bind/connect)
|
||||
void UpdateMethod(const std::string& method) { fMethod = method; Invalidate(); }
|
||||
|
||||
/// Set socket address
|
||||
/// @param Socket address (e.g. "tcp://127.0.0.1:5555" or "ipc://abc")
|
||||
void UpdateAddress(const std::string& address) { fAddress = address; Invalidate(); }
|
||||
|
||||
/// Set channel transport
|
||||
/// @param transport transport string ("default", "zeromq" or "shmem")
|
||||
void UpdateTransport(const std::string& transport) { fTransportType = fair::mq::TransportType(transport); Invalidate(); }
|
||||
|
||||
/// Set socket send buffer size
|
||||
/// @param sndBufSize Socket send buffer size (in number of messages)
|
||||
void UpdateSndBufSize(const int sndBufSize) { fSndBufSize = sndBufSize; Invalidate(); }
|
||||
|
||||
/// Set socket receive buffer size
|
||||
/// @param rcvBufSize Socket receive buffer size (in number of messages)
|
||||
void UpdateRcvBufSize(const int rcvBufSize) { fRcvBufSize = rcvBufSize; Invalidate(); }
|
||||
|
||||
/// Set socket kernel transmit send buffer size (in bytes)
|
||||
/// @param sndKernelSize Socket send buffer size (in bytes)
|
||||
void UpdateSndKernelSize(const int sndKernelSize) { fSndKernelSize = sndKernelSize; Invalidate(); }
|
||||
|
||||
/// Set socket kernel transmit receive buffer size (in bytes)
|
||||
/// @param rcvKernelSize Socket receive buffer size (in bytes)
|
||||
void UpdateRcvKernelSize(const int rcvKernelSize) { fRcvKernelSize = rcvKernelSize; Invalidate(); }
|
||||
|
||||
/// Set linger duration (in milliseconds)
|
||||
/// @param duration linger duration (in milliseconds)
|
||||
void UpdateLinger(const int duration) { fLinger = duration; Invalidate(); }
|
||||
|
||||
/// Set socket rate logging interval (in seconds)
|
||||
/// @param rateLogging Socket rate logging interval (in seconds)
|
||||
void UpdateRateLogging(const int rateLogging) { fRateLogging = rateLogging; Invalidate(); }
|
||||
|
||||
/// Set start of the port range for automatic binding
|
||||
/// @param minPort start of the port range
|
||||
void UpdatePortRangeMin(const int minPort) { fPortRangeMin = minPort; Invalidate(); }
|
||||
|
||||
/// Set end of the port range for automatic binding
|
||||
/// @param maxPort end of the port range
|
||||
void UpdatePortRangeMax(const int maxPort) { fPortRangeMax = maxPort; Invalidate(); }
|
||||
|
||||
/// Set automatic binding (pick random port if bind fails)
|
||||
/// @param autobind true/false, true to enable automatic binding
|
||||
void UpdateAutoBind(const bool autobind) { fAutoBind = autobind; Invalidate(); }
|
||||
|
||||
/// Checks if the configured channel settings are valid (checks the validity parameter, without running full validation (as oposed to ValidateChannel()))
|
||||
/// @return true if channel settings are valid, false otherwise.
|
||||
bool IsValid() const { return fValid; }
|
||||
|
||||
/// Validates channel configuration
|
||||
/// @return true if channel settings are valid, false otherwise.
|
||||
bool Validate();
|
||||
|
||||
void Init();
|
||||
|
||||
bool ConnectEndpoint(const std::string& endpoint);
|
||||
|
||||
bool BindEndpoint(std::string& endpoint);
|
||||
|
||||
/// invalidates the channel (requires validation to be used again).
|
||||
void Invalidate() { fValid = false; }
|
||||
|
||||
/// Sends a message to the socket queue.
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(FairMQMessagePtr& msg, int sndTimeoutInMs = -1)
|
||||
{
|
||||
CheckSendCompatibility(msg);
|
||||
return fSocket->Send(msg, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Receives a message from the socket queue.
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
CheckReceiveCompatibility(msg);
|
||||
return fSocket->Receive(msg, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Send a vector of messages
|
||||
/// @param msgVec message vector reference
|
||||
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs = -1)
|
||||
{
|
||||
CheckSendCompatibility(msgVec);
|
||||
return fSocket->Send(msgVec, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Receive a vector of messages
|
||||
/// @param msgVec message vector reference
|
||||
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
CheckReceiveCompatibility(msgVec);
|
||||
return fSocket->Receive(msgVec, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Send FairMQParts
|
||||
/// @param parts FairMQParts reference
|
||||
/// @param sndTimeoutInMs send timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(FairMQParts& parts, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return Send(parts.fParts, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Receive FairMQParts
|
||||
/// @param parts FairMQParts reference
|
||||
/// @param rcvTimeoutInMs receive timeout in ms. -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return Receive(parts.fParts, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
unsigned long GetBytesTx() const { return fSocket->GetBytesTx(); }
|
||||
unsigned long GetBytesRx() const { return fSocket->GetBytesRx(); }
|
||||
unsigned long GetMessagesTx() const { return fSocket->GetMessagesTx(); }
|
||||
unsigned long GetMessagesRx() const { return fSocket->GetMessagesRx(); }
|
||||
|
||||
auto Transport() -> FairMQTransportFactory* { return fTransportFactory.get(); };
|
||||
|
||||
template<typename... Args>
|
||||
FairMQMessagePtr NewMessage(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewStaticMessage(data);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
FairMQUnmanagedRegionPtr NewUnmanagedRegion(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateUnmanagedRegion(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static constexpr fair::mq::Transport DefaultTransportType = fair::mq::Transport::DEFAULT;
|
||||
static constexpr const char* DefaultTransportName = "default";
|
||||
static constexpr const char* DefaultName = "";
|
||||
static constexpr const char* DefaultType = "unspecified";
|
||||
static constexpr const char* DefaultMethod = "unspecified";
|
||||
static constexpr const char* DefaultAddress = "unspecified";
|
||||
static constexpr int DefaultSndBufSize = 1000;
|
||||
static constexpr int DefaultRcvBufSize = 1000;
|
||||
static constexpr int DefaultSndKernelSize = 0;
|
||||
static constexpr int DefaultRcvKernelSize = 0;
|
||||
static constexpr int DefaultLinger = 500;
|
||||
static constexpr int DefaultRateLogging = 1;
|
||||
static constexpr int DefaultPortRangeMin = 22000;
|
||||
static constexpr int DefaultPortRangeMax = 23000;
|
||||
static constexpr bool DefaultAutoBind = true;
|
||||
|
||||
private:
|
||||
std::shared_ptr<FairMQTransportFactory> fTransportFactory;
|
||||
fair::mq::Transport fTransportType;
|
||||
std::unique_ptr<FairMQSocket> fSocket;
|
||||
|
||||
std::string fName;
|
||||
std::string fType;
|
||||
std::string fMethod;
|
||||
std::string fAddress;
|
||||
int fSndBufSize;
|
||||
int fRcvBufSize;
|
||||
int fSndKernelSize;
|
||||
int fRcvKernelSize;
|
||||
int fLinger;
|
||||
int fRateLogging;
|
||||
int fPortRangeMin;
|
||||
int fPortRangeMax;
|
||||
bool fAutoBind;
|
||||
|
||||
bool fValid;
|
||||
|
||||
bool fMultipart;
|
||||
|
||||
void CheckSendCompatibility(FairMQMessagePtr& msg)
|
||||
{
|
||||
if (fTransportType != msg->GetType()) {
|
||||
FairMQMessagePtr msgWrapper(NewMessage(
|
||||
msg->GetData(),
|
||||
msg->GetSize(),
|
||||
[](void* /*data*/, void* _msg) { delete static_cast<FairMQMessage*>(_msg); },
|
||||
msg.get()
|
||||
));
|
||||
msg.release();
|
||||
msg = move(msgWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec)
|
||||
{
|
||||
for (auto& msg : msgVec) {
|
||||
if (fTransportType != msg->GetType()) {
|
||||
|
||||
FairMQMessagePtr msgWrapper(NewMessage(
|
||||
msg->GetData(),
|
||||
msg->GetSize(),
|
||||
[](void* /*data*/, void* _msg) { delete static_cast<FairMQMessage*>(_msg); },
|
||||
msg.get()
|
||||
));
|
||||
msg.release();
|
||||
msg = move(msgWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckReceiveCompatibility(FairMQMessagePtr& msg)
|
||||
{
|
||||
if (fTransportType != msg->GetType()) {
|
||||
FairMQMessagePtr newMsg(NewMessage());
|
||||
msg = move(newMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec)
|
||||
{
|
||||
for (auto& msg : msgVec) {
|
||||
if (fTransportType != msg->GetType()) {
|
||||
|
||||
FairMQMessagePtr newMsg(NewMessage());
|
||||
msg = move(newMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitTransport(std::shared_ptr<FairMQTransportFactory> factory)
|
||||
{
|
||||
fTransportFactory = factory;
|
||||
fTransportType = factory->GetType();
|
||||
}
|
||||
};
|
||||
#include <fairmq/Channel.h>
|
||||
|
||||
#endif /* FAIRMQCHANNEL_H_ */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2012-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2012-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,545 +9,12 @@
|
||||
#ifndef FAIRMQDEVICE_H_
|
||||
#define FAIRMQDEVICE_H_
|
||||
|
||||
#include <FairMQChannel.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <FairMQMessage.h>
|
||||
#include <FairMQParts.h>
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <FairMQUnmanagedRegion.h>
|
||||
#include <fairmq/ProgOptions.h>
|
||||
#include <fairmq/StateMachine.h>
|
||||
#include <fairmq/StateQueue.h>
|
||||
#include <fairmq/Transports.h>
|
||||
#include <fairmq/tools/Version.h>
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_DEVICE_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/Device.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <memory> // unique_ptr
|
||||
#include <algorithm> // find
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <utility> // pair
|
||||
|
||||
using FairMQChannelMap = std::unordered_map<std::string, std::vector<FairMQChannel>>;
|
||||
|
||||
using InputMsgCallback = std::function<bool(FairMQMessagePtr&, int)>;
|
||||
using InputMultipartCallback = std::function<bool(FairMQParts&, int)>;
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
struct OngoingTransition : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
}
|
||||
|
||||
class FairMQDevice
|
||||
{
|
||||
friend class FairMQChannel;
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
FairMQDevice();
|
||||
/// Constructor with external fair::mq::ProgOptions
|
||||
FairMQDevice(fair::mq::ProgOptions& config);
|
||||
|
||||
/// Constructor that sets the version
|
||||
FairMQDevice(const fair::mq::tools::Version version);
|
||||
|
||||
/// Constructor that sets the version and external fair::mq::ProgOptions
|
||||
FairMQDevice(fair::mq::ProgOptions& config, const fair::mq::tools::Version version);
|
||||
|
||||
private:
|
||||
FairMQDevice(fair::mq::ProgOptions* config, const fair::mq::tools::Version version);
|
||||
|
||||
public:
|
||||
/// Copy constructor (disabled)
|
||||
FairMQDevice(const FairMQDevice&) = delete;
|
||||
/// Assignment operator (disabled)
|
||||
FairMQDevice operator=(const FairMQDevice&) = delete;
|
||||
/// Default destructor
|
||||
virtual ~FairMQDevice();
|
||||
|
||||
/// Outputs the socket transfer rates
|
||||
virtual void LogSocketRates();
|
||||
|
||||
template<typename Serializer, typename DataType, typename... Args>
|
||||
void Serialize(FairMQMessage& msg, DataType&& data, Args&&... args) const
|
||||
{
|
||||
Serializer().Serialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename Deserializer, typename DataType, typename... Args>
|
||||
void Deserialize(FairMQMessage& msg, DataType&& data, Args&&... args) const
|
||||
{
|
||||
Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/// Shorthand method to send `msg` on `chan` at index `i`
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(FairMQMessagePtr& msg, const std::string& channel, const int index = 0, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Send(msg, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to receive `msg` on `chan` at index `i`
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(FairMQMessagePtr& msg, const std::string& channel, const int index = 0, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Receive(msg, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to send FairMQParts on `chan` at index `i`
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param sndTimeoutInMs send timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot send)
|
||||
/// @return Number of bytes that have been queued, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Send(FairMQParts& parts, const std::string& channel, const int index = 0, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Send(parts.fParts, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to receive FairMQParts on `chan` at index `i`
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @param rcvTimeoutInMs receive timeout in ms, -1 will wait forever (or until interrupt (e.g. via state change)), 0 will not wait (return immediately if cannot receive)
|
||||
/// @return Number of bytes that have been received, TransferCode::timeout if timed out, TransferCode::error if there was an error, TransferCode::interrupted if interrupted (e.g. by requested state change)
|
||||
int64_t Receive(FairMQParts& parts, const std::string& channel, const int index = 0, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return GetChannel(channel, index).Receive(parts.fParts, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// @brief Getter for default transport factory
|
||||
auto Transport() const -> FairMQTransportFactory*
|
||||
{
|
||||
return fTransportFactory.get();
|
||||
}
|
||||
|
||||
// creates message with the default device transport
|
||||
template<typename... Args>
|
||||
FairMQMessagePtr NewMessage(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// creates message with the transport of the specified channel
|
||||
template<typename... Args>
|
||||
FairMQMessagePtr NewMessageFor(const std::string& channel, int index, Args&&... args)
|
||||
{
|
||||
return GetChannel(channel, index).NewMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// creates a message that will not be cleaned up after transfer, with the default device transport
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewStaticMessage(data);
|
||||
}
|
||||
|
||||
// creates a message that will not be cleaned up after transfer, with the transport of the specified channel
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessageFor(const std::string& channel, int index, const T& data)
|
||||
{
|
||||
return GetChannel(channel, index).NewStaticMessage(data);
|
||||
}
|
||||
|
||||
// creates a message with a copy of the provided data, with the default device transport
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
// creates a message with a copy of the provided data, with the transport of the specified channel
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessageFor(const std::string& channel, int index, const T& data)
|
||||
{
|
||||
return GetChannel(channel, index).NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
// creates unamanaged region with the default device transport
|
||||
template<typename... Args>
|
||||
FairMQUnmanagedRegionPtr NewUnmanagedRegion(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateUnmanagedRegion(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// creates unmanaged region with the transport of the specified channel
|
||||
template<typename... Args>
|
||||
FairMQUnmanagedRegionPtr NewUnmanagedRegionFor(const std::string& channel, int index, Args&&... args)
|
||||
{
|
||||
return GetChannel(channel, index).NewUnmanagedRegion(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename ...Ts>
|
||||
FairMQPollerPtr NewPoller(const Ts&... inputs)
|
||||
{
|
||||
std::vector<std::string> chans{inputs...};
|
||||
|
||||
// if more than one channel provided, check compatibility
|
||||
if (chans.size() > 1)
|
||||
{
|
||||
fair::mq::Transport type = GetChannel(chans.at(0), 0).Transport()->GetType();
|
||||
|
||||
for (unsigned int i = 1; i < chans.size(); ++i)
|
||||
{
|
||||
if (type != GetChannel(chans.at(i), 0).Transport()->GetType())
|
||||
{
|
||||
LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state.";
|
||||
throw std::runtime_error("poller failed: different transports within same poller are not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GetChannel(chans.at(0), 0).Transport()->CreatePoller(fChannels, chans);
|
||||
}
|
||||
|
||||
FairMQPollerPtr NewPoller(const std::vector<FairMQChannel*>& channels)
|
||||
{
|
||||
// if more than one channel provided, check compatibility
|
||||
if (channels.size() > 1)
|
||||
{
|
||||
fair::mq::Transport type = channels.at(0)->Transport()->GetType();
|
||||
|
||||
for (unsigned int i = 1; i < channels.size(); ++i)
|
||||
{
|
||||
if (type != channels.at(i)->Transport()->GetType())
|
||||
{
|
||||
LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state.";
|
||||
throw std::runtime_error("poller failed: different transports within same poller are not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return channels.at(0)->Transport()->CreatePoller(channels);
|
||||
}
|
||||
|
||||
/// Adds a transport to the device if it doesn't exist
|
||||
/// @param transport Transport string ("zeromq"/"shmem")
|
||||
std::shared_ptr<FairMQTransportFactory> AddTransport(const fair::mq::Transport transport);
|
||||
|
||||
/// Assigns config to the device
|
||||
void SetConfig(fair::mq::ProgOptions& config);
|
||||
/// Get pointer to the config
|
||||
fair::mq::ProgOptions* GetConfig() const
|
||||
{
|
||||
return fConfig;
|
||||
}
|
||||
|
||||
// overload to easily bind member functions
|
||||
template<typename T>
|
||||
void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQMessagePtr& msg, int index))
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMsgInputs.insert(std::make_pair(channelName, [this, memberFunction](FairMQMessagePtr& msg, int index)
|
||||
{
|
||||
return (static_cast<T*>(this)->*memberFunction)(msg, index);
|
||||
}));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName) == fInputChannelKeys.end())
|
||||
{
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
void OnData(const std::string& channelName, InputMsgCallback callback)
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMsgInputs.insert(make_pair(channelName, callback));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName) == fInputChannelKeys.end())
|
||||
{
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
// overload to easily bind member functions
|
||||
template<typename T>
|
||||
void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQParts& parts, int index))
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMultipartInputs.insert(std::make_pair(channelName, [this, memberFunction](FairMQParts& parts, int index)
|
||||
{
|
||||
return (static_cast<T*>(this)->*memberFunction)(parts, index);
|
||||
}));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName) == fInputChannelKeys.end())
|
||||
{
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
void OnData(const std::string& channelName, InputMultipartCallback callback)
|
||||
{
|
||||
fDataCallbacks = true;
|
||||
fMultipartInputs.insert(make_pair(channelName, callback));
|
||||
|
||||
if (find(fInputChannelKeys.begin(), fInputChannelKeys.end(), channelName) == fInputChannelKeys.end())
|
||||
{
|
||||
fInputChannelKeys.push_back(channelName);
|
||||
}
|
||||
}
|
||||
|
||||
FairMQChannel& GetChannel(const std::string& channelName, const int index = 0)
|
||||
try {
|
||||
return fChannels.at(channelName).at(index);
|
||||
} catch (const std::out_of_range& oor) {
|
||||
LOG(error) << "requested channel has not been configured? check channel names/configuration.";
|
||||
LOG(error) << "channel: " << channelName << ", index: " << index;
|
||||
LOG(error) << "out of range: " << oor.what();
|
||||
throw;
|
||||
}
|
||||
|
||||
virtual void RegisterChannelEndpoints() {}
|
||||
|
||||
bool RegisterChannelEndpoint(const std::string& channelName, uint16_t minNumSubChannels = 1, uint16_t maxNumSubChannels = 1)
|
||||
{
|
||||
bool ok = fChannelRegistry.insert(std::make_pair(channelName, std::make_pair(minNumSubChannels, maxNumSubChannels))).second;
|
||||
if (!ok) {
|
||||
LOG(warn) << "Registering channel: name already registered: \"" << channelName << "\"";
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void PrintRegisteredChannels()
|
||||
{
|
||||
if (fChannelRegistry.size() < 1) {
|
||||
LOGV(info, verylow) << "no channels registered.";
|
||||
} else {
|
||||
for (const auto& c : fChannelRegistry) {
|
||||
LOGV(info, verylow) << c.first << ":" << c.second.first << ":" << c.second.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetId(const std::string& id) { fId = id; }
|
||||
std::string GetId() { return fId; }
|
||||
|
||||
const fair::mq::tools::Version GetVersion() const { return fVersion; }
|
||||
|
||||
void SetNumIoThreads(int numIoThreads) { fConfig->SetProperty("io-threads", numIoThreads);}
|
||||
int GetNumIoThreads() const { return fConfig->GetProperty<int>("io-threads", DefaultIOThreads); }
|
||||
|
||||
void SetNetworkInterface(const std::string& networkInterface) { fConfig->SetProperty("network-interface", networkInterface); }
|
||||
std::string GetNetworkInterface() const { return fConfig->GetProperty<std::string>("network-interface", DefaultNetworkInterface); }
|
||||
|
||||
void SetDefaultTransport(const std::string& name) { fConfig->SetProperty("transport", name); }
|
||||
std::string GetDefaultTransport() const { return fConfig->GetProperty<std::string>("transport", DefaultTransportName); }
|
||||
|
||||
void SetInitTimeoutInS(int initTimeoutInS) { fConfig->SetProperty("init-timeout", initTimeoutInS); }
|
||||
int GetInitTimeoutInS() const { return fConfig->GetProperty<int>("init-timeout", DefaultInitTimeout); }
|
||||
|
||||
/// Sets the default transport for the device
|
||||
/// @param transport Transport string ("zeromq"/"shmem")
|
||||
void SetTransport(const std::string& transport) { fConfig->SetProperty("transport", transport); }
|
||||
/// Gets the default transport name
|
||||
std::string GetTransportName() const { return fConfig->GetProperty<std::string>("transport", DefaultTransportName); }
|
||||
|
||||
void SetRawCmdLineArgs(const std::vector<std::string>& args) { fRawCmdLineArgs = args; }
|
||||
std::vector<std::string> GetRawCmdLineArgs() const { return fRawCmdLineArgs; }
|
||||
|
||||
void RunStateMachine()
|
||||
{
|
||||
fStateMachine.ProcessWork();
|
||||
};
|
||||
|
||||
/// Wait for the supplied amount of time or for interruption.
|
||||
/// If interrupted, returns false, otherwise true.
|
||||
/// @param duration wait duration
|
||||
template<typename Rep, typename Period>
|
||||
bool WaitFor(std::chrono::duration<Rep, Period> const& duration)
|
||||
{
|
||||
return !fStateMachine.WaitForPendingStateFor(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FairMQTransportFactory> fTransportFactory; ///< Default transport factory
|
||||
std::unordered_map<fair::mq::Transport, std::shared_ptr<FairMQTransportFactory>> fTransports; ///< Container for transports
|
||||
|
||||
public:
|
||||
std::unordered_map<std::string, std::vector<FairMQChannel>> fChannels; ///< Device channels
|
||||
std::unique_ptr<fair::mq::ProgOptions> fInternalConfig; ///< Internal program options configuration
|
||||
fair::mq::ProgOptions* fConfig; ///< Pointer to config (internal or external)
|
||||
|
||||
void AddChannel(const std::string& name, FairMQChannel&& channel)
|
||||
{
|
||||
fConfig->AddChannel(name, channel);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string fId; ///< Device ID
|
||||
|
||||
/// Additional user initialization (can be overloaded in child classes). Prefer to use InitTask().
|
||||
virtual void Init() {}
|
||||
|
||||
virtual void Bind() {}
|
||||
|
||||
virtual void Connect() {}
|
||||
|
||||
/// Task initialization (can be overloaded in child classes)
|
||||
virtual void InitTask() {}
|
||||
|
||||
/// Runs the device (to be overloaded in child classes)
|
||||
virtual void Run() {}
|
||||
|
||||
/// Called in the RUNNING state once before executing the Run()/ConditionalRun() method
|
||||
virtual void PreRun() {}
|
||||
|
||||
/// Called during RUNNING state repeatedly until it returns false or device state changes
|
||||
virtual bool ConditionalRun() { return false; }
|
||||
|
||||
/// Called in the RUNNING state once after executing the Run()/ConditionalRun() method
|
||||
virtual void PostRun() {}
|
||||
|
||||
/// Resets the user task (to be overloaded in child classes)
|
||||
virtual void ResetTask() {}
|
||||
|
||||
/// Resets the device (can be overloaded in child classes)
|
||||
virtual void Reset() {}
|
||||
|
||||
public:
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
///
|
||||
/// The state transition may not happen immediately, but when the current state evaluates the
|
||||
/// pending transition event and terminates. In other words, the device states are scheduled cooperatively.
|
||||
bool ChangeState(const fair::mq::Transition transition) { return fStateMachine.ChangeState(transition); }
|
||||
/// @brief Request a device state transition
|
||||
/// @param transition state transition
|
||||
///
|
||||
/// The state transition may not happen immediately, but when the current state evaluates the
|
||||
/// pending transition event and terminates. In other words, the device states are scheduled cooperatively.
|
||||
bool ChangeState(const std::string& transition) { return fStateMachine.ChangeState(fair::mq::GetTransition(transition)); }
|
||||
|
||||
/// @brief waits for the next state (any) to occur
|
||||
fair::mq::State WaitForNextState() { return fStateQueue.WaitForNext(); }
|
||||
/// @brief waits for the specified state to occur
|
||||
/// @param state state to wait for
|
||||
void WaitForState(fair::mq::State state) { fStateQueue.WaitForState(state); }
|
||||
/// @brief waits for the specified state to occur
|
||||
/// @param state state to wait for
|
||||
void WaitForState(const std::string& state) { WaitForState(fair::mq::GetState(state)); }
|
||||
|
||||
void TransitionTo(const fair::mq::State state);
|
||||
|
||||
/// @brief Subscribe with a callback to state changes
|
||||
/// @param key id to identify your subscription
|
||||
/// @param callback callback (called with the new state as the parameter)
|
||||
///
|
||||
/// The callback is called at the beginning of a new state.
|
||||
/// The callback is called from the thread the state is running in.
|
||||
void SubscribeToStateChange(const std::string& key, std::function<void(const fair::mq::State)> callback) { fStateMachine.SubscribeToStateChange(key, callback); }
|
||||
/// @brief Unsubscribe from state changes
|
||||
/// @param key id (that was used when subscribing)
|
||||
void UnsubscribeFromStateChange(const std::string& key) { fStateMachine.UnsubscribeFromStateChange(key); }
|
||||
|
||||
/// @brief Subscribe with a callback to incoming state transitions
|
||||
/// @param key id to identify your subscription
|
||||
/// @param callback callback (called with the incoming transition as the parameter)
|
||||
/// The callback is called when new transition is initiated.
|
||||
/// The callback is called from the thread that initiates the transition (via ChangeState).
|
||||
void SubscribeToNewTransition(const std::string& key, std::function<void(const fair::mq::Transition)> callback) { fStateMachine.SubscribeToNewTransition(key, callback); }
|
||||
/// @brief Unsubscribe from state transitions
|
||||
/// @param key id (that was used when subscribing)
|
||||
void UnsubscribeFromNewTransition(const std::string& key) { fStateMachine.UnsubscribeFromNewTransition(key); }
|
||||
|
||||
/// @brief Returns true if a new state has been requested, signaling the current handler to stop.
|
||||
bool NewStatePending() const { return fStateMachine.NewStatePending(); }
|
||||
|
||||
/// @brief Returns the current state
|
||||
fair::mq::State GetCurrentState() const { return fStateMachine.GetCurrentState(); }
|
||||
/// @brief Returns the name of the current state as a string
|
||||
std::string GetCurrentStateName() const { return fStateMachine.GetCurrentStateName(); }
|
||||
|
||||
/// @brief Returns name of the given state as a string
|
||||
/// @param state state
|
||||
static std::string GetStateName(const fair::mq::State state) { return fair::mq::GetStateName(state); }
|
||||
/// @brief Returns name of the given transition as a string
|
||||
/// @param transition transition
|
||||
static std::string GetTransitionName(const fair::mq::Transition transition) { return fair::mq::GetTransitionName(transition); }
|
||||
|
||||
static constexpr const char* DefaultId = "";
|
||||
static constexpr int DefaultIOThreads = 1;
|
||||
static constexpr const char* DefaultTransportName = "zeromq";
|
||||
static constexpr fair::mq::Transport DefaultTransportType = fair::mq::Transport::ZMQ;
|
||||
static constexpr const char* DefaultNetworkInterface = "default";
|
||||
static constexpr int DefaultInitTimeout = 120;
|
||||
static constexpr uint64_t DefaultMaxRunTime = 0;
|
||||
static constexpr float DefaultRate = 0.;
|
||||
static constexpr const char* DefaultSession = "default";
|
||||
|
||||
private:
|
||||
fair::mq::Transport fDefaultTransportType; ///< Default transport for the device
|
||||
fair::mq::StateMachine fStateMachine;
|
||||
|
||||
/// Handles the initialization
|
||||
void InitWrapper();
|
||||
/// Initializes binding channels
|
||||
void BindWrapper();
|
||||
/// Initializes connecting channels
|
||||
void ConnectWrapper();
|
||||
/// Handles the InitTask() method
|
||||
void InitTaskWrapper();
|
||||
/// Handles the Run() method
|
||||
void RunWrapper();
|
||||
/// Handles the ResetTask() method
|
||||
void ResetTaskWrapper();
|
||||
/// Handles the Reset() method
|
||||
void ResetWrapper();
|
||||
|
||||
/// Notifies transports to cease any blocking activity
|
||||
void UnblockTransports();
|
||||
|
||||
/// Shuts down the transports and the device
|
||||
void Exit() {}
|
||||
|
||||
/// Attach (bind/connect) channels in the list
|
||||
void AttachChannels(std::vector<FairMQChannel*>& chans);
|
||||
bool AttachChannel(FairMQChannel& ch);
|
||||
|
||||
void HandleSingleChannelInput();
|
||||
void HandleMultipleChannelInput();
|
||||
void HandleMultipleTransportInput();
|
||||
void PollForTransport(const FairMQTransportFactory* factory, const std::vector<std::string>& channelKeys);
|
||||
|
||||
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i);
|
||||
bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i);
|
||||
|
||||
std::vector<FairMQChannel*> fUninitializedBindingChannels;
|
||||
std::vector<FairMQChannel*> fUninitializedConnectingChannels;
|
||||
|
||||
bool fDataCallbacks;
|
||||
std::unordered_map<std::string, InputMsgCallback> fMsgInputs;
|
||||
std::unordered_map<std::string, InputMultipartCallback> fMultipartInputs;
|
||||
std::unordered_map<fair::mq::Transport, std::vector<std::string>> fMultitransportInputs;
|
||||
std::unordered_map<std::string, std::pair<uint16_t, uint16_t>> fChannelRegistry;
|
||||
std::vector<std::string> fInputChannelKeys;
|
||||
std::mutex fMultitransportMutex;
|
||||
std::atomic<bool> fMultitransportProceed;
|
||||
|
||||
const fair::mq::tools::Version fVersion;
|
||||
float fRate; ///< Rate limiting for ConditionalRun
|
||||
uint64_t fMaxRunRuntimeInS; ///< Maximum runtime for the Running state handler, after which state will change to Ready (in seconds, 0 for no limit).
|
||||
int fInitializationTimeoutInS;
|
||||
std::vector<std::string> fRawCmdLineArgs;
|
||||
|
||||
fair::mq::StateQueue fStateQueue;
|
||||
|
||||
std::mutex fTransitionMtx;
|
||||
bool fTransitioning;
|
||||
};
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
#endif /* FAIRMQDEVICE_H_ */
|
||||
|
@@ -1,15 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQLogger.cxx
|
||||
*
|
||||
* @since 2012-12-04
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include "FairMQLogger.h"
|
@@ -1,13 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQMessage.cxx
|
||||
*
|
||||
* @since 2012-12-05
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,65 +9,12 @@
|
||||
#ifndef FAIRMQMESSAGE_H_
|
||||
#define FAIRMQMESSAGE_H_
|
||||
|
||||
#include <cstddef> // for size_t
|
||||
#include <memory> // unique_ptr
|
||||
#include <stdexcept>
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_MESSAGE_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/Message.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <fairmq/Transports.h>
|
||||
|
||||
using fairmq_free_fn = void(void* data, void* hint);
|
||||
class FairMQTransportFactory;
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
struct Alignment
|
||||
{
|
||||
size_t alignment;
|
||||
explicit operator size_t() const { return alignment; }
|
||||
};
|
||||
|
||||
} // namespace fair::mq
|
||||
|
||||
class FairMQMessage
|
||||
{
|
||||
public:
|
||||
FairMQMessage() = default;
|
||||
FairMQMessage(FairMQTransportFactory* factory) : fTransport(factory) {}
|
||||
|
||||
virtual void Rebuild() = 0;
|
||||
virtual void Rebuild(fair::mq::Alignment alignment) = 0;
|
||||
virtual void Rebuild(const size_t size) = 0;
|
||||
virtual void Rebuild(const size_t size, fair::mq::Alignment alignment) = 0;
|
||||
virtual void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
|
||||
|
||||
virtual void* GetData() const = 0;
|
||||
virtual size_t GetSize() const = 0;
|
||||
|
||||
virtual bool SetUsedSize(const size_t size) = 0;
|
||||
|
||||
virtual fair::mq::Transport GetType() const = 0;
|
||||
FairMQTransportFactory* GetTransport() { return fTransport; }
|
||||
void SetTransport(FairMQTransportFactory* transport) { fTransport = transport; }
|
||||
|
||||
virtual void Copy(const FairMQMessage& msg) = 0;
|
||||
|
||||
virtual ~FairMQMessage() {};
|
||||
|
||||
private:
|
||||
FairMQTransportFactory* fTransport{nullptr};
|
||||
};
|
||||
|
||||
using FairMQMessagePtr = std::unique_ptr<FairMQMessage>;
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
using Message = FairMQMessage;
|
||||
using MessagePtr = FairMQMessagePtr;
|
||||
struct MessageError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
struct MessageBadAlloc : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
} // namespace fair::mq
|
||||
#include <fairmq/Message.h>
|
||||
|
||||
#endif /* FAIRMQMESSAGE_H_ */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,90 +9,12 @@
|
||||
#ifndef FAIRMQPARTS_H_
|
||||
#define FAIRMQPARTS_H_
|
||||
|
||||
#include "FairMQTransportFactory.h"
|
||||
#include "FairMQMessage.h"
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_PARTS_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/Parts.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <memory> // unique_ptr
|
||||
|
||||
/// FairMQParts is a lightweight convenience wrapper around a vector of unique pointers to FairMQMessage, used for sending multi-part messages
|
||||
|
||||
class FairMQParts
|
||||
{
|
||||
private:
|
||||
using container = std::vector<std::unique_ptr<FairMQMessage>>;
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
FairMQParts() : fParts() {};
|
||||
/// Copy Constructor
|
||||
FairMQParts(const FairMQParts&) = delete;
|
||||
/// Move constructor
|
||||
FairMQParts(FairMQParts&& p) = default;
|
||||
/// Assignment operator
|
||||
FairMQParts& operator=(const FairMQParts&) = delete;
|
||||
/// Constructor from argument pack of std::unique_ptr<FairMQMessage> rvalues
|
||||
template <typename... Ts>
|
||||
FairMQParts(Ts&&... messages) : fParts() { AddPart(std::forward<Ts>(messages)...); }
|
||||
/// Default destructor
|
||||
~FairMQParts() {};
|
||||
|
||||
/// Adds part (FairMQMessage) to the container
|
||||
/// @param msg message pointer (for example created with NewMessage() method of FairMQDevice)
|
||||
void AddPart(FairMQMessage* msg)
|
||||
{
|
||||
fParts.push_back(std::unique_ptr<FairMQMessage>(msg));
|
||||
}
|
||||
|
||||
/// Adds part (std::unique_ptr<FairMQMessage>&) to the container (move)
|
||||
/// @param msg unique pointer to FairMQMessage
|
||||
/// rvalue ref (move required when passing argument)
|
||||
void AddPart(std::unique_ptr<FairMQMessage>&& msg)
|
||||
{
|
||||
fParts.push_back(std::move(msg));
|
||||
}
|
||||
|
||||
/// Add variable list of parts to the container (move)
|
||||
template <typename... Ts>
|
||||
void AddPart(std::unique_ptr<FairMQMessage>&& first, Ts&&... remaining)
|
||||
{
|
||||
AddPart(std::move(first));
|
||||
AddPart(std::forward<Ts>(remaining)...);
|
||||
}
|
||||
|
||||
/// Add content of another object by move
|
||||
void AddPart(FairMQParts&& other)
|
||||
{
|
||||
container parts = std::move(other.fParts);
|
||||
for (auto& part : parts) {
|
||||
fParts.push_back(std::move(part));
|
||||
}
|
||||
}
|
||||
|
||||
/// Get reference to part in the container at index (without bounds check)
|
||||
/// @param index container index
|
||||
FairMQMessage& operator[](const int index) { return *(fParts[index]); }
|
||||
|
||||
/// Get reference to unique pointer to part in the container at index (with bounds check)
|
||||
/// @param index container index
|
||||
std::unique_ptr<FairMQMessage>& At(const int index) { return fParts.at(index); }
|
||||
|
||||
// ref version
|
||||
FairMQMessage& AtRef(const int index) { return *(fParts.at(index)); }
|
||||
|
||||
/// Get number of parts in the container
|
||||
/// @return number of parts in the container
|
||||
int Size() const { return fParts.size(); }
|
||||
|
||||
container fParts;
|
||||
|
||||
// forward container iterators
|
||||
using iterator = container::iterator;
|
||||
using const_iterator = container::const_iterator;
|
||||
auto begin() -> decltype(fParts.begin()) { return fParts.begin(); }
|
||||
auto end() -> decltype(fParts.end()) { return fParts.end(); }
|
||||
auto cbegin() -> decltype(fParts.cbegin()) { return fParts.cbegin(); }
|
||||
auto cend() -> decltype(fParts.cend()) { return fParts.cend(); }
|
||||
};
|
||||
#include <fairmq/Parts.h>
|
||||
|
||||
#endif /* FAIRMQPARTS_H_ */
|
||||
|
@@ -1,13 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQPoller.cxx
|
||||
*
|
||||
* @since 2014-01-23
|
||||
* @author A. Rybalchenko
|
||||
*/
|
@@ -9,31 +9,12 @@
|
||||
#ifndef FAIRMQPOLLER_H_
|
||||
#define FAIRMQPOLLER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_POLLER_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/Poller.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class FairMQPoller
|
||||
{
|
||||
public:
|
||||
virtual void Poll(const int timeout) = 0;
|
||||
virtual bool CheckInput(const int index) = 0;
|
||||
virtual bool CheckOutput(const int index) = 0;
|
||||
virtual bool CheckInput(const std::string& channelKey, const int index) = 0;
|
||||
virtual bool CheckOutput(const std::string& channelKey, const int index) = 0;
|
||||
|
||||
virtual ~FairMQPoller() {};
|
||||
};
|
||||
|
||||
using FairMQPollerPtr = std::unique_ptr<FairMQPoller>;
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
using Poller = FairMQPoller;
|
||||
using PollerPtr = FairMQPollerPtr;
|
||||
struct PollerError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
} // namespace fair::mq
|
||||
#include <fairmq/Poller.h>
|
||||
|
||||
#endif /* FAIRMQPOLLER_H_ */
|
||||
|
@@ -1,9 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <FairMQSocket.h>
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,88 +9,12 @@
|
||||
#ifndef FAIRMQSOCKET_H_
|
||||
#define FAIRMQSOCKET_H_
|
||||
|
||||
#include "FairMQMessage.h"
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_SOCKET_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/Socket.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class FairMQTransportFactory;
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
enum class TransferCode : int
|
||||
{
|
||||
success = 0,
|
||||
error = -1,
|
||||
timeout = -2,
|
||||
interrupted = -3
|
||||
};
|
||||
|
||||
} // namespace fair::mq
|
||||
|
||||
class FairMQSocket
|
||||
{
|
||||
public:
|
||||
FairMQSocket() {}
|
||||
FairMQSocket(FairMQTransportFactory* fac) : fTransport(fac) {}
|
||||
|
||||
virtual std::string GetId() const = 0;
|
||||
|
||||
virtual bool Bind(const std::string& address) = 0;
|
||||
virtual bool Connect(const std::string& address) = 0;
|
||||
|
||||
virtual int64_t Send(FairMQMessagePtr& msg, int timeout = -1) = 0;
|
||||
virtual int64_t Receive(FairMQMessagePtr& msg, int timeout = -1) = 0;
|
||||
virtual int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = -1) = 0;
|
||||
virtual int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = -1) = 0;
|
||||
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual void SetOption(const std::string& option, const void* value, size_t valueSize) = 0;
|
||||
virtual void GetOption(const std::string& option, void* value, size_t* valueSize) = 0;
|
||||
|
||||
/// If the backend supports it, fills the unsigned integer @a events with the ZMQ_EVENTS value
|
||||
/// DISCLAIMER: this API is experimental and unsupported and might be dropped / refactored in
|
||||
/// the future.
|
||||
virtual int Events(uint32_t* events) = 0;
|
||||
virtual void SetLinger(const int value) = 0;
|
||||
virtual int GetLinger() const = 0;
|
||||
virtual void SetSndBufSize(const int value) = 0;
|
||||
virtual int GetSndBufSize() const = 0;
|
||||
virtual void SetRcvBufSize(const int value) = 0;
|
||||
virtual int GetRcvBufSize() const = 0;
|
||||
virtual void SetSndKernelSize(const int value) = 0;
|
||||
virtual int GetSndKernelSize() const = 0;
|
||||
virtual void SetRcvKernelSize(const int value) = 0;
|
||||
virtual int GetRcvKernelSize() const = 0;
|
||||
|
||||
virtual unsigned long GetBytesTx() const = 0;
|
||||
virtual unsigned long GetBytesRx() const = 0;
|
||||
virtual unsigned long GetMessagesTx() const = 0;
|
||||
virtual unsigned long GetMessagesRx() const = 0;
|
||||
|
||||
FairMQTransportFactory* GetTransport() { return fTransport; }
|
||||
void SetTransport(FairMQTransportFactory* transport) { fTransport = transport; }
|
||||
|
||||
virtual ~FairMQSocket() {};
|
||||
|
||||
private:
|
||||
FairMQTransportFactory* fTransport{nullptr};
|
||||
};
|
||||
|
||||
using FairMQSocketPtr = std::unique_ptr<FairMQSocket>;
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
using Socket = FairMQSocket;
|
||||
using SocketPtr = FairMQSocketPtr;
|
||||
struct SocketError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
} // namespace fair::mq
|
||||
#include <fairmq/Socket.h>
|
||||
|
||||
#endif /* FAIRMQSOCKET_H_ */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,174 +9,12 @@
|
||||
#ifndef FAIRMQTRANSPORTFACTORY_H_
|
||||
#define FAIRMQTRANSPORTFACTORY_H_
|
||||
|
||||
#include <FairMQMessage.h>
|
||||
#include <FairMQPoller.h>
|
||||
#include <FairMQSocket.h>
|
||||
#include <FairMQUnmanagedRegion.h>
|
||||
#include <fairmq/MemoryResources.h>
|
||||
#include <fairmq/Transports.h>
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_TRANSPORTFACTORY_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/TransportFactory.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <memory> // shared_ptr
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <stdexcept>
|
||||
#include <cstddef> // size_t
|
||||
|
||||
class FairMQChannel;
|
||||
namespace fair::mq { class ProgOptions; }
|
||||
|
||||
class FairMQTransportFactory
|
||||
{
|
||||
private:
|
||||
/// Topology wide unique id
|
||||
const std::string fkId;
|
||||
|
||||
/// The polymorphic memory resource associated with the transport
|
||||
fair::mq::ChannelResource fMemoryResource{this};
|
||||
|
||||
public:
|
||||
/// ctor
|
||||
/// @param id Topology wide unique id, usually the device id.
|
||||
FairMQTransportFactory(const std::string& id);
|
||||
|
||||
auto GetId() const -> const std::string { return fkId; };
|
||||
|
||||
/// Get a pointer to the associated polymorphic memory resource
|
||||
fair::mq::ChannelResource* GetMemoryResource() { return &fMemoryResource; }
|
||||
operator fair::mq::ChannelResource*() { return &fMemoryResource; }
|
||||
|
||||
/// @brief Create empty FairMQMessage (for receiving)
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage() = 0;
|
||||
/// @brief Create empty FairMQMessage (for receiving), align received buffer to specified alignment
|
||||
/// @param alignment alignment to align received buffer to
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage(fair::mq::Alignment alignment) = 0;
|
||||
/// @brief Create new FairMQMessage of specified size
|
||||
/// @param size message size
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage(const size_t size) = 0;
|
||||
/// @brief Create new FairMQMessage of specified size and alignment
|
||||
/// @param size message size
|
||||
/// @param alignment message alignment
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage(const size_t size, fair::mq::Alignment alignment) = 0;
|
||||
/// @brief Create new FairMQMessage with user provided buffer and size
|
||||
/// @param data pointer to user provided buffer
|
||||
/// @param size size of the user provided buffer
|
||||
/// @param ffn callback, called when the message is transfered (and can be deleted)
|
||||
/// @param obj optional helper pointer that can be used in the callback
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
|
||||
/// @brief create a message with the buffer located within the corresponding unmanaged region
|
||||
/// @param unmanagedRegion the unmanaged region that this message buffer belongs to
|
||||
/// @param data message buffer (must be within the region - checked at runtime by the transport)
|
||||
/// @param size size of the message
|
||||
/// @param hint optional parameter, returned to the user in the FairMQRegionCallback
|
||||
virtual FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& unmanagedRegion, void* data, const size_t size, void* hint = 0) = 0;
|
||||
|
||||
/// @brief Create a socket
|
||||
virtual FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) = 0;
|
||||
|
||||
/// @brief Create a poller for a single channel (all subchannels)
|
||||
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const = 0;
|
||||
/// @brief Create a poller for specific channels
|
||||
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const = 0;
|
||||
/// @brief Create a poller for specific channels (all subchannels)
|
||||
virtual FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const = 0;
|
||||
|
||||
/// @brief Create new UnmanagedRegion
|
||||
/// @param size size of the region
|
||||
/// @param callback callback to be called when a message belonging to this region is no longer needed by the transport
|
||||
/// @param path optional parameter to pass to the underlying transport
|
||||
/// @param flags optional parameter to pass to the underlying transport
|
||||
/// @return pointer to UnmanagedRegion
|
||||
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr, const std::string& path = "", int flags = 0, fair::mq::RegionConfig cfg = fair::mq::RegionConfig()) = 0;
|
||||
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionBulkCallback callback = nullptr, const std::string& path = "", int flags = 0, fair::mq::RegionConfig cfg = fair::mq::RegionConfig()) = 0;
|
||||
/// @brief Create new UnmanagedRegion
|
||||
/// @param size size of the region
|
||||
/// @param userFlags flags to be stored with the region, have no effect on the transport, but can be retrieved from the region by the user
|
||||
/// @param callback callback to be called when a message belonging to this region is no longer needed by the transport
|
||||
/// @param path optional parameter to pass to the underlying transport
|
||||
/// @param flags optional parameter to pass to the underlying transport
|
||||
/// @return pointer to UnmanagedRegion
|
||||
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, const int64_t userFlags, FairMQRegionCallback callback = nullptr, const std::string& path = "", int flags = 0, fair::mq::RegionConfig cfg = fair::mq::RegionConfig()) = 0;
|
||||
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, const int64_t userFlags, FairMQRegionBulkCallback callback = nullptr, const std::string& path = "", int flags = 0, fair::mq::RegionConfig cfg = fair::mq::RegionConfig()) = 0;
|
||||
|
||||
/// @brief Subscribe to region events (creation, destruction, ...)
|
||||
/// @param callback the callback that is called when a region event occurs
|
||||
virtual void SubscribeToRegionEvents(FairMQRegionEventCallback callback) = 0;
|
||||
/// @brief Check if there is an active subscription to region events
|
||||
/// @return true/false
|
||||
virtual bool SubscribedToRegionEvents() = 0;
|
||||
/// @brief Unsubscribe from region events
|
||||
virtual void UnsubscribeFromRegionEvents() = 0;
|
||||
|
||||
virtual std::vector<FairMQRegionInfo> GetRegionInfo() = 0;
|
||||
|
||||
/// Get transport type
|
||||
virtual fair::mq::Transport GetType() const = 0;
|
||||
|
||||
virtual void Interrupt() = 0;
|
||||
virtual void Resume() = 0;
|
||||
virtual void Reset() = 0;
|
||||
|
||||
virtual ~FairMQTransportFactory() {};
|
||||
|
||||
static auto CreateTransportFactory(const std::string& type, const std::string& id = "", const fair::mq::ProgOptions* config = nullptr) -> std::shared_ptr<FairMQTransportFactory>;
|
||||
|
||||
static void FairMQNoCleanup(void* /*data*/, void* /*obj*/)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void FairMQSimpleMsgCleanup(void* /*data*/, void* obj)
|
||||
{
|
||||
delete static_cast<T*>(obj);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
// todo: is_trivially_copyable not available on gcc < 5, workaround?
|
||||
// static_assert(std::is_trivially_copyable<T>::value, "The argument type for NewSimpleMessage has to be trivially copyable!");
|
||||
T* dataCopy = new T(data);
|
||||
return CreateMessage(dataCopy, sizeof(T), FairMQSimpleMsgCleanup<T>, dataCopy);
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
FairMQMessagePtr NewSimpleMessage(const char(&data)[N])
|
||||
{
|
||||
std::string* msgStr = new std::string(data);
|
||||
return CreateMessage(const_cast<char*>(msgStr->c_str()), msgStr->length(), FairMQSimpleMsgCleanup<std::string>, msgStr);
|
||||
}
|
||||
|
||||
FairMQMessagePtr NewSimpleMessage(const std::string& str)
|
||||
{
|
||||
|
||||
std::string* msgStr = new std::string(str);
|
||||
return CreateMessage(const_cast<char*>(msgStr->c_str()), msgStr->length(), FairMQSimpleMsgCleanup<std::string>, msgStr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return CreateMessage(data, sizeof(T), FairMQNoCleanup, nullptr);
|
||||
}
|
||||
|
||||
FairMQMessagePtr NewStaticMessage(const std::string& str)
|
||||
{
|
||||
return CreateMessage(const_cast<char*>(str.c_str()), str.length(), FairMQNoCleanup, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
using TransportFactory = FairMQTransportFactory;
|
||||
struct TransportFactoryError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
} // namespace fair::mq
|
||||
#include <fairmq/TransportFactory.h>
|
||||
|
||||
#endif /* FAIRMQTRANSPORTFACTORY_H_ */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -9,127 +9,12 @@
|
||||
#ifndef FAIRMQUNMANAGEDREGION_H_
|
||||
#define FAIRMQUNMANAGEDREGION_H_
|
||||
|
||||
#include <cstddef> // size_t
|
||||
#include <cstdint> // uint32_t
|
||||
#include <memory> // std::unique_ptr
|
||||
#include <functional> // std::function
|
||||
#include <ostream> // std::ostream
|
||||
#include <vector>
|
||||
#if 0
|
||||
#ifndef FAIR_MQ_UNMANAGEDREGION_H
|
||||
#pragma GCC warning "Deprecated header: Use <fairmq/UnmanagedRegion.h> instead"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class FairMQTransportFactory;
|
||||
|
||||
enum class FairMQRegionEvent : int
|
||||
{
|
||||
created,
|
||||
destroyed,
|
||||
local_only
|
||||
};
|
||||
|
||||
struct FairMQRegionInfo
|
||||
{
|
||||
FairMQRegionInfo()
|
||||
: managed(true)
|
||||
, id(0)
|
||||
, ptr(nullptr)
|
||||
, size(0)
|
||||
, flags(0)
|
||||
, event(FairMQRegionEvent::created)
|
||||
{}
|
||||
|
||||
FairMQRegionInfo(bool _managed, uint64_t _id, void* _ptr, size_t _size, int64_t _flags, FairMQRegionEvent _event)
|
||||
: managed(_managed)
|
||||
, id(_id)
|
||||
, ptr(_ptr)
|
||||
, size(_size)
|
||||
, flags(_flags)
|
||||
, event(_event)
|
||||
{}
|
||||
|
||||
bool managed; // managed/unmanaged
|
||||
uint64_t id; // id of the region
|
||||
void* ptr; // pointer to the start of the region
|
||||
size_t size; // region size
|
||||
int64_t flags; // custom flags set by the creator
|
||||
FairMQRegionEvent event;
|
||||
};
|
||||
|
||||
struct FairMQRegionBlock {
|
||||
void* ptr;
|
||||
size_t size;
|
||||
void* hint;
|
||||
|
||||
FairMQRegionBlock(void* p, size_t s, void* h)
|
||||
: ptr(p), size(s), hint(h)
|
||||
{}
|
||||
};
|
||||
|
||||
using FairMQRegionCallback = std::function<void(void*, size_t, void*)>;
|
||||
using FairMQRegionBulkCallback = std::function<void(const std::vector<FairMQRegionBlock>&)>;
|
||||
using FairMQRegionEventCallback = std::function<void(FairMQRegionInfo)>;
|
||||
|
||||
class FairMQUnmanagedRegion
|
||||
{
|
||||
public:
|
||||
FairMQUnmanagedRegion() {}
|
||||
FairMQUnmanagedRegion(FairMQTransportFactory* factory) : fTransport(factory) {}
|
||||
|
||||
virtual void* GetData() const = 0;
|
||||
virtual size_t GetSize() const = 0;
|
||||
virtual uint16_t GetId() const = 0;
|
||||
virtual void SetLinger(uint32_t linger) = 0;
|
||||
virtual uint32_t GetLinger() const = 0;
|
||||
|
||||
virtual fair::mq::Transport GetType() const = 0;
|
||||
FairMQTransportFactory* GetTransport() { return fTransport; }
|
||||
void SetTransport(FairMQTransportFactory* transport) { fTransport = transport; }
|
||||
|
||||
virtual ~FairMQUnmanagedRegion() {};
|
||||
|
||||
private:
|
||||
FairMQTransportFactory* fTransport{nullptr};
|
||||
};
|
||||
|
||||
using FairMQUnmanagedRegionPtr = std::unique_ptr<FairMQUnmanagedRegion>;
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const FairMQRegionEvent& event)
|
||||
{
|
||||
switch (event) {
|
||||
case FairMQRegionEvent::created:
|
||||
return os << "created";
|
||||
case FairMQRegionEvent::destroyed:
|
||||
return os << "destroyed";
|
||||
case FairMQRegionEvent::local_only:
|
||||
return os << "local_only";
|
||||
default:
|
||||
return os << "unrecognized event";
|
||||
}
|
||||
}
|
||||
|
||||
namespace fair::mq
|
||||
{
|
||||
|
||||
struct RegionConfig {
|
||||
bool lock;
|
||||
bool zero;
|
||||
|
||||
RegionConfig()
|
||||
: lock(false), zero(false)
|
||||
{}
|
||||
|
||||
RegionConfig(bool l, bool z)
|
||||
: lock(l), zero(z)
|
||||
{}
|
||||
};
|
||||
|
||||
using RegionCallback = FairMQRegionCallback;
|
||||
using RegionBulkCallback = FairMQRegionBulkCallback;
|
||||
using RegionEventCallback = FairMQRegionEventCallback;
|
||||
using RegionEvent = FairMQRegionEvent;
|
||||
using RegionInfo = FairMQRegionInfo;
|
||||
using RegionBlock = FairMQRegionBlock;
|
||||
using UnmanagedRegion = FairMQUnmanagedRegion;
|
||||
using UnmanagedRegionPtr = FairMQUnmanagedRegionPtr;
|
||||
|
||||
} // namespace fair::mq
|
||||
#include <fairmq/UnmanagedRegion.h>
|
||||
|
||||
#endif /* FAIRMQUNMANAGEDREGION_H_ */
|
||||
|
45
fairmq/FwdDecls.h
Normal file
45
fairmq/FwdDecls.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_FWDDECLS_H
|
||||
#define FAIR_MQ_FWDDECLS_H
|
||||
|
||||
#include <fairmq/ProgOptionsFwd.h>
|
||||
|
||||
namespace fair::mq {
|
||||
|
||||
class Channel;
|
||||
class Device;
|
||||
class MemoryResource;
|
||||
class Message;
|
||||
class Parts;
|
||||
class Poller;
|
||||
class RegionBlock;
|
||||
class RegionConfig;
|
||||
class RegionInfo;
|
||||
class Socket;
|
||||
class TransportFactory;
|
||||
class UnmanagedRegion;
|
||||
|
||||
using FairMQMemoryResource = MemoryResource;
|
||||
|
||||
} // namespace fair::mq
|
||||
|
||||
using FairMQChannel = fair::mq::Channel;
|
||||
using FairMQDevice = fair::mq::Device;
|
||||
using FairMQMessage = fair::mq::Message;
|
||||
using FairMQParts = fair::mq::Parts;
|
||||
using FairMQPoller = fair::mq::Poller;
|
||||
using FairMQRegionBlock = fair::mq::RegionBlock;
|
||||
using FairMQRegionConfig = fair::mq::RegionConfig;
|
||||
using FairMQRegionInfo = fair::mq::RegionInfo;
|
||||
using FairMQSocket = fair::mq::Socket;
|
||||
using FairMQTransportFactory = fair::mq::TransportFactory;
|
||||
using FairMQUnmanagedRegion = fair::mq::UnmanagedRegion;
|
||||
|
||||
#endif // FAIR_MQ_FWDDECLS_H
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -13,16 +13,19 @@
|
||||
*/
|
||||
|
||||
#include "JSONParser.h"
|
||||
#include "FairMQChannel.h"
|
||||
#include <fairmq/PropertyOutput.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
|
||||
#include <fairlogger/Logger.h>
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/any.hpp>
|
||||
|
||||
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#undef BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <fairlogger/Logger.h>
|
||||
#include <fairmq/Channel.h>
|
||||
#include <fairmq/JSONParser.h>
|
||||
#include <fairmq/PropertyOutput.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
@@ -35,7 +38,7 @@ namespace fair::mq
|
||||
|
||||
fair::mq::Properties PtreeParser(const ptree& pt, const string& id)
|
||||
{
|
||||
if (id == "") {
|
||||
if (id.empty()) {
|
||||
throw ParserError("no device ID provided. Provide with `--id` cmd option");
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user