From a05dc8040231e3ebf2039c8efabaf7cc2bdb5502 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Thu, 19 May 2016 10:22:02 +0200 Subject: [PATCH] Refactor DDS example and tools to be able to run with/without DDS --- fairmq/CMakeLists.txt | 43 +++++++++++-- fairmq/deployment/CMakeLists.txt | 60 ------------------- .../{deployment => run}/runDDSCommandUI.cxx | 0 fairmq/{deployment => tools}/FairMQDDSTools.h | 0 fairmq/tools/runSimpleMQStateMachine.h | 30 +++++++--- 5 files changed, 60 insertions(+), 73 deletions(-) delete mode 100644 fairmq/deployment/CMakeLists.txt rename fairmq/{deployment => run}/runDDSCommandUI.cxx (100%) rename fairmq/{deployment => tools}/FairMQDDSTools.h (100%) diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index 4b882c75..8c5ba744 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -12,10 +12,6 @@ configure_file(${CMAKE_SOURCE_DIR}/fairmq/run/benchmark.json ${CMAKE_BINARY_DIR} add_subdirectory(logger) add_subdirectory(test) -If(DDS_FOUND) - add_subdirectory(deployment) -EndIf(DDS_FOUND) - Set(INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/fairmq ${CMAKE_SOURCE_DIR}/fairmq/devices @@ -31,6 +27,14 @@ Set(SYSTEM_INCLUDE_DIRECTORIES ${ZMQ_INCLUDE_DIR} ) +If(DDS_FOUND) + add_definitions(-DDDS_FOUND) + Set(SYSTEM_INCLUDE_DIRECTORIES + ${SYSTEM_INCLUDE_DIRECTORIES} + ${DDS_INCLUDE_DIR} + ) +EndIf(DDS_FOUND) + If(NANOMSG_FOUND) add_definitions(-DNANOMSG_FOUND) Set(INCLUDE_DIRECTORIES @@ -57,6 +61,13 @@ Set(LINK_DIRECTORIES ${Boost_LIBRARY_DIRS} ) +If(DDS_FOUND) + Set(LINK_DIRECTORIES + ${LINK_DIRECTORIES} + DDS_LIBRARY_DIR + ) +EndIf(DDS_FOUND) + Link_Directories(${LINK_DIRECTORIES}) Set(SRCS @@ -113,6 +124,7 @@ Set(FAIRMQHEADERS devices/BaseSourcePolicy.h options/FairProgOptionsHelper.h tools/FairMQTools.h + tools/FairMQDDSTools.h tools/runSimpleMQStateMachine.h ) Install(FILES ${FAIRMQHEADERS} DESTINATION include) @@ -139,6 +151,15 @@ If(NANOMSG_FOUND) ) EndIf(NANOMSG_FOUND) +If(DDS_FOUND) + Set(DEPENDENCIES + ${DEPENDENCIES} + ${DDS_INTERCOM_LIBRARY_SHARED} + ${DDS_PROTOCOL_LIBRARY_SHARED} # also link the two DDS dependency libraries to avoid linking issues on some osx systems + ${DDS_USER_DEFAULTS_LIBRARY_SHARED} + ) +EndIf(DDS_FOUND) + Set(LIBRARY_NAME FairMQ) GENERATE_LIBRARY() @@ -151,6 +172,13 @@ Set(Exe_Names proxy ) +If(DDS_FOUND) + Set(Exe_Names + ${Exe_Names} + fairmq-dds-command-ui + ) +EndIf(DDS_FOUND) + Set(Exe_Source run/runBenchmarkSampler.cxx run/runSink.cxx @@ -159,6 +187,13 @@ Set(Exe_Source run/runProxy.cxx ) +If(DDS_FOUND) + Set(Exe_Source + ${Exe_Source} + run/runDDSCommandUI.cxx + ) +EndIf(DDS_FOUND) + list(LENGTH Exe_Names _length) math(EXPR _length ${_length}-1) diff --git a/fairmq/deployment/CMakeLists.txt b/fairmq/deployment/CMakeLists.txt deleted file mode 100644 index 3dfeb738..00000000 --- a/fairmq/deployment/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ - ################################################################################ - # Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # - # # - # This software is distributed under the terms of the # - # GNU Lesser General Public Licence version 3 (LGPL) version 3, # - # copied verbatim in the file "LICENSE" # - ################################################################################ - -Set(INCLUDE_DIRECTORIES - ${CMAKE_SOURCE_DIR}/fairmq - ${CMAKE_SOURCE_DIR}/fairmq/zeromq - ${CMAKE_SOURCE_DIR}/fairmq/nanomsg - ${CMAKE_SOURCE_DIR}/fairmq/devices - ${CMAKE_SOURCE_DIR}/fairmq/tools - ${CMAKE_SOURCE_DIR}/fairmq/options - ${CMAKE_SOURCE_DIR}/fairmq/deployment - ${CMAKE_CURRENT_BINARY_DIR} -) - -Set(SYSTEM_INCLUDE_DIRECTORIES - ${SYSTEM_INCLUDE_DIRECTORIES} - ${Boost_INCLUDE_DIR} - ${DDS_INCLUDE_DIR} - ${ZMQ_INCLUDE_DIR} -) - -Include_Directories(${INCLUDE_DIRECTORIES}) -Include_Directories(SYSTEM ${SYSTEM_INCLUDE_DIRECTORIES}) - -Set(LINK_DIRECTORIES - ${LINK_DIRECTORIES} - ${Boost_LIBRARY_DIRS} - ${DDS_LIBRARY_DIR} -) - -Link_Directories(${LINK_DIRECTORIES}) - -Install(FILES FairMQDDSTools.h DESTINATION include) - -Set(Exe_Names - ${Exe_Names} - fairmq-dds-command-ui -) - -Set(Exe_Source - ${Exe_Source} - runDDSCommandUI.cxx -) - -list(LENGTH Exe_Names _length) -math(EXPR _length ${_length}-1) - -ForEach(_file RANGE 0 ${_length}) - list(GET Exe_Names ${_file} _name) - list(GET Exe_Source ${_file} _src) - set(EXE_NAME ${_name}) - set(SRCS ${_src}) - set(DEPENDENCIES FairMQ dds_intercom_lib) - GENERATE_EXECUTABLE() -EndForEach(_file RANGE 0 ${_length}) diff --git a/fairmq/deployment/runDDSCommandUI.cxx b/fairmq/run/runDDSCommandUI.cxx similarity index 100% rename from fairmq/deployment/runDDSCommandUI.cxx rename to fairmq/run/runDDSCommandUI.cxx diff --git a/fairmq/deployment/FairMQDDSTools.h b/fairmq/tools/FairMQDDSTools.h similarity index 100% rename from fairmq/deployment/FairMQDDSTools.h rename to fairmq/tools/FairMQDDSTools.h diff --git a/fairmq/tools/runSimpleMQStateMachine.h b/fairmq/tools/runSimpleMQStateMachine.h index a9f9f235..61703687 100644 --- a/fairmq/tools/runSimpleMQStateMachine.h +++ b/fairmq/tools/runSimpleMQStateMachine.h @@ -8,28 +8,34 @@ #ifndef RUNSIMPLEMQSTATEMACHINE_H #define RUNSIMPLEMQSTATEMACHINE_H -/// std #include -#include #include -/// boost -#include "boost/program_options.hpp" +#ifdef DDS_FOUND +#include "FairMQDDSTools.h" +#endif /*DDS_FOUND*/ -/// FairRoot - FairMQ #include "FairMQLogger.h" #include "FairMQParser.h" #include "FairMQProgOptions.h" // template function that takes any device -// and runs a simple MQ state machine configured from a JSON file +// and runs a simple MQ state machine configured from a JSON file and/or (optionally) DDS. template inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config) { device.CatchSignals(); device.SetConfig(config); + std::string control = config.GetValue("control"); + device.ChangeState(TMQDevice::INIT_DEVICE); +#ifdef DDS_FOUND + if (control == "dds") + { + HandleConfigViaDDS(device); + } +#endif /*DDS_FOUND*/ device.WaitForEndOfState(TMQDevice::INIT_DEVICE); device.ChangeState(TMQDevice::INIT_TASK); @@ -37,9 +43,6 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config) device.ChangeState(TMQDevice::RUN); - std::string control = config.GetValue("control"); - - // TODO: Extend this with DDS (requires optional dependency?)? if (control == "interactive") { device.InteractiveStateLoop(); @@ -59,12 +62,21 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config) device.ChangeState(TMQDevice::END); } } +#ifdef DDS_FOUND + else if (control == "dds") + { + runDDSStateHandler(device); + } +#endif /*DDS_FOUND*/ else { LOG(ERROR) << "Requested control mechanism '" << control << "' is not available."; LOG(ERROR) << "Currently available are:" << " 'interactive'" << ", 'static'" +#ifdef DDS_FOUND + << ", 'dds'" +#endif /*DDS_FOUND*/ << ". Exiting."; exit(EXIT_FAILURE); }