mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Compare commits
108 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
5e4876c947 | ||
|
3b5b2b501f | ||
|
3561255cf9 | ||
|
cbab7649be | ||
|
6ac94b7bc7 | ||
|
f9658f69a4 | ||
|
34286ef75e | ||
|
1a07137dda | ||
|
1f42f49ae5 | ||
|
d40bbfe208 | ||
|
310b9647b5 | ||
|
919193a1ad | ||
|
0cfa9192d7 | ||
|
c40bd7d6a9 | ||
|
4951433330 | ||
|
1b53538d8c | ||
|
d4a4ea14d2 | ||
|
ffab4ac78c | ||
|
ce4062f3a0 | ||
|
f8824335a5 | ||
|
2e7005225e | ||
|
dfa1b68867 | ||
|
00800f16f1 | ||
|
44acd4997d | ||
|
cfb727181f | ||
|
e090967645 | ||
|
1d45095d75 | ||
|
1fdf510ae7 | ||
|
78acb954cd | ||
|
3a1b769937 | ||
|
9f325451e5 | ||
|
a78d35d90d | ||
|
cb199e7283 | ||
|
e39316c866 | ||
|
bde12f58b2 | ||
|
45354f268b | ||
|
1aab354a5d | ||
|
e1f555bc05 | ||
|
985150437a | ||
|
cf9a2944c2 | ||
|
94297f9833 | ||
|
957233cf95 | ||
|
5397cef9d1 | ||
|
f6c1f5dc0f | ||
|
c4145e9ef1 | ||
|
4123ebc9d4 | ||
|
88f897536e | ||
|
e3c55a0ff8 | ||
|
60f27b94b2 | ||
|
adfa0e2c95 | ||
|
c2bea85b90 | ||
|
2c6b2e7f04 | ||
|
6f7ffeef13 | ||
|
2eddde0e5f | ||
|
4aae1ad8d4 | ||
|
b89c309768 | ||
|
c02fbed331 | ||
|
76aeb2c7e6 | ||
|
db5f3d794c | ||
|
b814e40c87 | ||
|
5d37ab2f01 | ||
|
5303e916fb | ||
|
7d5e76dece | ||
|
2498837b8e | ||
|
6545daeda7 | ||
|
e95096eb37 | ||
|
1bb558a457 | ||
|
1c78b8ef0a | ||
|
017c5cdc3f | ||
|
d4daa9c262 | ||
|
9564b13c19 | ||
|
56cdb3812d | ||
|
2a002a2984 | ||
|
a7429ed79b | ||
|
09ef175736 | ||
|
a55db74848 | ||
|
8b3e3bbe28 | ||
|
e71c9c1121 | ||
|
fc0adba26b | ||
|
24dff2fd76 | ||
|
70ffc0d8c6 | ||
|
ff701006fd | ||
|
c8bd19b7a1 | ||
|
aee2ba7b9b | ||
|
9184d5bdae | ||
|
5e6f3a5430 | ||
|
d0fe175cab | ||
|
6f22ccf4c1 | ||
|
b2034c20cf | ||
|
ab6fd35a86 | ||
|
4a8e46c65c | ||
|
90e00730b1 | ||
|
924c8ac5f6 | ||
|
1e0159b775 | ||
|
ef3eb5f83e | ||
|
ee8afd7d2b | ||
|
a53ef79552 | ||
|
c064da91df | ||
|
f5e3212cbf | ||
|
c1d61007a1 | ||
|
93fb407af6 | ||
|
8e7e23e2d0 | ||
|
f0ec5fa2be | ||
|
aaaadf0a0b | ||
|
daec266341 | ||
|
38a149d50c | ||
|
cfebfb3407 | ||
|
e403d18cb9 |
33
.clang-format
Normal file
33
.clang-format
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Mozilla
|
||||
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: true
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
ColumnLimit: 100
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: true
|
||||
FixNamespaceComments: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: true
|
||||
IncludeBlocks: Regroup
|
||||
NamespaceIndentation: None
|
||||
PointerAlignment: Left
|
||||
SortIncludes: true
|
||||
SpacesBeforeTrailingComments: 3
|
||||
Standard: Cpp11
|
||||
UseTab: Never
|
||||
...
|
2
.codecov.yml
Normal file
2
.codecov.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
comment:
|
||||
layout: "diff, files"
|
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
30
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Describe environment
|
||||
2. Describe compile options used
|
||||
3. Give commands you invoked
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Logs / Screenshots**
|
||||
If applicable, add logs or screenshots to help explain your problem.
|
||||
|
||||
**System information (please complete the following information):**
|
||||
- OS: [e.g. MacOS 10.13, Fedora 28, Ubuntu 14.04]
|
||||
- Compiler: [e.g. GCC 8.1, Clang 3.5]
|
||||
- Environment: [e.g. FairSoft version, alfadist revision]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
See [github markdown cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code) on how to format inline codes examples and logs.
|
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
7
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
7
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
name: Question / Support
|
||||
about: Any FairMQ related matter you are interested in
|
||||
|
||||
---
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
Replace me with your description.
|
||||
Describe your proposal.
|
||||
|
||||
Mention any issue this PR is resolves or is related to.
|
||||
|
||||
---
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
build
|
||||
|
||||
.DS_Store
|
||||
|
||||
.vscode
|
||||
|
@@ -34,26 +34,31 @@ cmake_dependent_option(BUILD_OFI_TRANSPORT "Build experimental OFI transport." O
|
||||
cmake_dependent_option(BUILD_DDS_PLUGIN "Build DDS plugin." OFF "BUILD_FAIRMQ" OFF)
|
||||
cmake_dependent_option(BUILD_EXAMPLES "Build FairMQ examples." ON "BUILD_FAIRMQ" OFF)
|
||||
option(BUILD_DOCS "Build FairMQ documentation." OFF)
|
||||
option(FAST_BUILD "Fast production build. Not recommended for development." OFF)
|
||||
################################################################################
|
||||
|
||||
|
||||
# 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_FAIRMQ)
|
||||
find_package2(PUBLIC Boost VERSION 1.64 REQUIRED
|
||||
COMPONENTS program_options thread system filesystem regex date_time signals
|
||||
COMPONENTS container program_options thread system filesystem regex date_time signals
|
||||
)
|
||||
find_package2(PUBLIC FairLogger VERSION 1.2.0 REQUIRED)
|
||||
find_package2(PRIVATE ZeroMQ VERSION 4.1.5 REQUIRED)
|
||||
endif()
|
||||
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
find_package2(PRIVATE nanomsg VERSION 1.0.0 REQUIRED)
|
||||
find_package2(PRIVATE msgpack VERSION 3.0.0)
|
||||
set(PROJECT_msgpack_VERSION 2.1.5)
|
||||
if(NOT msgpack_FOUND)
|
||||
find_package2(PRIVATE msgpack VERSION 2.1.5 REQUIRED)
|
||||
endif()
|
||||
set(msgpack_ROOT ${PACKAGE_PREFIX_DIR})
|
||||
find_package2(PRIVATE nanomsg REQUIRED)
|
||||
set(PROJECT_nanomsg_VERSION 1.1.3) # Once upstream releases 1.1.5, we should bump again and use version check
|
||||
find_package2(PRIVATE msgpack VERSION 3.1.0 REQUIRED)
|
||||
endif()
|
||||
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
@@ -145,11 +150,6 @@ if(BUILD_DDS_PLUGIN)
|
||||
DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR}
|
||||
)
|
||||
endif()
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
install(FILES cmake/Findnanomsg.cmake
|
||||
DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR}
|
||||
)
|
||||
endif()
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
install(FILES cmake/FindOFI.cmake
|
||||
DESTINATION ${PROJECT_INSTALL_CMAKEMODDIR}
|
||||
@@ -166,6 +166,29 @@ install_cmake_package()
|
||||
|
||||
|
||||
# Summary ######################################################################
|
||||
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}")
|
||||
@@ -193,9 +216,13 @@ if(PROJECT_PACKAGE_DEPENDENCIES)
|
||||
elseif(${dep} STREQUAL GTest)
|
||||
get_filename_component(prefix ${GTEST_INCLUDE_DIRS}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL msgpack)
|
||||
set(prefix ${msgpack_ROOT})
|
||||
get_target_property(msgpack_include msgpackc-cxx INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_filename_component(prefix ${msgpack_include}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL OFI)
|
||||
get_filename_component(prefix ${${dep}_INCLUDE_DIRS}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL nanomsg)
|
||||
get_target_property(nn_include nanomsg INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_filename_component(prefix ${nn_include}/.. ABSOLUTE)
|
||||
elseif(${dep} STREQUAL Doxygen)
|
||||
get_target_property(doxygen_bin Doxygen::doxygen INTERFACE_LOCATION)
|
||||
get_filename_component(prefix ${doxygen_bin} DIRECTORY)
|
||||
|
41
COPYRIGHT
Normal file
41
COPYRIGHT
Normal file
@@ -0,0 +1,41 @@
|
||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: FairMQ
|
||||
Upstream-Contact: Mohammad Al-Turany <m.al-turany@gsi.de>
|
||||
Source: https://github.com/FairRootGroup/FairMQ
|
||||
|
||||
Files: *
|
||||
Copyright: 2012-2018, GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
|
||||
Copyright: 2012-2018, [see AUTHORS file]
|
||||
Copyright: 2012-2018, [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
|
||||
|
||||
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.
|
40
Dart.sh
40
Dart.sh
@@ -41,13 +41,15 @@ if [ "$#" -lt "2" ]; then
|
||||
fi
|
||||
|
||||
# test if a valid ctest model is defined
|
||||
if [ "$1" == "Experimental" -o "$1" == "Nightly" -o "$1" == "Continuous" -o "$1" == "Profile" -o "$1" == "alfa_ci" ]; then
|
||||
echo ""
|
||||
else
|
||||
echo "-- Error -- This ctest model is not supported."
|
||||
echo "-- Error -- Possible arguments are Nightly, Experimental, Continuous or Profile."
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
@@ -61,6 +63,9 @@ 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=1
|
||||
else
|
||||
export ctest_model=$1
|
||||
fi
|
||||
@@ -83,13 +88,20 @@ else
|
||||
COMPILER=$CXX$($CXX -dumpversion)
|
||||
fi
|
||||
|
||||
if [ "$1" == "alfa_ci" ]; then
|
||||
export LABEL1=alfa_ci-$COMPILER-FairMQ_$GIT_BRANCH
|
||||
export LABEL=$(echo $LABEL1 | sed -e 's#/#_#g')
|
||||
else
|
||||
export LABEL1=${LINUX_FLAVOUR}-$chip-$COMPILER-FairMQ_$GIT_BRANCH
|
||||
export LABEL=$(echo $LABEL1 | sed -e 's#/#_#g')
|
||||
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
|
||||
|
@@ -19,7 +19,7 @@ Set(BUILD_COMMAND "make")
|
||||
Set(CTEST_BUILD_COMMAND "${BUILD_COMMAND} -j$ENV{number_of_processors}")
|
||||
|
||||
String(TOUPPER $ENV{ctest_model} _Model)
|
||||
Set(configure_options "-DCMAKE_BUILD_TYPE=${_Model}")
|
||||
Set(configure_options "-DCMAKE_BUILD_TYPE=$ENV{ctest_model}")
|
||||
|
||||
Set(CTEST_USE_LAUNCHERS 1)
|
||||
Set(configure_options "${configure_options};-DCTEST_USE_LAUNCHERS=${CTEST_USE_LAUNCHERS}")
|
||||
@@ -28,24 +28,24 @@ Set(configure_options "${configure_options};-DDISABLE_COLOR=ON")
|
||||
Set(configure_options "${configure_options};-DCMAKE_PREFIX_PATH=$ENV{SIMPATH}")
|
||||
Set(configure_options "${configure_options};-DBUILD_NANOMSG_TRANSPORT=ON")
|
||||
Set(configure_options "${configure_options};-DBUILD_DDS_PLUGIN=ON")
|
||||
Set(configure_options "${configure_options};-DFAST_BUILD=ON")
|
||||
Set(configure_options "${configure_options};-DCOTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES=-j$ENV{number_of_processors}")
|
||||
|
||||
Set(EXTRA_FLAGS $ENV{EXTRA_FLAGS})
|
||||
If(EXTRA_FLAGS)
|
||||
Set(configure_options "${configure_options};${EXTRA_FLAGS}")
|
||||
EndIf()
|
||||
|
||||
If($ENV{ctest_model} MATCHES Nightly OR $ENV{ctest_model} MATCHES Profile)
|
||||
|
||||
If($ENV{ctest_model} MATCHES Profile)
|
||||
Find_Program(GCOV_COMMAND gcov)
|
||||
If(GCOV_COMMAND)
|
||||
Message("Found GCOV: ${GCOV_COMMAND}")
|
||||
Set(CTEST_COVERAGE_COMMAND ${GCOV_COMMAND})
|
||||
EndIf(GCOV_COMMAND)
|
||||
EndIf()
|
||||
|
||||
Set(ENV{ctest_model} Nightly)
|
||||
|
||||
CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY})
|
||||
|
||||
If($ENV{ctest_model} MATCHES Nightly OR $ENV{ctest_model} MATCHES Profile)
|
||||
Ctest_Empty_Binary_Directory(${CTEST_BINARY_DIRECTORY})
|
||||
EndIf()
|
||||
|
||||
Ctest_Start($ENV{ctest_model})
|
||||
@@ -60,9 +60,26 @@ Ctest_Test(BUILD "${CTEST_BINARY_DIRECTORY}"
|
||||
PARALLEL_LEVEL $ENV{number_of_processors}
|
||||
RETURN_VALUE _ctest_test_ret_val
|
||||
)
|
||||
If("$ENV{do_codecov_upload}")
|
||||
ForEach(i RANGE 4)
|
||||
# Gather statistics to catch time sensitive branches
|
||||
Ctest_Test(BUILD "${CTEST_BINARY_DIRECTORY}"
|
||||
PARALLEL_LEVEL $ENV{number_of_processors}
|
||||
)
|
||||
EndForEach()
|
||||
EndIf()
|
||||
|
||||
If(GCOV_COMMAND)
|
||||
Ctest_Coverage(BUILD "${CTEST_BINARY_DIRECTORY}")
|
||||
Ctest_Coverage(BUILD "${CTEST_BINARY_DIRECTORY}" LABELS coverage)
|
||||
EndIf()
|
||||
|
||||
If("$ENV{do_codecov_upload}")
|
||||
Execute_Process(COMMAND curl https://codecov.io/bash -o codecov_uploader.sh
|
||||
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY}
|
||||
TIMEOUT 60)
|
||||
Execute_Process(COMMAND bash ./codecov_uploader.sh -X gcov
|
||||
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY}
|
||||
TIMEOUT 60)
|
||||
EndIf()
|
||||
|
||||
Ctest_Submit()
|
||||
|
40
Jenkinsfile
vendored
40
Jenkinsfile
vendored
@@ -4,24 +4,31 @@ def specToLabel(Map spec) {
|
||||
return "${spec.os}-${spec.arch}-${spec.compiler}-FairSoft_${spec.fairsoft}"
|
||||
}
|
||||
|
||||
def buildMatrix(List specs, Closure callback) {
|
||||
def jobMatrix(String prefix, List specs, Closure callback) {
|
||||
def nodes = [:]
|
||||
for (spec in specs) {
|
||||
def label = specToLabel(spec)
|
||||
nodes[label] = {
|
||||
nodes["${prefix}/${label}"] = {
|
||||
node(label) {
|
||||
githubNotify(context: "alfa-ci/${label}", description: 'Building ...', status: 'PENDING')
|
||||
githubNotify(context: "${prefix}/${label}", description: 'Building ...', status: 'PENDING')
|
||||
try {
|
||||
deleteDir()
|
||||
checkout scm
|
||||
|
||||
sh '''\
|
||||
echo "export BUILDDIR=$PWD/build" >> Dart.cfg
|
||||
echo "export SOURCEDIR=$PWD" >> Dart.cfg
|
||||
echo "export PATH=$SIMPATH/bin:$PATH" >> Dart.cfg
|
||||
echo "export GIT_BRANCH=$JOB_BASE_NAME" >> Dart.cfg
|
||||
'''
|
||||
|
||||
callback.call(spec, label)
|
||||
|
||||
deleteDir()
|
||||
githubNotify(context: "alfa-ci/${label}", description: 'Success', status: 'SUCCESS')
|
||||
githubNotify(context: "${prefix}/${label}", description: 'Success', status: 'SUCCESS')
|
||||
} catch (e) {
|
||||
deleteDir()
|
||||
githubNotify(context: "alfa-ci/${label}", description: 'Error', status: 'ERROR')
|
||||
githubNotify(context: "${prefix}/${label}", description: 'Error', status: 'ERROR')
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -33,22 +40,25 @@ def buildMatrix(List specs, Closure callback) {
|
||||
pipeline{
|
||||
agent none
|
||||
stages {
|
||||
stage("Run Build/Test Matrix") {
|
||||
stage("Run CI Matrix") {
|
||||
steps{
|
||||
script {
|
||||
parallel(buildMatrix([
|
||||
def build_jobs = jobMatrix('alfa-ci/build', [
|
||||
[os: 'Debian8', arch: 'x86_64', compiler: 'gcc4.9', fairsoft: 'may18'],
|
||||
[os: 'MacOS10.11', arch: 'x86_64', compiler: 'AppleLLVM8.0.0', fairsoft: 'may18'],
|
||||
[os: 'MacOS10.13', arch: 'x86_64', compiler: 'AppleLLVM9.0.0', fairsoft: 'may18'],
|
||||
]) { spec, label ->
|
||||
sh '''\
|
||||
echo "export BUILDDIR=$PWD/build" >> Dart.cfg
|
||||
echo "export SOURCEDIR=$PWD" >> Dart.cfg
|
||||
echo "export PATH=$SIMPATH/bin:$PATH" >> Dart.cfg
|
||||
echo "export GIT_BRANCH=$JOB_BASE_NAME" >> Dart.cfg
|
||||
'''
|
||||
sh './Dart.sh alfa_ci Dart.cfg'
|
||||
})
|
||||
}
|
||||
|
||||
def profile_jobs = jobMatrix('alfa-ci/codecov', [
|
||||
[os: 'Debian8', arch: 'x86_64', compiler: 'gcc4.9', fairsoft: 'may18'],
|
||||
]) { spec, label ->
|
||||
withCredentials([string(credentialsId: 'fairmq_codecov_token', variable: 'CODECOV_TOKEN')]) {
|
||||
sh './Dart.sh codecov Dart.cfg'
|
||||
}
|
||||
}
|
||||
|
||||
parallel(build_jobs + profile_jobs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
51
README.md
51
README.md
@@ -1,12 +1,16 @@
|
||||
<!-- {#mainpage} -->
|
||||
# FairMQ
|
||||
# FairMQ [](COPYRIGHT) [](https://alfa-ci.gsi.de/blue/organizations/jenkins/FairRootGroup%2FFairMQ/branches) [](https://codecov.io/gh/FairRootGroup/FairMQ/branch/master) [](https://www.codacy.com/app/dennisklein/FairMQ?utm_source=github.com&utm_medium=referral&utm_content=FairRootGroup/FairMQ&utm_campaign=Badge_Grade)
|
||||
|
||||
C++ Message passing framework
|
||||
C++ Message Queuing Library and Framework
|
||||
|
||||
| Branch | Build Status |
|
||||
| :---: | :--- |
|
||||
| `master` |  |
|
||||
| `dev` |  |
|
||||
| Release | Version | Docs |
|
||||
| :---: | :--- | :--- |
|
||||
| `stable` | [](https://github.com/FairRootGroup/FairMQ/releases/latest) | [API](https://fairrootgroup.github.io/FairMQ/latest), [Book](https://github.com/FairRootGroup/FairMQ/blob/master/README.md#documentation) |
|
||||
| `testing` | [](https://github.com/FairRootGroup/FairMQ/tags) | [Book](https://github.com/FairRootGroup/FairMQ/blob/dev/README.md#documentation) |
|
||||
|
||||
Find all FairMQ releases [here](https://github.com/FairRootGroup/FairMQ/releases).
|
||||
|
||||
## Introduction
|
||||
|
||||
FairMQ is designed to help implementing large-scale data processing workflows needed in next-generation Particle Physics experiments. FairMQ is written in C++ and aims to
|
||||
* provide **an asynchronous message passing abstraction** of different data transport technologies,
|
||||
@@ -31,30 +35,13 @@ a simulation, reconstruction and analysis framework.
|
||||
|
||||
## Dependencies
|
||||
|
||||
* [**Boost**](https://www.boost.org/) (PUBLIC)
|
||||
* [**FairLogger**](https://github.com/FairRootGroup/FairLogger) (PUBLIC)
|
||||
* [CMake](https://cmake.org/) (BUILD)
|
||||
* [GTest](https://github.com/google/googletest) (BUILD, optional, `tests`)
|
||||
* [Doxygen](http://www.doxygen.org/) (BUILD, optional, `docs`)
|
||||
* [ZeroMQ](http://zeromq.org/) (PRIVATE)
|
||||
* [Msgpack](https://msgpack.org/index.html) (PRIVATE, optional, `nanomsg_transport`)
|
||||
* [nanomsg](http://nanomsg.org/) (PRIVATE, optional, `nanomsg_transport`)
|
||||
* [OFI](https://ofiwg.github.io/libfabric/) (PRIVATE, optional, `ofi_transport`)
|
||||
* [Protobuf](https://developers.google.com/protocol-buffers/) (PRIVATE, optional, `ofi_transport`)
|
||||
* [DDS](http://dds.gsi.de) (PRIVATE, optional, `dds_plugin`)
|
||||
* PUBLIC: [**Boost**](https://www.boost.org/), [**FairLogger**](https://github.com/FairRootGroup/FairLogger)
|
||||
* BUILD: [CMake](https://cmake.org/), [GTest](https://github.com/google/googletest), [Doxygen](http://www.doxygen.org/)
|
||||
* PRIVATE: [ZeroMQ](http://zeromq.org/), [Msgpack](https://msgpack.org/index.html), [nanomsg](http://nanomsg.org/),
|
||||
[OFI](https://ofiwg.github.io/libfabric/), [Protobuf](https://developers.google.com/protocol-buffers/), [DDS](http://dds.gsi.de)
|
||||
|
||||
Supported platforms: Linux and MacOS.
|
||||
|
||||
## Releases
|
||||
|
||||
| Stable release | Date | API Docs |
|
||||
| --- | --- | --- |
|
||||
| [**1.2.3**](https://github.com/FairRootGroup/FairMQ/releases/tag/v1.2.3) | May 2018 | [link](https://fairrootgroup.github.io/FairMQ/v1.2.3/index.html) |
|
||||
| [**1.2.1**](https://github.com/FairRootGroup/FairMQ/releases/tag/v1.2.1) | May 2018 | [link](https://fairrootgroup.github.io/FairMQ/v1.2.1/index.html) |
|
||||
| [**1.2.0**](https://github.com/FairRootGroup/FairMQ/releases/tag/v1.2.0) | May 2018 | [link](https://fairrootgroup.github.io/FairMQ/v1.2.0/index.html) |
|
||||
|
||||
Find all FairMQ stable and development releases [here](https://github.com/FairRootGroup/FairMQ/releases).
|
||||
|
||||
## Installation from Source
|
||||
|
||||
```bash
|
||||
@@ -89,7 +76,7 @@ In order to succesfully compile and link against the `FairMQ::FairMQ` target, yo
|
||||
find_package(FairMQ)
|
||||
if(FairMQ_FOUND)
|
||||
find_package(FairLogger ${FairMQ_FairLogger_VERSION})
|
||||
find_package(Boost ${FairMQ_Boost_VERSION} COMPONENTS ${FairMQ_BOOST_COMPONENTS})
|
||||
find_package(Boost ${FairMQ_Boost_VERSION} COMPONENTS ${FairMQ_Boost_COMPONENTS})
|
||||
endif()
|
||||
```
|
||||
|
||||
@@ -101,7 +88,7 @@ Optionally, you can require certain FairMQ package components and a minimum vers
|
||||
find_package(FairMQ 1.1.0 COMPONENTS nanomsg_transport dds_plugin)
|
||||
if(FairMQ_FOUND)
|
||||
find_package(FairLogger ${FairMQ_FairLogger_VERSION})
|
||||
find_package(Boost ${FairMQ_Boost_VERSION} COMPONENTS ${FairMQ_BOOST_COMPONENTS})
|
||||
find_package(Boost ${FairMQ_Boost_VERSION} COMPONENTS ${FairMQ_Boost_COMPONENTS})
|
||||
endif()
|
||||
```
|
||||
|
||||
@@ -169,9 +156,3 @@ After the `find_package(FairMQ)` call the following CMake variables are defined:
|
||||
4. [File output](docs/Logging.md#54-file-output)
|
||||
5. [Custom sinks](docs/Logging.md#55-custom-sinks)
|
||||
6. [Examples](docs/Examples.md#6-examples)
|
||||
|
||||
## License
|
||||
|
||||
GNU Lesser General Public Licence (LGPL) version 3, see [LICENSE](LICENSE).
|
||||
|
||||
Copyright (C) 2013-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
|
||||
|
@@ -23,6 +23,7 @@ set_and_check(@PROJECT_NAME@_CMAKEMODDIR @PACKAGE_CMAKE_INSTALL_PREFIX@/@PROJECT
|
||||
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@)
|
||||
|
||||
### Import cmake modules
|
||||
set(CMAKE_MODULE_PATH ${@PROJECT_NAME@_CMAKEMODDIR} ${CMAKE_MODULE_PATH})
|
||||
|
@@ -112,7 +112,6 @@ macro(set_fairmq_defaults)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo)
|
||||
endif()
|
||||
|
||||
|
||||
# Handle C++ standard level
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
if(NOT CMAKE_CXX_STANDARD)
|
||||
@@ -124,8 +123,14 @@ macro(set_fairmq_defaults)
|
||||
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
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
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)
|
||||
@@ -158,9 +163,30 @@ macro(set_fairmq_defaults)
|
||||
# Define export set, only one for now
|
||||
set(PROJECT_EXPORT_SET ${PROJECT_NAME}Targets)
|
||||
|
||||
# Override CMake defaults
|
||||
set(CMAKE_CXX_FLAGS_NIGHTLY "-O2 -g -Wshadow -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs -Wshadow -Wall -Wextra -Wunused-variable")
|
||||
# Configure build types
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" "RelWithDebInfo" "Nightly" "Profile" "Experimental" "AdressSan" "ThreadSan")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wshadow -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -Wshadow -Wall -Wextra -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_NIGHTLY "-O2 -g -Wshadow -Wall -Wextra")
|
||||
set(CMAKE_CXX_FLAGS_PROFILE "-g3 -Wshadow -Wall -Wextra -fno-inline -ftest-coverage -fprofile-arcs")
|
||||
set(CMAKE_CXX_FLAGS_EXPERIMENTAL "-O2 -g -Wshadow -Wall -Wextra -DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_ADRESSSAN "-O2 -g -Wshadow -Wall -Wextra -fsanitize=address -fno-omit-frame-pointer")
|
||||
set(CMAKE_CXX_FLAGS_THREADSAN "-O2 -g -Wshadow -Wall -Wextra -fsanitize=thread")
|
||||
|
||||
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()
|
||||
endmacro()
|
||||
|
||||
function(join VALUES GLUE OUTPUT)
|
||||
@@ -237,7 +263,7 @@ endfunction()
|
||||
macro(install_cmake_package)
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(PACKAGE_INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${PROJECT_GIT_VERSION}
|
||||
)
|
||||
if(BUILD_FAIRMQ)
|
||||
install(EXPORT ${PROJECT_EXPORT_SET}
|
||||
|
@@ -89,7 +89,7 @@ endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(ZeroMQ
|
||||
REQUIRED_VARS ZeroMQ_LIBRARY_SHARED ZeroMQ_INCLUDE_DIR ZeroMQ_LIBRARY_STATIC
|
||||
REQUIRED_VARS ZeroMQ_LIBRARY_SHARED ZeroMQ_INCLUDE_DIR
|
||||
VERSION_VAR ZeroMQ_VERSION
|
||||
)
|
||||
|
||||
|
@@ -1,34 +0,0 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2014-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" #
|
||||
################################################################################
|
||||
|
||||
find_path(nanomsg_INCLUDE_DIR
|
||||
NAMES nanomsg/nn.h
|
||||
HINTS ${NANOMSG_ROOT} $ENV{NANOMSG_ROOT}
|
||||
PATH_SUFFIXES include
|
||||
DOC "Path to nanomsg include header files."
|
||||
)
|
||||
|
||||
find_library(nanomsg_LIBRARY_SHARED
|
||||
NAMES libnanomsg.dylib libnanomsg.so
|
||||
HINTS ${NANOMSG_ROOT} $ENV{NANOMSG_ROOT}
|
||||
PATH_SUFFIXES lib
|
||||
DOC "Path to libnanomsg.dylib libnanomsg.so."
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(nanomsg
|
||||
REQUIRED_VARS nanomsg_LIBRARY_SHARED nanomsg_INCLUDE_DIR
|
||||
)
|
||||
|
||||
if(NOT TARGET nanomsg AND nanomsg_FOUND)
|
||||
add_library(nanomsg SHARED IMPORTED)
|
||||
set_target_properties(nanomsg PROPERTIES
|
||||
IMPORTED_LOCATION ${nanomsg_LIBRARY_SHARED}
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${nanomsg_INCLUDE_DIR}
|
||||
)
|
||||
endif()
|
@@ -51,7 +51,7 @@ function(add_testsuite suitename)
|
||||
cmake_parse_arguments(testsuite
|
||||
""
|
||||
"TIMEOUT;RUN_SERIAL"
|
||||
"SOURCES;LINKS;DEPENDS;INCLUDES"
|
||||
"SOURCES;LINKS;DEPENDS;INCLUDES;DEFINITIONS"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
@@ -69,6 +69,9 @@ function(add_testsuite suitename)
|
||||
if(testsuite_INCLUDES)
|
||||
target_include_directories(${target} PUBLIC ${testsuite_INCLUDES})
|
||||
endif()
|
||||
if(testsuite_DEFINITIONS)
|
||||
target_compile_definitions("${target}" PUBLIC ${testsuite_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
add_test(NAME "${suitename}" WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND ${target})
|
||||
if(testsuite_TIMEOUT)
|
||||
@@ -86,7 +89,7 @@ function(add_testhelper helpername)
|
||||
cmake_parse_arguments(testhelper
|
||||
""
|
||||
""
|
||||
"SOURCES;LINKS;DEPENDS;INCLUDES"
|
||||
"SOURCES;LINKS;DEPENDS;INCLUDES;DEFINITIONS"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
@@ -102,6 +105,9 @@ function(add_testhelper helpername)
|
||||
if(testhelper_INCLUDES)
|
||||
target_include_directories(${target} PUBLIC ${testhelper_INCLUDES})
|
||||
endif()
|
||||
if(testhelper_DEFINITIONS)
|
||||
target_compile_definitions(${target} PUBLIC ${testhelper_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
list(APPEND ALL_TEST_TARGETS ${target})
|
||||
set(ALL_TEST_TARGETS ${ALL_TEST_TARGETS} PARENT_SCOPE)
|
||||
@@ -111,7 +117,7 @@ function(add_testlib libname)
|
||||
cmake_parse_arguments(testlib
|
||||
"HIDDEN"
|
||||
"VERSION"
|
||||
"SOURCES;LINKS;DEPENDS;INCLUDES"
|
||||
"SOURCES;LINKS;DEPENDS;INCLUDES;DEFINITIONS"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
@@ -133,6 +139,9 @@ function(add_testlib libname)
|
||||
if(testlib_VERSION)
|
||||
set_target_properties(${target} PROPERTIES VERSION ${testlib_VERSION})
|
||||
endif()
|
||||
if(testlib_DEFINITIONS)
|
||||
target_compile_definitions(${target} PUBLIC ${testlib_DEFINITIONS})
|
||||
endif()
|
||||
|
||||
list(APPEND ALL_TEST_TARGETS ${target})
|
||||
set(ALL_TEST_TARGETS ${ALL_TEST_TARGETS} PARENT_SCOPE)
|
||||
|
4190
cmake/cotire.cmake
Normal file
4190
cmake/cotire.cmake
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,10 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-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" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* Sampler.cpp
|
||||
*
|
||||
* @since 2014-10-10
|
||||
* @author A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <thread> // this_thread::sleep_for
|
||||
#include <chrono>
|
||||
@@ -64,8 +58,6 @@ bool Sampler::ConditionalRun()
|
||||
return false;
|
||||
}
|
||||
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,7 @@ export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
|
||||
|
||||
SAMPLER="fairmq-ex-1-1-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --rate 1"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"
|
||||
xterm -geometry 80x23+0+0 -hold -e @EX_BIN_DIR@/$SAMPLER &
|
||||
|
||||
|
@@ -8,13 +8,17 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
transport=$1
|
||||
fi
|
||||
|
||||
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SINK_PID;' TERM
|
||||
|
||||
SAMPLER="fairmq-ex-1-1-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --rate 1"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --verbosity veryhigh"
|
||||
SAMPLER+=" --session $SESSION"
|
||||
SAMPLER+=" --control static --color false"
|
||||
SAMPLER+=" --max-iterations 1"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"
|
||||
@@ -25,6 +29,7 @@ SINK="fairmq-ex-1-1-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --transport $transport"
|
||||
SINK+=" --verbosity veryhigh"
|
||||
SINK+=" --session $SESSION"
|
||||
SINK+=" --control static --color false"
|
||||
SINK+=" --max-iterations 1"
|
||||
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://localhost:5555,rateLogging=0"
|
||||
|
@@ -9,6 +9,7 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
fi
|
||||
|
||||
ex2config="@CMAKE_CURRENT_BINARY_DIR@/ex-1-n-1.json"
|
||||
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; kill -TERM $PROCESSOR1_PID; kill -TERM $PROCESSOR2_PID; wait $SAMPLER_PID; wait $SINK_PID; wait $PROCESSOR1_PID; wait $PROCESSOR2_PID;' TERM
|
||||
@@ -17,6 +18,7 @@ SAMPLER="fairmq-ex-1-n-1-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --verbosity veryhigh"
|
||||
SAMPLER+=" --session $SESSION"
|
||||
SAMPLER+=" --control static --color false"
|
||||
SAMPLER+=" --max-iterations 2"
|
||||
SAMPLER+=" --mq-config $ex2config"
|
||||
@@ -27,6 +29,7 @@ PROCESSOR1="fairmq-ex-1-n-1-processor"
|
||||
PROCESSOR1+=" --id processor1"
|
||||
PROCESSOR1+=" --transport $transport"
|
||||
PROCESSOR1+=" --verbosity veryhigh"
|
||||
PROCESSOR1+=" --session $SESSION"
|
||||
PROCESSOR1+=" --control static --color false"
|
||||
PROCESSOR1+=" --mq-config $ex2config"
|
||||
PROCESSOR1+=" --config-key processor"
|
||||
@@ -37,6 +40,7 @@ PROCESSOR2="fairmq-ex-1-n-1-processor"
|
||||
PROCESSOR2+=" --id processor2"
|
||||
PROCESSOR2+=" --transport $transport"
|
||||
PROCESSOR2+=" --verbosity veryhigh"
|
||||
PROCESSOR2+=" --session $SESSION"
|
||||
PROCESSOR2+=" --control static --color false"
|
||||
PROCESSOR2+=" --mq-config $ex2config"
|
||||
PROCESSOR2+=" --config-key processor"
|
||||
@@ -47,6 +51,7 @@ SINK="fairmq-ex-1-n-1-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --transport $transport"
|
||||
SINK+=" --verbosity veryhigh"
|
||||
SINK+=" --session $SESSION"
|
||||
SINK+=" --control static --color false"
|
||||
SINK+=" --max-iterations 2"
|
||||
SINK+=" --mq-config $ex2config"
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
add_subdirectory(1-1)
|
||||
add_subdirectory(1-n-1)
|
||||
add_subdirectory(builtin-devices)
|
||||
add_subdirectory(copypush)
|
||||
add_subdirectory(dds)
|
||||
add_subdirectory(multipart)
|
||||
|
50
examples/builtin-devices/CMakeLists.txt
Normal file
50
examples/builtin-devices/CMakeLists.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
################################################################################
|
||||
# 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" #
|
||||
################################################################################
|
||||
|
||||
set(EX_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(FAIRMQ_BIN_DIR ${CMAKE_BINARY_DIR}/fairmq)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-builtin-devices.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-builtin-devices.sh)
|
||||
|
||||
# test
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-ex-builtin-devices.sh.in ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh)
|
||||
|
||||
add_test(NAME Example-Builtin-Devices-zeromq COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh zeromq)
|
||||
set_tests_properties(Example-Builtin-Devices-zeromq PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
|
||||
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
add_test(NAME Example-Builtin-Devices-nanomsg COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh nanomsg)
|
||||
set_tests_properties(Example-Builtin-Devices-nanomsg PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
|
||||
endif()
|
||||
|
||||
add_test(NAME Example-Builtin-Devices-shmem COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh shmem)
|
||||
set_tests_properties(Example-Builtin-Devices-shmem PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
|
||||
|
||||
add_test(NAME Example-Builtin-Devices-zeromq-multipart COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh zeromq true 2)
|
||||
set_tests_properties(Example-Builtin-Devices-zeromq-multipart PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
|
||||
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
add_test(NAME Example-Builtin-Devices-nanomsg-multipart COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh nanomsg true 2)
|
||||
set_tests_properties(Example-Builtin-Devices-nanomsg-multipart PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
|
||||
endif()
|
||||
|
||||
add_test(NAME Example-Builtin-Devices-shmem-multipart COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test-ex-builtin-devices.sh shmem true 2)
|
||||
set_tests_properties(Example-Builtin-Devices-shmem-multipart PROPERTIES TIMEOUT "30" RUN_SERIAL true PASS_REGULAR_EXPRESSION "Configured maximum number of iterations reached")
|
||||
|
||||
# install
|
||||
|
||||
# configure run script with different executable paths for build and for install directories
|
||||
set(EX_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_BINDIR})
|
||||
set(FAIRMQ_BIN_DIR ${CMAKE_INSTALL_PREFIX}/${PROJECT_INSTALL_BINDIR}/fairmq)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/fairmq-start-ex-builtin-devices.sh.in ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-builtin-devices.sh_install)
|
||||
|
||||
install(
|
||||
PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/fairmq-start-ex-builtin-devices.sh_install
|
||||
DESTINATION ${PROJECT_INSTALL_BINDIR}
|
||||
RENAME fairmq-start-ex-builtin-devices.sh
|
||||
)
|
4
examples/builtin-devices/README.md
Normal file
4
examples/builtin-devices/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Built-in devices
|
||||
==========================
|
||||
|
||||
This example demonstrates use of generic devices that are provided with FairMQ - BenchmarkSampler, Merger, Multiplier, Proxy, Sink, Splitter. They are all connected in one topology and transfer some dummy buffers generated by the BenchmarkSampler.
|
93
examples/builtin-devices/fairmq-start-ex-builtin-devices.sh.in
Executable file
93
examples/builtin-devices/fairmq-start-ex-builtin-devices.sh.in
Executable file
@@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
|
||||
export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
|
||||
|
||||
transport="zeromq"
|
||||
multipart="false"
|
||||
numParts="1"
|
||||
|
||||
if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
transport=$1
|
||||
fi
|
||||
|
||||
if [[ $2 =~ ^[a-z]+$ ]]; then
|
||||
multipart=$2
|
||||
fi
|
||||
|
||||
if [[ $3 =~ ^[0-9]+$ ]]; then
|
||||
numParts=$3
|
||||
fi
|
||||
|
||||
SAMPLER="fairmq-bsampler"
|
||||
SAMPLER+=" --id bsampler1"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --control interactive"
|
||||
SAMPLER+=" --severity debug"
|
||||
SAMPLER+=" --msg-size 100000"
|
||||
SAMPLER+=" --multipart $multipart"
|
||||
SAMPLER+=" --num-parts $numParts"
|
||||
SAMPLER+=" --msg-rate 100"
|
||||
SAMPLER+=" --max-iterations 0"
|
||||
SAMPLER+=" --out-channel data1"
|
||||
SAMPLER+=" --channel-config name=data1,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
|
||||
xterm -geometry 90x20+0+175 -hold -e @FAIRMQ_BIN_DIR@/$SAMPLER &
|
||||
|
||||
SPLITTER="fairmq-splitter"
|
||||
SPLITTER+=" --id splitter"
|
||||
SPLITTER+=" --transport $transport"
|
||||
SPLITTER+=" --multipart $multipart"
|
||||
SPLITTER+=" --in-channel data1"
|
||||
SPLITTER+=" --out-channel data2"
|
||||
SPLITTER+=" --channel-config name=data1,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
|
||||
SPLITTER+=" name=data2,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556,address=tcp://localhost:5557"
|
||||
xterm -geometry 90x20+0+475 -hold -e @FAIRMQ_BIN_DIR@/$SPLITTER &
|
||||
|
||||
PROXY1="fairmq-proxy"
|
||||
PROXY1+=" --id proxy1"
|
||||
PROXY1+=" --transport $transport"
|
||||
PROXY1+=" --multipart $multipart"
|
||||
PROXY1+=" --in-channel data2"
|
||||
PROXY1+=" --out-channel data3"
|
||||
PROXY1+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556"
|
||||
PROXY1+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558"
|
||||
xterm -geometry 90x20+550+175 -hold -e @FAIRMQ_BIN_DIR@/$PROXY1 &
|
||||
|
||||
PROXY2="fairmq-proxy"
|
||||
PROXY2+=" --id proxy2"
|
||||
PROXY2+=" --transport $transport"
|
||||
PROXY2+=" --multipart $multipart"
|
||||
PROXY2+=" --in-channel data2"
|
||||
PROXY2+=" --out-channel data3"
|
||||
PROXY2+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5557"
|
||||
PROXY2+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5559"
|
||||
xterm -geometry 90x20+550+475 -hold -e @FAIRMQ_BIN_DIR@/$PROXY2 &
|
||||
|
||||
MERGER="fairmq-merger"
|
||||
MERGER+=" --id merger"
|
||||
MERGER+=" --transport $transport"
|
||||
MERGER+=" --multipart $multipart"
|
||||
MERGER+=" --in-channel data3"
|
||||
MERGER+=" --out-channel data4"
|
||||
MERGER+=" --channel-config name=data3,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558,address=tcp://localhost:5559"
|
||||
MERGER+=" name=data4,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
|
||||
xterm -geometry 90x20+1100+50 -hold -e @FAIRMQ_BIN_DIR@/$MERGER &
|
||||
|
||||
MULTIPLIER="fairmq-multiplier"
|
||||
MULTIPLIER+=" --id multiplier"
|
||||
MULTIPLIER+=" --transport $transport"
|
||||
MULTIPLIER+=" --multipart $multipart"
|
||||
MULTIPLIER+=" --in-channel data4"
|
||||
MULTIPLIER+=" --out-channel data5"
|
||||
MULTIPLIER+=" --channel-config name=data4,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
|
||||
MULTIPLIER+=" name=data5,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561,address=tcp://localhost:5561"
|
||||
xterm -geometry 90x20+1100+350 -hold -e @FAIRMQ_BIN_DIR@/$MULTIPLIER &
|
||||
|
||||
SINK="fairmq-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --transport $transport"
|
||||
SINK+=" --severity debug"
|
||||
SINK+=" --multipart $multipart"
|
||||
SINK+=" --max-iterations 0"
|
||||
SINK+=" --in-channel data5"
|
||||
SINK+=" --channel-config name=data5,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561"
|
||||
xterm -geometry 90x20+1100+650 -hold -e @FAIRMQ_BIN_DIR@/$SINK &
|
148
examples/builtin-devices/test-ex-builtin-devices.sh.in
Executable file
148
examples/builtin-devices/test-ex-builtin-devices.sh.in
Executable file
@@ -0,0 +1,148 @@
|
||||
#!/bin/bash
|
||||
|
||||
export FAIRMQ_PATH=@FAIRMQ_BIN_DIR@
|
||||
|
||||
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||
|
||||
transport="zeromq"
|
||||
multipart="false"
|
||||
numParts="1"
|
||||
|
||||
if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
transport=$1
|
||||
fi
|
||||
|
||||
if [[ $2 =~ ^[a-z]+$ ]]; then
|
||||
multipart=$2
|
||||
fi
|
||||
|
||||
if [[ $3 =~ ^[0-9]+$ ]]; then
|
||||
numParts=$3
|
||||
fi
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SPLITTER_PID; kill -TERM $PROXY1_PID; kill -TERM $PROXY2_PID; kill -TERM $MERGER_PID; kill -TERM $MULTIPLIER_PID; kill -TERM $SINK_PID;' TERM
|
||||
|
||||
SAMPLER="fairmq-bsampler"
|
||||
SAMPLER+=" --id bsampler1"
|
||||
SAMPLER+=" --session $SESSION"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --color false"
|
||||
SAMPLER+=" --control static"
|
||||
SAMPLER+=" --verbosity veryhigh"
|
||||
SAMPLER+=" --severity debug"
|
||||
SAMPLER+=" --msg-size 100000"
|
||||
SAMPLER+=" --multipart $multipart"
|
||||
SAMPLER+=" --num-parts $numParts"
|
||||
SAMPLER+=" --msg-rate 1"
|
||||
SAMPLER+=" --max-iterations 0"
|
||||
SAMPLER+=" --out-channel data1"
|
||||
SAMPLER+=" --channel-config name=data1,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
|
||||
@FAIRMQ_BIN_DIR@/$SAMPLER &
|
||||
SAMPLER_PID=$!
|
||||
|
||||
SPLITTER="fairmq-splitter"
|
||||
SPLITTER+=" --id splitter"
|
||||
SPLITTER+=" --session $SESSION"
|
||||
SPLITTER+=" --transport $transport"
|
||||
SPLITTER+=" --color false"
|
||||
SPLITTER+=" --control static"
|
||||
SPLITTER+=" --verbosity veryhigh"
|
||||
SPLITTER+=" --multipart $multipart"
|
||||
SPLITTER+=" --in-channel data1"
|
||||
SPLITTER+=" --out-channel data2"
|
||||
SPLITTER+=" --channel-config name=data1,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5555"
|
||||
SPLITTER+=" name=data2,type=push,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556,address=tcp://localhost:5557"
|
||||
@FAIRMQ_BIN_DIR@/$SPLITTER &
|
||||
SPLITTER_PID=$!
|
||||
|
||||
PROXY1="fairmq-proxy"
|
||||
PROXY1+=" --id proxy1"
|
||||
PROXY1+=" --session $SESSION"
|
||||
PROXY1+=" --transport $transport"
|
||||
PROXY1+=" --color false"
|
||||
PROXY1+=" --control static"
|
||||
PROXY1+=" --verbosity veryhigh"
|
||||
PROXY1+=" --multipart $multipart"
|
||||
PROXY1+=" --in-channel data2"
|
||||
PROXY1+=" --out-channel data3"
|
||||
PROXY1+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5556"
|
||||
PROXY1+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558"
|
||||
@FAIRMQ_BIN_DIR@/$PROXY1 &
|
||||
PROXY1_PID=$!
|
||||
|
||||
PROXY2="fairmq-proxy"
|
||||
PROXY2+=" --id proxy2"
|
||||
PROXY2+=" --session $SESSION"
|
||||
PROXY2+=" --transport $transport"
|
||||
PROXY2+=" --color false"
|
||||
PROXY2+=" --control static"
|
||||
PROXY2+=" --verbosity veryhigh"
|
||||
PROXY2+=" --multipart $multipart"
|
||||
PROXY2+=" --in-channel data2"
|
||||
PROXY2+=" --out-channel data3"
|
||||
PROXY2+=" --channel-config name=data2,type=pull,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5557"
|
||||
PROXY2+=" name=data3,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5559"
|
||||
@FAIRMQ_BIN_DIR@/$PROXY2 &
|
||||
PROXY2_PID=$!
|
||||
|
||||
MERGER="fairmq-merger"
|
||||
MERGER+=" --id merger"
|
||||
MERGER+=" --session $SESSION"
|
||||
MERGER+=" --transport $transport"
|
||||
MERGER+=" --color false"
|
||||
MERGER+=" --control static"
|
||||
MERGER+=" --verbosity veryhigh"
|
||||
MERGER+=" --multipart $multipart"
|
||||
MERGER+=" --in-channel data3"
|
||||
MERGER+=" --out-channel data4"
|
||||
MERGER+=" --channel-config name=data3,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5558,address=tcp://localhost:5559"
|
||||
MERGER+=" name=data4,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
|
||||
@FAIRMQ_BIN_DIR@/$MERGER &
|
||||
MERGER_PID=$!
|
||||
|
||||
MULTIPLIER="fairmq-multiplier"
|
||||
MULTIPLIER+=" --id multiplier"
|
||||
MULTIPLIER+=" --session $SESSION"
|
||||
MULTIPLIER+=" --transport $transport"
|
||||
MULTIPLIER+=" --color false"
|
||||
MULTIPLIER+=" --control static"
|
||||
MULTIPLIER+=" --verbosity veryhigh"
|
||||
MULTIPLIER+=" --multipart $multipart"
|
||||
MULTIPLIER+=" --in-channel data4"
|
||||
MULTIPLIER+=" --out-channel data5"
|
||||
MULTIPLIER+=" --channel-config name=data4,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5560"
|
||||
MULTIPLIER+=" name=data5,type=push,method=connect,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561,address=tcp://localhost:5561"
|
||||
@FAIRMQ_BIN_DIR@/$MULTIPLIER &
|
||||
MULTIPLIER_PID=$!
|
||||
|
||||
SINK="fairmq-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --session $SESSION"
|
||||
SINK+=" --transport $transport"
|
||||
SINK+=" --color false"
|
||||
SINK+=" --control static"
|
||||
SINK+=" --verbosity veryhigh"
|
||||
SINK+=" --severity debug"
|
||||
SINK+=" --multipart $multipart"
|
||||
SINK+=" --max-iterations 2"
|
||||
SINK+=" --in-channel data5"
|
||||
SINK+=" --channel-config name=data5,type=pull,method=bind,sndBufSize=50,rcvBufSize=50,address=tcp://localhost:5561"
|
||||
@FAIRMQ_BIN_DIR@/$SINK &
|
||||
SINK_PID=$!
|
||||
|
||||
wait $SINK_PID
|
||||
|
||||
kill -SIGINT $SAMPLER_PID
|
||||
kill -SIGINT $SPLITTER_PID
|
||||
kill -SIGINT $PROXY1_PID
|
||||
kill -SIGINT $PROXY2_PID
|
||||
kill -SIGINT $MERGER_PID
|
||||
kill -SIGINT $MULTIPLIER_PID
|
||||
|
||||
wait $SAMPLER_PID
|
||||
wait $SPLITTER_PID
|
||||
wait $PROXY1_PID
|
||||
wait $PROXY2_PID
|
||||
wait $MERGER_PID
|
||||
wait $MULTIPLIER_PID
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
transport=$1
|
||||
fi
|
||||
|
||||
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK1_PID; kill -TERM $SINK2_PID; wait $SAMPLER_PID; wait $SINK1_PID; wait $SINK2_PID;' TERM
|
||||
|
||||
@@ -15,6 +17,7 @@ SAMPLER="fairmq-ex-copypush-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --verbosity veryhigh"
|
||||
SAMPLER+=" --session $SESSION"
|
||||
SAMPLER+=" --control static --color false"
|
||||
SAMPLER+=" --max-iterations 1"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,rateLogging=0,address=tcp://*:5555,address=tcp://*:5556"
|
||||
@@ -25,6 +28,7 @@ SINK1="fairmq-ex-copypush-sink"
|
||||
SINK1+=" --id sink1"
|
||||
SINK1+=" --transport $transport"
|
||||
SINK1+=" --verbosity veryhigh"
|
||||
SINK1+=" --session $SESSION"
|
||||
SINK1+=" --control static --color false"
|
||||
SINK1+=" --max-iterations 1"
|
||||
SINK1+=" --channel-config name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5555"
|
||||
@@ -35,6 +39,7 @@ SINK2="fairmq-ex-copypush-sink"
|
||||
SINK2+=" --id sink2"
|
||||
SINK2+=" --transport $transport"
|
||||
SINK2+=" --verbosity veryhigh"
|
||||
SINK2+=" --session $SESSION"
|
||||
SINK2+=" --control static --color false"
|
||||
SINK2+=" --max-iterations 1"
|
||||
SINK2+=" --channel-config name=data,type=pull,method=connect,rateLogging=0,address=tcp://localhost:5556"
|
||||
|
@@ -1,23 +1,17 @@
|
||||
DDS Example
|
||||
===========
|
||||
|
||||
This example demonstrates usage of the Dynamic Deployment System ([DDS](http://dds.gsi.de/)) to dynamically deploy and configure a topology of devices. The topology is similar to those of Example 2, but now it can be easily distributed on different computing nodes without the need for manual socket reconfiguration of the devices.
|
||||
|
||||
To make use of DDS functionality the example executables need to find the DDS plugin libraries that are compiled with FairRoot when FairRoot find DDS installed. Custom DDS location can be given to CMake as follows:
|
||||
|
||||
```bash
|
||||
cmake -DDDS_ROOT="/path/to/dds/install/dir/" ..
|
||||
```
|
||||
This example demonstrates usage of the Dynamic Deployment System ([DDS](http://dds.gsi.de/)) to dynamically deploy and configure a topology of devices. The topology is similar to the one in Example 1-n-1, but now it can be easily distributed on different computing nodes without the need for manual addresses reconfiguration of the devices.
|
||||
|
||||
The description below outlines the minimal steps needed to run the example with DDS. For general DDS help please refer to DDS documentation on [DDS Website](http://dds.gsi.de/).
|
||||
|
||||
##### 1. The device handles the socket addresses and ports configuration via DDS Plugin.
|
||||
##### 1. The device handles the channel addresses and ports configuration via DDS Plugin.
|
||||
|
||||
It is sufficient to provide the `-S "<@FAIRROOT_INSTALL_DIR@/lib" -P dds` (`<` prepends the following path to the default plugin search paths; put in the path which points to the library dir of your FairRoot installation) command line arguments to let the devices be configured dynamically. No code changes in the device are necessary. See the XML topology file for example of using the command line arguments.
|
||||
It is sufficient to provide the `-S "<@FAIRMQ_INSTALL_DIR@/lib" -P dds` (`<` prepends the following path to the default plugin search paths; put in the path which points to the library dir of your FairRoot installation) command line arguments to let the devices be configured dynamically. No code changes in the device are necessary. See the XML topology file for example of using the command line arguments.
|
||||
|
||||
##### 2a. Write DDS hosts file that contains a list of worker nodes to run the topology on (When deploying using the SSH plug-in).
|
||||
|
||||
We run this example on the local machine for simplicity. The file below defines three workers, sampler, processor and sink, with a total of 12 DDS agents (thus able to accept 12 tasks). The parameters for each worker node are:
|
||||
We run this example on the local machine for simplicity. The file below defines 3 workers - sampler, processor and sink - with a total of 12 DDS agents (thus able to accept 12 tasks). The parameters for each worker node are:
|
||||
- user-chosen worker ID (must be unique)
|
||||
- a host name with or without a login, in a form: login@host.fqdn (password-less SSH access to these hosts must be possible)
|
||||
- additional SSH params (can be empty)
|
||||
@@ -40,23 +34,27 @@ If you want to deploy on a single host DDS 1.6+ provides a localhost rms plug-in
|
||||
|
||||
##### 3. Write DDS topology file that describes which tasks (processes) to run and their topology and configuration.
|
||||
|
||||
Take a look at `ex-dds-topology.xml`. It consists of a definition part (properties, tasks, collections and more) and execution part (main). In our example Sampler, Processor and Sink tasks are defines, containing their executables and exchanged properties. The `<main>` of the topology uses the defined tasks. Besides one Sampler and one Sink task, a group containing Processor task is defined. The group has a multiplicity of 10, meaninig 10 Processors will be executed. Each of the Processors will receive the properties with Sampler and Sink addresses.
|
||||
Take a look at `ex-dds-topology.xml`. It consists of a definition part (properties, tasks, collections and more) and execution part (main). In our example Sampler, Processor and Sink tasks are defined, containing their executables and exchanged properties. The `<main>` of the topology uses the defined tasks. Besides one Sampler and one Sink task, a group containing Processor task is defined. The group has a multiplicity of 10, meaninig 10 Processors will be executed. Each of the Processors will receive the properties with Sampler and Sink addresses.
|
||||
|
||||
The configuration of the channel connection addresses is done by the DDS plugin via the channel names. The task property names must correspond to the channel names (data1, data2), with binding channels writing the properties and connecting channel reading the properties (see the example XML and JSON files).
|
||||
The configuration of the channel connection addresses is done by the DDS plugin via the channel names. The task property names must correspond to the channel names (data1, data2), with binding channels writing the properties and connecting channel reading the properties.
|
||||
|
||||
If `eth0` network interface (default for binding) is not available on your system, specify another one in the topology file for each task. For example: `--network-interface lo0`.
|
||||
|
||||
If you chose step 2b earlier, then modify the provided `ex-dds-topology.xml` in the top that the following lines read as following:
|
||||
**If you chose step 2b earlier**, then modify the provided `ex-dds-topology.xml` in the top that the following lines read as following:
|
||||
```xml
|
||||
<declrequirement id="SamplerWorker" type="wnname" value=".*"/>
|
||||
<declrequirement id="ProcessorWorker" type="wnname" value=".*"/>
|
||||
<declrequirement id="SinkWorker" type="wnname" value=".*"/>
|
||||
<declrequirement id="SamplerWorker" type="wnname" value=".*"/>
|
||||
<declrequirement id="ProcessorWorker" type="wnname" value=".*"/>
|
||||
<declrequirement id="SinkWorker" type="wnname" value=".*"/>
|
||||
```
|
||||
|
||||
Note that the attributes `value` contain a different value.
|
||||
|
||||
##### 4. Start DDS server.
|
||||
|
||||
First you need to initialize DDS environment:
|
||||
|
||||
```bash
|
||||
source DDS_env.sh # this script is located in the DDS installation directory
|
||||
```
|
||||
|
||||
The DDS server is started with:
|
||||
|
||||
```bash
|
||||
@@ -71,7 +69,7 @@ dds-submit --rms ssh --config ex-dds-hosts.cfg
|
||||
```
|
||||
The `--rms` option defines a destination resource management system. The `--config` specifies an SSH plug-in resource definition file.
|
||||
|
||||
If you chose step 2b earlier, run the following command instead:
|
||||
**If you chose step 2b earlier**, run the following command instead:
|
||||
|
||||
```bash
|
||||
dds-submit --rms localhost -n 12
|
||||
@@ -85,13 +83,30 @@ dds-topology --activate ex-dds-topology.xml
|
||||
|
||||
##### 7. Run
|
||||
|
||||
After activation, agents will execute the defined tasks on the worker nodes. Output of the tasks will be stored in the directory that was specified in the hosts file.
|
||||
After activation, agents will execute the defined tasks on the worker nodes. Output of the tasks will be stored in the directory that was specified in the hosts file (or in the system temporary directory when using the localhost plugin).
|
||||
|
||||
##### 8. (optional) Use example command UI to check state of the devices
|
||||
|
||||
A simple utility (fairmq-dds-command-ui) is included with FairRoot to send commands to devices and receive replies from them. The utility uses the DDS intercom library to send "check-state" string to all devices, to which they reply with their ID and state they are in. The utility also allows requesting state changes from devices. To let the device listen to the commands from the utility, start the device with `-S "<@FAIRROOT_INSTALL_DIR@/lib" -P dds` cmd option (see example XML topology).
|
||||
A simple utility (fairmq-dds-command-ui) is included with FairMQ to send commands to devices and receive replies from them. The utility uses the DDS intercom library to query state/config of devices and allows changing their state. To let the device listen to the commands from the utility, start the device with `-S "<@FAIRMQ_INSTALL_DIR@/lib" -P dds` cmd option (see example XML topology).
|
||||
|
||||
To see it in action, start the fairmq-dds-command-ui while the topology is running.
|
||||
To see it in action, start the fairmq-dds-command-ui while the topology is running. Run the utility with `-h` to see everything that it can do.
|
||||
|
||||
The utility requires a session parameter to connect to appropriate DDS session. The session value is given when starting dds-server.
|
||||
|
||||
By default the command UI sends commands to all tasks. This can be further refined by giving a specific topology path via `-p` argument.
|
||||
Given our topology file, here are some examples of valid paths:
|
||||
```bash
|
||||
# get state of all devices
|
||||
./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c
|
||||
# get state of sampler
|
||||
./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c -p main/Sampler
|
||||
# get state of sink
|
||||
./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c -p main/Sink
|
||||
# get state all processors
|
||||
./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c -p main/ProcessorGroup/Processor
|
||||
# get state of a specific processor
|
||||
./fairmq/plugins/DDS/fairmq-dds-command-ui -s 937ffbca-b524-44d8-9898-1d69aedc3751 -c c -p main/ProcessorGroup/Processor_9
|
||||
```
|
||||
|
||||
##### 9. Stop DDS server/topology.
|
||||
|
||||
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
transport=$1
|
||||
fi
|
||||
|
||||
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $SAMPLER_PID; kill -TERM $SINK_PID; wait $SAMPLER_PID; wait $SINK_PID;' TERM
|
||||
|
||||
@@ -15,6 +17,7 @@ SAMPLER="fairmq-ex-multipart-sampler"
|
||||
SAMPLER+=" --id sampler1"
|
||||
SAMPLER+=" --transport $transport"
|
||||
SAMPLER+=" --verbosity veryhigh"
|
||||
SAMPLER+=" --session $SESSION"
|
||||
SAMPLER+=" --max-iterations 1"
|
||||
SAMPLER+=" --control static --color false"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=connect,rateLogging=0,address=tcp://127.0.0.1:5555"
|
||||
@@ -25,6 +28,7 @@ SINK="fairmq-ex-multipart-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --transport $transport"
|
||||
SINK+=" --verbosity veryhigh"
|
||||
SINK+=" --session $SESSION"
|
||||
SINK+=" --control static --color false"
|
||||
SINK+=" --channel-config name=data,type=pull,method=bind,rateLogging=0,address=tcp://127.0.0.1:5555"
|
||||
@CMAKE_CURRENT_BINARY_DIR@/$SINK &
|
||||
|
@@ -14,12 +14,12 @@ SAMPLER+=" --severity debug"
|
||||
SAMPLER+=" --msg-size $msgSize"
|
||||
# SAMPLER+=" --rate 10"
|
||||
SAMPLER+=" --transport shmem"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:7777"
|
||||
SAMPLER+=" --channel-config name=data,type=push,method=bind,address=tcp://127.0.0.1:7777,sndKernelSize=212992"
|
||||
xterm -geometry 80x23+0+0 -hold -e @EX_BIN_DIR@/$SAMPLER &
|
||||
|
||||
SINK="fairmq-ex-region-sink"
|
||||
SINK+=" --id sink1"
|
||||
SINK+=" --severity debug"
|
||||
SINK+=" --transport shmem"
|
||||
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:7777"
|
||||
SINK+=" --channel-config name=data,type=pull,method=connect,address=tcp://127.0.0.1:7777,rcvKernelSize=212992"
|
||||
xterm -geometry 80x23+500+0 -hold -e @EX_BIN_DIR@/$SINK &
|
||||
|
@@ -8,6 +8,8 @@ if [[ $1 =~ ^[a-z]+$ ]]; then
|
||||
transport=$1
|
||||
fi
|
||||
|
||||
SESSION="$(@CMAKE_BINARY_DIR@/fairmq/fairmq-uuid-gen -h)"
|
||||
|
||||
# setup a trap to kill everything if the test fails/timeouts
|
||||
trap 'kill -TERM $CLIENT_PID; kill -TERM $SERVER_PID; wait $CLIENT_PID; wait $SERVER_PID;' TERM
|
||||
|
||||
@@ -15,6 +17,7 @@ CLIENT="fairmq-ex-req-rep-client"
|
||||
CLIENT+=" --id client"
|
||||
CLIENT+=" --transport $transport"
|
||||
CLIENT+=" --verbosity veryhigh"
|
||||
CLIENT+=" --session $SESSION"
|
||||
CLIENT+=" --control static --color false"
|
||||
CLIENT+=" --max-iterations 1"
|
||||
CLIENT+=" --channel-config name=data,type=req,method=connect,rateLogging=0,address=tcp://127.0.0.1:5005"
|
||||
@@ -25,6 +28,7 @@ SERVER="fairmq-ex-req-rep-server"
|
||||
SERVER+=" --id server"
|
||||
SERVER+=" --transport $transport"
|
||||
SERVER+=" --verbosity veryhigh"
|
||||
SERVER+=" --session $SESSION"
|
||||
SERVER+=" --control static --color false"
|
||||
SERVER+=" --max-iterations 1"
|
||||
SERVER+=" --channel-config name=data,type=rep,method=bind,rateLogging=0,address=tcp://127.0.0.1:5005"
|
||||
|
@@ -1,54 +0,0 @@
|
||||
---
|
||||
Language: Cpp
|
||||
#AccessModifierOffset: -4
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
|
||||
# It is broken on windows. Breaks all #include "header.h"
|
||||
#AlwaysBreakBeforeMultilineStrings: true
|
||||
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
BinPackParameters: false
|
||||
ColumnLimit: 160
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
DerivePointerBinding: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
IndentCaseLabels: true
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: false
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PointerBindsToType: true
|
||||
SpacesBeforeTrailingComments: 1
|
||||
Cpp11BracedListStyle: false
|
||||
Standard: Cpp11
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
BreakBeforeBraces: Allman
|
||||
IndentFunctionDeclarationAfterType: true
|
||||
SpacesInParentheses: false
|
||||
SpacesInAngles: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
ContinuationIndentWidth: 4
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
SpaceBeforeParens: ControlStatements
|
||||
...
|
@@ -28,7 +28,6 @@ endif()
|
||||
##################
|
||||
# subdirectories #
|
||||
##################
|
||||
# add_subdirectory(shmem/prototype)
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
add_subdirectory(ofi)
|
||||
endif()
|
||||
@@ -38,145 +37,147 @@ endif()
|
||||
# libFairMQ header files #
|
||||
##########################
|
||||
set(FAIRMQ_PUBLIC_HEADER_FILES
|
||||
DeviceRunner.h
|
||||
EventManager.h
|
||||
FairMQChannel.h
|
||||
FairMQDevice.h
|
||||
FairMQLogger.h
|
||||
FairMQMessage.h
|
||||
FairMQParts.h
|
||||
FairMQPoller.h
|
||||
FairMQUnmanagedRegion.h
|
||||
FairMQSocket.h
|
||||
FairMQStateMachine.h
|
||||
FairMQTransportFactory.h
|
||||
Tools.h
|
||||
Transports.h
|
||||
options/FairMQProgOptions.h
|
||||
options/FairProgOptions.h
|
||||
Plugin.h
|
||||
PluginManager.h
|
||||
PluginServices.h
|
||||
runFairMQDevice.h
|
||||
tools/CppSTL.h
|
||||
tools/Network.h
|
||||
tools/Process.h
|
||||
tools/Strings.h
|
||||
tools/Unique.h
|
||||
tools/Version.h
|
||||
DeviceRunner.h
|
||||
EventManager.h
|
||||
FairMQChannel.h
|
||||
FairMQDevice.h
|
||||
FairMQLogger.h
|
||||
FairMQMessage.h
|
||||
FairMQParts.h
|
||||
FairMQPoller.h
|
||||
FairMQUnmanagedRegion.h
|
||||
FairMQSocket.h
|
||||
FairMQStateMachine.h
|
||||
FairMQTransportFactory.h
|
||||
MemoryResources.h
|
||||
MemoryResourceTools.h
|
||||
Tools.h
|
||||
Transports.h
|
||||
options/FairMQProgOptions.h
|
||||
options/FairProgOptions.h
|
||||
Plugin.h
|
||||
PluginManager.h
|
||||
PluginServices.h
|
||||
runFairMQDevice.h
|
||||
tools/CppSTL.h
|
||||
tools/Network.h
|
||||
tools/Process.h
|
||||
tools/RateLimit.h
|
||||
tools/Strings.h
|
||||
tools/Unique.h
|
||||
tools/Version.h
|
||||
)
|
||||
|
||||
set(FAIRMQ_PRIVATE_HEADER_FILES
|
||||
devices/FairMQBenchmarkSampler.h
|
||||
devices/FairMQMerger.h
|
||||
devices/FairMQMultiplier.h
|
||||
devices/FairMQProxy.h
|
||||
devices/FairMQSink.h
|
||||
devices/FairMQSplitter.h
|
||||
options/FairMQParser.h
|
||||
options/FairMQSuboptParser.h
|
||||
options/FairProgOptionsHelper.h
|
||||
plugins/Builtin.h
|
||||
plugins/Control.h
|
||||
StateMachine.h
|
||||
shmem/FairMQMessageSHM.h
|
||||
shmem/FairMQPollerSHM.h
|
||||
shmem/FairMQUnmanagedRegionSHM.h
|
||||
shmem/FairMQSocketSHM.h
|
||||
shmem/FairMQTransportFactorySHM.h
|
||||
shmem/Common.h
|
||||
shmem/Manager.h
|
||||
shmem/Monitor.h
|
||||
shmem/Region.h
|
||||
zeromq/FairMQMessageZMQ.h
|
||||
zeromq/FairMQPollerZMQ.h
|
||||
zeromq/FairMQUnmanagedRegionZMQ.h
|
||||
zeromq/FairMQSocketZMQ.h
|
||||
zeromq/FairMQTransportFactoryZMQ.h
|
||||
devices/FairMQBenchmarkSampler.h
|
||||
devices/FairMQMerger.h
|
||||
devices/FairMQMultiplier.h
|
||||
devices/FairMQProxy.h
|
||||
devices/FairMQSink.h
|
||||
devices/FairMQSplitter.h
|
||||
options/FairMQParser.h
|
||||
options/FairMQSuboptParser.h
|
||||
options/FairProgOptionsHelper.h
|
||||
plugins/Builtin.h
|
||||
plugins/Control.h
|
||||
StateMachine.h
|
||||
shmem/FairMQMessageSHM.h
|
||||
shmem/FairMQPollerSHM.h
|
||||
shmem/FairMQUnmanagedRegionSHM.h
|
||||
shmem/FairMQSocketSHM.h
|
||||
shmem/FairMQTransportFactorySHM.h
|
||||
shmem/Common.h
|
||||
shmem/Manager.h
|
||||
shmem/Region.h
|
||||
zeromq/FairMQMessageZMQ.h
|
||||
zeromq/FairMQPollerZMQ.h
|
||||
zeromq/FairMQUnmanagedRegionZMQ.h
|
||||
zeromq/FairMQSocketZMQ.h
|
||||
zeromq/FairMQTransportFactoryZMQ.h
|
||||
)
|
||||
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
set(FAIRMQ_PRIVATE_HEADER_FILES ${FAIRMQ_PRIVATE_HEADER_FILES}
|
||||
nanomsg/FairMQMessageNN.h
|
||||
nanomsg/FairMQPollerNN.h
|
||||
nanomsg/FairMQUnmanagedRegionNN.h
|
||||
nanomsg/FairMQSocketNN.h
|
||||
nanomsg/FairMQTransportFactoryNN.h
|
||||
)
|
||||
nanomsg/FairMQMessageNN.h
|
||||
nanomsg/FairMQPollerNN.h
|
||||
nanomsg/FairMQUnmanagedRegionNN.h
|
||||
nanomsg/FairMQSocketNN.h
|
||||
nanomsg/FairMQTransportFactoryNN.h
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(FAIRMQ_PRIVATE_HEADER_FILES ${FAIRMQ_PRIVATE_HEADER_FILES}
|
||||
ofi/Context.h
|
||||
ofi/Message.h
|
||||
ofi/Poller.h
|
||||
ofi/Socket.h
|
||||
ofi/TransportFactory.h
|
||||
)
|
||||
ofi/Context.h
|
||||
ofi/Message.h
|
||||
ofi/Poller.h
|
||||
ofi/Socket.h
|
||||
ofi/TransportFactory.h
|
||||
)
|
||||
endif()
|
||||
|
||||
##########################
|
||||
# libFairMQ source files #
|
||||
##########################
|
||||
set(FAIRMQ_SOURCE_FILES
|
||||
DeviceRunner.cxx
|
||||
FairMQChannel.cxx
|
||||
FairMQDevice.cxx
|
||||
FairMQLogger.cxx
|
||||
FairMQMessage.cxx
|
||||
FairMQPoller.cxx
|
||||
FairMQSocket.cxx
|
||||
FairMQStateMachine.cxx
|
||||
FairMQTransportFactory.cxx
|
||||
devices/FairMQBenchmarkSampler.cxx
|
||||
devices/FairMQMerger.cxx
|
||||
devices/FairMQMultiplier.cxx
|
||||
devices/FairMQProxy.cxx
|
||||
devices/FairMQSplitter.cxx
|
||||
options/FairMQParser.cxx
|
||||
options/FairMQProgOptions.cxx
|
||||
options/FairMQSuboptParser.cxx
|
||||
Plugin.cxx
|
||||
PluginManager.cxx
|
||||
PluginServices.cxx
|
||||
plugins/Control.cxx
|
||||
StateMachine.cxx
|
||||
shmem/FairMQMessageSHM.cxx
|
||||
shmem/FairMQPollerSHM.cxx
|
||||
shmem/FairMQUnmanagedRegionSHM.cxx
|
||||
shmem/FairMQSocketSHM.cxx
|
||||
shmem/FairMQTransportFactorySHM.cxx
|
||||
shmem/Manager.cxx
|
||||
shmem/Monitor.cxx
|
||||
shmem/Region.cxx
|
||||
tools/Network.cxx
|
||||
tools/Process.cxx
|
||||
tools/Unique.cxx
|
||||
zeromq/FairMQMessageZMQ.cxx
|
||||
zeromq/FairMQPollerZMQ.cxx
|
||||
zeromq/FairMQUnmanagedRegionZMQ.cxx
|
||||
zeromq/FairMQSocketZMQ.cxx
|
||||
zeromq/FairMQTransportFactoryZMQ.cxx
|
||||
DeviceRunner.cxx
|
||||
FairMQChannel.cxx
|
||||
FairMQDevice.cxx
|
||||
FairMQLogger.cxx
|
||||
FairMQMessage.cxx
|
||||
FairMQPoller.cxx
|
||||
FairMQSocket.cxx
|
||||
FairMQStateMachine.cxx
|
||||
FairMQTransportFactory.cxx
|
||||
devices/FairMQBenchmarkSampler.cxx
|
||||
devices/FairMQMerger.cxx
|
||||
devices/FairMQMultiplier.cxx
|
||||
devices/FairMQProxy.cxx
|
||||
devices/FairMQSplitter.cxx
|
||||
options/FairMQParser.cxx
|
||||
options/FairMQProgOptions.cxx
|
||||
options/FairMQSuboptParser.cxx
|
||||
Plugin.cxx
|
||||
PluginManager.cxx
|
||||
PluginServices.cxx
|
||||
plugins/Control.cxx
|
||||
StateMachine.cxx
|
||||
shmem/FairMQMessageSHM.cxx
|
||||
shmem/FairMQPollerSHM.cxx
|
||||
shmem/FairMQUnmanagedRegionSHM.cxx
|
||||
shmem/FairMQSocketSHM.cxx
|
||||
shmem/FairMQTransportFactorySHM.cxx
|
||||
shmem/Manager.cxx
|
||||
shmem/Region.cxx
|
||||
tools/Network.cxx
|
||||
tools/Process.cxx
|
||||
tools/Unique.cxx
|
||||
zeromq/FairMQMessageZMQ.cxx
|
||||
zeromq/FairMQPollerZMQ.cxx
|
||||
zeromq/FairMQUnmanagedRegionZMQ.cxx
|
||||
zeromq/FairMQSocketZMQ.cxx
|
||||
zeromq/FairMQTransportFactoryZMQ.cxx
|
||||
MemoryResources.cxx
|
||||
)
|
||||
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
set(FAIRMQ_SOURCE_FILES ${FAIRMQ_SOURCE_FILES}
|
||||
nanomsg/FairMQMessageNN.cxx
|
||||
nanomsg/FairMQPollerNN.cxx
|
||||
nanomsg/FairMQUnmanagedRegionNN.cxx
|
||||
nanomsg/FairMQSocketNN.cxx
|
||||
nanomsg/FairMQTransportFactoryNN.cxx
|
||||
)
|
||||
set(FAIRMQ_SOURCE_FILES ${FAIRMQ_SOURCE_FILES}
|
||||
nanomsg/FairMQMessageNN.cxx
|
||||
nanomsg/FairMQPollerNN.cxx
|
||||
nanomsg/FairMQUnmanagedRegionNN.cxx
|
||||
nanomsg/FairMQSocketNN.cxx
|
||||
nanomsg/FairMQTransportFactoryNN.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(FAIRMQ_SOURCE_FILES ${FAIRMQ_SOURCE_FILES}
|
||||
ofi/Context.cxx
|
||||
ofi/Message.cxx
|
||||
ofi/Poller.cxx
|
||||
ofi/Socket.cxx
|
||||
ofi/TransportFactory.cxx
|
||||
)
|
||||
set(FAIRMQ_SOURCE_FILES ${FAIRMQ_SOURCE_FILES}
|
||||
ofi/Context.cxx
|
||||
ofi/Message.cxx
|
||||
ofi/Poller.cxx
|
||||
ofi/Socket.cxx
|
||||
ofi/TransportFactory.cxx
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -191,62 +192,94 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/options/startConfigExample.sh.in ${CM
|
||||
#################################
|
||||
# define libFairMQ build target #
|
||||
#################################
|
||||
add_library(FairMQ SHARED
|
||||
if(FAST_BUILD)
|
||||
set(_target FairMQ_)
|
||||
else()
|
||||
set(_target FairMQ)
|
||||
endif()
|
||||
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()
|
||||
|
||||
#######################
|
||||
# include directories #
|
||||
#######################
|
||||
target_include_directories(FairMQ
|
||||
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>
|
||||
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>
|
||||
)
|
||||
|
||||
##################
|
||||
# link libraries #
|
||||
##################
|
||||
if(BUILD_NANOMSG_TRANSPORT)
|
||||
set(NANOMSG_DEPS nanomsg msgpackc)
|
||||
set(NANOMSG_DEPS nanomsg msgpackc-cxx)
|
||||
endif()
|
||||
if(BUILD_OFI_TRANSPORT)
|
||||
set(OFI_DEPS OFI::libfabric protobuf::libprotobuf $<TARGET_OBJECTS:OfiTransport>)
|
||||
endif()
|
||||
target_link_libraries(FairMQ
|
||||
INTERFACE # only consumers link against interface dependencies
|
||||
set(optional_deps ${NANOMSG_DEPS} ${OFI_DEPS})
|
||||
if(optional_deps)
|
||||
list(REMOVE_DUPLICATES optional_deps)
|
||||
endif()
|
||||
|
||||
PUBLIC # libFairMQ AND consumers of libFairMQ link aginst public dependencies
|
||||
dl
|
||||
Boost::boost
|
||||
Boost::program_options
|
||||
Boost::thread
|
||||
Boost::system
|
||||
Boost::filesystem
|
||||
Boost::regex
|
||||
Boost::date_time
|
||||
Boost::signals
|
||||
FairLogger::FairLogger
|
||||
target_link_libraries(${_target}
|
||||
INTERFACE # only consumers link against interface dependencies
|
||||
Boost::container
|
||||
|
||||
PRIVATE # only libFairMQ links against private dependencies
|
||||
libzmq
|
||||
${NANOMSG_DEPS}
|
||||
${OFI_DEPS}
|
||||
PUBLIC # libFairMQ AND consumers of libFairMQ link aginst public dependencies
|
||||
Threads::Threads
|
||||
dl
|
||||
$<$<PLATFORM_ID:Linux>:rt>
|
||||
Boost::boost
|
||||
Boost::program_options
|
||||
Boost::thread
|
||||
Boost::system
|
||||
Boost::filesystem
|
||||
Boost::regex
|
||||
Boost::date_time
|
||||
Boost::signals
|
||||
FairLogger::FairLogger
|
||||
|
||||
PRIVATE # only libFairMQ links against private dependencies
|
||||
libzmq
|
||||
${NANOMSG_DEPS}
|
||||
${OFI_DEPS}
|
||||
)
|
||||
set_target_properties(FairMQ PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
set_target_properties(${_target} PROPERTIES
|
||||
VERSION ${PROJECT_GIT_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)
|
||||
endif()
|
||||
|
||||
|
||||
###############
|
||||
# executables #
|
||||
###############
|
||||
|
||||
add_executable(fairmq-bsampler run/runBenchmarkSampler.cxx)
|
||||
target_link_libraries(fairmq-bsampler FairMQ)
|
||||
|
||||
@@ -268,37 +301,48 @@ target_link_libraries(fairmq-splitter FairMQ)
|
||||
add_executable(runConfigExample options/runConfigEx.cxx)
|
||||
target_link_libraries(runConfigExample FairMQ)
|
||||
|
||||
add_executable(fairmq-shmmonitor shmem/runMonitor.cxx)
|
||||
target_link_libraries(fairmq-shmmonitor FairMQ)
|
||||
add_executable(fairmq-shmmonitor shmem/Monitor.cxx shmem/Monitor.h shmem/runMonitor.cxx)
|
||||
target_link_libraries(fairmq-shmmonitor PUBLIC
|
||||
Threads::Threads
|
||||
$<$<PLATFORM_ID:Linux>:rt>
|
||||
Boost::boost
|
||||
Boost::date_time
|
||||
Boost::program_options
|
||||
)
|
||||
target_include_directories(fairmq-shmmonitor PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
|
||||
)
|
||||
|
||||
add_executable(fairmq-uuid-gen run/runUuidGenerator.cxx)
|
||||
target_link_libraries(fairmq-uuid-gen FairMQ)
|
||||
|
||||
|
||||
###########
|
||||
# install #
|
||||
###########
|
||||
install(
|
||||
TARGETS # FairMQFull, tests are not installed
|
||||
FairMQ
|
||||
fairmq-bsampler
|
||||
fairmq-merger
|
||||
fairmq-multiplier
|
||||
fairmq-proxy
|
||||
fairmq-sink
|
||||
fairmq-splitter
|
||||
fairmq-shmmonitor
|
||||
fairmq-uuid-gen
|
||||
TARGETS
|
||||
FairMQ
|
||||
fairmq-bsampler
|
||||
fairmq-merger
|
||||
fairmq-multiplier
|
||||
fairmq-proxy
|
||||
fairmq-sink
|
||||
fairmq-splitter
|
||||
fairmq-shmmonitor
|
||||
fairmq-uuid-gen
|
||||
|
||||
EXPORT ${PROJECT_EXPORT_SET}
|
||||
LIBRARY DESTINATION ${PROJECT_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR}
|
||||
EXPORT ${PROJECT_EXPORT_SET}
|
||||
RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR}
|
||||
LIBRARY DESTINATION ${PROJECT_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${PROJECT_INSTALL_LIBDIR}
|
||||
)
|
||||
|
||||
# preserve relative path and prepend fairmq
|
||||
foreach(HEADER ${FAIRMQ_PUBLIC_HEADER_FILES})
|
||||
get_filename_component(_path ${HEADER} DIRECTORY)
|
||||
file(TO_CMAKE_PATH ${PROJECT_INSTALL_INCDIR}/${_path} _destination)
|
||||
install(FILES ${HEADER}
|
||||
DESTINATION ${_destination}
|
||||
)
|
||||
get_filename_component(_path ${HEADER} DIRECTORY)
|
||||
file(TO_CMAKE_PATH ${PROJECT_INSTALL_INCDIR}/${_path} _destination)
|
||||
install(FILES ${HEADER}
|
||||
DESTINATION ${_destination}
|
||||
)
|
||||
endforeach()
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -7,17 +7,21 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include "DeviceRunner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <exception>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <fairmq/Version.h>
|
||||
|
||||
using namespace fair::mq;
|
||||
|
||||
DeviceRunner::DeviceRunner(int argc, char* const argv[])
|
||||
: fRawCmdLineArgs{tools::ToStrVector(argc, argv, false)}
|
||||
, fPluginManager{PluginManager::MakeFromCommandLineOptions(fRawCmdLineArgs)}
|
||||
, fDevice{nullptr}
|
||||
{
|
||||
}
|
||||
DeviceRunner::DeviceRunner(int argc, char* const argv[], bool printLogo)
|
||||
: fRawCmdLineArgs(tools::ToStrVector(argc, argv, false))
|
||||
, fConfig()
|
||||
, fDevice(nullptr)
|
||||
, fPluginManager(fRawCmdLineArgs)
|
||||
, fPrintLogo(printLogo)
|
||||
, fEvents()
|
||||
{}
|
||||
|
||||
auto DeviceRunner::Run() -> int
|
||||
{
|
||||
@@ -26,32 +30,40 @@ auto DeviceRunner::Run() -> int
|
||||
////////////////////////
|
||||
|
||||
// Load builtin plugins last
|
||||
fPluginManager->LoadPlugin("s:control");
|
||||
fPluginManager.LoadPlugin("s:control");
|
||||
|
||||
////// CALL HOOK ///////
|
||||
fEvents.Emit<hooks::SetCustomCmdLineOptions>(*this);
|
||||
////////////////////////
|
||||
|
||||
fPluginManager->ForEachPluginProgOptions([&](boost::program_options::options_description options){
|
||||
fConfig.AddToCmdLineOptions(options);
|
||||
});
|
||||
fConfig.AddToCmdLineOptions(fPluginManager->ProgramOptions());
|
||||
fPluginManager.ForEachPluginProgOptions(
|
||||
[&](boost::program_options::options_description options) {
|
||||
fConfig.AddToCmdLineOptions(options);
|
||||
});
|
||||
fConfig.AddToCmdLineOptions(fPluginManager.ProgramOptions());
|
||||
|
||||
////// CALL HOOK ///////
|
||||
fEvents.Emit<hooks::ModifyRawCmdLineArgs>(*this);
|
||||
////////////////////////
|
||||
|
||||
if (fConfig.ParseAll(fRawCmdLineArgs, true))
|
||||
{
|
||||
if (fConfig.ParseAll(fRawCmdLineArgs, true)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fPrintLogo) {
|
||||
LOG(info) << std::endl
|
||||
<< " ______ _ _______ _________ " << std::endl
|
||||
<< " / ____/___ _(_)_______ |/ /_ __ \\ version " << FAIRMQ_GIT_VERSION << std::endl
|
||||
<< " / /_ / __ `/ / ___/__ /|_/ /_ / / / build " << FAIRMQ_BUILD_TYPE << std::endl
|
||||
<< " / __/ / /_/ / / / _ / / / / /_/ / " << FAIRMQ_REPO_URL << std::endl
|
||||
<< " /_/ \\__,_/_/_/ /_/ /_/ \\___\\_\\ " << FAIRMQ_LICENSE << " © " << FAIRMQ_COPYRIGHT << std::endl;
|
||||
}
|
||||
|
||||
////// CALL HOOK ///////
|
||||
fEvents.Emit<hooks::InstantiateDevice>(*this);
|
||||
////////////////////////
|
||||
|
||||
if (!fDevice)
|
||||
{
|
||||
if (!fDevice) {
|
||||
LOG(error) << "getDevice(): no valid device provided. Exiting.";
|
||||
return 1;
|
||||
}
|
||||
@@ -60,16 +72,14 @@ auto DeviceRunner::Run() -> int
|
||||
|
||||
// Handle --print-channels
|
||||
fDevice->RegisterChannelEndpoints();
|
||||
if (fConfig.Count("print-channels"))
|
||||
{
|
||||
if (fConfig.Count("print-channels")) {
|
||||
fDevice->PrintRegisteredChannels();
|
||||
fDevice->ChangeState(FairMQDevice::END);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Handle --version
|
||||
if (fConfig.Count("version"))
|
||||
{
|
||||
if (fConfig.Count("version")) {
|
||||
std::cout << "User device version: " << fDevice->GetVersion() << std::endl;
|
||||
std::cout << "FAIRMQ_INTERFACE_VERSION: " << FAIRMQ_INTERFACE_VERSION << std::endl;
|
||||
fDevice->ChangeState(FairMQDevice::END);
|
||||
@@ -82,31 +92,29 @@ auto DeviceRunner::Run() -> int
|
||||
fDevice->SetConfig(fConfig);
|
||||
|
||||
// Initialize plugin services
|
||||
fPluginManager->EmplacePluginServices(&fConfig, fDevice);
|
||||
fPluginManager.EmplacePluginServices(fConfig, *fDevice);
|
||||
|
||||
// Instantiate and run plugins
|
||||
fPluginManager->InstantiatePlugins();
|
||||
fPluginManager.InstantiatePlugins();
|
||||
|
||||
// Run the device
|
||||
fDevice->RunStateMachine();
|
||||
|
||||
// Wait for control plugin to release device control
|
||||
fPluginManager->WaitForPluginsToReleaseDeviceControl();
|
||||
fPluginManager.WaitForPluginsToReleaseDeviceControl();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto DeviceRunner::RunWithExceptionHandlers() -> int
|
||||
{
|
||||
try
|
||||
{
|
||||
try {
|
||||
return Run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG(error) << "Unhandled exception reached the top of main: " << e.what() << ", application will now exit";
|
||||
} catch (std::exception& e) {
|
||||
LOG(error) << "Uncaught exception reached the top of DeviceRunner: " << e.what();
|
||||
return 1;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG(error) << "Non-exception instance being thrown. Please make sure you use std::runtime_exception() instead. Application will now exit.";
|
||||
} catch (...) {
|
||||
LOG(error) << "Uncaught exception reached the top of DeviceRunner.";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -20,10 +20,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
|
||||
/**
|
||||
* @class DeviceRunner DeviceRunner.h <fairmq/DeviceRunner.h>
|
||||
@@ -31,7 +29,8 @@ namespace mq
|
||||
*
|
||||
* Runs a single FairMQ device with config and plugin support.
|
||||
*
|
||||
* For customization user hooks are executed at various steps during device launch/shutdown in the following sequence:
|
||||
* For customization user hooks are executed at various steps during device launch/shutdown in the
|
||||
* following sequence:
|
||||
*
|
||||
* LoadPlugins
|
||||
* |
|
||||
@@ -44,34 +43,41 @@ namespace mq
|
||||
* v
|
||||
* InstatiateDevice
|
||||
*
|
||||
* Each hook has access to all members of the DeviceRunner and really only differs by the point in time it is called.
|
||||
* Each hook has access to all members of the DeviceRunner and really only differs by the point in
|
||||
* time it is called.
|
||||
*
|
||||
* For an example usage of this class see the fairmq/runFairMQDevice.h header.
|
||||
*/
|
||||
class DeviceRunner
|
||||
{
|
||||
public:
|
||||
DeviceRunner(int argc, char* const argv[]);
|
||||
DeviceRunner(int argc, char* const argv[], bool printLogo = true);
|
||||
|
||||
auto Run() -> int;
|
||||
auto RunWithExceptionHandlers() -> int;
|
||||
|
||||
template<typename H>
|
||||
auto AddHook(std::function<void(DeviceRunner&)> hook) -> void { fEvents.Subscribe<H>("runner", hook); }
|
||||
auto AddHook(std::function<void(DeviceRunner&)> hook) -> void
|
||||
{
|
||||
fEvents.Subscribe<H>("runner", hook);
|
||||
}
|
||||
template<typename H>
|
||||
auto RemoveHook() -> void { fEvents.Unsubscribe<H>("runner"); }
|
||||
auto RemoveHook() -> void
|
||||
{
|
||||
fEvents.Unsubscribe<H>("runner");
|
||||
}
|
||||
|
||||
std::vector<std::string> fRawCmdLineArgs;
|
||||
std::shared_ptr<PluginManager> fPluginManager;
|
||||
FairMQProgOptions fConfig;
|
||||
std::shared_ptr<FairMQDevice> fDevice;
|
||||
std::unique_ptr<FairMQDevice> fDevice;
|
||||
PluginManager fPluginManager;
|
||||
const bool fPrintLogo;
|
||||
|
||||
private:
|
||||
EventManager fEvents;
|
||||
};
|
||||
|
||||
namespace hooks
|
||||
{
|
||||
namespace hooks {
|
||||
struct LoadPlugins : Event<DeviceRunner&> {};
|
||||
struct SetCustomCmdLineOptions : Event<DeviceRunner&> {};
|
||||
struct ModifyRawCmdLineArgs : Event<DeviceRunner&> {};
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <FairMQSocket.h>
|
||||
@@ -51,7 +52,9 @@ class FairMQChannel
|
||||
/// Default destructor
|
||||
virtual ~FairMQChannel();
|
||||
|
||||
FairMQSocket const & GetSocket() const;
|
||||
struct ChannelConfigurationError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
FairMQSocket& GetSocket() const;
|
||||
|
||||
auto Bind(const std::string& address) -> bool
|
||||
{
|
||||
@@ -111,6 +114,10 @@ class FairMQChannel
|
||||
/// @return Returns socket kernel transmit receive buffer size (in bytes)
|
||||
int GetRcvKernelSize() const;
|
||||
|
||||
/// Get linger duration (in milliseconds)
|
||||
/// @return Returns linger duration (in milliseconds)
|
||||
int GetLinger() const;
|
||||
|
||||
/// Get socket rate logging interval (in seconds)
|
||||
/// @return Returns socket rate logging interval (in seconds)
|
||||
int GetRateLogging() const;
|
||||
@@ -147,6 +154,10 @@ class FairMQChannel
|
||||
/// @param rcvKernelSize Socket receive buffer size (in bytes)
|
||||
void UpdateRcvKernelSize(const int rcvKernelSize);
|
||||
|
||||
/// Set linger duration (in milliseconds)
|
||||
/// @param duration linger duration (in milliseconds)
|
||||
void UpdateLinger(const int duration);
|
||||
|
||||
/// Set socket rate logging interval (in seconds)
|
||||
/// @param rateLogging Socket rate logging interval (in seconds)
|
||||
void UpdateRateLogging(const int rateLogging);
|
||||
@@ -166,106 +177,62 @@ class FairMQChannel
|
||||
/// Resets the channel (requires validation to be used again).
|
||||
void ResetChannel();
|
||||
|
||||
int Send(FairMQMessagePtr& msg) const;
|
||||
int Receive(FairMQMessagePtr& msg) const;
|
||||
|
||||
/// Sends a message to the socket queue.
|
||||
/// @details Send method attempts to send a message by
|
||||
/// putting it in the output queue. If the queue is full or queueing is not possible
|
||||
/// for some other reason (e.g. no peers connected for a binding socket), the method blocks.
|
||||
///
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int Send(FairMQMessagePtr& msg, int sndTimeoutInMs) const;
|
||||
/// @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. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||
int Send(FairMQMessagePtr& msg, int sndTimeoutInMs = -1);
|
||||
|
||||
/// Receives a message from the socket queue.
|
||||
/// @details Receive method attempts to receive a message from the input queue.
|
||||
/// If the queue is empty the method blocks.
|
||||
///
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs) const;
|
||||
/// @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. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||
int Receive(FairMQMessagePtr& msg, int rcvTimeoutInMs = -1);
|
||||
|
||||
/// Sends a message in non-blocking mode.
|
||||
/// @details SendAsync method attempts to send a message without blocking by
|
||||
/// putting it in the queue.
|
||||
///
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @return Number of bytes that have been queued. If queueing failed due to
|
||||
/// full queue or no connected peers (when binding), returns -2.
|
||||
/// In case of errors, returns -1.
|
||||
int SendAsync(FairMQMessagePtr& msg) const;
|
||||
|
||||
/// Receives a message in non-blocking mode.
|
||||
///
|
||||
/// @param msg Constant reference of unique_ptr to a FairMQMessage
|
||||
/// @return Number of bytes that have been received. If queue is empty, returns -2.
|
||||
/// In case of errors, returns -1.
|
||||
int ReceiveAsync(FairMQMessagePtr& msg) const;
|
||||
|
||||
int64_t Send(std::vector<FairMQMessagePtr>& msgVec) const;
|
||||
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec) const;
|
||||
int SendAsync(FairMQMessagePtr& msg) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msg, timeout);")));
|
||||
int ReceiveAsync(FairMQMessagePtr& msg) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, timeout);")));
|
||||
|
||||
/// Send a vector of messages
|
||||
///
|
||||
/// @param msgVec message vector reference
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs) const;
|
||||
/// @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. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||
int64_t Send(std::vector<FairMQMessagePtr>& msgVec, int sndTimeoutInMs = -1);
|
||||
|
||||
/// Receive a vector of messages
|
||||
///
|
||||
/// @param msgVec message vector reference
|
||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs) const;
|
||||
/// @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. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||
int64_t Receive(std::vector<FairMQMessagePtr>& msgVec, int rcvTimeoutInMs = -1);
|
||||
|
||||
/// Sends a vector of message in non-blocking mode.
|
||||
/// @details SendAsync method attempts to send a vector of messages without blocking by
|
||||
/// putting it them the queue.
|
||||
///
|
||||
/// @param msgVec message vector reference
|
||||
/// @return Number of bytes that have been queued. If queueing failed due to
|
||||
/// full queue or no connected peers (when binding), returns -2. In case of errors, returns -1.
|
||||
int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) const;
|
||||
int64_t SendAsync(std::vector<FairMQMessagePtr>& msgVec) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msgVec, timeout);")));
|
||||
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msgVec, timeout);")));
|
||||
|
||||
/// Receives a vector of messages in non-blocking mode.
|
||||
///
|
||||
/// @param msgVec message vector reference
|
||||
/// @return Number of bytes that have been received. If queue is empty, returns -2.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t ReceiveAsync(std::vector<FairMQMessagePtr>& msgVec) const;
|
||||
|
||||
int64_t Send(FairMQParts& parts) const
|
||||
{
|
||||
return Send(parts.fParts);
|
||||
}
|
||||
|
||||
int64_t Receive(FairMQParts& parts) const
|
||||
{
|
||||
return Receive(parts.fParts);
|
||||
}
|
||||
|
||||
int64_t Send(FairMQParts& parts, int sndTimeoutInMs) const
|
||||
/// 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. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||
int64_t Send(FairMQParts& parts, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return Send(parts.fParts, sndTimeoutInMs);
|
||||
}
|
||||
|
||||
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs) const
|
||||
/// 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. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||
int64_t Receive(FairMQParts& parts, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return Receive(parts.fParts, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
int64_t SendAsync(FairMQParts& parts) const
|
||||
int64_t SendAsync(FairMQParts& parts) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(parts, timeout);")))
|
||||
{
|
||||
return SendAsync(parts.fParts);
|
||||
return Send(parts.fParts, 0);
|
||||
}
|
||||
|
||||
int64_t ReceiveAsync(FairMQParts& parts) const
|
||||
int64_t ReceiveAsync(FairMQParts& parts) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(parts, timeout);")))
|
||||
{
|
||||
return ReceiveAsync(parts.fParts);
|
||||
return Receive(parts.fParts, 0);
|
||||
}
|
||||
|
||||
unsigned long GetBytesTx() const;
|
||||
@@ -273,25 +240,25 @@ class FairMQChannel
|
||||
unsigned long GetMessagesTx() const;
|
||||
unsigned long GetMessagesRx() const;
|
||||
|
||||
auto Transport() const -> const FairMQTransportFactory*
|
||||
auto Transport() -> FairMQTransportFactory*
|
||||
{
|
||||
return fTransportFactory.get();
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
FairMQMessagePtr NewMessage(Args&&... args) const
|
||||
FairMQMessagePtr NewMessage(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data) const
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data) const
|
||||
FairMQMessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewStaticMessage(data);
|
||||
}
|
||||
@@ -307,6 +274,7 @@ class FairMQChannel
|
||||
int fRcvBufSize;
|
||||
int fSndKernelSize;
|
||||
int fRcvKernelSize;
|
||||
int fLinger;
|
||||
int fRateLogging;
|
||||
|
||||
std::string fName;
|
||||
@@ -314,10 +282,10 @@ class FairMQChannel
|
||||
|
||||
std::shared_ptr<FairMQTransportFactory> fTransportFactory;
|
||||
|
||||
void CheckSendCompatibility(FairMQMessagePtr& msg) const;
|
||||
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec) const;
|
||||
void CheckReceiveCompatibility(FairMQMessagePtr& msg) const;
|
||||
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec) const;
|
||||
void CheckSendCompatibility(FairMQMessagePtr& msg);
|
||||
void CheckSendCompatibility(std::vector<FairMQMessagePtr>& msgVec);
|
||||
void CheckReceiveCompatibility(FairMQMessagePtr& msg);
|
||||
void CheckReceiveCompatibility(std::vector<FairMQMessagePtr>& msgVec);
|
||||
|
||||
void InitTransport(std::shared_ptr<FairMQTransportFactory> factory);
|
||||
|
||||
|
@@ -8,9 +8,6 @@
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
|
||||
#include <fairmq/Tools.h>
|
||||
#include <fairmq/Transports.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
@@ -19,7 +16,6 @@
|
||||
|
||||
#include <list>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
@@ -27,57 +23,41 @@
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <future>
|
||||
#include <algorithm> // std::max
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
FairMQDevice::FairMQDevice()
|
||||
: fTransportFactory(nullptr)
|
||||
, fTransports()
|
||||
, fChannels()
|
||||
, fConfig(nullptr)
|
||||
, fId()
|
||||
, fNumIoThreads(1)
|
||||
, fInitialValidationFinished(false)
|
||||
, fInitialValidationCondition()
|
||||
, fInitialValidationMutex()
|
||||
, fPortRangeMin(22000)
|
||||
, fPortRangeMax(32000)
|
||||
, fNetworkInterface()
|
||||
, fDefaultTransportType(fair::mq::Transport::DEFAULT)
|
||||
, fInitializationTimeoutInS(120)
|
||||
, fDataCallbacks(false)
|
||||
, fMsgInputs()
|
||||
, fMultipartInputs()
|
||||
, fMultitransportInputs()
|
||||
, fChannelRegistry()
|
||||
, fInputChannelKeys()
|
||||
, fMultitransportMutex()
|
||||
, fMultitransportProceed(false)
|
||||
, fExternalConfig(false)
|
||||
, fVersion({0, 0, 0})
|
||||
, fRate(0.)
|
||||
, fLastTime(0)
|
||||
, fRawCmdLineArgs()
|
||||
: FairMQDevice(nullptr, {0, 0, 0})
|
||||
{
|
||||
}
|
||||
|
||||
FairMQDevice::FairMQDevice(FairMQProgOptions& config)
|
||||
: FairMQDevice(&config, {0, 0, 0})
|
||||
{
|
||||
}
|
||||
|
||||
FairMQDevice::FairMQDevice(const fair::mq::tools::Version version)
|
||||
: FairMQDevice(nullptr, version)
|
||||
{
|
||||
}
|
||||
|
||||
FairMQDevice::FairMQDevice(FairMQProgOptions& config, const fair::mq::tools::Version version)
|
||||
: FairMQDevice(&config, version)
|
||||
{
|
||||
}
|
||||
|
||||
FairMQDevice::FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Version version)
|
||||
: fTransportFactory(nullptr)
|
||||
, fTransports()
|
||||
, fChannels()
|
||||
, fConfig(nullptr)
|
||||
, fInternalConfig(config ? nullptr : fair::mq::tools::make_unique<FairMQProgOptions>())
|
||||
, fConfig(config ? config : fInternalConfig.get())
|
||||
, fId()
|
||||
, fNumIoThreads(1)
|
||||
, fInitialValidationFinished(false)
|
||||
, fInitialValidationCondition()
|
||||
, fInitialValidationMutex()
|
||||
, fPortRangeMin(22000)
|
||||
, fPortRangeMax(32000)
|
||||
, fNetworkInterface()
|
||||
, fDefaultTransportType(fair::mq::Transport::DEFAULT)
|
||||
, fInitializationTimeoutInS(120)
|
||||
, fDataCallbacks(false)
|
||||
, fMsgInputs()
|
||||
, fMultipartInputs()
|
||||
@@ -86,26 +66,54 @@ FairMQDevice::FairMQDevice(const fair::mq::tools::Version version)
|
||||
, fInputChannelKeys()
|
||||
, fMultitransportMutex()
|
||||
, fMultitransportProceed(false)
|
||||
, fExternalConfig(false)
|
||||
, fVersion(version)
|
||||
, fRate(0.)
|
||||
, fLastTime(0)
|
||||
, fRawCmdLineArgs()
|
||||
, fInterrupted(false)
|
||||
, fInterruptedCV()
|
||||
, fInterruptedMtx()
|
||||
, fRateLogging(true)
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQDevice::InitWrapper()
|
||||
{
|
||||
if (!fTransportFactory)
|
||||
{
|
||||
LOG(error) << "Transport not initialized. Did you call SetTransport()?";
|
||||
exit(EXIT_FAILURE);
|
||||
fId = fConfig->GetValue<string>("id");
|
||||
fRate = fConfig->GetValue<float>("rate");
|
||||
fPortRangeMin = fConfig->GetValue<int>("port-range-min");
|
||||
fPortRangeMax = fConfig->GetValue<int>("port-range-max");
|
||||
|
||||
try {
|
||||
fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue<string>("transport"));
|
||||
} catch (const exception& e) {
|
||||
LOG(error) << "exception: " << e.what();
|
||||
LOG(error) << "invalid transport type provided: " << fConfig->GetValue<string>("transport");
|
||||
throw;
|
||||
}
|
||||
|
||||
for (auto& c : fConfig->GetFairMQMap())
|
||||
{
|
||||
if (fChannels.find(c.first) == fChannels.end())
|
||||
{
|
||||
LOG(debug) << "Inserting new device channel from config: " << c.first;
|
||||
fChannels.insert(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(debug) << "Updating existing device channel from config: " << c.first;
|
||||
fChannels[c.first] = c.second;
|
||||
}
|
||||
}
|
||||
|
||||
LOG(debug) << "Requesting '" << fair::mq::TransportNames.at(fDefaultTransportType) << "' as default transport for the device";
|
||||
fTransportFactory = AddTransport(fDefaultTransportType);
|
||||
|
||||
// Containers to store the uninitialized channels.
|
||||
vector<FairMQChannel*> uninitializedBindingChannels;
|
||||
vector<FairMQChannel*> uninitializedConnectingChannels;
|
||||
|
||||
string networkInterface = fConfig->GetValue<string>("network-interface");
|
||||
|
||||
// Fill the uninitialized channel containers
|
||||
for (auto& mi : fChannels)
|
||||
{
|
||||
@@ -126,11 +134,11 @@ void FairMQDevice::InitWrapper()
|
||||
if (vi->fAddress == "unspecified" || vi->fAddress == "")
|
||||
{
|
||||
// if the configured network interface is default, get its name from the default route
|
||||
if (fNetworkInterface == "default")
|
||||
if (networkInterface == "default")
|
||||
{
|
||||
fNetworkInterface = fair::mq::tools::getDefaultRouteNetworkInterface();
|
||||
networkInterface = fair::mq::tools::getDefaultRouteNetworkInterface();
|
||||
}
|
||||
vi->fAddress = "tcp://" + fair::mq::tools::getInterfaceIP(fNetworkInterface) + ":1";
|
||||
vi->fAddress = "tcp://" + fair::mq::tools::getInterfaceIP(networkInterface) + ":1";
|
||||
}
|
||||
// fill the uninitialized list
|
||||
uninitializedBindingChannels.push_back(&(*vi));
|
||||
@@ -147,9 +155,8 @@ void FairMQDevice::InitWrapper()
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Cannot update configuration. Socket method (bind/connect) not specified.";
|
||||
ChangeState(ERROR_FOUND);
|
||||
// throw runtime_error("Cannot update configuration. Socket method (bind/connect) not specified.");
|
||||
LOG(error) << "Cannot update configuration. Socket method (bind/connect) for channel '" << vi->fName << "' not specified.";
|
||||
throw runtime_error(fair::mq::tools::ToString("Cannot update configuration. Socket method (bind/connect) for channel ", vi->fName, " not specified."));
|
||||
}
|
||||
// }
|
||||
}
|
||||
@@ -159,26 +166,20 @@ void FairMQDevice::InitWrapper()
|
||||
// If necessary this could be handled in the same way as the connecting channels
|
||||
AttachChannels(uninitializedBindingChannels);
|
||||
|
||||
if (uninitializedBindingChannels.size() > 0)
|
||||
if (!uninitializedBindingChannels.empty())
|
||||
{
|
||||
LOG(error) << uninitializedBindingChannels.size() << " of the binding channels could not initialize. Initial configuration incomplete.";
|
||||
ChangeState(ERROR_FOUND);
|
||||
// throw runtime_error(fair::mq::tools::ToString(uninitializedBindingChannels.size(), " of the binding channels could not initialize. Initial configuration incomplete."));
|
||||
throw runtime_error(fair::mq::tools::ToString(uninitializedBindingChannels.size(), " of the binding channels could not initialize. Initial configuration incomplete."));
|
||||
}
|
||||
|
||||
CallStateChangeCallbacks(INITIALIZING_DEVICE);
|
||||
|
||||
// notify parent thread about completion of first validation.
|
||||
{
|
||||
lock_guard<mutex> lock(fInitialValidationMutex);
|
||||
fInitialValidationFinished = true;
|
||||
fInitialValidationCondition.notify_one();
|
||||
}
|
||||
int initializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout");
|
||||
|
||||
// go over the list of channels until all are initialized (and removed from the uninitialized list)
|
||||
int numAttempts = 1;
|
||||
auto sleepTimeInMS = 50;
|
||||
auto maxAttempts = fInitializationTimeoutInS * 1000 / sleepTimeInMS;
|
||||
auto maxAttempts = initializationTimeoutInS * 1000 / sleepTimeInMS;
|
||||
// first attempt
|
||||
AttachChannels(uninitializedConnectingChannels);
|
||||
// if not all channels could be connected, update their address values from config and retry
|
||||
@@ -186,24 +187,20 @@ void FairMQDevice::InitWrapper()
|
||||
{
|
||||
this_thread::sleep_for(chrono::milliseconds(sleepTimeInMS));
|
||||
|
||||
if (fConfig)
|
||||
for (auto& chan : uninitializedConnectingChannels)
|
||||
{
|
||||
for (auto& chan : uninitializedConnectingChannels)
|
||||
string key{"chans." + chan->GetChannelPrefix() + "." + chan->GetChannelIndex() + ".address"};
|
||||
string newAddress = fConfig->GetValue<string>(key);
|
||||
if (newAddress != chan->GetAddress())
|
||||
{
|
||||
string key{"chans." + chan->GetChannelPrefix() + "." + chan->GetChannelIndex() + ".address"};
|
||||
string newAddress = fConfig->GetValue<string>(key);
|
||||
if (newAddress != chan->GetAddress())
|
||||
{
|
||||
chan->UpdateAddress(newAddress);
|
||||
}
|
||||
chan->UpdateAddress(newAddress);
|
||||
}
|
||||
}
|
||||
|
||||
if (numAttempts++ > maxAttempts)
|
||||
{
|
||||
LOG(error) << "could not connect all channels after " << fInitializationTimeoutInS << " attempts";
|
||||
ChangeState(ERROR_FOUND);
|
||||
// throw runtime_error(fair::mq::tools::ToString("could not connect all channels after ", fInitializationTimeoutInS, " attempts"));
|
||||
LOG(error) << "could not connect all channels after " << initializationTimeoutInS << " attempts";
|
||||
throw runtime_error(fair::mq::tools::ToString("could not connect all channels after ", initializationTimeoutInS, " attempts"));
|
||||
}
|
||||
|
||||
AttachChannels(uninitializedConnectingChannels);
|
||||
@@ -211,13 +208,11 @@ void FairMQDevice::InitWrapper()
|
||||
|
||||
Init();
|
||||
|
||||
ChangeState(internal_DEVICE_READY);
|
||||
}
|
||||
if (fChannels.empty()) {
|
||||
LOG(warn) << "No channels created after finishing initialization";
|
||||
}
|
||||
|
||||
void FairMQDevice::WaitForInitialValidation()
|
||||
{
|
||||
unique_lock<mutex> lock(fInitialValidationMutex);
|
||||
fInitialValidationCondition.wait(lock, [&] () { return fInitialValidationFinished; });
|
||||
ChangeState(internal_DEVICE_READY);
|
||||
}
|
||||
|
||||
void FairMQDevice::Init()
|
||||
@@ -252,19 +247,15 @@ void FairMQDevice::AttachChannels(vector<FairMQChannel*>& chans)
|
||||
|
||||
bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
||||
{
|
||||
if (!ch.fTransportFactory)
|
||||
if (ch.fTransportType == fair::mq::Transport::DEFAULT || ch.fTransportType == fTransportFactory->GetType())
|
||||
{
|
||||
if (ch.fTransportType == fair::mq::Transport::DEFAULT || ch.fTransportType == fTransportFactory->GetType())
|
||||
{
|
||||
LOG(debug) << ch.fName << ": using default transport";
|
||||
ch.InitTransport(fTransportFactory);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(debug) << ch.fName << ": channel transport (" << fair::mq::TransportNames.at(fDefaultTransportType) << ") overriden to " << fair::mq::TransportNames.at(ch.fTransportType);
|
||||
ch.InitTransport(AddTransport(ch.fTransportType));
|
||||
}
|
||||
ch.fTransportType = ch.fTransportFactory->GetType();
|
||||
LOG(debug) << ch.fName << ": using default transport";
|
||||
ch.InitTransport(fTransportFactory);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(debug) << ch.fName << ": channel transport (" << fair::mq::TransportNames.at(fDefaultTransportType) << ") overriden to " << fair::mq::TransportNames.at(ch.fTransportType);
|
||||
ch.InitTransport(AddTransport(ch.fTransportType));
|
||||
}
|
||||
|
||||
vector<string> endpoints;
|
||||
@@ -285,18 +276,21 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
||||
}
|
||||
}
|
||||
|
||||
// set high water marks
|
||||
ch.fSocket->SetOption("snd-hwm", &(ch.fSndBufSize), sizeof(ch.fSndBufSize));
|
||||
ch.fSocket->SetOption("rcv-hwm", &(ch.fRcvBufSize), sizeof(ch.fRcvBufSize));
|
||||
// set linger duration (how long socket should wait for outstanding transfers before shutdown)
|
||||
ch.fSocket->SetLinger(ch.fLinger);
|
||||
|
||||
// set kernel transmit size
|
||||
// set high water marks
|
||||
ch.fSocket->SetSndBufSize(ch.fSndBufSize);
|
||||
ch.fSocket->SetRcvBufSize(ch.fRcvBufSize);
|
||||
|
||||
// set kernel transmit size (set it only if value is not the default value)
|
||||
if (ch.fSndKernelSize != 0)
|
||||
{
|
||||
ch.fSocket->SetOption("snd-size", &(ch.fSndKernelSize), sizeof(ch.fSndKernelSize));
|
||||
ch.fSocket->SetSndKernelSize(ch.fSndKernelSize);
|
||||
}
|
||||
if (ch.fRcvKernelSize != 0)
|
||||
{
|
||||
ch.fSocket->SetOption("rcv-size", &(ch.fRcvKernelSize), sizeof(ch.fRcvKernelSize));
|
||||
ch.fSocket->SetRcvKernelSize(ch.fRcvKernelSize);
|
||||
}
|
||||
|
||||
// attach
|
||||
@@ -321,7 +315,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
||||
if (address.compare(0, 6, "tcp://") == 0)
|
||||
{
|
||||
string addressString = address.substr(6);
|
||||
auto pos = addressString.find(":");
|
||||
auto pos = addressString.find(':');
|
||||
string hostPart = addressString.substr(0, pos);
|
||||
if (!(bind && hostPart == "*"))
|
||||
{
|
||||
@@ -355,7 +349,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
||||
}
|
||||
endpoint += address;
|
||||
|
||||
LOG(debug) << "Attached channel " << ch.fName << " to " << endpoint << (bind ? " (bind) " : " (connect) ");
|
||||
LOG(debug) << "Attached channel " << ch.fName << " to " << endpoint << (bind ? " (bind) " : " (connect) ") << "(" << ch.fType << ")";
|
||||
|
||||
// after the book keeping is done, exit in case of errors
|
||||
if (!success)
|
||||
@@ -369,11 +363,8 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch)
|
||||
if (newAddress != ch.fAddress)
|
||||
{
|
||||
ch.UpdateAddress(newAddress);
|
||||
if (fConfig)
|
||||
{
|
||||
string key{"chans." + ch.GetChannelPrefix() + "." + ch.GetChannelIndex() + ".address"};
|
||||
fConfig->SetValue(key, newAddress);
|
||||
}
|
||||
string key{"chans." + ch.GetChannelPrefix() + "." + ch.GetChannelIndex() + ".address"};
|
||||
fConfig->SetValue(key, newAddress);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -408,7 +399,7 @@ bool FairMQDevice::BindEndpoint(FairMQSocket& socket, string& endpoint)
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t pos = endpoint.rfind(":");
|
||||
size_t pos = endpoint.rfind(':');
|
||||
endpoint = endpoint.substr(0, pos + 1) + fair::mq::tools::ToString(static_cast<int>(randomPort(generator)));
|
||||
}
|
||||
|
||||
@@ -458,15 +449,15 @@ void FairMQDevice::PrintChannel(const string& name)
|
||||
{
|
||||
if (fChannels.find(name) != fChannels.end())
|
||||
{
|
||||
for (auto vi = fChannels[name].begin(); vi != fChannels[name].end(); ++vi)
|
||||
for (const auto& vi : fChannels[name])
|
||||
{
|
||||
LOG(info) << vi->fName << ": "
|
||||
<< vi->fType << " | "
|
||||
<< vi->fMethod << " | "
|
||||
<< vi->fAddress << " | "
|
||||
<< vi->fSndBufSize << " | "
|
||||
<< vi->fRcvBufSize << " | "
|
||||
<< vi->fRateLogging;
|
||||
LOG(info) << vi.fName << ": "
|
||||
<< vi.fType << " | "
|
||||
<< vi.fMethod << " | "
|
||||
<< vi.fAddress << " | "
|
||||
<< vi.fSndBufSize << " | "
|
||||
<< vi.fRcvBufSize << " | "
|
||||
<< vi.fRateLogging;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -482,16 +473,20 @@ void FairMQDevice::RunWrapper()
|
||||
LOG(info) << "DEVICE: Running...";
|
||||
|
||||
// start the rate logger thread
|
||||
thread rateLogger(&FairMQDevice::LogSocketRates, this);
|
||||
fRateLogging = true;
|
||||
future<void> rateLogger = async(launch::async, &FairMQDevice::LogSocketRates, this);
|
||||
|
||||
// notify transports to resume transfers
|
||||
{
|
||||
lock_guard<mutex> guard(fInterruptedMtx);
|
||||
fInterrupted = false;
|
||||
}
|
||||
for (auto& t : fTransports)
|
||||
{
|
||||
t.second->Resume();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
PreRun();
|
||||
|
||||
// process either data callbacks or ConditionalRun/Run
|
||||
@@ -509,29 +504,26 @@ void FairMQDevice::RunWrapper()
|
||||
}
|
||||
else
|
||||
{
|
||||
using Clock = chrono::steady_clock;
|
||||
using TimeScale = chrono::microseconds;
|
||||
const TimeScale::rep period = TimeScale::period::den / fRate;
|
||||
const auto reftime = Clock::now();
|
||||
fair::mq::tools::RateLimiter rateLimiter(fRate);
|
||||
|
||||
while (CheckCurrentState(RUNNING) && ConditionalRun())
|
||||
{
|
||||
if (fRate > 0.001) {
|
||||
auto timespan = static_cast<TimeScale::rep>(chrono::duration_cast<TimeScale>(Clock::now() - reftime).count() - fLastTime);
|
||||
if (timespan < period) {
|
||||
TimeScale sleepfor(period - timespan);
|
||||
this_thread::sleep_for(sleepfor);
|
||||
if (fRate > 0.001)
|
||||
{
|
||||
rateLimiter.maybe_sleep();
|
||||
}
|
||||
fLastTime = chrono::duration_cast<TimeScale>(Clock::now() - reftime).count();
|
||||
}
|
||||
}
|
||||
|
||||
Run();
|
||||
}
|
||||
}
|
||||
catch (const out_of_range& oor)
|
||||
{
|
||||
} catch (const out_of_range& oor) {
|
||||
LOG(error) << "out of range: " << oor.what();
|
||||
LOG(error) << "incorrect/incomplete channel configuration?";
|
||||
fRateLogging = false;
|
||||
throw;
|
||||
} catch (...) {
|
||||
fRateLogging = false;
|
||||
throw;
|
||||
}
|
||||
|
||||
// if Run() exited and the state is still RUNNING, transition to READY.
|
||||
@@ -542,7 +534,7 @@ void FairMQDevice::RunWrapper()
|
||||
|
||||
PostRun();
|
||||
|
||||
rateLogger.join();
|
||||
rateLogger.get();
|
||||
}
|
||||
|
||||
void FairMQDevice::HandleSingleChannelInput()
|
||||
@@ -585,17 +577,17 @@ void FairMQDevice::HandleMultipleChannelInput()
|
||||
|
||||
for (const auto& mi : fMsgInputs)
|
||||
{
|
||||
for (unsigned int i = 0; i < fChannels.at(mi.first).size(); ++i)
|
||||
for (auto& i : fChannels.at(mi.first))
|
||||
{
|
||||
fChannels.at(mi.first).at(i).fMultipart = false;
|
||||
i.fMultipart = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& mi : fMultipartInputs)
|
||||
{
|
||||
for (unsigned int i = 0; i < fChannels.at(mi.first).size(); ++i)
|
||||
for (auto& i : fChannels.at(mi.first))
|
||||
{
|
||||
fChannels.at(mi.first).at(i).fMultipart = true;
|
||||
i.fMultipart = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,7 +645,7 @@ void FairMQDevice::HandleMultipleTransportInput()
|
||||
|
||||
for (const auto& i : fMultitransportInputs)
|
||||
{
|
||||
threads.push_back(thread(&FairMQDevice::PollForTransport, this, fTransports.at(i.first).get(), i.second));
|
||||
threads.emplace_back(thread(&FairMQDevice::PollForTransport, this, fTransports.at(i.first).get(), i.second));
|
||||
}
|
||||
|
||||
for (thread& t : threads)
|
||||
@@ -710,11 +702,11 @@ void FairMQDevice::PollForTransport(const FairMQTransportFactory* factory, const
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(error) << "FairMQDevice::PollForTransport() failed: " << e.what() << ", going to ERROR state.";
|
||||
ChangeState(ERROR_FOUND);
|
||||
throw runtime_error(fair::mq::tools::ToString("FairMQDevice::PollForTransport() failed: ", e.what(), ", going to ERROR state."));
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback& callback, int i) const
|
||||
bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback& callback, int i)
|
||||
{
|
||||
unique_ptr<FairMQMessage> input(fChannels.at(chName).at(i).fTransportFactory->CreateMessage());
|
||||
|
||||
@@ -728,7 +720,7 @@ bool FairMQDevice::HandleMsgInput(const string& chName, const InputMsgCallback&
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQDevice::HandleMultipartInput(const string& chName, const InputMultipartCallback& callback, int i) const
|
||||
bool FairMQDevice::HandleMultipartInput(const string& chName, const InputMultipartCallback& callback, int i)
|
||||
{
|
||||
FairMQParts input;
|
||||
|
||||
@@ -798,78 +790,10 @@ shared_ptr<FairMQTransportFactory> FairMQDevice::AddTransport(const fair::mq::Tr
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::CreateOwnConfig()
|
||||
{
|
||||
// TODO: make fConfig a shared_ptr when no old user code has FairMQProgOptions ptr*
|
||||
fConfig = new FairMQProgOptions();
|
||||
|
||||
string id{boost::uuids::to_string(boost::uuids::random_generator()())};
|
||||
LOG(warn) << "No FairMQProgOptions provided, creating one internally and setting device ID to " << id;
|
||||
|
||||
// dummy argc+argv
|
||||
char arg0[] = "undefined"; // executable name
|
||||
char arg1[] = "--id";
|
||||
char* arg2 = const_cast<char*>(id.c_str()); // device ID
|
||||
const char* argv[] = { &arg0[0], &arg1[0], arg2, nullptr };
|
||||
int argc = static_cast<int>((sizeof(argv) / sizeof(argv[0])) - 1);
|
||||
|
||||
fConfig->ParseAll(argc, &argv[0]);
|
||||
|
||||
fId = fConfig->GetValue<string>("id");
|
||||
fNetworkInterface = fConfig->GetValue<string>("network-interface");
|
||||
fNumIoThreads = fConfig->GetValue<int>("io-threads");
|
||||
fInitializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout");
|
||||
fRate = fConfig->GetValue<float>("rate");
|
||||
try {
|
||||
fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue<string>("transport"));
|
||||
} catch(const exception& e) {
|
||||
LOG(error) << "invalid transport type provided: " << fConfig->GetValue<string>("transport");
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::SetTransport(const string& transport)
|
||||
{
|
||||
// This method is the first to be called, if FairMQProgOptions are not used (either SetTransport() or SetConfig() make sense, not both).
|
||||
// Make sure here that at least internal config is available.
|
||||
if (!fExternalConfig && !fConfig)
|
||||
{
|
||||
CreateOwnConfig();
|
||||
}
|
||||
|
||||
if (fTransports.empty())
|
||||
{
|
||||
LOG(debug) << "Requesting '" << transport << "' as default transport for the device";
|
||||
fTransportFactory = AddTransport(fair::mq::TransportTypes.at(transport));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "Transports container is not empty when setting transport. Setting default twice?";
|
||||
ChangeState(ERROR_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::SetConfig(FairMQProgOptions& config)
|
||||
{
|
||||
fExternalConfig = true;
|
||||
fInternalConfig.reset();
|
||||
fConfig = &config;
|
||||
for (auto& c : fConfig->GetFairMQMap())
|
||||
{
|
||||
if (!fChannels.insert(c).second)
|
||||
{
|
||||
LOG(warn) << "did not insert channel '" << c.first << "', it is already in the device.";
|
||||
}
|
||||
}
|
||||
fId = fConfig->GetValue<string>("id");
|
||||
fNetworkInterface = fConfig->GetValue<string>("network-interface");
|
||||
fNumIoThreads = fConfig->GetValue<int>("io-threads");
|
||||
fInitializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout");
|
||||
fRate = fConfig->GetValue<float>("rate");
|
||||
try {
|
||||
fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue<string>("transport"));
|
||||
} catch(const exception& e) {
|
||||
LOG(error) << "invalid transport type provided: " << fConfig->GetValue<string>("transport");
|
||||
}
|
||||
SetTransport(fConfig->GetValue<string>("transport"));
|
||||
}
|
||||
|
||||
void FairMQDevice::LogSocketRates()
|
||||
@@ -877,8 +801,6 @@ void FairMQDevice::LogSocketRates()
|
||||
chrono::time_point<chrono::high_resolution_clock> t0;
|
||||
chrono::time_point<chrono::high_resolution_clock> t1;
|
||||
|
||||
unsigned long long msSinceLastLog;
|
||||
|
||||
vector<FairMQSocket*> filteredSockets;
|
||||
vector<string> filteredChannelNames;
|
||||
vector<int> logIntervals;
|
||||
@@ -936,11 +858,11 @@ void FairMQDevice::LogSocketRates()
|
||||
|
||||
LOG(debug) << "<channel>: in: <#msgs> (<MB>) out: <#msgs> (<MB>)";
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
while (fRateLogging)
|
||||
{
|
||||
t1 = chrono::high_resolution_clock::now();
|
||||
|
||||
msSinceLastLog = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
|
||||
unsigned long long msSinceLastLog = chrono::duration_cast<chrono::milliseconds>(t1 - t0).count();
|
||||
|
||||
i = 0;
|
||||
|
||||
@@ -976,7 +898,7 @@ void FairMQDevice::LogSocketRates()
|
||||
}
|
||||
|
||||
t0 = t1;
|
||||
this_thread::sleep_for(chrono::milliseconds(1000));
|
||||
WaitFor(chrono::milliseconds(1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -987,6 +909,12 @@ void FairMQDevice::Unblock()
|
||||
{
|
||||
t.second->Interrupt();
|
||||
}
|
||||
{
|
||||
lock_guard<mutex> guard(fInterruptedMtx);
|
||||
fInterrupted = true;
|
||||
fRateLogging = false;
|
||||
}
|
||||
fInterruptedCV.notify_all();
|
||||
}
|
||||
|
||||
void FairMQDevice::ResetTaskWrapper()
|
||||
@@ -1006,13 +934,11 @@ void FairMQDevice::ResetWrapper()
|
||||
{
|
||||
CallStateChangeCallbacks(RESETTING_DEVICE);
|
||||
|
||||
Reset();
|
||||
for (auto& t : fTransports)
|
||||
{
|
||||
t.second->Reset();
|
||||
}
|
||||
|
||||
ChangeState(internal_IDLE);
|
||||
}
|
||||
|
||||
void FairMQDevice::Reset()
|
||||
{
|
||||
// iterate over the channels map
|
||||
for (auto& mi : fChannels)
|
||||
{
|
||||
@@ -1020,22 +946,21 @@ void FairMQDevice::Reset()
|
||||
for (auto& vi : mi.second)
|
||||
{
|
||||
// vi.fReset = true;
|
||||
vi.fSocket.reset();
|
||||
vi.fSocket.reset(); // destroy FairMQSocket
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
|
||||
ChangeState(internal_IDLE);
|
||||
}
|
||||
|
||||
const FairMQChannel& FairMQDevice::GetChannel(const string& channelName, const int index) const
|
||||
void FairMQDevice::Reset()
|
||||
{
|
||||
return fChannels.at(channelName).at(index);
|
||||
}
|
||||
|
||||
void FairMQDevice::Exit()
|
||||
{
|
||||
if (!fExternalConfig && fConfig)
|
||||
{
|
||||
delete fConfig;
|
||||
}
|
||||
}
|
||||
|
||||
FairMQDevice::~FairMQDevice()
|
||||
|
@@ -25,11 +25,13 @@
|
||||
#include <memory> // unique_ptr
|
||||
#include <algorithm> // std::sort()
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <assert.h> // static_assert
|
||||
#include <type_traits> // is_trivially_copyable
|
||||
#include <stdexcept>
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
@@ -48,9 +50,19 @@ class FairMQDevice : public FairMQStateMachine
|
||||
public:
|
||||
/// Default constructor
|
||||
FairMQDevice();
|
||||
/// Constructor with external FairMQProgOptions
|
||||
FairMQDevice(FairMQProgOptions& config);
|
||||
|
||||
/// Constructor that sets the version
|
||||
FairMQDevice(const fair::mq::tools::Version version);
|
||||
|
||||
/// Constructor that sets the version and external FairMQProgOptions
|
||||
FairMQDevice(FairMQProgOptions& config, const fair::mq::tools::Version version);
|
||||
|
||||
private:
|
||||
FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Version version);
|
||||
|
||||
public:
|
||||
/// Copy constructor (disabled)
|
||||
FairMQDevice(const FairMQDevice&) = delete;
|
||||
/// Assignment operator (disabled)
|
||||
@@ -85,154 +97,108 @@ class FairMQDevice : public FairMQStateMachine
|
||||
Deserializer().Deserialize(msg, std::forward<DataType>(data), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
||||
{
|
||||
return fChannels.at(chan).at(i).Send(msg);
|
||||
}
|
||||
|
||||
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
||||
{
|
||||
return fChannels.at(chan).at(i).Receive(msg);
|
||||
}
|
||||
|
||||
/// Shorthand method to send `msg` on `chan` at index `i`
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int Send(FairMQMessagePtr& msg, const std::string& chan, const int i, int sndTimeoutInMs) const
|
||||
/// @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. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||
int Send(FairMQMessagePtr& msg, const std::string& channel, const int index = 0, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return fChannels.at(chan).at(i).Send(msg, sndTimeoutInMs);
|
||||
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
|
||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int Receive(FairMQMessagePtr& msg, const std::string& chan, const int i, int rcvTimeoutInMs) const
|
||||
/// @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. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||
int Receive(FairMQMessagePtr& msg, const std::string& channel, const int index = 0, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return fChannels.at(chan).at(i).Receive(msg, rcvTimeoutInMs);
|
||||
return GetChannel(channel, index).Receive(msg, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to send `msg` on `chan` at index `i` without blocking
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int SendAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
||||
int SendAsync(FairMQMessagePtr& msg, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(msg, \"channelA\", subchannelIndex, timeout);")))
|
||||
{
|
||||
return fChannels.at(chan).at(i).SendAsync(msg);
|
||||
return GetChannel(channel, index).Send(msg, 0);
|
||||
}
|
||||
|
||||
/// Shorthand method to receive `msg` on `chan` at index `i` without blocking
|
||||
/// @param msg message reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int ReceiveAsync(FairMQMessagePtr& msg, const std::string& chan, const int i = 0) const
|
||||
int ReceiveAsync(FairMQMessagePtr& msg, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(msg, \"channelA\", subchannelIndex, timeout);")))
|
||||
{
|
||||
return fChannels.at(chan).at(i).ReceiveAsync(msg);
|
||||
}
|
||||
|
||||
int64_t Send(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
||||
{
|
||||
return fChannels.at(chan).at(i).Send(parts.fParts);
|
||||
}
|
||||
|
||||
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
||||
{
|
||||
return fChannels.at(chan).at(i).Receive(parts.fParts);
|
||||
return GetChannel(channel, index).Receive(msg, 0);
|
||||
}
|
||||
|
||||
/// Shorthand method to send FairMQParts on `chan` at index `i`
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t Send(FairMQParts& parts, const std::string& chan, const int i, int sndTimeoutInMs) const
|
||||
/// @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. -2 If queueing was not possible or timed out. -1 if there was an error.
|
||||
int64_t Send(FairMQParts& parts, const std::string& channel, const int index = 0, int sndTimeoutInMs = -1)
|
||||
{
|
||||
return fChannels.at(chan).at(i).Send(parts.fParts, sndTimeoutInMs);
|
||||
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
|
||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t Receive(FairMQParts& parts, const std::string& chan, const int i, int rcvTimeoutInMs) const
|
||||
/// @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. -2 if reading from the queue was not possible or timed out. -1 if there was an error.
|
||||
int64_t Receive(FairMQParts& parts, const std::string& channel, const int index = 0, int rcvTimeoutInMs = -1)
|
||||
{
|
||||
return fChannels.at(chan).at(i).Receive(parts.fParts, rcvTimeoutInMs);
|
||||
return GetChannel(channel, index).Receive(parts.fParts, rcvTimeoutInMs);
|
||||
}
|
||||
|
||||
/// Shorthand method to send FairMQParts on `chan` at index `i` without blocking
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @return Number of bytes that have been queued. -2 If queueing was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t SendAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
||||
int64_t SendAsync(FairMQParts& parts, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Send, use timeout version with timeout of 0: Send(parts, \"channelA\", subchannelIndex, timeout);")))
|
||||
{
|
||||
return fChannels.at(chan).at(i).SendAsync(parts.fParts);
|
||||
return GetChannel(channel, index).Send(parts.fParts, 0);
|
||||
}
|
||||
|
||||
/// Shorthand method to receive FairMQParts on `chan` at index `i` without blocking
|
||||
/// @param parts parts reference
|
||||
/// @param chan channel name
|
||||
/// @param i channel index
|
||||
/// @return Number of bytes that have been received. -2 If reading from the queue was not possible or timed out.
|
||||
/// In case of errors, returns -1.
|
||||
int64_t ReceiveAsync(FairMQParts& parts, const std::string& chan, const int i = 0) const
|
||||
int64_t ReceiveAsync(FairMQParts& parts, const std::string& channel, const int index = 0) __attribute__((deprecated("For non-blocking Receive, use timeout version with timeout of 0: Receive(parts, \"channelA\", subchannelIndex, timeout);")))
|
||||
{
|
||||
return fChannels.at(chan).at(i).ReceiveAsync(parts.fParts);
|
||||
return GetChannel(channel, index).Receive(parts.fParts, 0);
|
||||
}
|
||||
|
||||
/// @brief Getter for default transport factory
|
||||
auto Transport() const -> const FairMQTransportFactory*
|
||||
auto Transport() const -> FairMQTransportFactory*
|
||||
{
|
||||
return fTransportFactory.get();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
FairMQMessagePtr NewMessage(Args&&... args) const
|
||||
FairMQMessagePtr NewMessage(Args&&... args)
|
||||
{
|
||||
return Transport()->CreateMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
FairMQMessagePtr NewMessageFor(const std::string& channel, int index, Args&&... args) const
|
||||
FairMQMessagePtr NewMessageFor(const std::string& channel, int index, Args&&... args)
|
||||
{
|
||||
return fChannels.at(channel).at(index).NewMessage(std::forward<Args>(args)...);
|
||||
return GetChannel(channel, index).NewMessage(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data) const
|
||||
FairMQMessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewStaticMessage(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessageFor(const std::string& channel, int index, const T& data) const
|
||||
FairMQMessagePtr NewStaticMessageFor(const std::string& channel, int index, const T& data)
|
||||
{
|
||||
return fChannels.at(channel).at(index).NewStaticMessage(data);
|
||||
return GetChannel(channel, index).NewStaticMessage(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data) const
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data)
|
||||
{
|
||||
return Transport()->NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessageFor(const std::string& channel, int index, const T& data) const
|
||||
FairMQMessagePtr NewSimpleMessageFor(const std::string& channel, int index, const T& data)
|
||||
{
|
||||
return fChannels.at(channel).at(index).NewSimpleMessage(data);
|
||||
return GetChannel(channel, index).NewSimpleMessage(data);
|
||||
}
|
||||
|
||||
FairMQUnmanagedRegionPtr NewUnmanagedRegion(const size_t size)
|
||||
@@ -242,7 +208,7 @@ class FairMQDevice : public FairMQStateMachine
|
||||
|
||||
FairMQUnmanagedRegionPtr NewUnmanagedRegionFor(const std::string& channel, int index, const size_t size, FairMQRegionCallback callback = nullptr)
|
||||
{
|
||||
return fChannels.at(channel).at(index).Transport()->CreateUnmanagedRegion(size, callback);
|
||||
return GetChannel(channel, index).Transport()->CreateUnmanagedRegion(size, callback);
|
||||
}
|
||||
|
||||
template<typename ...Ts>
|
||||
@@ -253,22 +219,22 @@ class FairMQDevice : public FairMQStateMachine
|
||||
// if more than one channel provided, check compatibility
|
||||
if (chans.size() > 1)
|
||||
{
|
||||
fair::mq::Transport type = fChannels.at(chans.at(0)).at(0).Transport()->GetType();
|
||||
fair::mq::Transport type = GetChannel(chans.at(0), 0).Transport()->GetType();
|
||||
|
||||
for (unsigned int i = 1; i < chans.size(); ++i)
|
||||
{
|
||||
if (type != fChannels.at(chans.at(i)).at(0).Transport()->GetType())
|
||||
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.";
|
||||
ChangeState(ERROR_FOUND);
|
||||
throw std::runtime_error("poller failed: different transports within same poller are not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fChannels.at(chans.at(0)).at(0).Transport()->CreatePoller(fChannels, chans);
|
||||
return GetChannel(chans.at(0), 0).Transport()->CreatePoller(fChannels, chans);
|
||||
}
|
||||
|
||||
FairMQPollerPtr NewPoller(const std::vector<const FairMQChannel*>& channels)
|
||||
FairMQPollerPtr NewPoller(const std::vector<FairMQChannel*>& channels)
|
||||
{
|
||||
// if more than one channel provided, check compatibility
|
||||
if (channels.size() > 1)
|
||||
@@ -280,7 +246,7 @@ class FairMQDevice : public FairMQStateMachine
|
||||
if (type != channels.at(i)->Transport()->GetType())
|
||||
{
|
||||
LOG(error) << "poller failed: different transports within same poller are not yet supported. Going to ERROR state.";
|
||||
ChangeState(ERROR_FOUND);
|
||||
throw std::runtime_error("poller failed: different transports within same poller are not yet supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,17 +255,16 @@ class FairMQDevice : public FairMQStateMachine
|
||||
}
|
||||
|
||||
/// Waits for the first initialization run to finish
|
||||
void WaitForInitialValidation();
|
||||
void WaitForInitialValidation() __attribute__((deprecated("This method will have no effect in future versions and will be removed. Instead subscribe for state changes and inspect configuration values."))) {}
|
||||
|
||||
/// Adds a transport to the device if it doesn't exist
|
||||
/// @param transport Transport string ("zeromq"/"nanomsg"/"shmem")
|
||||
std::shared_ptr<FairMQTransportFactory> AddTransport(const fair::mq::Transport transport);
|
||||
/// Sets the default transport for the device
|
||||
/// @param transport Transport string ("zeromq"/"nanomsg"/"shmem")
|
||||
void SetTransport(const std::string& transport = "zeromq");
|
||||
|
||||
/// Assigns config to the device
|
||||
void SetConfig(FairMQProgOptions& config);
|
||||
const FairMQProgOptions* GetConfig() const
|
||||
/// Get pointer to the config
|
||||
FairMQProgOptions* GetConfig() const
|
||||
{
|
||||
return fConfig;
|
||||
}
|
||||
@@ -309,6 +274,7 @@ class FairMQDevice : public FairMQStateMachine
|
||||
/// @param rhs Left hand side value for comparison
|
||||
static bool SortSocketsByAddress(const FairMQChannel &lhs, const FairMQChannel &rhs);
|
||||
|
||||
// overload to easily bind member functions
|
||||
template<typename T>
|
||||
void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQMessagePtr& msg, int index))
|
||||
{
|
||||
@@ -335,6 +301,7 @@ class FairMQDevice : public FairMQStateMachine
|
||||
}
|
||||
}
|
||||
|
||||
// overload to easily bind member functions
|
||||
template<typename T>
|
||||
void OnData(const std::string& channelName, bool (T::* memberFunction)(FairMQParts& parts, int index))
|
||||
{
|
||||
@@ -361,7 +328,15 @@ class FairMQDevice : public FairMQStateMachine
|
||||
}
|
||||
}
|
||||
|
||||
const FairMQChannel& GetChannel(const std::string& channelName, const int index = 0) const;
|
||||
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) << "out of range: " << oor.what();
|
||||
LOG(error) << "requested channel has not been configured? check channel names/configuration.";
|
||||
fRateLogging = false;
|
||||
throw;
|
||||
}
|
||||
|
||||
virtual void RegisterChannelEndpoints() {}
|
||||
|
||||
@@ -395,90 +370,99 @@ class FairMQDevice : public FairMQStateMachine
|
||||
|
||||
const fair::mq::tools::Version GetVersion() const { return fVersion; }
|
||||
|
||||
void SetNumIoThreads(int numIoThreads) { fNumIoThreads = numIoThreads; }
|
||||
int GetNumIoThreads() const { return fNumIoThreads; }
|
||||
void SetNumIoThreads(int numIoThreads) { fConfig->SetValue<int>("io-threads", numIoThreads);}
|
||||
int GetNumIoThreads() const { return fConfig->GetValue<int>("io-threads"); }
|
||||
|
||||
void SetPortRangeMin(int portRangeMin) { fPortRangeMin = portRangeMin; }
|
||||
int GetPortRangeMin() const { return fPortRangeMin; }
|
||||
void SetPortRangeMin(int portRangeMin) { fConfig->SetValue<int>("port-range-min", portRangeMin); }
|
||||
int GetPortRangeMin() const { return fConfig->GetValue<int>("port-range-min"); }
|
||||
|
||||
void SetPortRangeMax(int portRangeMax) { fPortRangeMax = portRangeMax; }
|
||||
int GetPortRangeMax() const { return fPortRangeMax; }
|
||||
void SetPortRangeMax(int portRangeMax) { fConfig->SetValue<int>("port-range-max", portRangeMax); }
|
||||
int GetPortRangeMax() const { return fConfig->GetValue<int>("port-range-max"); }
|
||||
|
||||
void SetNetworkInterface(const std::string& networkInterface) { fNetworkInterface = networkInterface; }
|
||||
std::string GetNetworkInterface() const { return fNetworkInterface; }
|
||||
void SetNetworkInterface(const std::string& networkInterface) { fConfig->SetValue<std::string>("network-interface", networkInterface); }
|
||||
std::string GetNetworkInterface() const { return fConfig->GetValue<std::string>("network-interface"); }
|
||||
|
||||
void SetDefaultTransport(const std::string& name) { fDefaultTransportType = fair::mq::TransportTypes.at(name); }
|
||||
std::string GetDefaultTransport() const { return fair::mq::TransportNames.at(fDefaultTransportType); }
|
||||
void SetDefaultTransport(const std::string& name) { fConfig->SetValue<std::string>("transport", name); }
|
||||
std::string GetDefaultTransport() const { return fConfig->GetValue<std::string>("transport"); }
|
||||
|
||||
void SetInitializationTimeoutInS(int initializationTimeoutInS) { fInitializationTimeoutInS = initializationTimeoutInS; }
|
||||
int GetInitializationTimeoutInS() const { return fInitializationTimeoutInS; }
|
||||
void SetInitializationTimeoutInS(int initializationTimeoutInS) { fConfig->SetValue<int>("initialization-timeout", initializationTimeoutInS); }
|
||||
int GetInitializationTimeoutInS() const { return fConfig->GetValue<int>("initialization-timeout"); }
|
||||
|
||||
/// Sets the default transport for the device
|
||||
/// @param transport Transport string ("zeromq"/"nanomsg"/"shmem")
|
||||
void SetTransport(const std::string& transport) { fConfig->SetValue<std::string>("transport", transport); }
|
||||
/// Gets the default transport name
|
||||
std::string GetTransportName() const { return fConfig->GetValue<std::string>("transport"); }
|
||||
|
||||
void SetRawCmdLineArgs(const std::vector<std::string>& args) { fRawCmdLineArgs = args; }
|
||||
std::vector<std::string> GetRawCmdLineArgs() const { return fRawCmdLineArgs; }
|
||||
|
||||
void RunStateMachine()
|
||||
{
|
||||
CallStateChangeCallbacks(FairMQStateMachine::IDLE);
|
||||
ProcessWork();
|
||||
};
|
||||
|
||||
/// Wait for the supplied amount of time or for interruption.
|
||||
/// If interrupted, returns false, otherwise true.
|
||||
/// @param duration wait duration
|
||||
template<class Rep, class Period>
|
||||
bool WaitFor(std::chrono::duration<Rep, Period> const& duration)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fInterruptedMtx);
|
||||
return !fInterruptedCV.wait_for(lock, duration, [&] { return fInterrupted.load(); }); // return true if no interruption happened
|
||||
}
|
||||
|
||||
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
|
||||
FairMQProgOptions* fConfig; ///< Program options configuration
|
||||
std::unique_ptr<FairMQProgOptions> fInternalConfig; ///< Internal program options configuration
|
||||
FairMQProgOptions* fConfig; ///< Pointer to config (internal or external)
|
||||
|
||||
void AddChannel(const std::string& channelName, const FairMQChannel& channel)
|
||||
{
|
||||
fConfig->AddChannel(channelName, channel);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string fId; ///< Device ID
|
||||
|
||||
int fNumIoThreads; ///< Number of ZeroMQ I/O threads
|
||||
|
||||
/// Additional user initialization (can be overloaded in child classes). Prefer to use InitTask().
|
||||
/// Executed in a worker thread
|
||||
virtual void Init();
|
||||
|
||||
/// Task initialization (can be overloaded in child classes)
|
||||
/// Executed in a worker thread
|
||||
virtual void InitTask();
|
||||
|
||||
/// Runs the device (to be overloaded in child classes)
|
||||
/// Executed in a worker thread
|
||||
virtual void Run();
|
||||
|
||||
/// Called in the RUNNING state once before executing the Run()/ConditionalRun() method
|
||||
/// Executed in a worker thread
|
||||
virtual void PreRun();
|
||||
|
||||
/// Called during RUNNING state repeatedly until it returns false or device state changes
|
||||
/// Executed in a worker thread
|
||||
virtual bool ConditionalRun();
|
||||
|
||||
/// Called in the RUNNING state once after executing the Run()/ConditionalRun() method
|
||||
/// Executed in a worker thread
|
||||
virtual void PostRun();
|
||||
|
||||
/// Handles the PAUSE state
|
||||
/// Executed in a worker thread
|
||||
virtual void Pause();
|
||||
|
||||
/// Resets the user task (to be overloaded in child classes)
|
||||
/// Executed in a worker thread
|
||||
virtual void ResetTask();
|
||||
|
||||
/// Resets the device (can be overloaded in child classes)
|
||||
/// Executed in a worker thread
|
||||
virtual void Reset();
|
||||
|
||||
private:
|
||||
// condition variable to notify parent thread about end of initial validation.
|
||||
bool fInitialValidationFinished;
|
||||
std::condition_variable fInitialValidationCondition;
|
||||
std::mutex fInitialValidationMutex;
|
||||
|
||||
int fPortRangeMin; ///< Minimum value for the port range (if dynamic)
|
||||
int fPortRangeMax; ///< Maximum value for the port range (if dynamic)
|
||||
|
||||
std::string fNetworkInterface; ///< Network interface to use for dynamic binding
|
||||
fair::mq::Transport fDefaultTransportType; ///< Default transport for the device
|
||||
|
||||
int fInitializationTimeoutInS; ///< Timeout for the initialization (in seconds)
|
||||
|
||||
/// Handles the initialization and the Init() method
|
||||
void InitWrapper();
|
||||
/// Handles the InitTask() method
|
||||
@@ -516,8 +500,8 @@ class FairMQDevice : public FairMQStateMachine
|
||||
void HandleMultipleTransportInput();
|
||||
void PollForTransport(const FairMQTransportFactory* factory, const std::vector<std::string>& channelKeys);
|
||||
|
||||
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i) const;
|
||||
bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i) const;
|
||||
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i);
|
||||
bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i);
|
||||
|
||||
void CreateOwnConfig();
|
||||
|
||||
@@ -530,12 +514,14 @@ class FairMQDevice : public FairMQStateMachine
|
||||
std::mutex fMultitransportMutex;
|
||||
std::atomic<bool> fMultitransportProceed;
|
||||
|
||||
bool fExternalConfig;
|
||||
|
||||
const fair::mq::tools::Version fVersion;
|
||||
float fRate; ///< Rate limiting for ConditionalRun
|
||||
size_t fLastTime; ///< Rate limiting for ConditionalRun
|
||||
std::vector<std::string> fRawCmdLineArgs;
|
||||
|
||||
std::atomic<bool> fInterrupted;
|
||||
std::condition_variable fInterruptedCV;
|
||||
std::mutex fInterruptedMtx;
|
||||
mutable std::atomic<bool> fRateLogging;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQDEVICE_H_ */
|
||||
|
@@ -15,10 +15,13 @@
|
||||
#include <fairmq/Transports.h>
|
||||
|
||||
using fairmq_free_fn = void(void* data, void* hint);
|
||||
class FairMQTransportFactory;
|
||||
|
||||
class FairMQMessage
|
||||
{
|
||||
public:
|
||||
FairMQMessage() = default;
|
||||
FairMQMessage(FairMQTransportFactory* factory):fTransport{factory} {}
|
||||
virtual void Rebuild() = 0;
|
||||
virtual void Rebuild(const size_t size) = 0;
|
||||
virtual void Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
|
||||
@@ -29,11 +32,16 @@ class FairMQMessage
|
||||
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 std::unique_ptr<FairMQMessage>& msg) __attribute__((deprecated("Use 'Copy(const FairMQMessage& msg)'"))) = 0;
|
||||
virtual void Copy(const FairMQMessage& msg) = 0;
|
||||
|
||||
virtual ~FairMQMessage() {};
|
||||
|
||||
private:
|
||||
FairMQTransportFactory* fTransport{nullptr};
|
||||
};
|
||||
|
||||
using FairMQMessagePtr = std::unique_ptr<FairMQMessage>;
|
||||
|
@@ -18,8 +18,8 @@ class FairMQPoller
|
||||
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 bool CheckInput(const std::string& channelKey, const int index) = 0;
|
||||
virtual bool CheckOutput(const std::string& channelKey, const int index) = 0;
|
||||
|
||||
virtual ~FairMQPoller() {};
|
||||
};
|
||||
|
@@ -25,34 +25,32 @@ class FairMQSocket
|
||||
virtual bool Bind(const std::string& address) = 0;
|
||||
virtual void Connect(const std::string& address) = 0;
|
||||
|
||||
virtual int Send(FairMQMessagePtr& msg, int timeout = 0) = 0;
|
||||
virtual int Receive(FairMQMessagePtr& msg, int timeout = 0) = 0;
|
||||
virtual int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = 0) = 0;
|
||||
virtual int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, int timeout = 0) = 0;
|
||||
|
||||
virtual int TrySend(FairMQMessagePtr& msg) = 0;
|
||||
virtual int TryReceive(FairMQMessagePtr& msg) = 0;
|
||||
virtual int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) = 0;
|
||||
virtual int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) = 0;
|
||||
|
||||
virtual void* GetSocket() const = 0;
|
||||
virtual int GetSocket(int nothing) const = 0;
|
||||
virtual int Send(FairMQMessagePtr& msg, int timeout = -1) = 0;
|
||||
virtual int 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;
|
||||
|
||||
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;
|
||||
|
||||
virtual bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) = 0;
|
||||
virtual int GetSendTimeout() const = 0;
|
||||
virtual bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) = 0;
|
||||
virtual int GetReceiveTimeout() const = 0;
|
||||
|
||||
virtual ~FairMQSocket() {};
|
||||
};
|
||||
|
||||
|
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
#include "FairMQStateMachine.h"
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
// Increase maximum number of boost::msm states (default is 10)
|
||||
// This #define has to be before any msm header includes
|
||||
@@ -29,13 +30,20 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::msm::front;
|
||||
|
||||
namespace msmf = boost::msm::front;
|
||||
namespace std
|
||||
{
|
||||
|
||||
template<>
|
||||
struct hash<FairMQStateMachine::Event> : fair::mq::tools::HashEnum<FairMQStateMachine::Event> {};
|
||||
|
||||
} /* namespace std */
|
||||
|
||||
namespace fair
|
||||
{
|
||||
@@ -44,35 +52,111 @@ namespace mq
|
||||
namespace fsm
|
||||
{
|
||||
|
||||
// defining events for the boost MSM state machine
|
||||
struct INIT_DEVICE_E { string name() const { return "INIT_DEVICE"; } };
|
||||
struct internal_DEVICE_READY_E { string name() const { return "internal_DEVICE_READY"; } };
|
||||
struct INIT_TASK_E { string name() const { return "INIT_TASK"; } };
|
||||
struct internal_READY_E { string name() const { return "internal_READY"; } };
|
||||
struct RUN_E { string name() const { return "RUN"; } };
|
||||
struct PAUSE_E { string name() const { return "PAUSE"; } };
|
||||
struct STOP_E { string name() const { return "STOP"; } };
|
||||
struct RESET_TASK_E { string name() const { return "RESET_TASK"; } };
|
||||
struct RESET_DEVICE_E { string name() const { return "RESET_DEVICE"; } };
|
||||
struct internal_IDLE_E { string name() const { return "internal_IDLE"; } };
|
||||
struct END_E { string name() const { return "END"; } };
|
||||
struct ERROR_FOUND_E { string name() const { return "ERROR_FOUND"; } };
|
||||
// list of FSM states
|
||||
struct OK_FSM_STATE : public state<> { static string Name() { return "OK"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::OK; } };
|
||||
struct ERROR_FSM_STATE : public terminate_state<> { static string Name() { return "ERROR"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::Error; } };
|
||||
|
||||
// deactivate the warning for non-virtual destructor thrown in the boost library
|
||||
#if defined(__clang__)
|
||||
_Pragma("clang diagnostic push")
|
||||
_Pragma("clang diagnostic ignored \"-Wnon-virtual-dtor\"")
|
||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||
_Pragma("GCC diagnostic push")
|
||||
_Pragma("GCC diagnostic ignored \"-Wnon-virtual-dtor\"")
|
||||
#endif
|
||||
struct IDLE_FSM_STATE : public state<> { static string Name() { return "IDLE"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::IDLE; } };
|
||||
struct INITIALIZING_DEVICE_FSM_STATE : public state<> { static string Name() { return "INITIALIZING_DEVICE"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::INITIALIZING_DEVICE; } };
|
||||
struct DEVICE_READY_FSM_STATE : public state<> { static string Name() { return "DEVICE_READY"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::DEVICE_READY; } };
|
||||
struct INITIALIZING_TASK_FSM_STATE : public state<> { static string Name() { return "INITIALIZING_TASK"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::INITIALIZING_TASK; } };
|
||||
struct READY_FSM_STATE : public state<> { static string Name() { return "READY"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::READY; } };
|
||||
struct RUNNING_FSM_STATE : public state<> { static string Name() { return "RUNNING"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::RUNNING; } };
|
||||
struct PAUSED_FSM_STATE : public state<> { static string Name() { return "PAUSED"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::PAUSED; } };
|
||||
struct RESETTING_TASK_FSM_STATE : public state<> { static string Name() { return "RESETTING_TASK"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::RESETTING_TASK; } };
|
||||
struct RESETTING_DEVICE_FSM_STATE : public state<> { static string Name() { return "RESETTING_DEVICE"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::RESETTING_DEVICE; } };
|
||||
struct EXITING_FSM_STATE : public state<> { static string Name() { return "EXITING"; } static FairMQStateMachine::State Type() { return FairMQStateMachine::State::EXITING; } };
|
||||
|
||||
// list of FSM events
|
||||
struct INIT_DEVICE_FSM_EVENT { static string Name() { return "INIT_DEVICE"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::INIT_DEVICE; } };
|
||||
struct internal_DEVICE_READY_FSM_EVENT { static string Name() { return "internal_DEVICE_READY"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::internal_DEVICE_READY; } };
|
||||
struct INIT_TASK_FSM_EVENT { static string Name() { return "INIT_TASK"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::INIT_TASK; } };
|
||||
struct internal_READY_FSM_EVENT { static string Name() { return "internal_READY"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::internal_READY; } };
|
||||
struct RUN_FSM_EVENT { static string Name() { return "RUN"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::RUN; } };
|
||||
struct PAUSE_FSM_EVENT { static string Name() { return "PAUSE"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::PAUSE; } };
|
||||
struct STOP_FSM_EVENT { static string Name() { return "STOP"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::STOP; } };
|
||||
struct RESET_TASK_FSM_EVENT { static string Name() { return "RESET_TASK"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::RESET_TASK; } };
|
||||
struct RESET_DEVICE_FSM_EVENT { static string Name() { return "RESET_DEVICE"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::RESET_DEVICE; } };
|
||||
struct internal_IDLE_FSM_EVENT { static string Name() { return "internal_IDLE"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::internal_IDLE; } };
|
||||
struct END_FSM_EVENT { static string Name() { return "END"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::END; } };
|
||||
struct ERROR_FOUND_FSM_EVENT { static string Name() { return "ERROR_FOUND"; } static FairMQStateMachine::Event Type() { return FairMQStateMachine::Event::ERROR_FOUND; } };
|
||||
|
||||
static array<string, 12> stateNames =
|
||||
{
|
||||
{
|
||||
"OK",
|
||||
"Error",
|
||||
"IDLE",
|
||||
"INITIALIZING_DEVICE",
|
||||
"DEVICE_READY",
|
||||
"INITIALIZING_TASK",
|
||||
"READY",
|
||||
"RUNNING",
|
||||
"PAUSED",
|
||||
"RESETTING_TASK",
|
||||
"RESETTING_DEVICE",
|
||||
"EXITING"
|
||||
}
|
||||
};
|
||||
|
||||
static array<string, 12> eventNames =
|
||||
{
|
||||
{
|
||||
"INIT_DEVICE",
|
||||
"internal_DEVICE_READY",
|
||||
"INIT_TASK",
|
||||
"internal_READY",
|
||||
"RUN",
|
||||
"PAUSE",
|
||||
"STOP",
|
||||
"RESET_TASK",
|
||||
"RESET_DEVICE",
|
||||
"internal_IDLE",
|
||||
"END",
|
||||
"ERROR_FOUND"
|
||||
}
|
||||
};
|
||||
|
||||
static map<string, int> stateNumbers =
|
||||
{
|
||||
{ "OK", FairMQStateMachine::State::OK },
|
||||
{ "Error", FairMQStateMachine::State::Error },
|
||||
{ "IDLE", FairMQStateMachine::State::IDLE },
|
||||
{ "INITIALIZING_DEVICE", FairMQStateMachine::State::INITIALIZING_DEVICE },
|
||||
{ "DEVICE_READY", FairMQStateMachine::State::DEVICE_READY },
|
||||
{ "INITIALIZING_TASK", FairMQStateMachine::State::INITIALIZING_TASK },
|
||||
{ "READY", FairMQStateMachine::State::READY },
|
||||
{ "RUNNING", FairMQStateMachine::State::RUNNING },
|
||||
{ "PAUSED", FairMQStateMachine::State::PAUSED },
|
||||
{ "RESETTING_TASK", FairMQStateMachine::State::RESETTING_TASK },
|
||||
{ "RESETTING_DEVICE", FairMQStateMachine::State::RESETTING_DEVICE },
|
||||
{ "EXITING", FairMQStateMachine::State::EXITING }
|
||||
};
|
||||
|
||||
static map<string, int> eventNumbers =
|
||||
{
|
||||
{ "INIT_DEVICE", FairMQStateMachine::Event::INIT_DEVICE },
|
||||
{ "internal_DEVICE_READY", FairMQStateMachine::Event::internal_DEVICE_READY },
|
||||
{ "INIT_TASK", FairMQStateMachine::Event::INIT_TASK },
|
||||
{ "internal_READY", FairMQStateMachine::Event::internal_READY },
|
||||
{ "RUN", FairMQStateMachine::Event::RUN },
|
||||
{ "PAUSE", FairMQStateMachine::Event::PAUSE },
|
||||
{ "STOP", FairMQStateMachine::Event::STOP },
|
||||
{ "RESET_TASK", FairMQStateMachine::Event::RESET_TASK },
|
||||
{ "RESET_DEVICE", FairMQStateMachine::Event::RESET_DEVICE },
|
||||
{ "internal_IDLE", FairMQStateMachine::Event::internal_IDLE },
|
||||
{ "END", FairMQStateMachine::Event::END },
|
||||
{ "ERROR_FOUND", FairMQStateMachine::Event::ERROR_FOUND }
|
||||
};
|
||||
|
||||
// defining the boost MSM state machine
|
||||
struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
struct Machine_ : public state_machine_def<Machine_>
|
||||
{
|
||||
public:
|
||||
Machine_()
|
||||
: fWork()
|
||||
: fUnblockHandler()
|
||||
, fStateHandlers()
|
||||
, fWork()
|
||||
, fWorkAvailableCondition()
|
||||
, fWorkDoneCondition()
|
||||
, fWorkMutex()
|
||||
@@ -81,23 +165,23 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
, fWorkAvailable(false)
|
||||
, fStateChangeSignal()
|
||||
, fStateChangeSignalsMap()
|
||||
, fTerminationRequested(false)
|
||||
, fState()
|
||||
, fWorkerThread()
|
||||
{}
|
||||
|
||||
virtual ~Machine_()
|
||||
{}
|
||||
|
||||
// initial states
|
||||
using initial_state = boost::mpl::vector<IDLE_FSM_STATE, OK_FSM_STATE>;
|
||||
|
||||
template<typename Event, typename FSM>
|
||||
void on_entry(Event const&, FSM& fsm)
|
||||
void on_entry(Event const&, FSM& /*fsm*/)
|
||||
{
|
||||
LOG(state) << "Starting FairMQ state machine";
|
||||
fState = FairMQStateMachine::IDLE;
|
||||
fsm.CallStateChangeCallbacks(FairMQStateMachine::IDLE);
|
||||
|
||||
// start a worker thread to execute user states in.
|
||||
fsm.fWorkerThread = thread(&Machine_::Worker, &fsm);
|
||||
LOG(state) << "Entering IDLE state";
|
||||
// fsm.CallStateChangeCallbacks(FairMQStateMachine::IDLE);
|
||||
// we call this for now in FairMQDevice::RunStateMachine()
|
||||
}
|
||||
|
||||
template<typename Event, typename FSM>
|
||||
@@ -106,41 +190,23 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
LOG(state) << "Exiting FairMQ state machine";
|
||||
}
|
||||
|
||||
// list of FSM states
|
||||
struct OK_FSM : public msmf::state<> {};
|
||||
struct ERROR_FSM : public msmf::terminate_state<> {};
|
||||
|
||||
struct IDLE_FSM : public msmf::state<> {};
|
||||
struct INITIALIZING_DEVICE_FSM : public msmf::state<> {};
|
||||
struct DEVICE_READY_FSM : public msmf::state<> {};
|
||||
struct INITIALIZING_TASK_FSM : public msmf::state<> {};
|
||||
struct READY_FSM : public msmf::state<> {};
|
||||
struct RUNNING_FSM : public msmf::state<> {};
|
||||
struct PAUSED_FSM : public msmf::state<> {};
|
||||
struct RESETTING_TASK_FSM : public msmf::state<> {};
|
||||
struct RESETTING_DEVICE_FSM : public msmf::state<> {};
|
||||
struct EXITING_FSM : public msmf::state<> {};
|
||||
|
||||
// initial states
|
||||
using initial_state = boost::mpl::vector<IDLE_FSM, OK_FSM>;
|
||||
|
||||
// actions
|
||||
struct IdleFct
|
||||
struct AutomaticFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const&, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
LOG(state) << "Entering IDLE state";
|
||||
fsm.fState = FairMQStateMachine::IDLE;
|
||||
fsm.fState = ts.Type();
|
||||
LOG(state) << "Entering " << ts.Name() << " state";
|
||||
}
|
||||
};
|
||||
|
||||
struct InitDeviceFct
|
||||
struct DefaultFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const& e, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::INITIALIZING_DEVICE;
|
||||
fsm.fState = ts.Type();
|
||||
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
while (fsm.fWorkActive)
|
||||
@@ -148,66 +214,8 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering INITIALIZING DEVICE state";
|
||||
fsm.fWork = fsm.fInitWrapperHandler;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
struct DeviceReadyFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
LOG(state) << "Entering DEVICE READY state";
|
||||
fsm.fState = FairMQStateMachine::DEVICE_READY;
|
||||
}
|
||||
};
|
||||
|
||||
struct InitTaskFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::INITIALIZING_TASK;
|
||||
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
while (fsm.fWorkActive)
|
||||
{
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering INITIALIZING TASK state";
|
||||
fsm.fWork = fsm.fInitTaskWrapperHandler;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
struct ReadyFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
LOG(state) << "Entering READY state";
|
||||
fsm.fState = FairMQStateMachine::READY;
|
||||
}
|
||||
};
|
||||
|
||||
struct RunFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::RUNNING;
|
||||
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
while (fsm.fWorkActive)
|
||||
{
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering RUNNING state";
|
||||
fsm.fWork = fsm.fRunWrapperHandler;
|
||||
LOG(state) << "Entering " << ts.Name() << " state";
|
||||
fsm.fWork = fsm.fStateHandlers.at(e.Type());
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
};
|
||||
@@ -215,9 +223,9 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
struct PauseFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const&, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::PAUSED;
|
||||
fsm.fState = ts.Type();
|
||||
|
||||
fsm.fUnblockHandler();
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
@@ -226,37 +234,18 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering PAUSED state";
|
||||
LOG(state) << "Entering " << ts.Name() << " state";
|
||||
fsm.fWork = fsm.fPauseWrapperHandler;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
struct ResumeFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::RUNNING;
|
||||
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
while (fsm.fWorkActive)
|
||||
{
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering RUNNING state";
|
||||
fsm.fWork = fsm.fRunWrapperHandler;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
struct StopFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const&, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::READY;
|
||||
fsm.fState = ts.Type();
|
||||
|
||||
fsm.fUnblockHandler();
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
@@ -264,115 +253,70 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
{
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
LOG(state) << "Entering READY state";
|
||||
LOG(state) << "Entering " << ts.Name() << " state";
|
||||
}
|
||||
};
|
||||
|
||||
struct InternalStopFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const&, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::READY;
|
||||
fsm.fState = ts.Type();
|
||||
fsm.fUnblockHandler();
|
||||
LOG(state) << "RUNNING state finished without an external event, entering READY state";
|
||||
}
|
||||
};
|
||||
|
||||
struct ResetTaskFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::RESETTING_TASK;
|
||||
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
while (fsm.fWorkActive)
|
||||
{
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering RESETTING TASK state";
|
||||
fsm.fWork = fsm.fResetTaskWrapperHandler;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
struct ResetDeviceFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = FairMQStateMachine::RESETTING_DEVICE;
|
||||
|
||||
unique_lock<mutex> lock(fsm.fWorkMutex);
|
||||
while (fsm.fWorkActive)
|
||||
{
|
||||
fsm.fWorkDoneCondition.wait(lock);
|
||||
}
|
||||
fsm.fWorkAvailable = true;
|
||||
LOG(state) << "Entering RESETTING DEVICE state";
|
||||
fsm.fWork = fsm.fResetWrapperHandler;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
LOG(state) << "RUNNING state finished without an external event, entering " << ts.Name() << " state";
|
||||
}
|
||||
};
|
||||
|
||||
struct ExitingFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const& e, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
LOG(state) << "Entering EXITING state";
|
||||
fsm.fState = FairMQStateMachine::EXITING;
|
||||
fsm.fTerminationRequested = true;
|
||||
LOG(state) << "Entering " << ts.Name() << " state";
|
||||
fsm.fState = ts.Type();
|
||||
fsm.CallStateChangeCallbacks(FairMQStateMachine::EXITING);
|
||||
|
||||
// terminate worker thread
|
||||
// Stop ProcessWork()
|
||||
{
|
||||
lock_guard<mutex> lock(fsm.fWorkMutex);
|
||||
fsm.fWorkerTerminated = true;
|
||||
fsm.fWorkAvailableCondition.notify_one();
|
||||
}
|
||||
|
||||
// join the worker thread (executing user states)
|
||||
if (fsm.fWorkerThread.joinable())
|
||||
{
|
||||
fsm.fWorkerThread.join();
|
||||
}
|
||||
|
||||
fsm.fExitHandler();
|
||||
fsm.fStateHandlers.at(e.Type())();
|
||||
}
|
||||
};
|
||||
|
||||
struct ErrorFoundFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
void operator()(EVT const&, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
LOG(state) << "Entering ERROR state";
|
||||
fsm.fState = FairMQStateMachine::Error;
|
||||
fsm.fState = ts.Type();
|
||||
LOG(state) << "Entering " << ts.Name() << " state";
|
||||
fsm.CallStateChangeCallbacks(FairMQStateMachine::Error);
|
||||
}
|
||||
};
|
||||
|
||||
// Transition table for Machine_
|
||||
struct transition_table : boost::mpl::vector<
|
||||
// Start Event Next Action Guard
|
||||
msmf::Row<IDLE_FSM, INIT_DEVICE_E, INITIALIZING_DEVICE_FSM, InitDeviceFct, msmf::none>,
|
||||
msmf::Row<IDLE_FSM, END_E, EXITING_FSM, ExitingFct, msmf::none>,
|
||||
msmf::Row<INITIALIZING_DEVICE_FSM, internal_DEVICE_READY_E, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
||||
msmf::Row<DEVICE_READY_FSM, INIT_TASK_E, INITIALIZING_TASK_FSM, InitTaskFct, msmf::none>,
|
||||
msmf::Row<DEVICE_READY_FSM, RESET_DEVICE_E, RESETTING_DEVICE_FSM, ResetDeviceFct, msmf::none>,
|
||||
msmf::Row<INITIALIZING_TASK_FSM, internal_READY_E, READY_FSM, ReadyFct, msmf::none>,
|
||||
msmf::Row<READY_FSM, RUN_E, RUNNING_FSM, RunFct, msmf::none>,
|
||||
msmf::Row<READY_FSM, RESET_TASK_E, RESETTING_TASK_FSM, ResetTaskFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, PAUSE_E, PAUSED_FSM, PauseFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, STOP_E, READY_FSM, StopFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, internal_READY_E, READY_FSM, InternalStopFct, msmf::none>,
|
||||
msmf::Row<PAUSED_FSM, RUN_E, RUNNING_FSM, ResumeFct, msmf::none>,
|
||||
msmf::Row<RESETTING_TASK_FSM, internal_DEVICE_READY_E, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
||||
msmf::Row<RESETTING_DEVICE_FSM, internal_IDLE_E, IDLE_FSM, IdleFct, msmf::none>,
|
||||
msmf::Row<OK_FSM, ERROR_FOUND_E, ERROR_FSM, ErrorFoundFct, msmf::none>>
|
||||
// Start Event Next Action Guard
|
||||
Row<IDLE_FSM_STATE, INIT_DEVICE_FSM_EVENT, INITIALIZING_DEVICE_FSM_STATE, DefaultFct, none>,
|
||||
Row<IDLE_FSM_STATE, END_FSM_EVENT, EXITING_FSM_STATE, ExitingFct, none>,
|
||||
Row<INITIALIZING_DEVICE_FSM_STATE, internal_DEVICE_READY_FSM_EVENT, DEVICE_READY_FSM_STATE, AutomaticFct, none>,
|
||||
Row<DEVICE_READY_FSM_STATE, INIT_TASK_FSM_EVENT, INITIALIZING_TASK_FSM_STATE, DefaultFct, none>,
|
||||
Row<DEVICE_READY_FSM_STATE, RESET_DEVICE_FSM_EVENT, RESETTING_DEVICE_FSM_STATE, DefaultFct, none>,
|
||||
Row<INITIALIZING_TASK_FSM_STATE, internal_READY_FSM_EVENT, READY_FSM_STATE, AutomaticFct, none>,
|
||||
Row<READY_FSM_STATE, RUN_FSM_EVENT, RUNNING_FSM_STATE, DefaultFct, none>,
|
||||
Row<READY_FSM_STATE, RESET_TASK_FSM_EVENT, RESETTING_TASK_FSM_STATE, DefaultFct, none>,
|
||||
Row<RUNNING_FSM_STATE, PAUSE_FSM_EVENT, PAUSED_FSM_STATE, DefaultFct, none>,
|
||||
Row<RUNNING_FSM_STATE, STOP_FSM_EVENT, READY_FSM_STATE, StopFct, none>,
|
||||
Row<RUNNING_FSM_STATE, internal_READY_FSM_EVENT, READY_FSM_STATE, InternalStopFct, none>,
|
||||
Row<PAUSED_FSM_STATE, RUN_FSM_EVENT, RUNNING_FSM_STATE, DefaultFct, none>,
|
||||
Row<RESETTING_TASK_FSM_STATE, internal_DEVICE_READY_FSM_EVENT, DEVICE_READY_FSM_STATE, AutomaticFct, none>,
|
||||
Row<RESETTING_DEVICE_FSM_STATE, internal_IDLE_FSM_EVENT, IDLE_FSM_STATE, AutomaticFct, none>,
|
||||
Row<OK_FSM_STATE, ERROR_FOUND_FSM_EVENT, ERROR_FSM_STATE, ErrorFoundFct, none>>
|
||||
{};
|
||||
|
||||
// replaces the default no-transition response.
|
||||
@@ -391,45 +335,12 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
if (pos != string::npos)
|
||||
{
|
||||
stateName = stateName.substr(pos + 1);
|
||||
stateName = stateName.substr(0, stateName.size() - 4);
|
||||
stateName = stateName.substr(0, stateName.size() - 10);
|
||||
}
|
||||
|
||||
if (stateName != "OK")
|
||||
{
|
||||
LOG(state) << "No transition from state " << stateName << " on event " << e.name();
|
||||
}
|
||||
}
|
||||
|
||||
static string GetStateName(const int state)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case FairMQStateMachine::OK:
|
||||
return "OK";
|
||||
case FairMQStateMachine::Error:
|
||||
return "Error";
|
||||
case FairMQStateMachine::IDLE:
|
||||
return "IDLE";
|
||||
case FairMQStateMachine::INITIALIZING_DEVICE:
|
||||
return "INITIALIZING_DEVICE";
|
||||
case FairMQStateMachine::DEVICE_READY:
|
||||
return "DEVICE_READY";
|
||||
case FairMQStateMachine::INITIALIZING_TASK:
|
||||
return "INITIALIZING_TASK";
|
||||
case FairMQStateMachine::READY:
|
||||
return "READY";
|
||||
case FairMQStateMachine::RUNNING:
|
||||
return "RUNNING";
|
||||
case FairMQStateMachine::PAUSED:
|
||||
return "PAUSED";
|
||||
case FairMQStateMachine::RESETTING_TASK:
|
||||
return "RESETTING_TASK";
|
||||
case FairMQStateMachine::RESETTING_DEVICE:
|
||||
return "RESETTING_DEVICE";
|
||||
case FairMQStateMachine::EXITING:
|
||||
return "EXITING";
|
||||
default:
|
||||
return "requested name for non-existent state...";
|
||||
LOG(state) << "No transition from state " << stateName << " on event " << e.Name();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,14 +352,8 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
}
|
||||
}
|
||||
|
||||
function<void(void)> fInitWrapperHandler;
|
||||
function<void(void)> fInitTaskWrapperHandler;
|
||||
function<void(void)> fRunWrapperHandler;
|
||||
function<void(void)> fPauseWrapperHandler;
|
||||
function<void(void)> fResetWrapperHandler;
|
||||
function<void(void)> fResetTaskWrapperHandler;
|
||||
function<void(void)> fExitHandler;
|
||||
function<void(void)> fUnblockHandler;
|
||||
unordered_map<FairMQStateMachine::Event, function<void(void)>> fStateHandlers;
|
||||
|
||||
// function to execute user states in a worker thread
|
||||
function<void(void)> fWork;
|
||||
@@ -461,12 +366,10 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
|
||||
boost::signals2::signal<void(const FairMQStateMachine::State)> fStateChangeSignal;
|
||||
unordered_map<string, boost::signals2::connection> fStateChangeSignalsMap;
|
||||
atomic<bool> fTerminationRequested;
|
||||
|
||||
atomic<FairMQStateMachine::State> fState;
|
||||
|
||||
private:
|
||||
void Worker()
|
||||
void ProcessWork()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@@ -475,7 +378,7 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
// Wait for work to be done.
|
||||
while (!fWorkAvailable && !fWorkerTerminated)
|
||||
{
|
||||
fWorkAvailableCondition.wait(lock);
|
||||
fWorkAvailableCondition.wait_for(lock, chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
if (fWorkerTerminated)
|
||||
@@ -497,20 +400,10 @@ struct Machine_ : public msmf::state_machine_def<Machine_>
|
||||
CallStateChangeCallbacks(fState);
|
||||
}
|
||||
}
|
||||
|
||||
// run state handlers in a separate thread
|
||||
thread fWorkerThread;
|
||||
}; // Machine_
|
||||
|
||||
using FairMQFSM = boost::msm::back::state_machine<Machine_>;
|
||||
|
||||
// reactivate the warning for non-virtual destructor
|
||||
#if defined(__clang__)
|
||||
_Pragma("clang diagnostic pop")
|
||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||
_Pragma("GCC diagnostic pop")
|
||||
#endif
|
||||
|
||||
} // namespace fsm
|
||||
} // namespace mq
|
||||
} // namespace fair
|
||||
@@ -521,13 +414,13 @@ FairMQStateMachine::FairMQStateMachine()
|
||||
: fChangeStateMutex()
|
||||
, fFsm(new FairMQFSM)
|
||||
{
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fInitWrapperHandler = bind(&FairMQStateMachine::InitWrapper, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fInitTaskWrapperHandler = bind(&FairMQStateMachine::InitTaskWrapper, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fRunWrapperHandler = bind(&FairMQStateMachine::RunWrapper, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fPauseWrapperHandler = bind(&FairMQStateMachine::PauseWrapper, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fResetWrapperHandler = bind(&FairMQStateMachine::ResetWrapper, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fResetTaskWrapperHandler = bind(&FairMQStateMachine::ResetTaskWrapper, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fExitHandler = bind(&FairMQStateMachine::Exit, this);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(INIT_DEVICE, bind(&FairMQStateMachine::InitWrapper, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(INIT_TASK, bind(&FairMQStateMachine::InitTaskWrapper, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(RUN, bind(&FairMQStateMachine::RunWrapper, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(PAUSE, bind(&FairMQStateMachine::PauseWrapper, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(RESET_TASK, bind(&FairMQStateMachine::ResetTaskWrapper, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(RESET_DEVICE, bind(&FairMQStateMachine::ResetWrapper, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fStateHandlers.emplace(END, bind(&FairMQStateMachine::Exit, this));
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fUnblockHandler = bind(&FairMQStateMachine::Unblock, this);
|
||||
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->start();
|
||||
@@ -552,79 +445,79 @@ bool FairMQStateMachine::ChangeState(int event)
|
||||
case INIT_DEVICE:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(INIT_DEVICE_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(INIT_DEVICE_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case internal_DEVICE_READY:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(internal_DEVICE_READY_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(internal_DEVICE_READY_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case INIT_TASK:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(INIT_TASK_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(INIT_TASK_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case internal_READY:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(internal_READY_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(internal_READY_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case RUN:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(RUN_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(RUN_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case PAUSE:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(PAUSE_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(PAUSE_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case STOP:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(STOP_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(STOP_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case RESET_DEVICE:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(RESET_DEVICE_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(RESET_DEVICE_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case RESET_TASK:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(RESET_TASK_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(RESET_TASK_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case internal_IDLE:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(internal_IDLE_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(internal_IDLE_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case END:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(END_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(END_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
case ERROR_FOUND:
|
||||
{
|
||||
lock_guard<mutex> lock(fChangeStateMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(ERROR_FOUND_E());
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->process_event(ERROR_FOUND_FSM_EVENT());
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
{
|
||||
LOG(error) << "Requested state transition with an unsupported event: " << event << endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, STOP, RESET_TASK, RESET_DEVICE, END, ERROR_FOUND";
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, STOP, RESET_TASK, RESET_DEVICE, END, ERROR_FOUND";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -738,7 +631,11 @@ void FairMQStateMachine::CallStateChangeCallbacks(const State state) const
|
||||
|
||||
string FairMQStateMachine::GetCurrentStateName() const
|
||||
{
|
||||
return static_pointer_cast<FairMQFSM>(fFsm)->GetStateName(static_pointer_cast<FairMQFSM>(fFsm)->fState);
|
||||
return GetStateName(static_pointer_cast<FairMQFSM>(fFsm)->fState);
|
||||
}
|
||||
string FairMQStateMachine::GetStateName(const State state)
|
||||
{
|
||||
return stateNames.at(state);
|
||||
}
|
||||
int FairMQStateMachine::GetCurrentState() const
|
||||
{
|
||||
@@ -748,28 +645,28 @@ bool FairMQStateMachine::CheckCurrentState(int state) const
|
||||
{
|
||||
return state == static_pointer_cast<FairMQFSM>(fFsm)->fState;
|
||||
}
|
||||
bool FairMQStateMachine::CheckCurrentState(string state) const
|
||||
bool FairMQStateMachine::CheckCurrentState(const string& state) const
|
||||
{
|
||||
return state == GetCurrentStateName();
|
||||
}
|
||||
|
||||
bool FairMQStateMachine::Terminated()
|
||||
void FairMQStateMachine::ProcessWork()
|
||||
try
|
||||
{
|
||||
return static_pointer_cast<FairMQFSM>(fFsm)->fTerminationRequested;
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->ProcessWork();
|
||||
} catch(...) {
|
||||
{
|
||||
lock_guard<mutex> lock(static_pointer_cast<FairMQFSM>(fFsm)->fWorkMutex);
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fWorkActive = false;
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fWorkAvailable = false;
|
||||
static_pointer_cast<FairMQFSM>(fFsm)->fWorkDoneCondition.notify_one();
|
||||
}
|
||||
ChangeState(ERROR_FOUND);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
int FairMQStateMachine::GetEventNumber(const string& event)
|
||||
{
|
||||
if (event == "INIT_DEVICE") return INIT_DEVICE;
|
||||
if (event == "INIT_TASK") return INIT_TASK;
|
||||
if (event == "RUN") return RUN;
|
||||
if (event == "PAUSE") return PAUSE;
|
||||
if (event == "STOP") return STOP;
|
||||
if (event == "RESET_DEVICE") return RESET_DEVICE;
|
||||
if (event == "RESET_TASK") return RESET_TASK;
|
||||
if (event == "END") return END;
|
||||
if (event == "ERROR_FOUND") return ERROR_FOUND;
|
||||
LOG(error) << "Requested number for non-existent event... " << event << endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, STOP, RESET_DEVICE, RESET_TASK, END, ERROR_FOUND";
|
||||
return -1;
|
||||
return eventNumbers.at(event);
|
||||
}
|
||||
|
@@ -79,10 +79,10 @@ class FairMQStateMachine
|
||||
void CallStateChangeCallbacks(const State state) const;
|
||||
|
||||
std::string GetCurrentStateName() const;
|
||||
static std::string GetStateName(const State);
|
||||
int GetCurrentState() const;
|
||||
bool CheckCurrentState(int state) const;
|
||||
bool CheckCurrentState(std::string state) const;
|
||||
bool Terminated();
|
||||
bool CheckCurrentState(const std::string& state) const;
|
||||
|
||||
// actions to be overwritten by derived classes
|
||||
virtual void InitWrapper() {}
|
||||
@@ -94,8 +94,10 @@ class FairMQStateMachine
|
||||
virtual void Exit() {}
|
||||
virtual void Unblock() {}
|
||||
|
||||
void ProcessWork();
|
||||
|
||||
private:
|
||||
int GetEventNumber(const std::string& event);
|
||||
static int GetEventNumber(const std::string& event);
|
||||
|
||||
std::mutex fChangeStateMutex;
|
||||
|
||||
|
@@ -9,11 +9,12 @@
|
||||
#ifndef FAIRMQTRANSPORTFACTORY_H_
|
||||
#define FAIRMQTRANSPORTFACTORY_H_
|
||||
|
||||
#include <FairMQMessage.h>
|
||||
#include <FairMQSocket.h>
|
||||
#include <FairMQPoller.h>
|
||||
#include <FairMQUnmanagedRegion.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <FairMQMessage.h>
|
||||
#include <FairMQPoller.h>
|
||||
#include <FairMQSocket.h>
|
||||
#include <FairMQUnmanagedRegion.h>
|
||||
#include <fairmq/MemoryResources.h>
|
||||
#include <fairmq/Transports.h>
|
||||
|
||||
#include <string>
|
||||
@@ -30,6 +31,9 @@ class FairMQTransportFactory
|
||||
/// 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.
|
||||
@@ -37,22 +41,25 @@ class FairMQTransportFactory
|
||||
|
||||
auto GetId() const -> const std::string { return fkId; };
|
||||
|
||||
/// Get a pointer to the associated polymorphic memory resource
|
||||
fair::mq::ChannelResource* GetMemoryResource() { return &fMemoryResource; }
|
||||
|
||||
/// @brief Create empty FairMQMessage
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage() const = 0;
|
||||
virtual FairMQMessagePtr CreateMessage() = 0;
|
||||
/// @brief Create new FairMQMessage of specified size
|
||||
/// @param size message size
|
||||
/// @return pointer to FairMQMessage
|
||||
virtual FairMQMessagePtr CreateMessage(const size_t size) const = 0;
|
||||
virtual FairMQMessagePtr CreateMessage(const size_t size) = 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) const = 0;
|
||||
virtual FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) = 0;
|
||||
|
||||
virtual FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& unmanagedRegion, void* data, const size_t size, void* hint = 0) const = 0;
|
||||
virtual FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& unmanagedRegion, void* data, const size_t size, void* hint = 0) = 0;
|
||||
|
||||
/// Create a socket
|
||||
virtual FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) const = 0;
|
||||
@@ -60,11 +67,9 @@ class FairMQTransportFactory
|
||||
/// Create a poller for a single channel (all subchannels)
|
||||
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const = 0;
|
||||
/// Create a poller for specific channels
|
||||
virtual FairMQPollerPtr CreatePoller(const std::vector<const FairMQChannel*>& channels) const = 0;
|
||||
virtual FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const = 0;
|
||||
/// 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;
|
||||
/// Create a poller for two sockets
|
||||
virtual FairMQPollerPtr CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const = 0;
|
||||
|
||||
virtual FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const = 0;
|
||||
|
||||
@@ -73,6 +78,7 @@ class FairMQTransportFactory
|
||||
|
||||
virtual void Interrupt() = 0;
|
||||
virtual void Resume() = 0;
|
||||
virtual void Reset() = 0;
|
||||
|
||||
virtual ~FairMQTransportFactory() {};
|
||||
|
||||
@@ -89,7 +95,7 @@ class FairMQTransportFactory
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewSimpleMessage(const T& data) const
|
||||
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!");
|
||||
@@ -98,13 +104,13 @@ class FairMQTransportFactory
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
FairMQMessagePtr NewSimpleMessage(const char(&data)[N]) const
|
||||
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) const
|
||||
FairMQMessagePtr NewSimpleMessage(const std::string& str)
|
||||
{
|
||||
|
||||
std::string* msgStr = new std::string(str);
|
||||
@@ -112,12 +118,12 @@ class FairMQTransportFactory
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
FairMQMessagePtr NewStaticMessage(const T& data) const
|
||||
FairMQMessagePtr NewStaticMessage(const T& data)
|
||||
{
|
||||
return CreateMessage(data, sizeof(T), FairMQNoCleanup, nullptr);
|
||||
}
|
||||
|
||||
FairMQMessagePtr NewStaticMessage(const std::string& str) const
|
||||
FairMQMessagePtr NewStaticMessage(const std::string& str)
|
||||
{
|
||||
return CreateMessage(const_cast<char*>(str.c_str()), str.length(), FairMQNoCleanup, nullptr);
|
||||
}
|
||||
|
60
fairmq/MemoryResourceTools.h
Normal file
60
fairmq/MemoryResourceTools.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2018 CERN and copyright holders of ALICE O2 *
|
||||
* 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" *
|
||||
********************************************************************************/
|
||||
|
||||
/// @brief Tools for interfacing containers to the transport via polymorphic
|
||||
/// allocators
|
||||
///
|
||||
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
|
||||
|
||||
#include <fairmq/FairMQTransportFactory.h>
|
||||
#include <fairmq/MemoryResources.h>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
|
||||
using BytePmrAllocator = pmr::polymorphic_allocator<fair::mq::byte>;
|
||||
|
||||
//_________________________________________________________________________________________________
|
||||
// return the message associated with the container or throw if it is not possible
|
||||
template<typename ContainerT>
|
||||
// typename std::enable_if<
|
||||
// std::is_base_of<
|
||||
// pmr::polymorphic_allocator<typename
|
||||
// ContainerT::value_type>,
|
||||
// typename ContainerT::allocator_type>::value == true,
|
||||
// FairMQMessagePtr>::type
|
||||
FairMQMessagePtr getMessage(ContainerT &&container_, FairMQMemoryResource *targetResource = nullptr)
|
||||
{
|
||||
auto container = std::move(container_);
|
||||
auto alloc = container.get_allocator();
|
||||
|
||||
auto resource = dynamic_cast<FairMQMemoryResource *>(alloc.resource());
|
||||
if (!resource && !targetResource) {
|
||||
throw std::runtime_error("Neither the container or target resource specified");
|
||||
}
|
||||
size_t containerSizeBytes = container.size() * sizeof(typename ContainerT::value_type);
|
||||
if ((!targetResource && resource)
|
||||
|| (resource && targetResource && resource->is_equal(*targetResource))) {
|
||||
auto message = resource->getMessage(static_cast<void *>(
|
||||
const_cast<typename std::remove_const<typename ContainerT::value_type>::type *>(
|
||||
container.data())));
|
||||
if (message)
|
||||
message->SetUsedSize(containerSizeBytes);
|
||||
return message;
|
||||
} else {
|
||||
auto message = targetResource->getTransportFactory()->CreateMessage(containerSizeBytes);
|
||||
std::memcpy(static_cast<fair::mq::byte *>(message->GetData()),
|
||||
container.data(),
|
||||
containerSizeBytes);
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
22
fairmq/MemoryResources.cxx
Normal file
22
fairmq/MemoryResources.cxx
Normal file
@@ -0,0 +1,22 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2018 CERN and copyright holders of ALICE O2 *
|
||||
* 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" *
|
||||
********************************************************************************/
|
||||
|
||||
/// @brief Memory allocators and interfaces related to managing memory via the
|
||||
/// trasport layer
|
||||
///
|
||||
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
|
||||
|
||||
#include <fairmq/FairMQTransportFactory.h>
|
||||
#include <fairmq/MemoryResources.h>
|
||||
|
||||
void *fair::mq::ChannelResource::do_allocate(std::size_t bytes, std::size_t /*alignment*/)
|
||||
{
|
||||
return setMessage(factory->CreateMessage(bytes));
|
||||
};
|
||||
|
116
fairmq/MemoryResources.h
Normal file
116
fairmq/MemoryResources.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2018 CERN and copyright holders of ALICE O2 *
|
||||
* 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" *
|
||||
********************************************************************************/
|
||||
|
||||
/// @brief Memory allocators and interfaces related to managing memory via the
|
||||
/// trasport layer
|
||||
///
|
||||
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
|
||||
|
||||
#ifndef FAIR_MQ_MEMORY_RESOURCES_H
|
||||
#define FAIR_MQ_MEMORY_RESOURCES_H
|
||||
|
||||
#include <fairmq/FairMQMessage.h>
|
||||
class FairMQTransportFactory;
|
||||
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <boost/container/pmr/memory_resource.hpp>
|
||||
#include <boost/container/pmr/monotonic_buffer_resource.hpp>
|
||||
#include <boost/container/pmr/polymorphic_allocator.hpp>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace fair {
|
||||
namespace mq {
|
||||
|
||||
using byte = unsigned char;
|
||||
namespace pmr = boost::container::pmr;
|
||||
|
||||
/// All FairMQ related memory resources need to inherit from this interface
|
||||
/// class for the
|
||||
/// getMessage() api.
|
||||
class FairMQMemoryResource : public pmr::memory_resource
|
||||
{
|
||||
public:
|
||||
/// return the message containing data associated with the pointer (to start
|
||||
/// of
|
||||
/// buffer), e.g. pointer returned by std::vector::data() return nullptr if
|
||||
/// returning
|
||||
/// a message does not make sense!
|
||||
virtual FairMQMessagePtr getMessage(void *p) = 0;
|
||||
virtual void *setMessage(FairMQMessagePtr) = 0;
|
||||
virtual FairMQTransportFactory *getTransportFactory() noexcept = 0;
|
||||
virtual size_t getNumberOfMessages() const noexcept = 0;
|
||||
};
|
||||
|
||||
/// This is the allocator that interfaces to FairMQ memory management. All
|
||||
/// allocations are
|
||||
/// delegated to FairMQ so standard (e.g. STL) containers can construct their
|
||||
/// stuff in
|
||||
/// memory regions appropriate for the data channel configuration.
|
||||
class ChannelResource : public FairMQMemoryResource
|
||||
{
|
||||
protected:
|
||||
FairMQTransportFactory *factory{nullptr};
|
||||
// TODO: for now a map to keep track of allocations, something else would
|
||||
// probably be
|
||||
// faster, but for now this does not need to be fast.
|
||||
boost::container::flat_map<void *, FairMQMessagePtr> messageMap;
|
||||
|
||||
public:
|
||||
ChannelResource() = delete;
|
||||
|
||||
ChannelResource(FairMQTransportFactory *_factory)
|
||||
: FairMQMemoryResource()
|
||||
, factory(_factory)
|
||||
, messageMap()
|
||||
{
|
||||
if (!_factory) {
|
||||
throw std::runtime_error("Tried to construct from a nullptr FairMQTransportFactory");
|
||||
}
|
||||
};
|
||||
|
||||
FairMQMessagePtr getMessage(void *p) override
|
||||
{
|
||||
auto mes = std::move(messageMap[p]);
|
||||
messageMap.erase(p);
|
||||
return mes;
|
||||
}
|
||||
|
||||
void *setMessage(FairMQMessagePtr message) override
|
||||
{
|
||||
void *addr = message->GetData();
|
||||
messageMap[addr] = std::move(message);
|
||||
return addr;
|
||||
}
|
||||
|
||||
FairMQTransportFactory *getTransportFactory() noexcept override { return factory; }
|
||||
|
||||
size_t getNumberOfMessages() const noexcept override { return messageMap.size(); }
|
||||
|
||||
protected:
|
||||
void *do_allocate(std::size_t bytes, std::size_t alignment) override;
|
||||
void do_deallocate(void *p, std::size_t /*bytes*/, std::size_t /*alignment*/) override
|
||||
{
|
||||
messageMap.erase(p);
|
||||
};
|
||||
|
||||
bool do_is_equal(const pmr::memory_resource &other) const noexcept override
|
||||
{
|
||||
return this == &other;
|
||||
};
|
||||
};
|
||||
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
#endif /* FAIR_MQ_MEMORY_RESOURCES_H */
|
@@ -116,9 +116,9 @@ class Plugin
|
||||
} /* namespace fair */
|
||||
|
||||
#define REGISTER_FAIRMQ_PLUGIN(KLASS, NAME, VERSION, MAINTAINER, HOMEPAGE, PROGOPTIONS) \
|
||||
static auto Make_##NAME##_Plugin(fair::mq::PluginServices* pluginServices) -> std::shared_ptr<fair::mq::Plugin> \
|
||||
static auto Make_##NAME##_Plugin(fair::mq::PluginServices* pluginServices) -> std::unique_ptr<fair::mq::Plugin> \
|
||||
{ \
|
||||
return std::make_shared<KLASS>(std::string{#NAME}, VERSION, std::string{MAINTAINER}, std::string{HOMEPAGE}, pluginServices); \
|
||||
return fair::mq::tools::make_unique<KLASS>(std::string{#NAME}, VERSION, std::string{MAINTAINER}, std::string{HOMEPAGE}, pluginServices); \
|
||||
} \
|
||||
BOOST_DLL_ALIAS(Make_##NAME##_Plugin, make_##NAME##_plugin) \
|
||||
BOOST_DLL_ALIAS(PROGOPTIONS, get_##NAME##_plugin_progoptions)
|
||||
|
@@ -31,13 +31,55 @@ const std::string fair::mq::PluginManager::fgkLibPrefix = "FairMQPlugin_";
|
||||
fair::mq::PluginManager::PluginManager()
|
||||
: fSearchPaths{{"."}}
|
||||
, fPluginFactories()
|
||||
, fPluginServices()
|
||||
, fPlugins()
|
||||
, fPluginOrder()
|
||||
, fPluginProgOptions()
|
||||
, fPluginServices()
|
||||
{
|
||||
}
|
||||
|
||||
fair::mq::PluginManager::PluginManager(const vector<string> args)
|
||||
: fSearchPaths{{"."}}
|
||||
, fPluginFactories()
|
||||
, fPluginServices()
|
||||
, fPlugins()
|
||||
, fPluginOrder()
|
||||
, fPluginProgOptions()
|
||||
{
|
||||
// Parse command line options
|
||||
auto options = ProgramOptions();
|
||||
auto vm = po::variables_map{};
|
||||
try
|
||||
{
|
||||
auto parsed = po::command_line_parser(args).options(options).allow_unregistered().run();
|
||||
po::store(parsed, vm);
|
||||
po::notify(vm);
|
||||
} catch (const po::error& e)
|
||||
{
|
||||
throw ProgramOptionsParseError{ToString("Error occured while parsing the 'Plugin Manager' program options: ", e.what())};
|
||||
}
|
||||
|
||||
// Process plugin search paths
|
||||
auto append = vector<fs::path>{};
|
||||
auto prepend = vector<fs::path>{};
|
||||
auto searchPaths = vector<fs::path>{};
|
||||
if (vm.count("plugin-search-path"))
|
||||
{
|
||||
for (const auto& path : vm["plugin-search-path"].as<vector<string>>())
|
||||
{
|
||||
if (path.substr(0, 1) == "<") { prepend.emplace_back(path.substr(1)); }
|
||||
else if (path.substr(0, 1) == ">") { append.emplace_back(path.substr(1)); }
|
||||
else { searchPaths.emplace_back(path); }
|
||||
}
|
||||
}
|
||||
|
||||
// Set supplied options
|
||||
SetSearchPaths(searchPaths);
|
||||
for(const auto& path : prepend) { PrependSearchPath(path); }
|
||||
for(const auto& path : append) { AppendSearchPath(path); }
|
||||
if (vm.count("plugin")) { LoadPlugins(vm["plugin"].as<vector<string>>()); }
|
||||
}
|
||||
|
||||
auto fair::mq::PluginManager::ValidateSearchPath(const fs::path& path) -> void
|
||||
{
|
||||
if (path.empty()) throw BadSearchPath{"Specified path is empty."};
|
||||
@@ -81,46 +123,6 @@ auto fair::mq::PluginManager::ProgramOptions() -> po::options_description
|
||||
return plugin_options;
|
||||
}
|
||||
|
||||
auto fair::mq::PluginManager::MakeFromCommandLineOptions(const vector<string> args) -> shared_ptr<PluginManager>
|
||||
{
|
||||
// Parse command line options
|
||||
auto options = ProgramOptions();
|
||||
auto vm = po::variables_map{};
|
||||
try
|
||||
{
|
||||
auto parsed = po::command_line_parser(args).options(options).allow_unregistered().run();
|
||||
po::store(parsed, vm);
|
||||
po::notify(vm);
|
||||
} catch (const po::error& e)
|
||||
{
|
||||
throw ProgramOptionsParseError{ToString("Error occured while parsing the 'Plugin Manager' program options: ", e.what())};
|
||||
}
|
||||
|
||||
// Process plugin search paths
|
||||
auto append = vector<fs::path>{};
|
||||
auto prepend = vector<fs::path>{};
|
||||
auto searchPaths = vector<fs::path>{};
|
||||
if (vm.count("plugin-search-path"))
|
||||
{
|
||||
for (const auto& path : vm["plugin-search-path"].as<vector<string>>())
|
||||
{
|
||||
if (path.substr(0, 1) == "<") { prepend.emplace_back(path.substr(1)); }
|
||||
else if (path.substr(0, 1) == ">") { append.emplace_back(path.substr(1)); }
|
||||
else { searchPaths.emplace_back(path); }
|
||||
}
|
||||
}
|
||||
|
||||
// Create PluginManager with supplied options
|
||||
auto mgr = make_shared<PluginManager>();
|
||||
mgr->SetSearchPaths(searchPaths);
|
||||
for(const auto& path : prepend) { mgr->PrependSearchPath(path); }
|
||||
for(const auto& path : append) { mgr->AppendSearchPath(path); }
|
||||
if (vm.count("plugin")) { mgr->LoadPlugins(vm["plugin"].as<vector<string>>()); }
|
||||
|
||||
// Return the plugin manager and command line options, that have not been recognized.
|
||||
return mgr;
|
||||
}
|
||||
|
||||
auto fair::mq::PluginManager::LoadPlugin(const string& pluginName) -> void
|
||||
{
|
||||
if (pluginName.substr(0,2) == "p:")
|
||||
|
@@ -47,9 +47,15 @@ namespace mq
|
||||
class PluginManager
|
||||
{
|
||||
public:
|
||||
using PluginFactory = std::shared_ptr<fair::mq::Plugin>(PluginServices&);
|
||||
using PluginFactory = std::unique_ptr<fair::mq::Plugin>(PluginServices&);
|
||||
|
||||
PluginManager();
|
||||
PluginManager(const std::vector<std::string> args);
|
||||
|
||||
~PluginManager()
|
||||
{
|
||||
LOG(debug) << "Shutting down Plugin Manager";
|
||||
}
|
||||
|
||||
auto SetSearchPaths(const std::vector<boost::filesystem::path>&) -> void;
|
||||
auto AppendSearchPath(const boost::filesystem::path&) -> void;
|
||||
@@ -64,7 +70,6 @@ class PluginManager
|
||||
struct PluginInstantiationError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
static auto ProgramOptions() -> boost::program_options::options_description;
|
||||
static auto MakeFromCommandLineOptions(const std::vector<std::string>) -> std::shared_ptr<PluginManager>;
|
||||
struct ProgramOptionsParseError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
static auto LibPrefix() -> const std::string& { return fgkLibPrefix; }
|
||||
@@ -111,10 +116,10 @@ class PluginManager
|
||||
static const std::string fgkLibPrefix;
|
||||
std::vector<boost::filesystem::path> fSearchPaths;
|
||||
std::map<std::string, std::function<PluginFactory>> fPluginFactories;
|
||||
std::map<std::string, std::shared_ptr<Plugin>> fPlugins;
|
||||
std::unique_ptr<PluginServices> fPluginServices;
|
||||
std::map<std::string, std::unique_ptr<Plugin>> fPlugins;
|
||||
std::vector<std::string> fPluginOrder;
|
||||
std::map<std::string, boost::program_options::options_description> fPluginProgOptions;
|
||||
std::unique_ptr<PluginServices> fPluginServices;
|
||||
}; /* class PluginManager */
|
||||
|
||||
} /* namespace mq */
|
||||
|
@@ -98,7 +98,7 @@ auto PluginServices::ChangeDeviceState(const std::string& controller, const Devi
|
||||
|
||||
if (fDeviceController == controller)
|
||||
{
|
||||
fDevice->ChangeState(fkDeviceStateTransitionMap.at(next));
|
||||
fDevice.ChangeState(fkDeviceStateTransitionMap.at(next));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
@@ -38,15 +39,20 @@ class PluginServices
|
||||
{
|
||||
public:
|
||||
PluginServices() = delete;
|
||||
PluginServices(FairMQProgOptions* config, std::shared_ptr<FairMQDevice> device)
|
||||
: fConfig{config}
|
||||
, fDevice{device}
|
||||
PluginServices(FairMQProgOptions& config, FairMQDevice& device)
|
||||
: fConfig(config)
|
||||
, fDevice(device)
|
||||
, fDeviceController()
|
||||
, fDeviceControllerMutex()
|
||||
, fReleaseDeviceControlCondition()
|
||||
{
|
||||
}
|
||||
|
||||
~PluginServices()
|
||||
{
|
||||
LOG(debug) << "Shutting down Plugin Services";
|
||||
}
|
||||
|
||||
PluginServices(const PluginServices&) = delete;
|
||||
PluginServices operator=(const PluginServices&) = delete;
|
||||
|
||||
@@ -109,7 +115,7 @@ class PluginServices
|
||||
friend auto operator<<(std::ostream& os, const DeviceStateTransition& transition) -> std::ostream& { return os << ToStr(transition); }
|
||||
|
||||
/// @return current device state
|
||||
auto GetCurrentDeviceState() const -> DeviceState { return fkDeviceStateMap.at(static_cast<FairMQDevice::State>(fDevice->GetCurrentState())); }
|
||||
auto GetCurrentDeviceState() const -> DeviceState { return fkDeviceStateMap.at(static_cast<FairMQDevice::State>(fDevice.GetCurrentState())); }
|
||||
|
||||
/// @brief Become device controller
|
||||
/// @param controller id
|
||||
@@ -155,19 +161,19 @@ class PluginServices
|
||||
/// the state is running in.
|
||||
auto SubscribeToDeviceStateChange(const std::string& subscriber, std::function<void(DeviceState /*newState*/)> callback) -> void
|
||||
{
|
||||
fDevice->SubscribeToStateChange(subscriber, [&,callback](FairMQDevice::State newState){
|
||||
fDevice.SubscribeToStateChange(subscriber, [&,callback](FairMQDevice::State newState){
|
||||
callback(fkDeviceStateMap.at(newState));
|
||||
});
|
||||
}
|
||||
|
||||
/// @brief Unsubscribe from device state changes
|
||||
/// @param subscriber id
|
||||
auto UnsubscribeFromDeviceStateChange(const std::string& subscriber) -> void { fDevice->UnsubscribeFromStateChange(subscriber); }
|
||||
auto UnsubscribeFromDeviceStateChange(const std::string& subscriber) -> void { fDevice.UnsubscribeFromStateChange(subscriber); }
|
||||
|
||||
// Config API
|
||||
struct PropertyNotFoundError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
auto PropertyExists(const std::string& key) const -> bool { return fConfig->Count(key) > 0; }
|
||||
auto PropertyExists(const std::string& key) const -> bool { return fConfig.Count(key) > 0; }
|
||||
|
||||
/// @brief Set config property
|
||||
/// @param key
|
||||
@@ -180,13 +186,16 @@ class PluginServices
|
||||
auto SetProperty(const std::string& key, T val) -> void
|
||||
{
|
||||
auto currentState = GetCurrentDeviceState();
|
||||
if (currentState == DeviceState::InitializingDevice)
|
||||
if ( (currentState == DeviceState::InitializingDevice)
|
||||
|| ((currentState == DeviceState::Idle) && (key == "channel-config")))
|
||||
{
|
||||
fConfig->SetValue(key, val);
|
||||
fConfig.SetValue(key, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw InvalidStateError{tools::ToString("PluginServices::SetProperty is not supported in device state ", currentState, ". Supported state is ", DeviceState::InitializingDevice, ".")};
|
||||
throw InvalidStateError{
|
||||
tools::ToString("PluginServices::SetProperty is not supported in device state ", currentState, ". ",
|
||||
"Supported state is ", DeviceState::InitializingDevice, ".")};
|
||||
}
|
||||
}
|
||||
struct InvalidStateError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
@@ -200,7 +209,7 @@ class PluginServices
|
||||
template<typename T>
|
||||
auto GetProperty(const std::string& key) const -> T {
|
||||
if (PropertyExists(key)) {
|
||||
return fConfig->GetValue<T>(key);
|
||||
return fConfig.GetValue<T>(key);
|
||||
}
|
||||
throw PropertyNotFoundError(fair::mq::tools::ToString("Config has no key: ", key));
|
||||
}
|
||||
@@ -212,16 +221,16 @@ class PluginServices
|
||||
/// If a type is not supported, the user can provide support by overloading the ostream operator for this type
|
||||
auto GetPropertyAsString(const std::string& key) const -> std::string {
|
||||
if (PropertyExists(key)) {
|
||||
return fConfig->GetStringValue(key);
|
||||
return fConfig.GetStringValue(key);
|
||||
}
|
||||
throw PropertyNotFoundError(fair::mq::tools::ToString("Config has no key: ", key));
|
||||
}
|
||||
|
||||
auto GetChannelInfo() const -> std::unordered_map<std::string, int> { return fConfig->GetChannelInfo(); }
|
||||
auto GetChannelInfo() const -> std::unordered_map<std::string, int> { return fConfig.GetChannelInfo(); }
|
||||
|
||||
/// @brief Discover the list of property keys
|
||||
/// @return list of property keys
|
||||
auto GetPropertyKeys() const -> std::vector<std::string> { return fConfig->GetPropertyKeys(); }
|
||||
auto GetPropertyKeys() const -> std::vector<std::string> { return fConfig.GetPropertyKeys(); }
|
||||
|
||||
/// @brief Subscribe to property updates of type T
|
||||
/// @param subscriber
|
||||
@@ -231,13 +240,13 @@ class PluginServices
|
||||
template<typename T>
|
||||
auto SubscribeToPropertyChange(const std::string& subscriber, std::function<void(const std::string& key, T)> callback) const -> void
|
||||
{
|
||||
fConfig->Subscribe<T>(subscriber, callback);
|
||||
fConfig.Subscribe<T>(subscriber, callback);
|
||||
}
|
||||
|
||||
/// @brief Unsubscribe from property updates of type T
|
||||
/// @param subscriber
|
||||
template<typename T>
|
||||
auto UnsubscribeFromPropertyChange(const std::string& subscriber) -> void { fConfig->Unsubscribe<T>(subscriber); }
|
||||
auto UnsubscribeFromPropertyChange(const std::string& subscriber) -> void { fConfig.Unsubscribe<T>(subscriber); }
|
||||
|
||||
/// @brief Subscribe to property updates
|
||||
/// @param subscriber
|
||||
@@ -246,12 +255,12 @@ class PluginServices
|
||||
/// Subscribe to property changes with a callback to monitor property changes in an event based fashion. Will convert the property to string.
|
||||
auto SubscribeToPropertyChangeAsString(const std::string& subscriber, std::function<void(const std::string& key, std::string)> callback) const -> void
|
||||
{
|
||||
fConfig->SubscribeAsString(subscriber, callback);
|
||||
fConfig.SubscribeAsString(subscriber, callback);
|
||||
}
|
||||
|
||||
/// @brief Unsubscribe from property updates that convert to string
|
||||
/// @param subscriber
|
||||
auto UnsubscribeFromPropertyChangeAsString(const std::string& subscriber) -> void { fConfig->UnsubscribeAsString(subscriber); }
|
||||
auto UnsubscribeFromPropertyChangeAsString(const std::string& subscriber) -> void { fConfig.UnsubscribeAsString(subscriber); }
|
||||
|
||||
auto CycleLogConsoleSeverityUp() -> void { Logger::CycleConsoleSeverityUp(); }
|
||||
auto CycleLogConsoleSeverityDown() -> void { Logger::CycleConsoleSeverityDown(); }
|
||||
@@ -266,8 +275,8 @@ class PluginServices
|
||||
static const std::unordered_map<DeviceStateTransition, FairMQDevice::Event, tools::HashEnum<DeviceStateTransition>> fkDeviceStateTransitionMap;
|
||||
|
||||
private:
|
||||
FairMQProgOptions* fConfig; // TODO make it a shared pointer, once old AliceO2 code is cleaned up
|
||||
std::shared_ptr<FairMQDevice> fDevice;
|
||||
FairMQProgOptions& fConfig;
|
||||
FairMQDevice& fDevice;
|
||||
boost::optional<std::string> fDeviceController;
|
||||
mutable std::mutex fDeviceControllerMutex;
|
||||
std::condition_variable fReleaseDeviceControlCondition;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <fairmq/tools/CppSTL.h>
|
||||
#include <fairmq/tools/Network.h>
|
||||
#include <fairmq/tools/Process.h>
|
||||
#include <fairmq/tools/RateLimit.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <fairmq/tools/Unique.h>
|
||||
#include <fairmq/tools/Version.h>
|
||||
|
@@ -9,11 +9,19 @@
|
||||
#ifndef FAIR_MQ_VERSION_H
|
||||
|
||||
#define FAIRMQ_VERSION "@PROJECT_VERSION@"
|
||||
#define FAIRMQ_VERSION_DEC (@PROJECT_VERSION_MAJOR@ * 10000) + (@PROJECT_VERSION_MINOR@ * 100) + @PROJECT_VERSION_PATCH@
|
||||
#define FAIRMQ_VERSION_DEC (@PROJECT_VERSION_MAJOR@ * 100000) \
|
||||
+ (@PROJECT_VERSION_MINOR@ * 1000) \
|
||||
+ (@PROJECT_VERSION_PATCH@ * 10) \
|
||||
+ @PROJECT_VERSION_HOTFIX@
|
||||
#define FAIRMQ_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||
#define FAIRMQ_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||
#define FAIRMQ_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||
#define FAIRMQ_VERSION_HOTFIX @PROJECT_VERSION_HOTFIX@
|
||||
#define FAIRMQ_GIT_VERSION "@PROJECT_GIT_VERSION@"
|
||||
#define FAIRMQ_GIT_DATE "@PROJECT_GIT_DATE@"
|
||||
#define FAIRMQ_REPO_URL "https://github.com/FairRootGroup/FairMQ"
|
||||
#define FAIRMQ_LICENSE "LGPL-3.0"
|
||||
#define FAIRMQ_COPYRIGHT "2012-2018 GSI"
|
||||
#define FAIRMQ_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
|
||||
|
||||
#endif // FAIR_MQ_VERSION_H
|
||||
|
@@ -1,36 +1,30 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQBenchmarkSampler.cpp
|
||||
*
|
||||
* @since 2013-04-23
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include "FairMQBenchmarkSampler.h"
|
||||
|
||||
#include <fairmq/Tools.h>
|
||||
#include "../FairMQLogger.h"
|
||||
#include "../options/FairMQProgOptions.h"
|
||||
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
|
||||
#include "../FairMQLogger.h"
|
||||
#include "../options/FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQBenchmarkSampler::FairMQBenchmarkSampler()
|
||||
: fSameMessage(true)
|
||||
: fMultipart(false)
|
||||
, fNumParts(1)
|
||||
, fMsgSize(10000)
|
||||
, fMsgCounter(0)
|
||||
, fMsgRate(1)
|
||||
, fMsgRate(0)
|
||||
, fNumIterations(0)
|
||||
, fMaxIterations(0)
|
||||
, fOutChannelName()
|
||||
, fResetMsgCounter()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,18 +34,14 @@ FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
|
||||
|
||||
void FairMQBenchmarkSampler::InitTask()
|
||||
{
|
||||
fSameMessage = fConfig->GetValue<bool>("same-msg");
|
||||
fMsgSize = fConfig->GetValue<int>("msg-size");
|
||||
fMsgRate = fConfig->GetValue<int>("msg-rate");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fNumParts = fConfig->GetValue<size_t>("num-parts");
|
||||
fMsgSize = fConfig->GetValue<size_t>("msg-size");
|
||||
fMsgRate = fConfig->GetValue<float>("msg-rate");
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::PreRun()
|
||||
{
|
||||
fResetMsgCounter = std::thread(&FairMQBenchmarkSampler::ResetMsgCounter, this);
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::Run()
|
||||
{
|
||||
// store the channel reference to avoid traversing the map on every loop iteration
|
||||
@@ -62,14 +52,20 @@ void FairMQBenchmarkSampler::Run()
|
||||
LOG(info) << "Starting the benchmark with message size of " << fMsgSize << " and " << fMaxIterations << " iterations.";
|
||||
auto tStart = chrono::high_resolution_clock::now();
|
||||
|
||||
fair::mq::tools::RateLimiter rateLimiter(fMsgRate);
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
if (fSameMessage)
|
||||
if (fMultipart)
|
||||
{
|
||||
FairMQMessagePtr msg(dataOutChannel.NewMessage());
|
||||
msg->Copy(*baseMsg);
|
||||
FairMQParts parts;
|
||||
|
||||
if (dataOutChannel.Send(msg) >= 0)
|
||||
for (size_t i = 0; i < fNumParts; ++i)
|
||||
{
|
||||
parts.AddPart(dataOutChannel.NewMessage(fMsgSize));
|
||||
}
|
||||
|
||||
if (dataOutChannel.Send(parts) >= 0)
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
@@ -98,31 +94,13 @@ void FairMQBenchmarkSampler::Run()
|
||||
}
|
||||
}
|
||||
|
||||
--fMsgCounter;
|
||||
|
||||
while (fMsgCounter == 0)
|
||||
if (fMsgRate > 0)
|
||||
{
|
||||
this_thread::sleep_for(chrono::milliseconds(1));
|
||||
rateLimiter.maybe_sleep();
|
||||
}
|
||||
}
|
||||
|
||||
auto tEnd = chrono::high_resolution_clock::now();
|
||||
|
||||
LOG(info) << "Done " << fNumIterations << " iterations in " << chrono::duration<double, milli>(tEnd - tStart).count() << "ms.";
|
||||
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::PostRun()
|
||||
{
|
||||
fResetMsgCounter.join();
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::ResetMsgCounter()
|
||||
{
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
fMsgCounter = fMsgRate / 100;
|
||||
this_thread::sleep_for(chrono::milliseconds(10));
|
||||
}
|
||||
fMsgCounter = -1;
|
||||
}
|
||||
|
@@ -1,22 +1,17 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-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" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQBenchmarkSampler.h
|
||||
*
|
||||
* @since 2013-04-23
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#ifndef FAIRMQBENCHMARKSAMPLER_H_
|
||||
#define FAIRMQBENCHMARKSAMPLER_H_
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
@@ -30,20 +25,15 @@ class FairMQBenchmarkSampler : public FairMQDevice
|
||||
FairMQBenchmarkSampler();
|
||||
virtual ~FairMQBenchmarkSampler();
|
||||
|
||||
void PreRun() override;
|
||||
void PostRun() override;
|
||||
|
||||
void ResetMsgCounter();
|
||||
|
||||
protected:
|
||||
bool fSameMessage;
|
||||
int fMsgSize;
|
||||
int fMsgCounter;
|
||||
int fMsgRate;
|
||||
bool fMultipart;
|
||||
size_t fNumParts;
|
||||
size_t fMsgSize;
|
||||
std::atomic<int> fMsgCounter;
|
||||
float fMsgRate;
|
||||
uint64_t fNumIterations;
|
||||
uint64_t fMaxIterations;
|
||||
std::string fOutChannelName;
|
||||
std::thread fResetMsgCounter;
|
||||
|
||||
virtual void InitTask() override;
|
||||
virtual void Run() override;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQMerger::FairMQMerger()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fInChannelName("data-in")
|
||||
, fOutChannelName("data-out")
|
||||
{
|
||||
@@ -30,6 +30,8 @@ void FairMQMerger::RegisterChannelEndpoints()
|
||||
{
|
||||
RegisterChannelEndpoint(fInChannelName, 1, 10000);
|
||||
RegisterChannelEndpoint(fOutChannelName, 1, 1);
|
||||
|
||||
PrintRegisteredChannels();
|
||||
}
|
||||
|
||||
FairMQMerger::~FairMQMerger()
|
||||
@@ -38,7 +40,7 @@ FairMQMerger::~FairMQMerger()
|
||||
|
||||
void FairMQMerger::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
@@ -47,7 +49,7 @@ void FairMQMerger::Run()
|
||||
{
|
||||
int numInputs = fChannels.at(fInChannelName).size();
|
||||
|
||||
vector<const FairMQChannel*> chans;
|
||||
vector<FairMQChannel*> chans;
|
||||
|
||||
for (auto& chan : fChannels.at(fInChannelName))
|
||||
{
|
||||
|
@@ -26,7 +26,7 @@ class FairMQMerger : public FairMQDevice
|
||||
virtual ~FairMQMerger();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQMultiplier::FairMQMultiplier()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fNumOutputs(0)
|
||||
, fInChannelName()
|
||||
, fOutChannelNames()
|
||||
@@ -27,7 +27,7 @@ FairMQMultiplier::~FairMQMultiplier()
|
||||
|
||||
void FairMQMultiplier::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelNames = fConfig->GetValue<vector<string>>("out-channel");
|
||||
fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size();
|
||||
|
@@ -20,7 +20,7 @@ class FairMQMultiplier : public FairMQDevice
|
||||
virtual ~FairMQMultiplier();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
int fNumOutputs;
|
||||
std::string fInChannelName;
|
||||
std::vector<std::string> fOutChannelNames;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQProxy::FairMQProxy()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fInChannelName()
|
||||
, fOutChannelName()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ FairMQProxy::~FairMQProxy()
|
||||
|
||||
void FairMQProxy::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ class FairMQProxy : public FairMQDevice
|
||||
virtual ~FairMQProxy();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
|
@@ -27,7 +27,8 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
||||
{
|
||||
public:
|
||||
FairMQSink()
|
||||
: fMaxIterations(0)
|
||||
: fMultipart(false)
|
||||
, fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
, fInChannelName()
|
||||
{}
|
||||
@@ -36,12 +37,14 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
||||
{}
|
||||
|
||||
protected:
|
||||
bool fMultipart;
|
||||
uint64_t fMaxIterations;
|
||||
uint64_t fNumIterations;
|
||||
std::string fInChannelName;
|
||||
|
||||
virtual void InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
fInChannelName = fConfig->GetValue<std::string>("in-channel");
|
||||
}
|
||||
@@ -56,18 +59,39 @@ class FairMQSink : public FairMQDevice//, public OutputPolicy
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
FairMQMessagePtr msg(dataInChannel.NewMessage());
|
||||
|
||||
if (dataInChannel.Receive(msg) >= 0)
|
||||
if (fMultipart)
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
FairMQParts parts;
|
||||
|
||||
if (dataInChannel.Receive(parts) >= 0)
|
||||
{
|
||||
if (fNumIterations >= fMaxIterations)
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
break;
|
||||
if (fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(info) << "Configured maximum number of iterations reached.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
fNumIterations++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FairMQMessagePtr msg(dataInChannel.NewMessage());
|
||||
|
||||
if (dataInChannel.Receive(msg) >= 0)
|
||||
{
|
||||
if (fMaxIterations > 0)
|
||||
{
|
||||
if (fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(info) << "Configured maximum number of iterations reached.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
fNumIterations++;
|
||||
}
|
||||
fNumIterations++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
|
||||
FairMQSplitter::FairMQSplitter()
|
||||
: fMultipart(1)
|
||||
: fMultipart(true)
|
||||
, fNumOutputs(0)
|
||||
, fDirection(0)
|
||||
, fInChannelName()
|
||||
@@ -34,7 +34,7 @@ FairMQSplitter::~FairMQSplitter()
|
||||
|
||||
void FairMQSplitter::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fMultipart = fConfig->GetValue<bool>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
fNumOutputs = fChannels.at(fOutChannelName).size();
|
||||
|
@@ -26,7 +26,7 @@ class FairMQSplitter : public FairMQDevice
|
||||
virtual ~FairMQSplitter();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
bool fMultipart;
|
||||
int fNumOutputs;
|
||||
int fDirection;
|
||||
std::string fInChannelName;
|
||||
|
@@ -24,8 +24,9 @@ using namespace std;
|
||||
|
||||
fair::mq::Transport FairMQMessageNN::fTransportType = fair::mq::Transport::NN;
|
||||
|
||||
FairMQMessageNN::FairMQMessageNN()
|
||||
: fMessage(nullptr)
|
||||
FairMQMessageNN::FairMQMessageNN(FairMQTransportFactory* factory)
|
||||
: FairMQMessage{factory}
|
||||
, fMessage(nullptr)
|
||||
, fSize(0)
|
||||
, fHint(0)
|
||||
, fReceiving(false)
|
||||
@@ -38,8 +39,9 @@ FairMQMessageNN::FairMQMessageNN()
|
||||
}
|
||||
}
|
||||
|
||||
FairMQMessageNN::FairMQMessageNN(const size_t size)
|
||||
: fMessage(nullptr)
|
||||
FairMQMessageNN::FairMQMessageNN(const size_t size, FairMQTransportFactory* factory)
|
||||
: FairMQMessage{factory}
|
||||
, fMessage(nullptr)
|
||||
, fSize(0)
|
||||
, fHint(0)
|
||||
, fReceiving(false)
|
||||
@@ -59,8 +61,9 @@ FairMQMessageNN::FairMQMessageNN(const size_t size)
|
||||
* create FairMQMessage object only with size parameter and fill it with data.
|
||||
* possible TODO: make this zero copy (will should then be as efficient as ZeroMQ).
|
||||
*/
|
||||
FairMQMessageNN::FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint)
|
||||
: fMessage(nullptr)
|
||||
FairMQMessageNN::FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint, FairMQTransportFactory* factory)
|
||||
: FairMQMessage{factory}
|
||||
, fMessage(nullptr)
|
||||
, fSize(0)
|
||||
, fHint(0)
|
||||
, fReceiving(false)
|
||||
@@ -86,8 +89,9 @@ FairMQMessageNN::FairMQMessageNN(void* data, const size_t size, fairmq_free_fn*
|
||||
}
|
||||
}
|
||||
|
||||
FairMQMessageNN::FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint)
|
||||
: fMessage(data)
|
||||
FairMQMessageNN::FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint, FairMQTransportFactory* factory)
|
||||
: FairMQMessage{factory}
|
||||
, fMessage(data)
|
||||
, fSize(size)
|
||||
, fHint(reinterpret_cast<size_t>(hint))
|
||||
, fReceiving(false)
|
||||
|
@@ -24,15 +24,15 @@
|
||||
|
||||
class FairMQSocketNN;
|
||||
|
||||
class FairMQMessageNN : public FairMQMessage
|
||||
class FairMQMessageNN final : public FairMQMessage
|
||||
{
|
||||
friend class FairMQSocketNN;
|
||||
|
||||
public:
|
||||
FairMQMessageNN();
|
||||
FairMQMessageNN(const size_t size);
|
||||
FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr);
|
||||
FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0);
|
||||
FairMQMessageNN(FairMQTransportFactory* factory = nullptr);
|
||||
FairMQMessageNN(const size_t size, FairMQTransportFactory* factory = nullptr);
|
||||
FairMQMessageNN(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr, FairMQTransportFactory* factory = nullptr);
|
||||
FairMQMessageNN(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0, FairMQTransportFactory* factory = nullptr);
|
||||
|
||||
FairMQMessageNN(const FairMQMessageNN&) = delete;
|
||||
FairMQMessageNN operator=(const FairMQMessageNN&) = delete;
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <nanomsg/pair.h>
|
||||
|
||||
#include "FairMQPollerNN.h"
|
||||
#include "FairMQSocketNN.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -33,17 +34,17 @@ FairMQPollerNN::FairMQPollerNN(const vector<FairMQChannel>& channels)
|
||||
|
||||
for (int i = 0; i < fNumItems; ++i)
|
||||
{
|
||||
fItems[i].fd = channels.at(i).GetSocket().GetSocket(1);
|
||||
fItems[i].fd = static_cast<const FairMQSocketNN*>(&(channels.at(i).GetSocket()))->GetSocket();
|
||||
|
||||
int type = 0;
|
||||
size_t sz = sizeof(type);
|
||||
nn_getsockopt(channels.at(i).GetSocket().GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
nn_getsockopt(static_cast<const FairMQSocketNN*>(&(channels.at(i).GetSocket()))->GetSocket(), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
|
||||
SetItemEvents(fItems[i], type);
|
||||
}
|
||||
}
|
||||
|
||||
FairMQPollerNN::FairMQPollerNN(const vector<const FairMQChannel*>& channels)
|
||||
FairMQPollerNN::FairMQPollerNN(const vector<FairMQChannel*>& channels)
|
||||
: fItems()
|
||||
, fNumItems(0)
|
||||
, fOffsetMap()
|
||||
@@ -53,11 +54,11 @@ FairMQPollerNN::FairMQPollerNN(const vector<const FairMQChannel*>& channels)
|
||||
|
||||
for (int i = 0; i < fNumItems; ++i)
|
||||
{
|
||||
fItems[i].fd = channels.at(i)->GetSocket().GetSocket(1);
|
||||
fItems[i].fd = static_cast<const FairMQSocketNN*>(&(channels.at(i)->GetSocket()))->GetSocket();
|
||||
|
||||
int type = 0;
|
||||
size_t sz = sizeof(type);
|
||||
nn_getsockopt(channels.at(i)->GetSocket().GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
nn_getsockopt(static_cast<const FairMQSocketNN*>(&(channels.at(i)->GetSocket()))->GetSocket(), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
|
||||
SetItemEvents(fItems[i], type);
|
||||
}
|
||||
@@ -68,10 +69,9 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map<string, vector<FairMQChannel>
|
||||
, fNumItems(0)
|
||||
, fOffsetMap()
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
try
|
||||
{
|
||||
int offset = 0;
|
||||
// calculate offsets and the total size of the poll item set
|
||||
for (string channel : channelList)
|
||||
{
|
||||
@@ -88,11 +88,11 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map<string, vector<FairMQChannel>
|
||||
for (unsigned int i = 0; i < channelsMap.at(channel).size(); ++i)
|
||||
{
|
||||
index = fOffsetMap[channel] + i;
|
||||
fItems[index].fd = channelsMap.at(channel).at(i).GetSocket().GetSocket(1);
|
||||
fItems[index].fd = static_cast<const FairMQSocketNN*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket();
|
||||
|
||||
int type = 0;
|
||||
size_t sz = sizeof(type);
|
||||
nn_getsockopt(channelsMap.at(channel).at(i).GetSocket().GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
nn_getsockopt(static_cast<const FairMQSocketNN*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket(), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
|
||||
SetItemEvents(fItems[index], type);
|
||||
}
|
||||
@@ -106,27 +106,6 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map<string, vector<FairMQChannel>
|
||||
}
|
||||
}
|
||||
|
||||
FairMQPollerNN::FairMQPollerNN(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket)
|
||||
: fItems()
|
||||
, fNumItems(2)
|
||||
, fOffsetMap()
|
||||
{
|
||||
fItems = new nn_pollfd[fNumItems];
|
||||
|
||||
fItems[0].fd = cmdSocket.GetSocket(1);
|
||||
fItems[0].events = NN_POLLIN;
|
||||
fItems[0].revents = 0;
|
||||
|
||||
fItems[1].fd = dataSocket.GetSocket(1);
|
||||
fItems[1].revents = 0;
|
||||
|
||||
int type = 0;
|
||||
size_t sz = sizeof(type);
|
||||
nn_getsockopt(dataSocket.GetSocket(1), NN_SOL_SOCKET, NN_PROTOCOL, &type, &sz);
|
||||
|
||||
SetItemEvents(fItems[1], type);
|
||||
}
|
||||
|
||||
void FairMQPollerNN::SetItemEvents(nn_pollfd& item, const int type)
|
||||
{
|
||||
if (type == NN_REQ || type == NN_REP || type == NN_PAIR)
|
||||
@@ -184,7 +163,7 @@ bool FairMQPollerNN::CheckOutput(const int index)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FairMQPollerNN::CheckInput(const string channelKey, const int index)
|
||||
bool FairMQPollerNN::CheckInput(const string& channelKey, const int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -203,7 +182,7 @@ bool FairMQPollerNN::CheckInput(const string channelKey, const int index)
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQPollerNN::CheckOutput(const string channelKey, const int index)
|
||||
bool FairMQPollerNN::CheckOutput(const string& channelKey, const int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -26,14 +26,14 @@
|
||||
class FairMQChannel;
|
||||
struct nn_pollfd;
|
||||
|
||||
class FairMQPollerNN : public FairMQPoller
|
||||
class FairMQPollerNN final : public FairMQPoller
|
||||
{
|
||||
friend class FairMQChannel;
|
||||
friend class FairMQTransportFactoryNN;
|
||||
|
||||
public:
|
||||
FairMQPollerNN(const std::vector<FairMQChannel>& channels);
|
||||
FairMQPollerNN(const std::vector<const FairMQChannel*>& channels);
|
||||
FairMQPollerNN(const std::vector<FairMQChannel*>& channels);
|
||||
FairMQPollerNN(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList);
|
||||
|
||||
FairMQPollerNN(const FairMQPollerNN&) = delete;
|
||||
@@ -41,21 +41,19 @@ class FairMQPollerNN : public FairMQPoller
|
||||
|
||||
void SetItemEvents(nn_pollfd& item, const int type);
|
||||
|
||||
virtual void Poll(const int timeout);
|
||||
virtual bool CheckInput(const int index);
|
||||
virtual bool CheckOutput(const int index);
|
||||
virtual bool CheckInput(const std::string channelKey, const int index);
|
||||
virtual bool CheckOutput(const std::string channelKey, const int index);
|
||||
void Poll(const int timeout) override;
|
||||
bool CheckInput(const int index) override;
|
||||
bool CheckOutput(const int index) override;
|
||||
bool CheckInput(const std::string& channelKey, const int index) override;
|
||||
bool CheckOutput(const std::string& channelKey, const int index) override;
|
||||
|
||||
virtual ~FairMQPollerNN();
|
||||
~FairMQPollerNN() override;
|
||||
|
||||
private:
|
||||
FairMQPollerNN(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket);
|
||||
|
||||
nn_pollfd* fItems;
|
||||
int fNumItems;
|
||||
|
||||
std::unordered_map<std::string, int> fOffsetMap;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQPOLLERNN_H_ */
|
||||
#endif /* FAIRMQPOLLERNN_H_ */
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include "FairMQMessageNN.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQUnmanagedRegionNN.h"
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <nanomsg/nn.h>
|
||||
#include <nanomsg/pipeline.h>
|
||||
@@ -27,6 +28,7 @@
|
||||
#include <msgpack.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
atomic<bool> FairMQSocketNN::fInterrupted(false);
|
||||
|
||||
@@ -39,6 +41,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const str
|
||||
, fMessagesRx(0)
|
||||
, fSndTimeout(100)
|
||||
, fRcvTimeout(100)
|
||||
, fLinger(500)
|
||||
{
|
||||
if (type == "router" || type == "dealer")
|
||||
{
|
||||
@@ -116,18 +119,13 @@ void FairMQSocketNN::Connect(const string& address)
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQSocketNN::Send(FairMQMessagePtr& msg, const int timeout) { return SendImpl(msg, 0, timeout); }
|
||||
int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int timeout) { return ReceiveImpl(msg, 0, timeout); }
|
||||
int64_t FairMQSocketNN::Send(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return SendImpl(msgVec, 0, timeout); }
|
||||
int64_t FairMQSocketNN::Receive(vector<unique_ptr<FairMQMessage>>& msgVec, const int timeout) { return ReceiveImpl(msgVec, 0, timeout); }
|
||||
|
||||
int FairMQSocketNN::TrySend(FairMQMessagePtr& msg) { return SendImpl(msg, NN_DONTWAIT, 0); }
|
||||
int FairMQSocketNN::TryReceive(FairMQMessagePtr& msg) { return ReceiveImpl(msg, NN_DONTWAIT, 0); }
|
||||
int64_t FairMQSocketNN::TrySend(vector<unique_ptr<FairMQMessage>>& msgVec) { return SendImpl(msgVec, NN_DONTWAIT, 0); }
|
||||
int64_t FairMQSocketNN::TryReceive(vector<unique_ptr<FairMQMessage>>& msgVec) { return ReceiveImpl(msgVec, NN_DONTWAIT, 0); }
|
||||
|
||||
int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
||||
int FairMQSocketNN::Send(FairMQMessagePtr& msg, const int timeout)
|
||||
{
|
||||
int flags = 0;
|
||||
if (timeout == 0)
|
||||
{
|
||||
flags = NN_DONTWAIT;
|
||||
}
|
||||
int nbytes = -1;
|
||||
int elapsed = 0;
|
||||
|
||||
@@ -155,15 +153,11 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
|
||||
else if (nn_errno() == ETIMEDOUT)
|
||||
#else
|
||||
else if (nn_errno() == EAGAIN)
|
||||
#endif
|
||||
{
|
||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||
{
|
||||
if (timeout)
|
||||
if (timeout > 0)
|
||||
{
|
||||
elapsed += fSndTimeout;
|
||||
if (elapsed >= timeout)
|
||||
@@ -195,9 +189,13 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout)
|
||||
int FairMQSocketNN::Receive(FairMQMessagePtr& msg, const int timeout)
|
||||
{
|
||||
int nbytes = -1;
|
||||
int flags = 0;
|
||||
if (timeout == 0)
|
||||
{
|
||||
flags = NN_DONTWAIT;
|
||||
}
|
||||
int elapsed = 0;
|
||||
|
||||
FairMQMessageNN* msgPtr = static_cast<FairMQMessageNN*>(msg.get());
|
||||
@@ -205,7 +203,7 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
|
||||
while (true)
|
||||
{
|
||||
void* ptr = nullptr;
|
||||
nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
||||
int nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
||||
if (nbytes >= 0)
|
||||
{
|
||||
fBytesRx += nbytes;
|
||||
@@ -214,15 +212,11 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
|
||||
msgPtr->fReceiving = true;
|
||||
return nbytes;
|
||||
}
|
||||
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
|
||||
else if (nn_errno() == ETIMEDOUT)
|
||||
#else
|
||||
else if (nn_errno() == EAGAIN)
|
||||
#endif
|
||||
{
|
||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||
{
|
||||
if (timeout)
|
||||
if (timeout > 0)
|
||||
{
|
||||
elapsed += fRcvTimeout;
|
||||
if (elapsed >= timeout)
|
||||
@@ -254,8 +248,13 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in
|
||||
}
|
||||
}
|
||||
|
||||
int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
||||
int64_t FairMQSocketNN::Send(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||
{
|
||||
int flags = 0;
|
||||
if (timeout == 0)
|
||||
{
|
||||
flags = NN_DONTWAIT;
|
||||
}
|
||||
const unsigned int vecSize = msgVec.size();
|
||||
int elapsed = 0;
|
||||
|
||||
@@ -279,26 +278,20 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
|
||||
}
|
||||
}
|
||||
|
||||
int64_t nbytes = -1;
|
||||
|
||||
while (true)
|
||||
{
|
||||
nbytes = nn_send(fSocket, sbuf.data(), sbuf.size(), flags);
|
||||
int64_t nbytes = nn_send(fSocket, sbuf.data(), sbuf.size(), flags);
|
||||
if (nbytes >= 0)
|
||||
{
|
||||
fBytesTx += nbytes;
|
||||
++fMessagesTx;
|
||||
return nbytes;
|
||||
}
|
||||
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
|
||||
else if (nn_errno() == ETIMEDOUT)
|
||||
#else
|
||||
else if (nn_errno() == EAGAIN)
|
||||
#endif
|
||||
{
|
||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||
{
|
||||
if (timeout)
|
||||
if (timeout > 0)
|
||||
{
|
||||
elapsed += fSndTimeout;
|
||||
if (elapsed >= timeout)
|
||||
@@ -330,8 +323,13 @@ int64_t FairMQSocketNN::SendImpl(vector<FairMQMessagePtr>& msgVec, const int fla
|
||||
}
|
||||
}
|
||||
|
||||
int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int flags, const int timeout)
|
||||
int64_t FairMQSocketNN::Receive(vector<FairMQMessagePtr>& msgVec, const int timeout)
|
||||
{
|
||||
int flags = 0;
|
||||
if (timeout == 0)
|
||||
{
|
||||
flags = NN_DONTWAIT;
|
||||
}
|
||||
// Warn if the vector is filled before Receive() and empty it.
|
||||
// if (msgVec.size() > 0)
|
||||
// {
|
||||
@@ -377,15 +375,11 @@ int64_t FairMQSocketNN::ReceiveImpl(vector<FairMQMessagePtr>& msgVec, const int
|
||||
nn_freemsg(ptr);
|
||||
return nbytes;
|
||||
}
|
||||
#if NN_VERSION_CURRENT>2 // backwards-compatibility with nanomsg version<=0.6
|
||||
else if (nn_errno() == ETIMEDOUT)
|
||||
#else
|
||||
else if (nn_errno() == EAGAIN)
|
||||
#endif
|
||||
{
|
||||
if (!fInterrupted && ((flags & NN_DONTWAIT) == 0))
|
||||
{
|
||||
if (timeout)
|
||||
if (timeout > 0)
|
||||
{
|
||||
elapsed += fRcvTimeout;
|
||||
if (elapsed >= timeout)
|
||||
@@ -432,12 +426,7 @@ void FairMQSocketNN::Resume()
|
||||
fInterrupted = false;
|
||||
}
|
||||
|
||||
void* FairMQSocketNN::GetSocket() const
|
||||
{
|
||||
return nullptr; // dummy method to comply with the interface. functionality not possible in zeromq.
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetSocket(int /*nothing*/) const
|
||||
int FairMQSocketNN::GetSocket() const
|
||||
{
|
||||
return fSocket;
|
||||
}
|
||||
@@ -449,7 +438,7 @@ void FairMQSocketNN::SetOption(const string& option, const void* value, size_t v
|
||||
int val = *(static_cast<int*>(const_cast<void*>(value)));
|
||||
if (val <= 0)
|
||||
{
|
||||
LOG(warn) << "value for sndKernelSize/rcvKernelSize should be greater than 0, using defaults (128kB).";
|
||||
LOG(warn) << "value for sndKernelSize/rcvKernelSize should be greater than 0, leaving unchanged.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -459,6 +448,12 @@ void FairMQSocketNN::SetOption(const string& option, const void* value, size_t v
|
||||
return;
|
||||
}
|
||||
|
||||
if (option == "linger")
|
||||
{
|
||||
fLinger = *static_cast<int*>(const_cast<void*>(value));
|
||||
return;
|
||||
}
|
||||
|
||||
int rc = nn_setsockopt(fSocket, NN_SOL_SOCKET, GetConstant(option), value, valueSize);
|
||||
if (rc < 0)
|
||||
{
|
||||
@@ -468,6 +463,19 @@ void FairMQSocketNN::SetOption(const string& option, const void* value, size_t v
|
||||
|
||||
void FairMQSocketNN::GetOption(const string& option, void* value, size_t* valueSize)
|
||||
{
|
||||
if (option == "linger")
|
||||
{
|
||||
*static_cast<int*>(value) = fLinger;
|
||||
return;
|
||||
}
|
||||
|
||||
if (option == "snd-hwm" || option == "rcv-hwm")
|
||||
{
|
||||
*static_cast<int*>(value) = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int rc = nn_getsockopt(fSocket, NN_SOL_SOCKET, GetConstant(option), value, valueSize);
|
||||
if (rc < 0)
|
||||
{
|
||||
@@ -475,6 +483,73 @@ void FairMQSocketNN::GetOption(const string& option, void* value, size_t* valueS
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQSocketNN::SetLinger(const int value)
|
||||
{
|
||||
fLinger = value;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetLinger() const
|
||||
{
|
||||
return fLinger;
|
||||
}
|
||||
|
||||
void FairMQSocketNN::SetSndBufSize(const int /* value */)
|
||||
{
|
||||
// not used in nanomsg
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetSndBufSize() const
|
||||
{
|
||||
// not used in nanomsg
|
||||
return -1;
|
||||
}
|
||||
|
||||
void FairMQSocketNN::SetRcvBufSize(const int /* value */)
|
||||
{
|
||||
// not used in nanomsg
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetRcvBufSize() const
|
||||
{
|
||||
// not used in nanomsg
|
||||
return -1;
|
||||
}
|
||||
|
||||
void FairMQSocketNN::SetSndKernelSize(const int value)
|
||||
{
|
||||
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_SNDBUF, &value, sizeof(value)) < 0) {
|
||||
throw SocketError(tools::ToString("failed setting NN_SNDBUF, reason: ", nn_strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetSndKernelSize() const
|
||||
{
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (nn_getsockopt(fSocket, NN_SOL_SOCKET, NN_SNDBUF, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting NN_SNDBUF, reason: ", nn_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void FairMQSocketNN::SetRcvKernelSize(const int value)
|
||||
{
|
||||
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_RCVBUF, &value, sizeof(value)) < 0) {
|
||||
throw SocketError(tools::ToString("failed setting NN_RCVBUF, reason: ", nn_strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetRcvKernelSize() const
|
||||
{
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (nn_getsockopt(fSocket, NN_SOL_SOCKET, NN_RCVBUF, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting NN_RCVBUF, reason: ", nn_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
unsigned long FairMQSocketNN::GetBytesTx() const
|
||||
{
|
||||
return fBytesTx;
|
||||
@@ -495,40 +570,6 @@ unsigned long FairMQSocketNN::GetMessagesRx() const
|
||||
return fMessagesRx;
|
||||
}
|
||||
|
||||
bool FairMQSocketNN::SetSendTimeout(const int timeout, const string& /*address*/, const string& /*method*/)
|
||||
{
|
||||
fSndTimeout = timeout;
|
||||
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
|
||||
{
|
||||
LOG(error) << "Failed setting option 'send timeout' on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetSendTimeout() const
|
||||
{
|
||||
return fSndTimeout;
|
||||
}
|
||||
|
||||
bool FairMQSocketNN::SetReceiveTimeout(const int timeout, const string& /*address*/, const string& /*method*/)
|
||||
{
|
||||
fRcvTimeout = timeout;
|
||||
if (nn_setsockopt(fSocket, NN_SOL_SOCKET, NN_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
|
||||
{
|
||||
LOG(error) << "Failed setting option 'receive timeout' on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetReceiveTimeout() const
|
||||
{
|
||||
return fRcvTimeout;
|
||||
}
|
||||
|
||||
int FairMQSocketNN::GetConstant(const string& constant)
|
||||
{
|
||||
if (constant == "")
|
||||
|
@@ -15,7 +15,7 @@
|
||||
#include "FairMQSocket.h"
|
||||
#include "FairMQMessage.h"
|
||||
|
||||
class FairMQSocketNN : public FairMQSocket
|
||||
class FairMQSocketNN final : public FairMQSocket
|
||||
{
|
||||
public:
|
||||
FairMQSocketNN(const std::string& type, const std::string& name, const std::string& id = "");
|
||||
@@ -27,18 +27,12 @@ class FairMQSocketNN : public FairMQSocket
|
||||
bool Bind(const std::string& address) override;
|
||||
void Connect(const std::string& address) override;
|
||||
|
||||
int Send(FairMQMessagePtr& msg, const int timeout = 0) override;
|
||||
int Receive(FairMQMessagePtr& msg, const int timeout = 0) override;
|
||||
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
|
||||
int Send(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||
int Receive(FairMQMessagePtr& msg, const int timeout = -1) override;
|
||||
int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||
int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = -1) override;
|
||||
|
||||
int TrySend(FairMQMessagePtr& msg) override;
|
||||
int TryReceive(FairMQMessagePtr& msg) override;
|
||||
int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
||||
int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
|
||||
|
||||
void* GetSocket() const override;
|
||||
int GetSocket(int nothing) const override;
|
||||
int GetSocket() const;
|
||||
|
||||
void Close() override;
|
||||
|
||||
@@ -48,16 +42,22 @@ class FairMQSocketNN : public FairMQSocket
|
||||
void SetOption(const std::string& option, const void* value, size_t valueSize) override;
|
||||
void GetOption(const std::string& option, void* value, size_t* valueSize) override;
|
||||
|
||||
void SetLinger(const int value) override;
|
||||
int GetLinger() const override;
|
||||
void SetSndBufSize(const int value) override;
|
||||
int GetSndBufSize() const override;
|
||||
void SetRcvBufSize(const int value) override;
|
||||
int GetRcvBufSize() const override;
|
||||
void SetSndKernelSize(const int value) override;
|
||||
int GetSndKernelSize() const override;
|
||||
void SetRcvKernelSize(const int value) override;
|
||||
int GetRcvKernelSize() const override;
|
||||
|
||||
unsigned long GetBytesTx() const override;
|
||||
unsigned long GetBytesRx() const override;
|
||||
unsigned long GetMessagesTx() const override;
|
||||
unsigned long GetMessagesRx() const override;
|
||||
|
||||
bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) override;
|
||||
int GetSendTimeout() const override;
|
||||
bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) override;
|
||||
int GetReceiveTimeout() const override;
|
||||
|
||||
static int GetConstant(const std::string& constant);
|
||||
|
||||
~FairMQSocketNN() override;
|
||||
@@ -74,11 +74,7 @@ class FairMQSocketNN : public FairMQSocket
|
||||
|
||||
int fSndTimeout;
|
||||
int fRcvTimeout;
|
||||
|
||||
int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
||||
int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
|
||||
int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
||||
int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
|
||||
int fLinger;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQSOCKETNN_H_ */
|
||||
|
@@ -9,6 +9,9 @@
|
||||
#include "FairMQTransportFactoryNN.h"
|
||||
|
||||
#include <nanomsg/nn.h>
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -20,29 +23,31 @@ FairMQTransportFactoryNN::FairMQTransportFactoryNN(const string& id, const FairM
|
||||
LOG(debug) << "Transport: Using nanomsg library";
|
||||
}
|
||||
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage() const
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage()
|
||||
{
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN());
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(this));
|
||||
}
|
||||
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(const size_t size) const
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(const size_t size)
|
||||
{
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(size));
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(size, this));
|
||||
}
|
||||
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) const
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint)
|
||||
{
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(data, size, ffn, hint));
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(data, size, ffn, hint, this));
|
||||
}
|
||||
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint) const
|
||||
FairMQMessagePtr FairMQTransportFactoryNN::CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint)
|
||||
{
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(region, data, size, hint));
|
||||
return unique_ptr<FairMQMessage>(new FairMQMessageNN(region, data, size, hint, this));
|
||||
}
|
||||
|
||||
FairMQSocketPtr FairMQTransportFactoryNN::CreateSocket(const string& type, const string& name) const
|
||||
{
|
||||
return unique_ptr<FairMQSocket>(new FairMQSocketNN(type, name, GetId()));
|
||||
unique_ptr<FairMQSocket> socket(new FairMQSocketNN(type, name, GetId()));
|
||||
fSockets.push_back(socket.get());
|
||||
return socket;
|
||||
}
|
||||
|
||||
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChannel>& channels) const
|
||||
@@ -50,7 +55,7 @@ FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChanne
|
||||
return unique_ptr<FairMQPoller>(new FairMQPollerNN(channels));
|
||||
}
|
||||
|
||||
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const std::vector<const FairMQChannel*>& channels) const
|
||||
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const std::vector<FairMQChannel*>& channels) const
|
||||
{
|
||||
return unique_ptr<FairMQPoller>(new FairMQPollerNN(channels));
|
||||
}
|
||||
@@ -60,11 +65,6 @@ FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const unordered_map<strin
|
||||
return unique_ptr<FairMQPoller>(new FairMQPollerNN(channelsMap, channelList));
|
||||
}
|
||||
|
||||
FairMQPollerPtr FairMQTransportFactoryNN::CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const
|
||||
{
|
||||
return unique_ptr<FairMQPoller>(new FairMQPollerNN(cmdSocket, dataSocket));
|
||||
}
|
||||
|
||||
FairMQUnmanagedRegionPtr FairMQTransportFactoryNN::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const
|
||||
{
|
||||
return unique_ptr<FairMQUnmanagedRegion>(new FairMQUnmanagedRegionNN(size, callback));
|
||||
@@ -75,6 +75,17 @@ fair::mq::Transport FairMQTransportFactoryNN::GetType() const
|
||||
return fTransportType;
|
||||
}
|
||||
|
||||
void FairMQTransportFactoryNN::Reset()
|
||||
{
|
||||
auto it = max_element(fSockets.begin(), fSockets.end(), [](FairMQSocket* s1, FairMQSocket* s2) {
|
||||
return static_cast<FairMQSocketNN*>(s1)->GetLinger() < static_cast<FairMQSocketNN*>(s2)->GetLinger();
|
||||
});
|
||||
if (it != fSockets.end()) {
|
||||
this_thread::sleep_for(chrono::milliseconds(static_cast<FairMQSocketNN*>(*it)->GetLinger()));
|
||||
}
|
||||
fSockets.clear();
|
||||
}
|
||||
|
||||
FairMQTransportFactoryNN::~FairMQTransportFactoryNN()
|
||||
{
|
||||
// nn_term();
|
||||
|
@@ -19,23 +19,22 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class FairMQTransportFactoryNN : public FairMQTransportFactory
|
||||
class FairMQTransportFactoryNN final : public FairMQTransportFactory
|
||||
{
|
||||
public:
|
||||
FairMQTransportFactoryNN(const std::string& id = "", const FairMQProgOptions* config = nullptr);
|
||||
~FairMQTransportFactoryNN() override;
|
||||
|
||||
FairMQMessagePtr CreateMessage() const override;
|
||||
FairMQMessagePtr CreateMessage(const size_t size) const override;
|
||||
FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) const override;
|
||||
FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) const override;
|
||||
FairMQMessagePtr CreateMessage() override;
|
||||
FairMQMessagePtr CreateMessage(const size_t size) override;
|
||||
FairMQMessagePtr CreateMessage(void* data, const size_t size, fairmq_free_fn* ffn, void* hint = nullptr) override;
|
||||
FairMQMessagePtr CreateMessage(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint = 0) override;
|
||||
|
||||
FairMQSocketPtr CreateSocket(const std::string& type, const std::string& name) const override;
|
||||
|
||||
FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel>& channels) const override;
|
||||
FairMQPollerPtr CreatePoller(const std::vector<const FairMQChannel*>& channels) const override;
|
||||
FairMQPollerPtr CreatePoller(const std::vector<FairMQChannel*>& channels) const override;
|
||||
FairMQPollerPtr CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const override;
|
||||
FairMQPollerPtr CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const override;
|
||||
|
||||
FairMQUnmanagedRegionPtr CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const override;
|
||||
|
||||
@@ -43,9 +42,11 @@ class FairMQTransportFactoryNN : public FairMQTransportFactory
|
||||
|
||||
void Interrupt() override { FairMQSocketNN::Interrupt(); }
|
||||
void Resume() override { FairMQSocketNN::Resume(); }
|
||||
void Reset() override;
|
||||
|
||||
private:
|
||||
static fair::mq::Transport fTransportType;
|
||||
mutable std::vector<FairMQSocket*> fSockets;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQTRANSPORTFACTORYNN_H_ */
|
||||
|
@@ -13,7 +13,7 @@
|
||||
|
||||
#include <cstddef> // size_t
|
||||
|
||||
class FairMQUnmanagedRegionNN : public FairMQUnmanagedRegion
|
||||
class FairMQUnmanagedRegionNN final : public FairMQUnmanagedRegion
|
||||
{
|
||||
friend class FairMQSocketNN;
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <fairmq/Tools.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <zmq.h>
|
||||
|
||||
@@ -53,7 +54,7 @@ Message::Message(void* data, const size_t size, fairmq_free_fn* ffn, void* hint)
|
||||
{
|
||||
}
|
||||
|
||||
Message::Message(FairMQUnmanagedRegionPtr& region, void* data, const size_t size, void* hint)
|
||||
Message::Message(FairMQUnmanagedRegionPtr& /*region*/, void* /*data*/, const size_t /*size*/, void* /*hint*/)
|
||||
{
|
||||
throw MessageError{"Not yet implemented."};
|
||||
}
|
||||
@@ -91,7 +92,7 @@ auto Message::Rebuild(const size_t size) -> void
|
||||
fHint = nullptr;
|
||||
}
|
||||
|
||||
auto Message::Rebuild(void* data, const size_t size, fairmq_free_fn* ffn, void* hint) -> void
|
||||
auto Message::Rebuild(void* /*data*/, const size_t size, fairmq_free_fn* ffn, void* hint) -> void
|
||||
{
|
||||
if (fFreeFunction) {
|
||||
fFreeFunction(fData, fHint);
|
||||
@@ -132,12 +133,12 @@ auto Message::SetUsedSize(const size_t size) -> bool
|
||||
}
|
||||
}
|
||||
|
||||
auto Message::Copy(const fair::mq::Message& msg) -> void
|
||||
auto Message::Copy(const fair::mq::Message& /*msg*/) -> void
|
||||
{
|
||||
throw MessageError{"Not yet implemented."};
|
||||
}
|
||||
|
||||
auto Message::Copy(const fair::mq::MessagePtr& msg) -> void
|
||||
auto Message::Copy(const fair::mq::MessagePtr& /*msg*/) -> void
|
||||
{
|
||||
throw MessageError{"Not yet implemented."};
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ namespace ofi
|
||||
*
|
||||
* @todo TODO insert long description
|
||||
*/
|
||||
class Message : public fair::mq::Message
|
||||
class Message final : public fair::mq::Message
|
||||
{
|
||||
public:
|
||||
Message();
|
||||
|
@@ -7,6 +7,7 @@
|
||||
********************************************************************************/
|
||||
|
||||
#include <fairmq/ofi/Poller.h>
|
||||
#include <fairmq/ofi/Socket.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
@@ -27,13 +28,13 @@ Poller::Poller(const vector<FairMQChannel>& channels)
|
||||
fItems = new zmq_pollitem_t[fNumItems];
|
||||
|
||||
for (int i = 0; i < fNumItems; ++i) {
|
||||
fItems[i].socket = channels.at(i).GetSocket().GetSocket();
|
||||
fItems[i].socket = static_cast<const Socket*>(&(channels.at(i).GetSocket()))->GetSocket();
|
||||
fItems[i].fd = 0;
|
||||
fItems[i].revents = 0;
|
||||
|
||||
int type = 0;
|
||||
size_t size = sizeof(type);
|
||||
zmq_getsockopt(channels.at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
zmq_getsockopt(static_cast<const Socket*>(&(channels.at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
|
||||
SetItemEvents(fItems[i], type);
|
||||
}
|
||||
@@ -45,13 +46,13 @@ Poller::Poller(const vector<const FairMQChannel*>& channels)
|
||||
fItems = new zmq_pollitem_t[fNumItems];
|
||||
|
||||
for (int i = 0; i < fNumItems; ++i) {
|
||||
fItems[i].socket = channels.at(i)->GetSocket().GetSocket();
|
||||
fItems[i].socket = static_cast<const Socket*>(&(channels.at(i)->GetSocket()))->GetSocket();
|
||||
fItems[i].fd = 0;
|
||||
fItems[i].revents = 0;
|
||||
|
||||
int type = 0;
|
||||
size_t size = sizeof(type);
|
||||
zmq_getsockopt(channels.at(i)->GetSocket().GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
zmq_getsockopt(static_cast<const Socket*>(&(channels.at(i)->GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
|
||||
SetItemEvents(fItems[i], type);
|
||||
}
|
||||
@@ -59,9 +60,8 @@ Poller::Poller(const vector<const FairMQChannel*>& channels)
|
||||
|
||||
Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap, const vector<string>& channelList)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
try {
|
||||
int offset = 0;
|
||||
// calculate offsets and the total size of the poll item set
|
||||
for (string channel : channelList) {
|
||||
fOffsetMap[channel] = offset;
|
||||
@@ -76,13 +76,13 @@ Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap,
|
||||
for (unsigned int i = 0; i < channelsMap.at(channel).size(); ++i) {
|
||||
index = fOffsetMap[channel] + i;
|
||||
|
||||
fItems[index].socket = channelsMap.at(channel).at(i).GetSocket().GetSocket();
|
||||
fItems[index].socket = static_cast<const Socket*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket();
|
||||
fItems[index].fd = 0;
|
||||
fItems[index].revents = 0;
|
||||
|
||||
int type = 0;
|
||||
size_t size = sizeof(type);
|
||||
zmq_getsockopt(channelsMap.at(channel).at(i).GetSocket().GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
zmq_getsockopt(static_cast<const Socket*>(&(channelsMap.at(channel).at(i).GetSocket()))->GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
|
||||
SetItemEvents(fItems[index], type);
|
||||
}
|
||||
@@ -94,27 +94,6 @@ Poller::Poller(const unordered_map<string, vector<FairMQChannel>>& channelsMap,
|
||||
}
|
||||
}
|
||||
|
||||
Poller::Poller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket)
|
||||
: fNumItems{2}
|
||||
{
|
||||
fItems = new zmq_pollitem_t[fNumItems];
|
||||
|
||||
fItems[0].socket = cmdSocket.GetSocket();
|
||||
fItems[0].fd = 0;
|
||||
fItems[0].events = ZMQ_POLLIN;
|
||||
fItems[0].revents = 0;
|
||||
|
||||
fItems[1].socket = dataSocket.GetSocket();
|
||||
fItems[1].fd = 0;
|
||||
fItems[1].revents = 0;
|
||||
|
||||
int type = 0;
|
||||
size_t size = sizeof(type);
|
||||
zmq_getsockopt(dataSocket.GetSocket(), ZMQ_TYPE, &type, &size);
|
||||
|
||||
SetItemEvents(fItems[1], type);
|
||||
}
|
||||
|
||||
auto Poller::SetItemEvents(zmq_pollitem_t& item, const int type) -> void
|
||||
{
|
||||
if (type == ZMQ_PAIR) {
|
||||
|
@@ -33,7 +33,7 @@ class TransportFactory;
|
||||
*
|
||||
* @todo TODO insert long description
|
||||
*/
|
||||
class Poller : public FairMQPoller
|
||||
class Poller final : public FairMQPoller
|
||||
{
|
||||
friend class FairMQChannel;
|
||||
friend class TransportFactory;
|
||||
@@ -57,8 +57,6 @@ class Poller : public FairMQPoller
|
||||
~Poller() override;
|
||||
|
||||
private:
|
||||
Poller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket);
|
||||
|
||||
zmq_pollitem_t* fItems;
|
||||
int fNumItems;
|
||||
|
||||
|
@@ -619,114 +619,82 @@ auto Socket::GetOption(const string& option, void* value, size_t* valueSize) ->
|
||||
}
|
||||
}
|
||||
|
||||
auto Socket::SetSendTimeout(const int timeout, const string& address, const string& method) -> bool
|
||||
int Socket::GetLinger() const
|
||||
{
|
||||
throw SocketError{"Not yet implemented."};
|
||||
// fSndTimeout = timeout;
|
||||
// if (method == "bind")
|
||||
// {
|
||||
// if (zmq_unbind(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_bind(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// else if (method == "connect")
|
||||
// {
|
||||
// if (zmq_disconnect(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_setsockopt(fSocket, ZMQ_SNDTIMEO, &fSndTimeout, sizeof(fSndTimeout)) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_connect(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LOG(error) << "timeout failed - unknown method provided!";
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (zmq_getsockopt(fControlSocket, ZMQ_LINGER, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_LINGER, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
auto Socket::GetSendTimeout() const -> int
|
||||
void Socket::SetSndBufSize(const int value)
|
||||
{
|
||||
throw SocketError{"Not yet implemented."};
|
||||
// return fSndTimeout;
|
||||
if (zmq_setsockopt(fControlSocket, ZMQ_SNDHWM, &value, sizeof(value)) < 0) {
|
||||
throw SocketError(tools::ToString("failed setting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
auto Socket::SetReceiveTimeout(const int timeout, const string& address, const string& method) -> bool
|
||||
int Socket::GetSndBufSize() const
|
||||
{
|
||||
throw SocketError{"Not yet implemented."};
|
||||
// fRcvTimeout = timeout;
|
||||
// if (method == "bind")
|
||||
// {
|
||||
// if (zmq_unbind(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed unbinding socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_bind(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// else if (method == "connect")
|
||||
// {
|
||||
// if (zmq_disconnect(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed disconnecting socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_setsockopt(fSocket, ZMQ_RCVTIMEO, &fRcvTimeout, sizeof(fRcvTimeout)) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed setting option on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// if (zmq_connect(fSocket, address.c_str()) != 0)
|
||||
// {
|
||||
// LOG(error) << "Failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LOG(error) << "timeout failed - unknown method provided!";
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (zmq_getsockopt(fControlSocket, ZMQ_SNDHWM, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_SNDHWM, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
auto Socket::GetReceiveTimeout() const -> int
|
||||
void Socket::SetRcvBufSize(const int value)
|
||||
{
|
||||
throw SocketError{"Not yet implemented."};
|
||||
// return fRcvTimeout;
|
||||
if (zmq_setsockopt(fControlSocket, ZMQ_RCVHWM, &value, sizeof(value)) < 0) {
|
||||
throw SocketError(tools::ToString("failed setting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
int Socket::GetRcvBufSize() const
|
||||
{
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (zmq_getsockopt(fControlSocket, ZMQ_RCVHWM, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_RCVHWM, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void Socket::SetSndKernelSize(const int value)
|
||||
{
|
||||
if (zmq_setsockopt(fControlSocket, ZMQ_SNDBUF, &value, sizeof(value)) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
int Socket::GetSndKernelSize() const
|
||||
{
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (zmq_getsockopt(fControlSocket, ZMQ_SNDBUF, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_SNDBUF, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void Socket::SetRcvKernelSize(const int value)
|
||||
{
|
||||
if (zmq_setsockopt(fControlSocket, ZMQ_RCVBUF, &value, sizeof(value)) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
int Socket::GetRcvKernelSize() const
|
||||
{
|
||||
int value = 0;
|
||||
size_t valueSize;
|
||||
if (zmq_getsockopt(fControlSocket, ZMQ_RCVBUF, &value, &valueSize) < 0) {
|
||||
throw SocketError(tools::ToString("failed getting ZMQ_RCVBUF, reason: ", zmq_strerror(errno)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
auto Socket::GetConstant(const string& constant) -> int
|
||||
|
@@ -32,7 +32,7 @@ namespace ofi
|
||||
*
|
||||
* @todo TODO insert long description
|
||||
*/
|
||||
class Socket : public fair::mq::Socket
|
||||
class Socket final : public fair::mq::Socket
|
||||
{
|
||||
public:
|
||||
Socket(Context& factory, const std::string& type, const std::string& name, const std::string& id = "");
|
||||
@@ -54,8 +54,18 @@ class Socket : public fair::mq::Socket
|
||||
auto TrySend(std::vector<MessagePtr>& msgVec) -> int64_t override;
|
||||
auto TryReceive(std::vector<MessagePtr>& msgVec) -> int64_t override;
|
||||
|
||||
auto GetSocket() const -> void* override { return fControlSocket; }
|
||||
auto GetSocket(int nothing) const -> int override { return -1; }
|
||||
auto GetSocket() const -> void* { return fControlSocket; }
|
||||
|
||||
void SetLinger(const int value) override;
|
||||
int GetLinger() const override;
|
||||
void SetSndBufSize(const int value) override;
|
||||
int GetSndBufSize() const override;
|
||||
void SetRcvBufSize(const int value) override;
|
||||
int GetRcvBufSize() const override;
|
||||
void SetSndKernelSize(const int value) override;
|
||||
int GetSndKernelSize() const override;
|
||||
void SetRcvKernelSize(const int value) override;
|
||||
int GetRcvKernelSize() const override;
|
||||
|
||||
auto Close() -> void override;
|
||||
|
||||
@@ -67,11 +77,6 @@ class Socket : public fair::mq::Socket
|
||||
auto GetMessagesTx() const -> unsigned long override { return fMessagesTx; }
|
||||
auto GetMessagesRx() const -> unsigned long override { return fMessagesRx; }
|
||||
|
||||
auto SetSendTimeout(const int timeout, const std::string& address, const std::string& method) -> bool override;
|
||||
auto GetSendTimeout() const -> int override;
|
||||
auto SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) -> bool override;
|
||||
auto GetReceiveTimeout() const -> int override;
|
||||
|
||||
static auto GetConstant(const std::string& constant) -> int;
|
||||
|
||||
~Socket() override;
|
||||
|
@@ -76,11 +76,6 @@ auto TransportFactory::CreatePoller(const unordered_map<string, vector<FairMQCha
|
||||
return PollerPtr{new Poller(channelsMap, channelList)};
|
||||
}
|
||||
|
||||
auto TransportFactory::CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const -> PollerPtr
|
||||
{
|
||||
return PollerPtr{new Poller(cmdSocket, dataSocket)};
|
||||
}
|
||||
|
||||
auto TransportFactory::CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback) const -> UnmanagedRegionPtr
|
||||
{
|
||||
throw runtime_error{"Not yet implemented UMR."};
|
||||
|
@@ -26,7 +26,7 @@ namespace ofi
|
||||
*
|
||||
* @todo TODO insert long description
|
||||
*/
|
||||
class TransportFactory : public FairMQTransportFactory
|
||||
class TransportFactory final : public FairMQTransportFactory
|
||||
{
|
||||
public:
|
||||
TransportFactory(const std::string& id = "", const FairMQProgOptions* config = nullptr);
|
||||
@@ -43,7 +43,6 @@ class TransportFactory : public FairMQTransportFactory
|
||||
auto CreatePoller(const std::vector<FairMQChannel>& channels) const -> PollerPtr override;
|
||||
auto CreatePoller(const std::vector<const FairMQChannel*>& channels) const -> PollerPtr override;
|
||||
auto CreatePoller(const std::unordered_map<std::string, std::vector<FairMQChannel>>& channelsMap, const std::vector<std::string>& channelList) const -> PollerPtr override;
|
||||
auto CreatePoller(const FairMQSocket& cmdSocket, const FairMQSocket& dataSocket) const -> PollerPtr override;
|
||||
|
||||
auto CreateUnmanagedRegion(const size_t size, FairMQRegionCallback callback = nullptr) const -> UnmanagedRegionPtr override;
|
||||
|
||||
@@ -51,6 +50,7 @@ class TransportFactory : public FairMQTransportFactory
|
||||
|
||||
void Interrupt() override {}
|
||||
void Resume() override {}
|
||||
void Reset() override {}
|
||||
|
||||
private:
|
||||
mutable Context fContext;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
@@ -151,6 +153,7 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
|
||||
commonChannel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
|
||||
commonChannel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", commonChannel.GetSndKernelSize()));
|
||||
commonChannel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", commonChannel.GetRcvKernelSize()));
|
||||
commonChannel.UpdateLinger(q.second.get<int>("linger", commonChannel.GetLinger()));
|
||||
commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
|
||||
|
||||
// temporary FairMQChannel container
|
||||
@@ -170,6 +173,7 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& ch
|
||||
LOG(debug) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
|
||||
LOG(debug) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize();
|
||||
LOG(debug) << "\trcvKernelSize = " << commonChannel.GetRcvKernelSize();
|
||||
LOG(debug) << "\tlinger = " << commonChannel.GetLinger();
|
||||
LOG(debug) << "\trateLogging = " << commonChannel.GetRateLogging();
|
||||
|
||||
for (int i = 0; i < numSockets; ++i)
|
||||
@@ -212,6 +216,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
|
||||
channel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
|
||||
channel.UpdateSndKernelSize(q.second.get<int>("sndKernelSize", channel.GetSndKernelSize()));
|
||||
channel.UpdateRcvKernelSize(q.second.get<int>("rcvKernelSize", channel.GetRcvKernelSize()));
|
||||
channel.UpdateLinger(q.second.get<int>("linger", channel.GetLinger()));
|
||||
channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging()));
|
||||
|
||||
LOG(debug) << "" << channelName << "[" << socketCounter << "]:";
|
||||
@@ -223,6 +228,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
|
||||
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
|
||||
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
|
||||
LOG(debug) << "\tlinger = " << channel.GetLinger();
|
||||
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
|
||||
|
||||
channelList.push_back(channel);
|
||||
@@ -251,6 +257,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
|
||||
LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize();
|
||||
LOG(debug) << "\trcvKernelSize = " << channel.GetRcvKernelSize();
|
||||
LOG(debug) << "\tlinger = " << channel.GetLinger();
|
||||
LOG(debug) << "\trateLogging = " << channel.GetRateLogging();
|
||||
|
||||
channelList.push_back(channel);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -20,6 +20,9 @@
|
||||
#include "FairMQSuboptParser.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
@@ -136,16 +139,16 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
|
||||
fair::Logger::SetConsoleSeverity(severity);
|
||||
}
|
||||
|
||||
string id;
|
||||
string idForParser;
|
||||
|
||||
// check if config-key for config parser is provided
|
||||
if (fVarMap.count("config-key"))
|
||||
{
|
||||
id = fVarMap["config-key"].as<string>();
|
||||
idForParser = fVarMap["config-key"].as<string>();
|
||||
}
|
||||
else if (fVarMap.count("id"))
|
||||
{
|
||||
id = fVarMap["id"].as<string>();
|
||||
idForParser = fVarMap["id"].as<string>();
|
||||
}
|
||||
|
||||
// check if any config parser is selected
|
||||
@@ -154,12 +157,12 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
|
||||
if (fVarMap.count("mq-config"))
|
||||
{
|
||||
LOG(debug) << "mq-config: Using default JSON parser";
|
||||
UpdateChannelMap(parser::JSON().UserParser(fVarMap.at("mq-config").as<string>(), id));
|
||||
UpdateChannelMap(parser::JSON().UserParser(fVarMap.at("mq-config").as<string>(), idForParser));
|
||||
}
|
||||
else if (fVarMap.count("channel-config"))
|
||||
{
|
||||
LOG(debug) << "channel-config: Parsing channel configuration";
|
||||
UpdateChannelMap(parser::SUBOPT().UserParser(fVarMap.at("channel-config").as<vector<string>>(), id));
|
||||
ParseChannelsFromCmdLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -182,8 +185,27 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FairMQProgOptions::ParseChannelsFromCmdLine()
|
||||
{
|
||||
string idForParser;
|
||||
|
||||
// check if config-key for config parser is provided
|
||||
if (fVarMap.count("config-key"))
|
||||
{
|
||||
idForParser = fVarMap["config-key"].as<string>();
|
||||
}
|
||||
else if (fVarMap.count("id"))
|
||||
{
|
||||
idForParser = fVarMap["id"].as<string>();
|
||||
}
|
||||
|
||||
UpdateChannelMap(parser::SUBOPT().UserParser(fVarMap.at("channel-config").as<vector<string>>(), idForParser));
|
||||
}
|
||||
|
||||
void FairMQProgOptions::ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered)
|
||||
{
|
||||
fVarMap.clear();
|
||||
|
||||
// get options from cmd line and store in variable map
|
||||
// here we use command_line_parser instead of parse_command_line, to allow unregistered and positional options
|
||||
if (allowUnregistered)
|
||||
@@ -205,8 +227,7 @@ void FairMQProgOptions::ParseCmdLine(const int argc, char const* const* argv, bo
|
||||
|
||||
void FairMQProgOptions::ParseDefaults()
|
||||
{
|
||||
vector<string> emptyArgs;
|
||||
emptyArgs.push_back("dummy");
|
||||
vector<string> emptyArgs = {"dummy", "--id", boost::uuids::to_string(boost::uuids::random_generator()())};
|
||||
|
||||
vector<const char*> argv(emptyArgs.size());
|
||||
|
||||
@@ -264,6 +285,7 @@ void FairMQProgOptions::UpdateMQValues()
|
||||
string rcvBufSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvBufSize";
|
||||
string sndKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".sndKernelSize";
|
||||
string rcvKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvKernelSize";
|
||||
string lingerKey = "chans." + p.first + "." + to_string(index) + ".linger";
|
||||
string rateLoggingKey = "chans." + p.first + "." + to_string(index) + ".rateLogging";
|
||||
|
||||
fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"};
|
||||
@@ -274,6 +296,7 @@ void FairMQProgOptions::UpdateMQValues()
|
||||
fChannelKeyMap[rcvBufSizeKey] = ChannelKey{p.first, index, "rcvBufSize"};
|
||||
fChannelKeyMap[sndKernelSizeKey] = ChannelKey{p.first, index, "sndKernelSize"};
|
||||
fChannelKeyMap[rcvKernelSizeKey] = ChannelKey{p.first, index, "rcvkernelSize"};
|
||||
fChannelKeyMap[lingerKey] = ChannelKey{p.first, index, "linger"};
|
||||
fChannelKeyMap[rateLoggingKey] = ChannelKey{p.first, index, "rateLogging"};
|
||||
|
||||
UpdateVarMap<string>(typeKey, channel.GetType());
|
||||
@@ -284,6 +307,7 @@ void FairMQProgOptions::UpdateMQValues()
|
||||
UpdateVarMap<int>(rcvBufSizeKey, channel.GetRcvBufSize());
|
||||
UpdateVarMap<int>(sndKernelSizeKey, channel.GetSndKernelSize());
|
||||
UpdateVarMap<int>(rcvKernelSizeKey, channel.GetRcvKernelSize());
|
||||
UpdateVarMap<int>(lingerKey, channel.GetLinger());
|
||||
UpdateVarMap<int>(rateLoggingKey, channel.GetRateLogging());
|
||||
|
||||
index++;
|
||||
@@ -339,6 +363,24 @@ int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "sndKernelSize")
|
||||
{
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateSndKernelSize(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "rcvKernelSize")
|
||||
{
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateRcvKernelSize(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "linger")
|
||||
{
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateLinger(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "rateLogging")
|
||||
{
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
|
||||
@@ -423,7 +465,7 @@ int FairMQProgOptions::PrintOptions()
|
||||
{
|
||||
ss << setfill(' ') << left
|
||||
<< setw(maxLenKey) << p.first << " = "
|
||||
<< setw(maxLenValue) << p.second.value
|
||||
<< setw(maxLenValue) << p.second.value << " "
|
||||
<< setw(maxLenType) << p.second.type
|
||||
<< setw(maxLenDefault) << p.second.defaulted
|
||||
<< "\n";
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -59,13 +59,13 @@ class FairMQProgOptions
|
||||
// update variable map
|
||||
UpdateVarMap<typename std::decay<T>::type>(key, val);
|
||||
|
||||
// update FairMQChannel map if the key is a channel key
|
||||
if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
|
||||
if (key == "channel-config")
|
||||
{
|
||||
if (fChannelKeyMap.count(key))
|
||||
{
|
||||
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val);
|
||||
}
|
||||
ParseChannelsFromCmdLine();
|
||||
}
|
||||
else if (fChannelKeyMap.count(key))
|
||||
{
|
||||
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val);
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
@@ -162,6 +162,11 @@ class FairMQProgOptions
|
||||
int PrintOptions();
|
||||
int PrintOptionsRaw();
|
||||
|
||||
void AddChannel(const std::string& channelName, const FairMQChannel& channel)
|
||||
{
|
||||
fFairMQChannelMap[channelName].push_back(channel);
|
||||
}
|
||||
|
||||
private:
|
||||
struct ChannelKey
|
||||
{
|
||||
@@ -205,6 +210,12 @@ class FairMQProgOptions
|
||||
}
|
||||
|
||||
int UpdateChannelMap(const FairMQChannelMap& map);
|
||||
template<typename T>
|
||||
int UpdateChannelValue(const std::string&, int, const std::string&, T)
|
||||
{
|
||||
LOG(error) << "update of FairMQChannel map failed, because value type not supported";
|
||||
return 1;
|
||||
}
|
||||
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, const std::string& val);
|
||||
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, int val);
|
||||
|
||||
@@ -218,6 +229,7 @@ class FairMQProgOptions
|
||||
vm[key].value() = boost::any(val);
|
||||
}
|
||||
|
||||
void ParseChannelsFromCmdLine();
|
||||
};
|
||||
|
||||
#endif /* FAIRMQPROGOPTIONS_H */
|
||||
|
@@ -56,6 +56,7 @@ struct SUBOPT
|
||||
RCVBUFSIZE, // size of the receive queue
|
||||
SNDKERNELSIZE,
|
||||
RCVKERNELSIZE,
|
||||
LINGER,
|
||||
RATELOGGING, // logging rate
|
||||
NUMSOCKETS,
|
||||
lastsocketkey
|
||||
@@ -71,6 +72,7 @@ struct SUBOPT
|
||||
/*[RCVBUFSIZE] = */ "rcvBufSize",
|
||||
/*[SNDKERNELSIZE] = */ "sndKernelSize",
|
||||
/*[RCVKERNELSIZE] = */ "rcvKernelSize",
|
||||
/*[LINGER] = */ "linger",
|
||||
/*[RATELOGGING] = */ "rateLogging",
|
||||
/*[NUMSOCKETS] = */ "numSockets",
|
||||
nullptr
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -11,18 +11,26 @@
|
||||
#include <termios.h> // for the interactive mode
|
||||
#include <poll.h> // for the interactive mode
|
||||
#include <csignal> // catching system signals
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace
|
||||
{
|
||||
// ugly global state, but std::signal gives us no other choice
|
||||
std::function<void(int)> gSignalHandlerClosure;
|
||||
std::atomic<sig_atomic_t> gLastSignal(0);
|
||||
std::atomic<int> gSignalCount(0);
|
||||
|
||||
extern "C" auto signal_handler(int signal) -> void
|
||||
{
|
||||
gSignalHandlerClosure(signal);
|
||||
++gSignalCount;
|
||||
gLastSignal = signal;
|
||||
|
||||
if (gSignalCount > 1)
|
||||
{
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,15 +41,27 @@ namespace mq
|
||||
namespace plugins
|
||||
{
|
||||
|
||||
Control::Control(const string name, const Plugin::Version version, const string maintainer, const string homepage, PluginServices* pluginServices)
|
||||
Control::Control(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices)
|
||||
: Plugin(name, version, maintainer, homepage, pluginServices)
|
||||
, fControllerThread()
|
||||
, fSignalHandlerThread()
|
||||
, fEvents()
|
||||
, fEventsMutex()
|
||||
, fControllerMutex()
|
||||
, fNewEvent()
|
||||
, fDeviceTerminationRequested{false}
|
||||
, fDeviceShutdownRequested(false)
|
||||
, fDeviceHasShutdown(false)
|
||||
, fPluginShutdownRequested(false)
|
||||
{
|
||||
SubscribeToDeviceStateChange([&](DeviceState newState)
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock{fEventsMutex};
|
||||
fEvents.push(newState);
|
||||
}
|
||||
fNewEvent.notify_one();
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
TakeDeviceControl();
|
||||
@@ -73,7 +93,7 @@ Control::Control(const string name, const Plugin::Version version, const string
|
||||
LOG(debug) << "catch-signals: " << GetProperty<int>("catch-signals");
|
||||
if (GetProperty<int>("catch-signals") > 0)
|
||||
{
|
||||
gSignalHandlerClosure = bind(&Control::SignalHandler, this, placeholders::_1);
|
||||
fSignalHandlerThread = thread(&Control::SignalHandler, this);
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
}
|
||||
@@ -93,124 +113,140 @@ auto ControlPluginProgramOptions() -> Plugin::ProgOptions
|
||||
return pluginOptions;
|
||||
}
|
||||
|
||||
auto Control::InteractiveMode() -> void
|
||||
struct terminal_config
|
||||
{
|
||||
try
|
||||
terminal_config()
|
||||
{
|
||||
RunStartupSequence();
|
||||
|
||||
char input; // hold the user console input
|
||||
pollfd cinfd[1];
|
||||
cinfd[0].fd = fileno(stdin);
|
||||
cinfd[0].events = POLLIN;
|
||||
|
||||
struct termios t;
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag &= ~ICANON; // disable canonical input
|
||||
t.c_lflag &= ~ECHO; // do not echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
|
||||
PrintInteractiveHelp();
|
||||
|
||||
bool keepRunning = true;
|
||||
|
||||
while (keepRunning)
|
||||
{
|
||||
if (poll(cinfd, 1, 500))
|
||||
{
|
||||
if (fDeviceTerminationRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
cin >> input;
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case 'i':
|
||||
LOG(info) << "\n\n --> [i] init device\n";
|
||||
ChangeDeviceState(DeviceStateTransition::InitDevice);
|
||||
break;
|
||||
case 'j':
|
||||
LOG(info) << "\n\n --> [j] init task\n";
|
||||
ChangeDeviceState(DeviceStateTransition::InitTask);
|
||||
break;
|
||||
case 'p':
|
||||
LOG(info) << "\n\n --> [p] pause\n";
|
||||
ChangeDeviceState(DeviceStateTransition::Pause);
|
||||
break;
|
||||
case 'r':
|
||||
LOG(info) << "\n\n --> [r] run\n";
|
||||
ChangeDeviceState(DeviceStateTransition::Run);
|
||||
break;
|
||||
case 's':
|
||||
LOG(info) << "\n\n --> [s] stop\n";
|
||||
ChangeDeviceState(DeviceStateTransition::Stop);
|
||||
break;
|
||||
case 't':
|
||||
LOG(info) << "\n\n --> [t] reset task\n";
|
||||
ChangeDeviceState(DeviceStateTransition::ResetTask);
|
||||
break;
|
||||
case 'd':
|
||||
LOG(info) << "\n\n --> [d] reset device\n";
|
||||
ChangeDeviceState(DeviceStateTransition::ResetDevice);
|
||||
break;
|
||||
case 'k':
|
||||
LOG(info) << "\n\n --> [k] increase log severity\n";
|
||||
CycleLogConsoleSeverityUp();
|
||||
break;
|
||||
case 'l':
|
||||
LOG(info) << "\n\n --> [l] decrease log severity\n";
|
||||
CycleLogConsoleSeverityDown();
|
||||
break;
|
||||
case 'n':
|
||||
LOG(info) << "\n\n --> [n] increase log verbosity\n";
|
||||
CycleLogVerbosityUp();
|
||||
break;
|
||||
case 'm':
|
||||
LOG(info) << "\n\n --> [m] decrease log verbosity\n";
|
||||
CycleLogVerbosityDown();
|
||||
break;
|
||||
case 'h':
|
||||
LOG(info) << "\n\n --> [h] help\n";
|
||||
PrintInteractiveHelp();
|
||||
break;
|
||||
// case 'x':
|
||||
// LOG(info) << "\n\n --> [x] ERROR\n";
|
||||
// ChangeDeviceState(DeviceStateTransition::ERROR_FOUND);
|
||||
// break;
|
||||
case 'q':
|
||||
LOG(info) << "\n\n --> [q] end\n";
|
||||
keepRunning = false;
|
||||
break;
|
||||
default:
|
||||
LOG(info) << "Invalid input: [" << input << "]";
|
||||
PrintInteractiveHelp();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fDeviceTerminationRequested)
|
||||
{
|
||||
keepRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
~terminal_config()
|
||||
{
|
||||
termios t;
|
||||
tcgetattr(STDIN_FILENO, &t); // get the current terminal I/O structure
|
||||
t.c_lflag |= ICANON; // re-enable canonical input
|
||||
t.c_lflag |= ECHO; // echo input chars
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
}
|
||||
};
|
||||
|
||||
if (!fDeviceTerminationRequested)
|
||||
auto Control::InteractiveMode() -> void
|
||||
try
|
||||
{
|
||||
RunStartupSequence();
|
||||
|
||||
char input; // hold the user console input
|
||||
pollfd cinfd[1];
|
||||
cinfd[0].fd = fileno(stdin);
|
||||
cinfd[0].events = POLLIN;
|
||||
cinfd[0].revents = 0;
|
||||
|
||||
terminal_config tconfig;
|
||||
|
||||
PrintInteractiveHelp();
|
||||
|
||||
bool keepRunning = true;
|
||||
|
||||
while (keepRunning)
|
||||
{
|
||||
if (poll(cinfd, 1, 500))
|
||||
{
|
||||
RunShutdownSequence();
|
||||
if (fDeviceShutdownRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
cin >> input;
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case 'i':
|
||||
LOG(info) << "\n\n --> [i] init device\n";
|
||||
ChangeDeviceState(DeviceStateTransition::InitDevice);
|
||||
break;
|
||||
case 'j':
|
||||
LOG(info) << "\n\n --> [j] init task\n";
|
||||
ChangeDeviceState(DeviceStateTransition::InitTask);
|
||||
break;
|
||||
case 'p':
|
||||
LOG(info) << "\n\n --> [p] pause\n";
|
||||
ChangeDeviceState(DeviceStateTransition::Pause);
|
||||
break;
|
||||
case 'r':
|
||||
LOG(info) << "\n\n --> [r] run\n";
|
||||
ChangeDeviceState(DeviceStateTransition::Run);
|
||||
break;
|
||||
case 's':
|
||||
LOG(info) << "\n\n --> [s] stop\n";
|
||||
ChangeDeviceState(DeviceStateTransition::Stop);
|
||||
break;
|
||||
case 't':
|
||||
LOG(info) << "\n\n --> [t] reset task\n";
|
||||
ChangeDeviceState(DeviceStateTransition::ResetTask);
|
||||
break;
|
||||
case 'd':
|
||||
LOG(info) << "\n\n --> [d] reset device\n";
|
||||
ChangeDeviceState(DeviceStateTransition::ResetDevice);
|
||||
break;
|
||||
case 'k':
|
||||
LOG(info) << "\n\n --> [k] increase log severity\n";
|
||||
CycleLogConsoleSeverityUp();
|
||||
break;
|
||||
case 'l':
|
||||
LOG(info) << "\n\n --> [l] decrease log severity\n";
|
||||
CycleLogConsoleSeverityDown();
|
||||
break;
|
||||
case 'n':
|
||||
LOG(info) << "\n\n --> [n] increase log verbosity\n";
|
||||
CycleLogVerbosityUp();
|
||||
break;
|
||||
case 'm':
|
||||
LOG(info) << "\n\n --> [m] decrease log verbosity\n";
|
||||
CycleLogVerbosityDown();
|
||||
break;
|
||||
case 'h':
|
||||
LOG(info) << "\n\n --> [h] help\n";
|
||||
PrintInteractiveHelp();
|
||||
break;
|
||||
// case 'x':
|
||||
// LOG(info) << "\n\n --> [x] ERROR\n";
|
||||
// ChangeDeviceState(DeviceStateTransition::ERROR_FOUND);
|
||||
// break;
|
||||
case 'q':
|
||||
LOG(info) << "\n\n --> [q] end\n";
|
||||
keepRunning = false;
|
||||
break;
|
||||
default:
|
||||
LOG(info) << "Invalid input: [" << input << "]";
|
||||
PrintInteractiveHelp();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetCurrentDeviceState() == DeviceState::Error)
|
||||
{
|
||||
throw DeviceErrorState("Controlled device transitioned to error state.");
|
||||
}
|
||||
|
||||
if (fDeviceShutdownRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (PluginServices::DeviceControlError& e)
|
||||
{
|
||||
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
||||
LOG(debug) << e.what();
|
||||
}
|
||||
|
||||
RunShutdownSequence();
|
||||
}
|
||||
catch (PluginServices::DeviceControlError& e)
|
||||
{
|
||||
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
||||
LOG(debug) << e.what();
|
||||
}
|
||||
catch (DeviceErrorState&)
|
||||
{
|
||||
}
|
||||
|
||||
auto Control::PrintInteractiveHelp() -> void
|
||||
@@ -231,66 +267,84 @@ auto Control::WaitForNextState() -> DeviceState
|
||||
}
|
||||
|
||||
auto result = fEvents.front();
|
||||
|
||||
if (result == DeviceState::Error)
|
||||
{
|
||||
throw DeviceErrorState("Controlled device transitioned to error state.");
|
||||
}
|
||||
|
||||
fEvents.pop();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
auto Control::StaticMode() -> void
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
RunStartupSequence();
|
||||
RunStartupSequence();
|
||||
|
||||
{
|
||||
// Wait for next state, which is DeviceState::Ready,
|
||||
// or for device shutdown request (Ctrl-C)
|
||||
unique_lock<mutex> lock{fEventsMutex};
|
||||
while (fEvents.empty() && !fDeviceShutdownRequested)
|
||||
{
|
||||
// Wait for next state, which is DeviceState::Ready,
|
||||
// or for device termination request
|
||||
unique_lock<mutex> lock{fEventsMutex};
|
||||
while (fEvents.empty() && !fDeviceTerminationRequested)
|
||||
{
|
||||
fNewEvent.wait(lock);
|
||||
}
|
||||
fNewEvent.wait_for(lock, chrono::milliseconds(50));
|
||||
}
|
||||
|
||||
if (!fDeviceTerminationRequested)
|
||||
if (fEvents.front() == DeviceState::Error)
|
||||
{
|
||||
RunShutdownSequence();
|
||||
throw DeviceErrorState("Controlled device transitioned to error state.");
|
||||
}
|
||||
}
|
||||
catch (PluginServices::DeviceControlError& e)
|
||||
{
|
||||
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
||||
LOG(debug) << e.what();
|
||||
}
|
||||
|
||||
RunShutdownSequence();
|
||||
}
|
||||
catch (PluginServices::DeviceControlError& e)
|
||||
{
|
||||
// If we are here, it means another plugin has taken control. That's fine, just print the exception message and do nothing else.
|
||||
LOG(debug) << e.what();
|
||||
}
|
||||
catch (DeviceErrorState&)
|
||||
{
|
||||
}
|
||||
|
||||
auto Control::SignalHandler(int signal) -> void
|
||||
auto Control::SignalHandler() -> void
|
||||
{
|
||||
if (!fDeviceTerminationRequested)
|
||||
while (gSignalCount == 0 && !fPluginShutdownRequested)
|
||||
{
|
||||
fDeviceTerminationRequested = true;
|
||||
this_thread::sleep_for(chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
StealDeviceControl();
|
||||
|
||||
LOG(info) << "Received device shutdown request (signal " << signal << ").";
|
||||
if (!fPluginShutdownRequested)
|
||||
{
|
||||
LOG(info) << "Received device shutdown request (signal " << gLastSignal << ").";
|
||||
LOG(info) << "Waiting for graceful device shutdown. Hit Ctrl-C again to abort immediately.";
|
||||
|
||||
UnsubscribeFromDeviceStateChange(); // In case, static or interactive mode have subscribed already
|
||||
SubscribeToDeviceStateChange([&](DeviceState newState)
|
||||
// Signal and wait for controller thread, if we are controller
|
||||
fDeviceShutdownRequested = true;
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock{fEventsMutex};
|
||||
fEvents.push(newState);
|
||||
}
|
||||
fNewEvent.notify_one();
|
||||
});
|
||||
unique_lock<mutex> lock(fControllerMutex);
|
||||
if (fControllerThread.joinable()) fControllerThread.join();
|
||||
}
|
||||
|
||||
fSignalHandlerThread = thread(&Control::RunShutdownSequence, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(warn) << "Received 2nd device shutdown request (signal " << signal << ").";
|
||||
LOG(warn) << "Aborting immediately !";
|
||||
abort();
|
||||
if (!fDeviceHasShutdown)
|
||||
{
|
||||
// Take over control and attempt graceful shutdown
|
||||
StealDeviceControl();
|
||||
try
|
||||
{
|
||||
RunShutdownSequence();
|
||||
}
|
||||
catch (PluginServices::DeviceControlError& e)
|
||||
{
|
||||
LOG(info) << "Graceful device shutdown failed: " << e.what() << " If hanging, hit Ctrl-C again to abort immediately.";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG(info) << "Graceful device shutdown failed. If hanging, hit Ctrl-C again to abort immediately.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +352,7 @@ auto Control::RunShutdownSequence() -> void
|
||||
{
|
||||
auto nextState = GetCurrentDeviceState();
|
||||
EmptyEventQueue();
|
||||
while (nextState != DeviceState::Exiting)
|
||||
while (nextState != DeviceState::Exiting && nextState != DeviceState::Error)
|
||||
{
|
||||
switch (nextState)
|
||||
{
|
||||
@@ -318,27 +372,19 @@ auto Control::RunShutdownSequence() -> void
|
||||
ChangeDeviceState(DeviceStateTransition::Resume);
|
||||
break;
|
||||
default:
|
||||
LOG(debug) << "Controller ignoring event: " << nextState;
|
||||
break;
|
||||
}
|
||||
|
||||
nextState = WaitForNextState();
|
||||
}
|
||||
|
||||
UnsubscribeFromDeviceStateChange();
|
||||
fDeviceHasShutdown = true;
|
||||
ReleaseDeviceControl();
|
||||
}
|
||||
|
||||
auto Control::RunStartupSequence() -> void
|
||||
{
|
||||
SubscribeToDeviceStateChange([&](DeviceState newState)
|
||||
{
|
||||
{
|
||||
lock_guard<mutex> lock{fEventsMutex};
|
||||
fEvents.push(newState);
|
||||
}
|
||||
fNewEvent.notify_one();
|
||||
});
|
||||
|
||||
ChangeDeviceState(DeviceStateTransition::InitDevice);
|
||||
while (WaitForNextState() != DeviceState::DeviceReady) {}
|
||||
ChangeDeviceState(DeviceStateTransition::InitTask);
|
||||
@@ -355,8 +401,16 @@ auto Control::EmptyEventQueue() -> void
|
||||
|
||||
Control::~Control()
|
||||
{
|
||||
if (fControllerThread.joinable()) fControllerThread.join();
|
||||
// Notify threads to exit
|
||||
fPluginShutdownRequested = true;
|
||||
|
||||
{
|
||||
unique_lock<mutex> lock(fControllerMutex);
|
||||
if (fControllerThread.joinable()) fControllerThread.join();
|
||||
}
|
||||
if (fSignalHandlerThread.joinable()) fSignalHandlerThread.join();
|
||||
|
||||
UnsubscribeFromDeviceStateChange();
|
||||
}
|
||||
|
||||
} /* namespace plugins */
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#define FAIR_MQ_PLUGINS_CONTROL
|
||||
|
||||
#include <fairmq/Plugin.h>
|
||||
#include <fairmq/Version.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
@@ -28,16 +30,16 @@ namespace plugins
|
||||
class Control : public Plugin
|
||||
{
|
||||
public:
|
||||
Control(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices);
|
||||
Control(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices);
|
||||
|
||||
~Control();
|
||||
|
||||
private:
|
||||
auto InteractiveMode() -> void;
|
||||
auto PrintInteractiveHelp() -> void;
|
||||
static auto PrintInteractiveHelp() -> void;
|
||||
auto StaticMode() -> void;
|
||||
auto WaitForNextState() -> DeviceState;
|
||||
auto SignalHandler(int signal) -> void;
|
||||
auto SignalHandler() -> void;
|
||||
auto RunShutdownSequence() -> void;
|
||||
auto RunStartupSequence() -> void;
|
||||
auto EmptyEventQueue() -> void;
|
||||
@@ -46,20 +48,28 @@ class Control : public Plugin
|
||||
std::thread fSignalHandlerThread;
|
||||
std::queue<DeviceState> fEvents;
|
||||
std::mutex fEventsMutex;
|
||||
std::mutex fControllerMutex;
|
||||
std::condition_variable fNewEvent;
|
||||
std::atomic<bool> fDeviceTerminationRequested;
|
||||
std::atomic<bool> fDeviceShutdownRequested;
|
||||
std::atomic<bool> fDeviceHasShutdown;
|
||||
std::atomic<bool> fPluginShutdownRequested;
|
||||
|
||||
struct DeviceErrorState : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
}; /* class Control */
|
||||
|
||||
auto ControlPluginProgramOptions() -> Plugin::ProgOptions;
|
||||
|
||||
REGISTER_FAIRMQ_PLUGIN(
|
||||
Control, // Class name
|
||||
control, // Plugin name (string, lower case chars only)
|
||||
(Plugin::Version{1,0,1}), // Version
|
||||
"FairRootGroup <fairroot@gsi.de>", // Maintainer
|
||||
"https://github.com/FairRootGroup/FairRoot", // Homepage
|
||||
ControlPluginProgramOptions // Free function which declares custom program options for the plugin
|
||||
// signature: () -> boost::optional<boost::program_options::options_description>
|
||||
Control, // Class name
|
||||
control, // Plugin name (string, lower case chars only)
|
||||
(Plugin::Version{FAIRMQ_VERSION_MAJOR,
|
||||
FAIRMQ_VERSION_MINOR,
|
||||
FAIRMQ_VERSION_PATCH}), // Version
|
||||
"FairRootGroup <fairroot@gsi.de>", // Maintainer
|
||||
"https://github.com/FairRootGroup/FairRoot", // Homepage
|
||||
ControlPluginProgramOptions // Free function which declares custom program options for the
|
||||
// plugin signature: () ->
|
||||
// boost::optional<boost::program_options::options_description>
|
||||
)
|
||||
|
||||
} /* namespace plugins */
|
||||
|
@@ -31,7 +31,7 @@ namespace mq
|
||||
namespace plugins
|
||||
{
|
||||
|
||||
DDS::DDS(const string name, const Plugin::Version version, const string maintainer, const string homepage, PluginServices* pluginServices)
|
||||
DDS::DDS(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices)
|
||||
: Plugin(name, version, maintainer, homepage, pluginServices)
|
||||
, fService()
|
||||
, fDDSCustomCmd(fService)
|
||||
|
@@ -61,7 +61,7 @@ struct IofN
|
||||
class DDS : public Plugin
|
||||
{
|
||||
public:
|
||||
DDS(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices);
|
||||
DDS(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices);
|
||||
|
||||
~DDS();
|
||||
|
||||
|
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <unistd.h>
|
||||
@@ -34,24 +33,27 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
string sessionID;
|
||||
char commandChar;
|
||||
char command = ' ';
|
||||
string topologyPath;
|
||||
|
||||
bpo::options_description options("fairmq-dds-command-ui options");
|
||||
options.add_options()
|
||||
("session,s", bpo::value<string>(&sessionID)->required(), "DDS Session ID")
|
||||
("command,c", bpo::value<char> (&commandChar)->default_value(' '), "Command character")
|
||||
("session,s", bpo::value<string> (&sessionID)->required(), "DDS Session ID")
|
||||
("command,c", bpo::value<char> (&command)->default_value(' '), "Command character")
|
||||
("path,p", bpo::value<string> (&topologyPath)->default_value(""), "DDS Topology path to send command to")
|
||||
("help,h", "Produce help message");
|
||||
|
||||
bpo::variables_map vm;
|
||||
bpo::store(bpo::command_line_parser(argc, argv).options(options).run(), vm);
|
||||
bpo::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
cout << "FairMQ DDS Command UI" << endl << options << endl;
|
||||
cout << "possible command characters: [c] check states, [o] dump config, [h] help, [p] pause, [r] run, [s] stop, [t] reset task, [d] reset device, [q] end, [j] init task, [i] init device" << endl;
|
||||
cout << "Commands: [c] check state, [o] dump config, [h] help, [p] pause, [r] run, [s] stop, [t] reset task, [d] reset device, [q] end, [j] init task, [i] init device" << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
CIntercomService service;
|
||||
CCustomCmd ddsCustomCmd(service);
|
||||
|
||||
@@ -61,7 +63,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// subscribe to receive messages from DDS
|
||||
ddsCustomCmd.subscribe([](const string& msg, const string& /*condition*/, uint64_t /*senderId*/) {
|
||||
cout << "Received: " << msg << endl;
|
||||
cout << "Received: " << endl << msg << endl;
|
||||
});
|
||||
|
||||
service.start(sessionID);
|
||||
@@ -74,8 +76,8 @@ int main(int argc, char* argv[])
|
||||
t.c_lflag &= ~ICANON; // disable canonical input
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &t); // apply the new settings
|
||||
|
||||
if (commandChar != ' ') {
|
||||
cin.putback(commandChar);
|
||||
if (command != ' ') {
|
||||
cin.putback(command);
|
||||
} else {
|
||||
PrintControlsHelp();
|
||||
}
|
||||
@@ -84,39 +86,39 @@ int main(int argc, char* argv[])
|
||||
switch (c) {
|
||||
case 'c':
|
||||
cout << " > checking state of the devices" << endl;
|
||||
ddsCustomCmd.send("check-state", "");
|
||||
ddsCustomCmd.send("check-state", topologyPath);
|
||||
break;
|
||||
case 'o':
|
||||
cout << " > dumping config of the devices" << endl;
|
||||
ddsCustomCmd.send("dump-config", "");
|
||||
ddsCustomCmd.send("dump-config", topologyPath);
|
||||
break;
|
||||
case 'i':
|
||||
cout << " > init devices" << endl;
|
||||
ddsCustomCmd.send("INIT DEVICE", "");
|
||||
ddsCustomCmd.send("INIT DEVICE", topologyPath);
|
||||
break;
|
||||
case 'j':
|
||||
cout << " > init tasks" << endl;
|
||||
ddsCustomCmd.send("INIT TASK", "");
|
||||
ddsCustomCmd.send("INIT TASK", topologyPath);
|
||||
break;
|
||||
case 'p':
|
||||
cout << " > pause devices" << endl;
|
||||
ddsCustomCmd.send("PAUSE", "");
|
||||
ddsCustomCmd.send("PAUSE", topologyPath);
|
||||
break;
|
||||
case 'r':
|
||||
cout << " > run tasks" << endl;
|
||||
ddsCustomCmd.send("RUN", "");
|
||||
ddsCustomCmd.send("RUN", topologyPath);
|
||||
break;
|
||||
case 's':
|
||||
cout << " > stop devices" << endl;
|
||||
ddsCustomCmd.send("STOP", "");
|
||||
ddsCustomCmd.send("STOP", topologyPath);
|
||||
break;
|
||||
case 't':
|
||||
cout << " > reset tasks" << endl;
|
||||
ddsCustomCmd.send("RESET TASK", "");
|
||||
ddsCustomCmd.send("RESET TASK", topologyPath);
|
||||
break;
|
||||
case 'd':
|
||||
cout << " > reset devices" << endl;
|
||||
ddsCustomCmd.send("RESET DEVICE", "");
|
||||
ddsCustomCmd.send("RESET DEVICE", topologyPath);
|
||||
break;
|
||||
case 'h':
|
||||
cout << " > help" << endl;
|
||||
@@ -124,7 +126,7 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
case 'q':
|
||||
cout << " > end" << endl;
|
||||
ddsCustomCmd.send("END", "");
|
||||
ddsCustomCmd.send("END", topologyPath);
|
||||
break;
|
||||
default:
|
||||
cout << "Invalid input: [" << c << "]" << endl;
|
||||
@@ -132,8 +134,8 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
if (commandChar != ' ') {
|
||||
usleep(50000);
|
||||
if (command != ' ') {
|
||||
this_thread::sleep_for(chrono::milliseconds(100)); // give dds a chance to complete request
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
@@ -16,9 +16,11 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("out-channel", bpo::value<std::string>()->default_value("data"), "Name of the output channel")
|
||||
("same-msg", bpo::value<bool>()->default_value(false), "Re-send the same message, or recreate for each iteration")
|
||||
("msg-size", bpo::value<int>()->default_value(1000000), "Message size in bytes")
|
||||
("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads")
|
||||
("num-parts", bpo::value<size_t>()->default_value(1), "Number of parts to send. 1 will send single messages, not parts")
|
||||
("msg-size", bpo::value<size_t>()->default_value(1000000), "Message size in bytes")
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)")
|
||||
("msg-rate", bpo::value<int>()->default_value(0), "Msg rate limit in maximum number of messages per second");
|
||||
("msg-rate", bpo::value<float>()->default_value(0), "Msg rate limit in maximum number of messages per second");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::vector<std::string>>()->multitoken(), "Names of the output channels")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -16,7 +16,7 @@ void addCustomOptions(bpo::options_description& options)
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data-in"), "Name of the input channel")
|
||||
("out-channel", bpo::value<std::string>()->default_value("data-out"), "Name of the output channel")
|
||||
("multipart", bpo::value<int>()->default_value(1), "Handle multipart payloads");
|
||||
("multipart", bpo::value<bool>()->default_value(true), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
@@ -15,7 +15,8 @@ void addCustomOptions(bpo::options_description& options)
|
||||
{
|
||||
options.add_options()
|
||||
("in-channel", bpo::value<std::string>()->default_value("data"), "Name of the input channel")
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)");
|
||||
("max-iterations", bpo::value<uint64_t>()->default_value(0), "Number of run iterations (0 - infinite)")
|
||||
("multipart", bpo::value<bool>()->default_value(false), "Handle multipart payloads");
|
||||
}
|
||||
|
||||
FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user