From 65f1b96dc3f0feb0f12587e06520f3ab1919e247 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Wed, 5 Jul 2017 08:37:31 +0200 Subject: [PATCH] Add Version member to FairMQDevice, settable via constructor --- fairmq/FairMQDevice.cxx | 32 ++++++++++++++++++ fairmq/FairMQDevice.h | 21 ++++++++---- fairmq/options/FairMQProgOptions.cxx | 10 ++---- fairmq/runFairMQDevice.h | 5 +++ fairmq/test/CMakeLists.txt | 2 ++ fairmq/test/device/TestVersion.h | 30 +++++++++++++++++ fairmq/test/device/_device_version.cxx | 46 ++++++++++++++++++++++++++ fairmq/tools/runSimpleMQStateMachine.h | 11 ++++++ 8 files changed, 143 insertions(+), 14 deletions(-) create mode 100644 fairmq/test/device/TestVersion.h create mode 100644 fairmq/test/device/_device_version.cxx diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index e17dac10..2aeed993 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -73,6 +73,38 @@ FairMQDevice::FairMQDevice() , fMultitransportMutex() , fMultitransportProceed(false) , fExternalConfig(false) + , fVersion({0, 0, 0}) +{ +} + +FairMQDevice::FairMQDevice(const fair::mq::tools::Version version) + : fChannels() + , fConfig(nullptr) + , fId() + , fNumIoThreads(1) + , fTransportFactory(nullptr) + , fTransports() + , fInitialValidationFinished(false) + , fInitialValidationCondition() + , fInitialValidationMutex() + , fPortRangeMin(22000) + , fPortRangeMax(32000) + , fNetworkInterface() + , fDefaultTransport() + , fInitializationTimeoutInS(120) + , fCatchingSignals(false) + , fTerminationRequested(false) + , fInteractiveRunning(false) + , fDataCallbacks(false) + , fDeviceCmdSockets() + , fMsgInputs() + , fMultipartInputs() + , fMultitransportInputs() + , fInputChannelKeys() + , fMultitransportMutex() + , fMultitransportProceed(false) + , fExternalConfig(false) + , fVersion(version) { } diff --git a/fairmq/FairMQDevice.h b/fairmq/FairMQDevice.h index 4ee3fa92..70e8494b 100644 --- a/fairmq/FairMQDevice.h +++ b/fairmq/FairMQDevice.h @@ -32,6 +32,8 @@ #include #include +#include + typedef std::unordered_map> FairMQChannelMap; typedef std::function InputMsgCallback; @@ -53,6 +55,9 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable /// Default constructor FairMQDevice(); + + /// Constructor that sets the version + FairMQDevice(const fair::mq::tools::Version version); /// Copy constructor (disabled) FairMQDevice(const FairMQDevice&) = delete; /// Assignment operator (disabled) @@ -428,23 +433,25 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable void SetId(const std::string& id) { fId = id; } std::string GetId() { return fId; } + const fair::mq::tools::Version GetVersion() const { return fVersion; } + void SetNumIoThreads(int numIoThreads) { fNumIoThreads = numIoThreads; } - int GetNumIoThreads() { return fNumIoThreads; } + int GetNumIoThreads() const { return fNumIoThreads; } void SetPortRangeMin(int portRangeMin) { fPortRangeMin = portRangeMin; } - int GetPortRangeMin() { return fPortRangeMin; } + int GetPortRangeMin() const { return fPortRangeMin; } void SetPortRangeMax(int portRangeMax) { fPortRangeMax = portRangeMax; } - int GetPortRangeMax() { return fPortRangeMax; } + int GetPortRangeMax() const { return fPortRangeMax; } void SetNetworkInterface(const std::string& networkInterface) { fNetworkInterface = networkInterface; } - std::string GetNetworkInterface() { return fNetworkInterface; } + std::string GetNetworkInterface() const { return fNetworkInterface; } void SetDefaultTransport(const std::string& defaultTransport) { fDefaultTransport = defaultTransport; } - std::string GetDefaultTransport() { return fDefaultTransport; } + std::string GetDefaultTransport() const { return fDefaultTransport; } void SetInitializationTimeoutInS(int initializationTimeoutInS) { fInitializationTimeoutInS = initializationTimeoutInS; } - int GetInitializationTimeoutInS() { return fInitializationTimeoutInS; } + int GetInitializationTimeoutInS() const { return fInitializationTimeoutInS; } protected: std::shared_ptr fTransportFactory; ///< Transport factory @@ -560,6 +567,8 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable std::atomic fMultitransportProceed; bool fExternalConfig; + + const fair::mq::tools::Version fVersion; }; #endif /* FAIRMQDEVICE_H_ */ diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index c56949cb..6398ab25 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -74,9 +74,9 @@ void FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool a exit(EXIT_SUCCESS); } - if (fVarMap.count("print-channels")) + // if these options are provided, do no further checks and let the device handle them + if (fVarMap.count("print-channels") || fVarMap.count("version")) { - // if this option is provided, do no further checks and let the device print the channels DefaultConsoleSetFilter(fSeverityMap.at("NOLOG")); return; } @@ -298,12 +298,6 @@ int FairMQProgOptions::NotifySwitchOption() return 1; } - if (fVarMap.count("version")) - { - LOG(INFO) << fVersion << "\n"; - return 1; - } - return 0; } diff --git a/fairmq/runFairMQDevice.h b/fairmq/runFairMQDevice.h index a5f1a2c3..47183efb 100644 --- a/fairmq/runFairMQDevice.h +++ b/fairmq/runFairMQDevice.h @@ -73,6 +73,11 @@ int main(int argc, const char** argv) int result = runStateMachine(*device, config); + if (config.Count("version")) + { + pluginManager->ForEachPlugin([](fair::mq::Plugin& plugin){ std::cout << "plugin: " << plugin << std::endl; }); + } + if (result > 0) { return 1; diff --git a/fairmq/test/CMakeLists.txt b/fairmq/test/CMakeLists.txt index 83191cd0..2462fc96 100644 --- a/fairmq/test/CMakeLists.txt +++ b/fairmq/test/CMakeLists.txt @@ -68,8 +68,10 @@ add_testsuite(FairMQ.Device SOURCES device/TestSender.h device/TestReceiver.h + device/TestVersion.h device/runner.cxx device/_multiple_devices.cxx + device/_device_version.cxx LINKS FairMQ INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/device diff --git a/fairmq/test/device/TestVersion.h b/fairmq/test/device/TestVersion.h new file mode 100644 index 00000000..c43b86c1 --- /dev/null +++ b/fairmq/test/device/TestVersion.h @@ -0,0 +1,30 @@ +/******************************************************************************** + * Copyright (C) 2015-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include +#include +#include + +namespace fair +{ +namespace mq +{ +namespace test +{ + +class TestVersion : public FairMQDevice +{ + public: + TestVersion(fair::mq::tools::Version version) + : FairMQDevice(version) + {} +}; + +} // namespace test +} // namespace mq +} // namespace fair diff --git a/fairmq/test/device/_device_version.cxx b/fairmq/test/device/_device_version.cxx new file mode 100644 index 00000000..1b264c54 --- /dev/null +++ b/fairmq/test/device/_device_version.cxx @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include "TestVersion.h" + +#include + +#include + +#include // std::stringstream +#include + +namespace +{ + +using namespace std; +using namespace fair::mq::test; + +class DeviceVersion : public ::testing::Test { + public: + DeviceVersion() + {} + + fair::mq::tools::Version TestDeviceVersion() + { + fair::mq::test::TestVersion versionDevice({1, 2, 3}); + versionDevice.ChangeState("END"); + + return versionDevice.GetVersion(); + } +}; + +TEST_F(DeviceVersion, getter) +{ + struct fair::mq::tools::Version v{1, 2, 3}; + fair::mq::tools::Version version = TestDeviceVersion(); + + EXPECT_EQ(v, version); +} + +} // namespace diff --git a/fairmq/tools/runSimpleMQStateMachine.h b/fairmq/tools/runSimpleMQStateMachine.h index 14f6a24f..931172b2 100644 --- a/fairmq/tools/runSimpleMQStateMachine.h +++ b/fairmq/tools/runSimpleMQStateMachine.h @@ -11,6 +11,8 @@ #include "FairMQLogger.h" #include "options/FairMQParser.h" #include "options/FairMQProgOptions.h" +#include +#include #include #include @@ -30,6 +32,15 @@ inline int runStateMachine(TMQDevice& device, FairMQProgOptions& cfg) return 0; } + if (cfg.Count("version")) + { + std::cout << "User device version: " << device.GetVersion() << std::endl; + std::cout << "FAIRMQ_INTERFACE_VERSION: " << FAIRMQ_INTERFACE_VERSION << std::endl; + + device.ChangeState(TMQDevice::END); + return 0; + } + if (cfg.GetValue("catch-signals") > 0) { device.CatchSignals();