From cba6d19781d2302a1fbb1883b84ef72e9ac34c15 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Wed, 29 May 2019 17:08:20 +0200 Subject: [PATCH] Add config plugin class. --- docs/Device.md | 2 +- examples/1-1/Sampler.cxx | 4 +- examples/1-1/Sink.cxx | 2 +- examples/1-1/runSampler.cxx | 2 +- examples/1-1/runSink.cxx | 2 +- examples/1-n-1/Sampler.cxx | 4 +- examples/1-n-1/Sink.cxx | 2 +- examples/1-n-1/runProcessor.cxx | 2 +- examples/1-n-1/runSampler.cxx | 2 +- examples/1-n-1/runSink.cxx | 2 +- examples/copypush/Sampler.cxx | 3 +- examples/copypush/Sink.cxx | 2 +- examples/copypush/runSampler.cxx | 2 +- examples/copypush/runSink.cxx | 2 +- examples/dds/runProcessor.cxx | 2 +- examples/dds/runSampler.cxx | 2 +- examples/dds/runSink.cxx | 2 +- examples/multipart/Sampler.cxx | 2 +- examples/multipart/runSampler.cxx | 2 +- examples/multipart/runSink.cxx | 2 +- examples/multiple-channels/Sampler.cxx | 4 +- examples/multiple-channels/Sink.cxx | 2 +- examples/multiple-channels/runBroadcaster.cxx | 2 +- examples/multiple-channels/runSampler.cxx | 2 +- examples/multiple-channels/runSink.cxx | 2 +- examples/multiple-transports/Sampler1.cxx | 2 +- examples/multiple-transports/Sampler2.cxx | 2 +- examples/multiple-transports/Sink.cxx | 2 +- examples/multiple-transports/runSampler1.cxx | 2 +- examples/multiple-transports/runSampler2.cxx | 2 +- examples/multiple-transports/runSink.cxx | 2 +- examples/readout/Builder.h | 2 +- examples/readout/Readout.h | 4 +- examples/readout/Receiver.h | 2 +- examples/readout/Sender.h | 2 +- examples/readout/runBuilder.cxx | 2 +- examples/readout/runProcessor.cxx | 2 +- examples/readout/runReadout.cxx | 2 +- examples/readout/runReceiver.cxx | 2 +- examples/readout/runSender.cxx | 2 +- examples/region/Sampler.cxx | 4 +- examples/region/Sink.cxx | 2 +- examples/region/runSampler.cxx | 2 +- examples/region/runSink.cxx | 2 +- examples/req-rep/Client.cxx | 4 +- examples/req-rep/Server.cxx | 2 +- examples/req-rep/runClient.cxx | 2 +- examples/req-rep/runServer.cxx | 2 +- fairmq/DeviceRunner.cxx | 50 +- fairmq/DeviceRunner.h | 4 +- fairmq/FairMQChannel.h | 2 +- fairmq/FairMQDevice.cxx | 48 +- fairmq/FairMQDevice.h | 50 +- fairmq/FairMQTransportFactory.cxx | 2 +- fairmq/FairMQTransportFactory.h | 4 +- .../FairMQParser.cxx => JSONParser.cxx} | 95 +-- .../{options/FairMQParser.h => JSONParser.h} | 22 +- fairmq/Plugin.h | 18 +- fairmq/PluginManager.cxx | 66 +- fairmq/PluginServices.cxx | 21 +- fairmq/PluginServices.h | 59 +- fairmq/ProgOptions.cxx | 404 ++++++++++++ fairmq/ProgOptions.h | 163 +++++ .../Properties.h => ProgOptionsFwd.h} | 19 +- fairmq/Properties.cxx | 125 ++++ fairmq/Properties.h | 74 +++ fairmq/PropertyOutput.h | 20 + ...airMQSuboptParser.cxx => SuboptParser.cxx} | 48 +- fairmq/SuboptParser.h | 49 ++ fairmq/devices/FairMQBenchmarkSampler.cxx | 13 +- fairmq/devices/FairMQMerger.cxx | 7 +- fairmq/devices/FairMQMultiplier.cxx | 7 +- fairmq/devices/FairMQProxy.cxx | 7 +- fairmq/devices/FairMQSink.h | 7 +- fairmq/devices/FairMQSplitter.cxx | 7 +- fairmq/nanomsg/FairMQTransportFactoryNN.cxx | 2 +- fairmq/nanomsg/FairMQTransportFactoryNN.h | 4 +- fairmq/ofi/TransportFactory.cxx | 4 +- fairmq/ofi/TransportFactory.h | 4 +- fairmq/options/FairMQProgOptions.cxx | 596 ------------------ fairmq/options/FairMQProgOptions.h | 199 +----- fairmq/options/FairMQSuboptParser.h | 94 --- fairmq/options/README.md | 10 +- fairmq/options/runConfigEx.cxx | 150 ----- fairmq/options/startConfigExample.sh.in | 5 - fairmq/plugins/Builtin.h | 1 + fairmq/plugins/config/Config.cxx | 89 +++ fairmq/plugins/config/Config.h | 47 ++ fairmq/run/runBenchmarkSampler.cxx | 2 +- fairmq/run/runMerger.cxx | 2 +- fairmq/run/runMultiplier.cxx | 2 +- fairmq/run/runProxy.cxx | 2 +- fairmq/run/runSink.cxx | 2 +- fairmq/run/runSplitter.cxx | 2 +- fairmq/runFairMQDevice.h | 13 +- fairmq/shmem/FairMQTransportFactorySHM.cxx | 12 +- fairmq/shmem/FairMQTransportFactorySHM.h | 4 +- fairmq/zeromq/FairMQTransportFactoryZMQ.cxx | 6 +- fairmq/zeromq/FairMQTransportFactoryZMQ.h | 4 +- test/device/_config.cxx | 10 +- test/helper/devices/TestPollIn.h | 4 +- test/helper/runTestDevice.cxx | 4 +- test/message/_message.cxx | 10 +- test/plugin_services/Fixture.h | 4 +- test/plugin_services/_config.cxx | 2 +- test/plugins/_plugin.cxx | 6 +- test/plugins/_plugin_manager.cxx | 10 +- test/protocols/_push_pull_multipart.cxx | 14 +- test/transport/_options.cxx | 6 +- 109 files changed, 1393 insertions(+), 1433 deletions(-) rename fairmq/{options/FairMQParser.cxx => JSONParser.cxx} (59%) rename fairmq/{options/FairMQParser.h => JSONParser.h} (77%) create mode 100644 fairmq/ProgOptions.cxx create mode 100644 fairmq/ProgOptions.h rename fairmq/{options/Properties.h => ProgOptionsFwd.h} (72%) create mode 100644 fairmq/Properties.cxx create mode 100644 fairmq/Properties.h create mode 100644 fairmq/PropertyOutput.h rename fairmq/{options/FairMQSuboptParser.cxx => SuboptParser.cxx} (64%) create mode 100644 fairmq/SuboptParser.h delete mode 100644 fairmq/options/FairMQProgOptions.cxx delete mode 100644 fairmq/options/FairMQSuboptParser.h delete mode 100644 fairmq/options/runConfigEx.cxx delete mode 100755 fairmq/options/startConfigExample.sh.in create mode 100644 fairmq/plugins/config/Config.cxx create mode 100644 fairmq/plugins/config/Config.h diff --git a/docs/Device.md b/docs/Device.md index 623c7ad5..ff8a0d78 100644 --- a/docs/Device.md +++ b/docs/Device.md @@ -48,6 +48,6 @@ Without the interactive mode, for example for a run in background, two other con ## 1.4 Multiple devices in the same process -Technically one can create two or more devices within the same process without any conflicts. However the configuration (FairMQProgOptions) currently assumes the supplied configuration values are for one device/process. +Technically one can create two or more devices within the same process without any conflicts. However the configuration (fair::mq::ProgOptions) currently assumes the supplied configuration values are for one device/process. ← [Back](../README.md) diff --git a/examples/1-1/Sampler.cxx b/examples/1-1/Sampler.cxx index 664a1ba4..4d3c66c6 100644 --- a/examples/1-1/Sampler.cxx +++ b/examples/1-1/Sampler.cxx @@ -26,8 +26,8 @@ Sampler::Sampler() void Sampler::InitTask() { // Get the fText and fMaxIterations values from the command line options (via fConfig) - fText = fConfig->GetValue("text"); - fMaxIterations = fConfig->GetValue("max-iterations"); + fText = fConfig->GetProperty("text"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sampler::ConditionalRun() diff --git a/examples/1-1/Sink.cxx b/examples/1-1/Sink.cxx index 298fe1f7..28f290df 100644 --- a/examples/1-1/Sink.cxx +++ b/examples/1-1/Sink.cxx @@ -30,7 +30,7 @@ Sink::Sink() void Sink::InitTask() { // Get the fMaxIterations value from the command line options (via fConfig) - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } // handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0) diff --git a/examples/1-1/runSampler.cxx b/examples/1-1/runSampler.cxx index 50cd13fb..b9ef19ed 100644 --- a/examples/1-1/runSampler.cxx +++ b/examples/1-1/runSampler.cxx @@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_1_1::Sampler(); } diff --git a/examples/1-1/runSink.cxx b/examples/1-1/runSink.cxx index f92ba05c..b7405caa 100644 --- a/examples/1-1/runSink.cxx +++ b/examples/1-1/runSink.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_1_1::Sink(); } diff --git a/examples/1-n-1/Sampler.cxx b/examples/1-n-1/Sampler.cxx index dfae72b9..8aac7e28 100644 --- a/examples/1-n-1/Sampler.cxx +++ b/examples/1-n-1/Sampler.cxx @@ -32,8 +32,8 @@ Sampler::Sampler() void Sampler::InitTask() { // Get the fText and fMaxIterations values from the command line options (via fConfig) - fText = fConfig->GetValue("text"); - fMaxIterations = fConfig->GetValue("max-iterations"); + fText = fConfig->GetProperty("text"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sampler::ConditionalRun() diff --git a/examples/1-n-1/Sink.cxx b/examples/1-n-1/Sink.cxx index 14e7d665..7587f1b3 100644 --- a/examples/1-n-1/Sink.cxx +++ b/examples/1-n-1/Sink.cxx @@ -30,7 +30,7 @@ Sink::Sink() void Sink::InitTask() { // Get the fMaxIterations value from the command line options (via fConfig) - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } // handler is called whenever a message arrives on "data2", with a reference to the message and a sub-channel index (here 0) diff --git a/examples/1-n-1/runProcessor.cxx b/examples/1-n-1/runProcessor.cxx index be3e80fb..cfebe051 100644 --- a/examples/1-n-1/runProcessor.cxx +++ b/examples/1-n-1/runProcessor.cxx @@ -15,7 +15,7 @@ void addCustomOptions(bpo::options_description& /*options*/) { } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_1_n_1::Processor(); } diff --git a/examples/1-n-1/runSampler.cxx b/examples/1-n-1/runSampler.cxx index 1a6da621..d8c991f7 100644 --- a/examples/1-n-1/runSampler.cxx +++ b/examples/1-n-1/runSampler.cxx @@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_1_n_1::Sampler(); } diff --git a/examples/1-n-1/runSink.cxx b/examples/1-n-1/runSink.cxx index 75f0be2f..f3b6c0df 100644 --- a/examples/1-n-1/runSink.cxx +++ b/examples/1-n-1/runSink.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_1_n_1::Sink(); } diff --git a/examples/copypush/Sampler.cxx b/examples/copypush/Sampler.cxx index 3575e4e7..92ca98ae 100644 --- a/examples/copypush/Sampler.cxx +++ b/examples/copypush/Sampler.cxx @@ -33,12 +33,11 @@ Sampler::Sampler() void Sampler::InitTask() { fNumDataChannels = fChannels.at("data").size(); - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sampler::ConditionalRun() { - // NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place). // Should only be used for small data because of the cost of an additional copy FairMQMessagePtr msg(NewSimpleMessage(fCounter++)); diff --git a/examples/copypush/Sink.cxx b/examples/copypush/Sink.cxx index 1b1d1f6d..1f490069 100644 --- a/examples/copypush/Sink.cxx +++ b/examples/copypush/Sink.cxx @@ -27,7 +27,7 @@ Sink::Sink() void Sink::InitTask() { // Get the fMaxIterations value from the command line options (via fConfig) - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sink::HandleData(FairMQMessagePtr& msg, int /*index*/) diff --git a/examples/copypush/runSampler.cxx b/examples/copypush/runSampler.cxx index 8c417e59..aad63884 100644 --- a/examples/copypush/runSampler.cxx +++ b/examples/copypush/runSampler.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_copypush::Sampler(); } diff --git a/examples/copypush/runSink.cxx b/examples/copypush/runSink.cxx index 5afc6a47..e5704688 100644 --- a/examples/copypush/runSink.cxx +++ b/examples/copypush/runSink.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_copypush::Sink(); } diff --git a/examples/dds/runProcessor.cxx b/examples/dds/runProcessor.cxx index ae5d09b7..da3ef777 100644 --- a/examples/dds/runProcessor.cxx +++ b/examples/dds/runProcessor.cxx @@ -15,7 +15,7 @@ void addCustomOptions(bpo::options_description& /*options*/) { } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_dds::Processor(); } diff --git a/examples/dds/runSampler.cxx b/examples/dds/runSampler.cxx index fff91f4b..a511f992 100644 --- a/examples/dds/runSampler.cxx +++ b/examples/dds/runSampler.cxx @@ -15,7 +15,7 @@ void addCustomOptions(bpo::options_description& /*options*/) { } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_dds::Sampler(); } diff --git a/examples/dds/runSink.cxx b/examples/dds/runSink.cxx index c4f73f9a..0c6cf710 100644 --- a/examples/dds/runSink.cxx +++ b/examples/dds/runSink.cxx @@ -15,7 +15,7 @@ void addCustomOptions(bpo::options_description& /*options*/) { } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_dds::Sink(); } diff --git a/examples/multipart/Sampler.cxx b/examples/multipart/Sampler.cxx index 3ebecc5b..038ab686 100644 --- a/examples/multipart/Sampler.cxx +++ b/examples/multipart/Sampler.cxx @@ -31,7 +31,7 @@ Sampler::Sampler() void Sampler::InitTask() { - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sampler::ConditionalRun() diff --git a/examples/multipart/runSampler.cxx b/examples/multipart/runSampler.cxx index 9347b549..7bbc1925 100644 --- a/examples/multipart/runSampler.cxx +++ b/examples/multipart/runSampler.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(5), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multipart::Sampler(); } diff --git a/examples/multipart/runSink.cxx b/examples/multipart/runSink.cxx index 80c9d57c..13c74558 100644 --- a/examples/multipart/runSink.cxx +++ b/examples/multipart/runSink.cxx @@ -15,7 +15,7 @@ void addCustomOptions(bpo::options_description& /*options*/) { } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multipart::Sink(); } diff --git a/examples/multiple-channels/Sampler.cxx b/examples/multiple-channels/Sampler.cxx index d2f74c04..e7f7a758 100644 --- a/examples/multiple-channels/Sampler.cxx +++ b/examples/multiple-channels/Sampler.cxx @@ -33,8 +33,8 @@ Sampler::Sampler() void Sampler::InitTask() { - fText = fConfig->GetValue("text"); - fMaxIterations = fConfig->GetValue("max-iterations"); + fText = fConfig->GetProperty("text"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } void Sampler::Run() diff --git a/examples/multiple-channels/Sink.cxx b/examples/multiple-channels/Sink.cxx index 4b460e56..473e4940 100644 --- a/examples/multiple-channels/Sink.cxx +++ b/examples/multiple-channels/Sink.cxx @@ -31,7 +31,7 @@ Sink::Sink() void Sink::InitTask() { - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sink::HandleBroadcast(FairMQMessagePtr& msg, int /*index*/) diff --git a/examples/multiple-channels/runBroadcaster.cxx b/examples/multiple-channels/runBroadcaster.cxx index 1b72785d..4fb25a6a 100644 --- a/examples/multiple-channels/runBroadcaster.cxx +++ b/examples/multiple-channels/runBroadcaster.cxx @@ -15,7 +15,7 @@ void addCustomOptions(bpo::options_description& /*options*/) { } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multiple_channels::Broadcaster(); } diff --git a/examples/multiple-channels/runSampler.cxx b/examples/multiple-channels/runSampler.cxx index a3902d7c..a8a4fd1b 100644 --- a/examples/multiple-channels/runSampler.cxx +++ b/examples/multiple-channels/runSampler.cxx @@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multiple_channels::Sampler(); } diff --git a/examples/multiple-channels/runSink.cxx b/examples/multiple-channels/runSink.cxx index 1ebf1067..756e0da0 100644 --- a/examples/multiple-channels/runSink.cxx +++ b/examples/multiple-channels/runSink.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multiple_channels::Sink(); } diff --git a/examples/multiple-transports/Sampler1.cxx b/examples/multiple-transports/Sampler1.cxx index 06959f75..d9c87c4b 100644 --- a/examples/multiple-transports/Sampler1.cxx +++ b/examples/multiple-transports/Sampler1.cxx @@ -22,7 +22,7 @@ Sampler1::Sampler1() void Sampler1::InitTask() { - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } void Sampler1::PreRun() diff --git a/examples/multiple-transports/Sampler2.cxx b/examples/multiple-transports/Sampler2.cxx index 1ac30274..9fcc9519 100644 --- a/examples/multiple-transports/Sampler2.cxx +++ b/examples/multiple-transports/Sampler2.cxx @@ -21,7 +21,7 @@ Sampler2::Sampler2() void Sampler2::InitTask() { - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Sampler2::ConditionalRun() diff --git a/examples/multiple-transports/Sink.cxx b/examples/multiple-transports/Sink.cxx index 84fc9ec1..183cc417 100644 --- a/examples/multiple-transports/Sink.cxx +++ b/examples/multiple-transports/Sink.cxx @@ -31,7 +31,7 @@ Sink::Sink() void Sink::InitTask() { - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } // handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0) diff --git a/examples/multiple-transports/runSampler1.cxx b/examples/multiple-transports/runSampler1.cxx index bd46785b..46c602e1 100644 --- a/examples/multiple-transports/runSampler1.cxx +++ b/examples/multiple-transports/runSampler1.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multiple_transports::Sampler1(); } diff --git a/examples/multiple-transports/runSampler2.cxx b/examples/multiple-transports/runSampler2.cxx index 879d926d..e1a0886f 100644 --- a/examples/multiple-transports/runSampler2.cxx +++ b/examples/multiple-transports/runSampler2.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multiple_transports::Sampler2(); } diff --git a/examples/multiple-transports/runSink.cxx b/examples/multiple-transports/runSink.cxx index 658a2c71..4af2d398 100644 --- a/examples/multiple-transports/runSink.cxx +++ b/examples/multiple-transports/runSink.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_multiple_transports::Sink(); } diff --git a/examples/readout/Builder.h b/examples/readout/Builder.h index cb832edf..fdbb3bbd 100644 --- a/examples/readout/Builder.h +++ b/examples/readout/Builder.h @@ -24,7 +24,7 @@ class Builder : public FairMQDevice void Init() override { - fOutputChannelName = fConfig->GetValue("output-name"); + fOutputChannelName = fConfig->GetProperty("output-name"); OnData("rb", &Builder::HandleData); } diff --git a/examples/readout/Readout.h b/examples/readout/Readout.h index 6d686372..3ac88667 100644 --- a/examples/readout/Readout.h +++ b/examples/readout/Readout.h @@ -31,8 +31,8 @@ class Readout : public FairMQDevice protected: void InitTask() override { - fMsgSize = fConfig->GetValue("msg-size"); - fMaxIterations = fConfig->GetValue("max-iterations"); + fMsgSize = fConfig->GetProperty("msg-size"); + fMaxIterations = fConfig->GetProperty("max-iterations"); fRegion = FairMQUnmanagedRegionPtr(NewUnmanagedRegionFor("rb", 0, diff --git a/examples/readout/Receiver.h b/examples/readout/Receiver.h index dae126ce..b0bc148b 100644 --- a/examples/readout/Receiver.h +++ b/examples/readout/Receiver.h @@ -25,7 +25,7 @@ class Receiver : public FairMQDevice void InitTask() override { // Get the fMaxIterations value from the command line options (via fConfig) - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } void Run() override diff --git a/examples/readout/Sender.h b/examples/readout/Sender.h index 35f54ddb..4fd77026 100644 --- a/examples/readout/Sender.h +++ b/examples/readout/Sender.h @@ -24,7 +24,7 @@ class Sender : public FairMQDevice void Init() override { - fInputChannelName = fConfig->GetValue("input-name"); + fInputChannelName = fConfig->GetProperty("input-name"); OnData(fInputChannelName, &Sender::HandleData); } diff --git a/examples/readout/runBuilder.cxx b/examples/readout/runBuilder.cxx index 89476fc4..4cbe046d 100644 --- a/examples/readout/runBuilder.cxx +++ b/examples/readout/runBuilder.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("output-name", bpo::value()->default_value("bs"), "Output channel name"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_readout::Builder(); } diff --git a/examples/readout/runProcessor.cxx b/examples/readout/runProcessor.cxx index 1da2e3df..1c78b11d 100644 --- a/examples/readout/runProcessor.cxx +++ b/examples/readout/runProcessor.cxx @@ -14,7 +14,7 @@ namespace bpo = boost::program_options; void addCustomOptions(bpo::options_description& /* options */) {} -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_readout::Processor(); } diff --git a/examples/readout/runReadout.cxx b/examples/readout/runReadout.cxx index 4c2fbef3..f3647927 100644 --- a/examples/readout/runReadout.cxx +++ b/examples/readout/runReadout.cxx @@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_readout::Readout(); } diff --git a/examples/readout/runReceiver.cxx b/examples/readout/runReceiver.cxx index aeed1e91..1b488cba 100644 --- a/examples/readout/runReceiver.cxx +++ b/examples/readout/runReceiver.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_readout::Receiver(); } diff --git a/examples/readout/runSender.cxx b/examples/readout/runSender.cxx index 2a4e4c99..f59825d3 100644 --- a/examples/readout/runSender.cxx +++ b/examples/readout/runSender.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("input-name", bpo::value()->default_value("bs"), "Input channel name"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_readout::Sender(); } diff --git a/examples/region/Sampler.cxx b/examples/region/Sampler.cxx index c5b9f51a..9a047922 100644 --- a/examples/region/Sampler.cxx +++ b/examples/region/Sampler.cxx @@ -32,8 +32,8 @@ Sampler::Sampler() void Sampler::InitTask() { - fMsgSize = fConfig->GetValue("msg-size"); - fMaxIterations = fConfig->GetValue("max-iterations"); + fMsgSize = fConfig->GetProperty("msg-size"); + fMaxIterations = fConfig->GetProperty("max-iterations"); fRegion = FairMQUnmanagedRegionPtr(NewUnmanagedRegionFor("data", 0, diff --git a/examples/region/Sink.cxx b/examples/region/Sink.cxx index 71d744ec..3163fe57 100644 --- a/examples/region/Sink.cxx +++ b/examples/region/Sink.cxx @@ -28,7 +28,7 @@ Sink::Sink() void Sink::InitTask() { // Get the fMaxIterations value from the command line options (via fConfig) - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } void Sink::Run() diff --git a/examples/region/runSampler.cxx b/examples/region/runSampler.cxx index 6b8166da..5806b48c 100644 --- a/examples/region/runSampler.cxx +++ b/examples/region/runSampler.cxx @@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_region::Sampler(); } diff --git a/examples/region/runSink.cxx b/examples/region/runSink.cxx index 1ad8f4bd..40c54308 100644 --- a/examples/region/runSink.cxx +++ b/examples/region/runSink.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_region::Sink(); } diff --git a/examples/req-rep/Client.cxx b/examples/req-rep/Client.cxx index 439041d1..f4c8f640 100644 --- a/examples/req-rep/Client.cxx +++ b/examples/req-rep/Client.cxx @@ -31,8 +31,8 @@ Client::Client() void Client::InitTask() { - fText = fConfig->GetValue("text"); - fMaxIterations = fConfig->GetValue("max-iterations"); + fText = fConfig->GetProperty("text"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Client::ConditionalRun() diff --git a/examples/req-rep/Server.cxx b/examples/req-rep/Server.cxx index 11448bb1..b32517dc 100644 --- a/examples/req-rep/Server.cxx +++ b/examples/req-rep/Server.cxx @@ -29,7 +29,7 @@ Server::Server() void Server::InitTask() { // Get the fMaxIterations value from the command line options (via fConfig) - fMaxIterations = fConfig->GetValue("max-iterations"); + fMaxIterations = fConfig->GetProperty("max-iterations"); } bool Server::HandleData(FairMQMessagePtr& req, int /*index*/) diff --git a/examples/req-rep/runClient.cxx b/examples/req-rep/runClient.cxx index acb417dc..7fd12b03 100644 --- a/examples/req-rep/runClient.cxx +++ b/examples/req-rep/runClient.cxx @@ -18,7 +18,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_req_rep::Client(); } diff --git a/examples/req-rep/runServer.cxx b/examples/req-rep/runServer.cxx index 21dc65ca..700bc74b 100644 --- a/examples/req-rep/runServer.cxx +++ b/examples/req-rep/runServer.cxx @@ -17,7 +17,7 @@ void addCustomOptions(bpo::options_description& options) ("max-iterations", bpo::value()->default_value(0), "Maximum number of iterations of Run/ConditionalRun/OnData (0 - infinite)"); } -FairMQDevicePtr getDevice(const FairMQProgOptions& /*config*/) +FairMQDevicePtr getDevice(const fair::mq::ProgOptions& /*config*/) { return new example_req_rep::Server(); } diff --git a/fairmq/DeviceRunner.cxx b/fairmq/DeviceRunner.cxx index d76e5d02..72a49dd9 100644 --- a/fairmq/DeviceRunner.cxx +++ b/fairmq/DeviceRunner.cxx @@ -25,6 +25,8 @@ DeviceRunner::DeviceRunner(int argc, char* const argv[], bool printLogo) auto DeviceRunner::Run() -> int { + fPluginManager.LoadPlugin("s:config"); + ////// CALL HOOK /////// fEvents.Emit(*this); //////////////////////// @@ -46,19 +48,50 @@ auto DeviceRunner::Run() -> int fEvents.Emit(*this); //////////////////////// - if (fConfig.ParseAll(fRawCmdLineArgs, true)) { + fConfig.ParseAll(fRawCmdLineArgs, true); + + if (fConfig.Count("help")) { + fConfig.PrintHelp(); 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; + if (fConfig.Count("print-options")) { + fConfig.PrintOptionsRaw(); + return 0; } + if (fConfig.Count("print-channels") || fConfig.Count("version")) { + fair::Logger::SetConsoleSeverity("nolog"); + } else { + std::string severity = fConfig.GetProperty("severity"); + std::string logFile = fConfig.GetProperty("log-to-file"); + bool color = fConfig.GetProperty("color"); + + std::string verbosity = fConfig.GetProperty("verbosity"); + fair::Logger::SetVerbosity(verbosity); + + if (logFile != "") { + fair::Logger::InitFileSink(severity, logFile); + fair::Logger::SetConsoleSeverity("nolog"); + } else { + fair::Logger::SetConsoleColor(color); + fair::Logger::SetConsoleSeverity(severity); + } + + 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; + } + + fConfig.PrintOptions(); + } + + fConfig.Notify(); + ////// CALL HOOK /////// fEvents.Emit(*this); //////////////////////// @@ -80,6 +113,7 @@ auto DeviceRunner::Run() -> int // Handle --version if (fConfig.Count("version")) { + std::cout << "FairMQ version: " << FAIRMQ_GIT_VERSION << std::endl; std::cout << "User device version: " << fDevice->GetVersion() << std::endl; fDevice->ChangeState(fair::mq::Transition::End); return 0; diff --git a/fairmq/DeviceRunner.h b/fairmq/DeviceRunner.h index 2995583b..f129fa1b 100644 --- a/fairmq/DeviceRunner.h +++ b/fairmq/DeviceRunner.h @@ -11,9 +11,9 @@ #include #include +#include #include #include -#include #include #include @@ -68,7 +68,7 @@ class DeviceRunner } std::vector fRawCmdLineArgs; - FairMQProgOptions fConfig; + fair::mq::ProgOptions fConfig; std::unique_ptr fDevice; PluginManager fPluginManager; const bool fPrintLogo; diff --git a/fairmq/FairMQChannel.h b/fairmq/FairMQChannel.h index 3c66059f..afca5d48 100644 --- a/fairmq/FairMQChannel.h +++ b/fairmq/FairMQChannel.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index e561b0e2..8bab18d0 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -58,32 +58,28 @@ static map backwardsCompatibilityChangeStateHelper = FairMQDevice::FairMQDevice() : FairMQDevice(nullptr, {0, 0, 0}) -{ -} +{} -FairMQDevice::FairMQDevice(FairMQProgOptions& config) +FairMQDevice::FairMQDevice(ProgOptions& config) : FairMQDevice(&config, {0, 0, 0}) -{ -} +{} FairMQDevice::FairMQDevice(const tools::Version version) : FairMQDevice(nullptr, version) -{ -} +{} -FairMQDevice::FairMQDevice(FairMQProgOptions& config, const tools::Version version) +FairMQDevice::FairMQDevice(ProgOptions& config, const tools::Version version) : FairMQDevice(&config, version) -{ -} +{} -FairMQDevice::FairMQDevice(FairMQProgOptions* config, const tools::Version version) +FairMQDevice::FairMQDevice(ProgOptions* config, const tools::Version version) : fTransportFactory(nullptr) , fTransports() , fChannels() - , fInternalConfig(config ? nullptr : tools::make_unique()) + , fInternalConfig(config ? nullptr : tools::make_unique()) , fConfig(config ? config : fInternalConfig.get()) - , fId() - , fDefaultTransportType(fair::mq::Transport::ZMQ) + , fId(DefaultId) + , fDefaultTransportType(DefaultTransportType) , fStateMachine() , fUninitializedBindingChannels() , fUninitializedConnectingChannels() @@ -96,8 +92,8 @@ FairMQDevice::FairMQDevice(FairMQProgOptions* config, const tools::Version versi , fMultitransportMutex() , fMultitransportProceed(false) , fVersion(version) - , fRate(0.) - , fMaxRunRuntimeInS(0) + , fRate(DefaultRate) + , fMaxRunRuntimeInS(DefaultMaxRunTime) , fRawCmdLineArgs() { SubscribeToNewTransition("device", [&](Transition transition) { @@ -192,18 +188,18 @@ void FairMQDevice::InitWrapper() { fStateMachine.WaitForPendingState(); - fId = fConfig->GetValue("id"); + fId = fConfig->GetProperty("id", DefaultId); Init(); - fRate = fConfig->GetValue("rate"); - fMaxRunRuntimeInS = fConfig->GetValue("max-run-time"); + fRate = fConfig->GetProperty("rate", DefaultRate); + fMaxRunRuntimeInS = fConfig->GetProperty("max-run-time", DefaultMaxRunTime); try { - fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue("transport")); + fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetProperty("transport", DefaultTransportName)); } catch (const exception& e) { LOG(error) << "exception: " << e.what(); - LOG(error) << "invalid transport type provided: " << fConfig->GetValue("transport"); + LOG(error) << "invalid transport type provided: " << fConfig->GetProperty("transport", "not provided"); throw; } @@ -217,7 +213,7 @@ void FairMQDevice::InitWrapper() LOG(debug) << "Setting '" << fair::mq::TransportNames.at(fDefaultTransportType) << "' as default transport for the device"; fTransportFactory = AddTransport(fDefaultTransportType); - string networkInterface = fConfig->GetValue("network-interface"); + string networkInterface = fConfig->GetProperty("network-interface", DefaultNetworkInterface); // Fill the uninitialized channel containers for (auto& mi : fChannels) { @@ -274,7 +270,7 @@ void FairMQDevice::BindWrapper() void FairMQDevice::ConnectWrapper() { - int initializationTimeoutInS = fConfig->GetValue("initialization-timeout"); + int initializationTimeoutInS = fConfig->GetProperty("init-timeout", DefaultInitTimeout); // go over the list of channels until all are initialized (and removed from the uninitialized list) int numAttempts = 1; @@ -288,7 +284,7 @@ void FairMQDevice::ConnectWrapper() for (auto& chan : fUninitializedConnectingChannels) { string key{"chans." + chan->GetPrefix() + "." + chan->GetIndex() + ".address"}; - string newAddress = fConfig->GetValue(key); + string newAddress = fConfig->GetProperty(key); if (newAddress != chan->GetAddress()) { chan->UpdateAddress(newAddress); } @@ -399,7 +395,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& chan) chan.UpdateAddress(newAddress); // update address in the config, it could have been modified during binding - fConfig->SetValue({"chans." + chan.GetPrefix() + "." + chan.GetIndex() + ".address"}, newAddress); + fConfig->SetProperty({"chans." + chan.GetPrefix() + "." + chan.GetIndex() + ".address"}, newAddress); } return true; @@ -710,7 +706,7 @@ shared_ptr FairMQDevice::AddTransport(fair::mq::Transpor } } -void FairMQDevice::SetConfig(FairMQProgOptions& config) +void FairMQDevice::SetConfig(ProgOptions& config) { fInternalConfig.reset(); fConfig = &config; diff --git a/fairmq/FairMQDevice.h b/fairmq/FairMQDevice.h index 451e747f..4ce50bfe 100644 --- a/fairmq/FairMQDevice.h +++ b/fairmq/FairMQDevice.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include // unique_ptr @@ -83,17 +83,17 @@ class FairMQDevice /// Default constructor FairMQDevice(); - /// Constructor with external FairMQProgOptions - FairMQDevice(FairMQProgOptions& config); + /// Constructor with external fair::mq::ProgOptions + FairMQDevice(fair::mq::ProgOptions& config); /// Constructor that sets the version FairMQDevice(const fair::mq::tools::Version version); - /// Constructor that sets the version and external FairMQProgOptions - FairMQDevice(FairMQProgOptions& config, const fair::mq::tools::Version version); + /// Constructor that sets the version and external fair::mq::ProgOptions + FairMQDevice(fair::mq::ProgOptions& config, const fair::mq::tools::Version version); private: - FairMQDevice(FairMQProgOptions* config, const fair::mq::tools::Version version); + FairMQDevice(fair::mq::ProgOptions* config, const fair::mq::tools::Version version); public: /// Copy constructor (disabled) @@ -296,9 +296,9 @@ class FairMQDevice std::shared_ptr AddTransport(const fair::mq::Transport transport); /// Assigns config to the device - void SetConfig(FairMQProgOptions& config); + void SetConfig(fair::mq::ProgOptions& config); /// Get pointer to the config - FairMQProgOptions* GetConfig() const + fair::mq::ProgOptions* GetConfig() const { return fConfig; } @@ -399,23 +399,23 @@ class FairMQDevice const fair::mq::tools::Version GetVersion() const { return fVersion; } - void SetNumIoThreads(int numIoThreads) { fConfig->SetValue("io-threads", numIoThreads);} - int GetNumIoThreads() const { return fConfig->GetValue("io-threads"); } + void SetNumIoThreads(int numIoThreads) { fConfig->SetProperty("io-threads", numIoThreads);} + int GetNumIoThreads() const { return fConfig->GetProperty("io-threads", DefaultIOThreads); } - void SetNetworkInterface(const std::string& networkInterface) { fConfig->SetValue("network-interface", networkInterface); } - std::string GetNetworkInterface() const { return fConfig->GetValue("network-interface"); } + void SetNetworkInterface(const std::string& networkInterface) { fConfig->SetProperty("network-interface", networkInterface); } + std::string GetNetworkInterface() const { return fConfig->GetProperty("network-interface", DefaultNetworkInterface); } - void SetDefaultTransport(const std::string& name) { fConfig->SetValue("transport", name); } - std::string GetDefaultTransport() const { return fConfig->GetValue("transport"); } + void SetDefaultTransport(const std::string& name) { fConfig->SetProperty("transport", name); } + std::string GetDefaultTransport() const { return fConfig->GetProperty("transport", DefaultTransportName); } - void SetInitializationTimeoutInS(int initializationTimeoutInS) { fConfig->SetValue("initialization-timeout", initializationTimeoutInS); } - int GetInitializationTimeoutInS() const { return fConfig->GetValue("initialization-timeout"); } + void SetInitTimeoutInS(int initTimeoutInS) { fConfig->SetProperty("init-timeout", initTimeoutInS); } + int GetInitTimeoutInS() const { return fConfig->GetProperty("init-timeout", DefaultInitTimeout); } /// Sets the default transport for the device /// @param transport Transport string ("zeromq"/"nanomsg"/"shmem") - void SetTransport(const std::string& transport) { fConfig->SetValue("transport", transport); } + void SetTransport(const std::string& transport) { fConfig->SetProperty("transport", transport); } /// Gets the default transport name - std::string GetTransportName() const { return fConfig->GetValue("transport"); } + std::string GetTransportName() const { return fConfig->GetProperty("transport", DefaultTransportName); } void SetRawCmdLineArgs(const std::vector& args) { fRawCmdLineArgs = args; } std::vector GetRawCmdLineArgs() const { return fRawCmdLineArgs; } @@ -440,8 +440,8 @@ class FairMQDevice public: std::unordered_map> fChannels; ///< Device channels - std::unique_ptr fInternalConfig; ///< Internal program options configuration - FairMQProgOptions* fConfig; ///< Pointer to config (internal or external) + std::unique_ptr fInternalConfig; ///< Internal program options configuration + fair::mq::ProgOptions* fConfig; ///< Pointer to config (internal or external) void AddChannel(const std::string& name, FairMQChannel&& channel) { @@ -514,6 +514,16 @@ class FairMQDevice struct DeviceStateError : std::runtime_error { using std::runtime_error::runtime_error; }; + static constexpr const char* DefaultId = ""; + static constexpr int DefaultIOThreads = 1; + static constexpr const char* DefaultTransportName = "zeromq"; + static constexpr fair::mq::Transport DefaultTransportType = fair::mq::Transport::ZMQ; + static constexpr const char* DefaultNetworkInterface = "default"; + static constexpr int DefaultInitTimeout = 120; + static constexpr uint64_t DefaultMaxRunTime = 0; + static constexpr float DefaultRate = 0.; + static constexpr const char* DefaultSession = "default"; + private: fair::mq::Transport fDefaultTransportType; ///< Default transport for the device fair::mq::StateMachine fStateMachine; diff --git a/fairmq/FairMQTransportFactory.cxx b/fairmq/FairMQTransportFactory.cxx index 544381d5..b9bc1bfc 100644 --- a/fairmq/FairMQTransportFactory.cxx +++ b/fairmq/FairMQTransportFactory.cxx @@ -27,7 +27,7 @@ FairMQTransportFactory::FairMQTransportFactory(const std::string& id) { } -auto FairMQTransportFactory::CreateTransportFactory(const std::string& type, const std::string& id, const FairMQProgOptions* config) -> std::shared_ptr +auto FairMQTransportFactory::CreateTransportFactory(const std::string& type, const std::string& id, const fair::mq::ProgOptions* config) -> std::shared_ptr { using namespace std; diff --git a/fairmq/FairMQTransportFactory.h b/fairmq/FairMQTransportFactory.h index 8fb32893..143b1e31 100644 --- a/fairmq/FairMQTransportFactory.h +++ b/fairmq/FairMQTransportFactory.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include class FairMQChannel; -class FairMQProgOptions; class FairMQTransportFactory { @@ -83,7 +83,7 @@ class FairMQTransportFactory virtual ~FairMQTransportFactory() {}; - static auto CreateTransportFactory(const std::string& type, const std::string& id = "", const FairMQProgOptions* config = nullptr) -> std::shared_ptr; + static auto CreateTransportFactory(const std::string& type, const std::string& id = "", const fair::mq::ProgOptions* config = nullptr) -> std::shared_ptr; static void FairMQNoCleanup(void* /*data*/, void* /*obj*/) { diff --git a/fairmq/options/FairMQParser.cxx b/fairmq/JSONParser.cxx similarity index 59% rename from fairmq/options/FairMQParser.cxx rename to fairmq/JSONParser.cxx index ac589634..76df6af7 100644 --- a/fairmq/options/FairMQParser.cxx +++ b/fairmq/JSONParser.cxx @@ -6,13 +6,14 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ /* - * File: FairMQParser.cxx + * File: JSONParser.cxx * Author: winckler * * Created on May 14, 2015, 5:01 PM */ -#include "FairMQParser.h" +#include +#include "JSONParser.h" #include "FairMQLogger.h" #include @@ -20,7 +21,10 @@ #include #include +#include + using namespace std; +using namespace fair::mq; using namespace fair::mq::tools; using namespace boost::property_tree; @@ -28,27 +32,27 @@ namespace fair { namespace mq { -namespace parser -{ -fair::mq::Properties ptreeToProperties(const ptree& pt, const string& id) +fair::mq::Properties PtreeParser(const ptree& pt, const string& id) { if (id == "") { throw ParserError("no device ID provided. Provide with `--id` cmd option"); } - return Helper::DeviceParser(pt.get_child("fairMQOptions"), id); + // json_parser::write_json(cout, pt); + + return helper::DeviceParser(pt.get_child("fairMQOptions"), id); } -fair::mq::Properties JSON::UserParser(const string& filename, const string& deviceId) +fair::mq::Properties JSONParser(const string& filename, const string& deviceId) { - ptree input; + ptree pt; LOG(debug) << "Parsing JSON from " << filename << " ..."; - read_json(filename, input); - return ptreeToProperties(input, deviceId); + read_json(filename, pt); + return PtreeParser(pt, deviceId); } -namespace Helper +namespace helper { fair::mq::Properties DeviceParser(const ptree& fairMQOptions, const string& deviceId) @@ -58,16 +62,8 @@ fair::mq::Properties DeviceParser(const ptree& fairMQOptions, const string& devi for (const auto& node : fairMQOptions) { if (node.first == "devices") { for (const auto& device : node.second) { - string deviceIdKey; - // check if key is provided, otherwise use id - string key = device.second.get("key", ""); - - if (key != "") { - deviceIdKey = key; - } else { - deviceIdKey = device.second.get("id"); - } + string deviceIdKey = device.second.get("key", device.second.get("id", "")); // if not correct device id, do not fill MQMap if (deviceId != deviceIdKey) { @@ -75,7 +71,6 @@ fair::mq::Properties DeviceParser(const ptree& fairMQOptions, const string& devi } LOG(trace) << "Found following channels for device ID '" << deviceId << "' :"; - ChannelParser(device.second, properties); } } @@ -111,20 +106,9 @@ void ChannelParser(const ptree& tree, fair::mq::Properties& properties) LOG(trace) << name << ":"; LOG(trace) << "\tnumSockets of " << numSockets << " specified, applying common settings to each:"; - // TODO: make a loop out of this - LOG(trace) << "\ttype = " << boost::any_cast(commonProperties.at("type")); - LOG(trace) << "\tmethod = " << boost::any_cast(commonProperties.at("method")); - LOG(trace) << "\taddress = " << boost::any_cast(commonProperties.at("address")); - LOG(trace) << "\ttransport = " << boost::any_cast(commonProperties.at("transport")); - LOG(trace) << "\tsndBufSize = " << boost::any_cast(commonProperties.at("sndBufSize")); - LOG(trace) << "\trcvBufSize = " << boost::any_cast(commonProperties.at("rcvBufSize")); - LOG(trace) << "\tsndKernelSize = " << boost::any_cast(commonProperties.at("sndKernelSize")); - LOG(trace) << "\trcvKernelSize = " << boost::any_cast(commonProperties.at("rcvKernelSize")); - LOG(trace) << "\tlinger = " << boost::any_cast(commonProperties.at("linger")); - LOG(trace) << "\trateLogging = " << boost::any_cast(commonProperties.at("rateLogging")); - LOG(trace) << "\tportRangeMin = " << boost::any_cast(commonProperties.at("portRangeMin")); - LOG(trace) << "\tportRangeMax = " << boost::any_cast(commonProperties.at("portRangeMax")); - LOG(trace) << "\tautoBind = " << boost::any_cast(commonProperties.at("autoBind")); + for (auto& p : commonProperties) { + LOG(trace) << "\t" << setw(13) << left << p.first << " : " << p.second; + } for (int i = 0; i < numSockets; ++i) { for (const auto& p : commonProperties) { @@ -166,20 +150,9 @@ void SubChannelParser(const ptree& channelTree, fair::mq::Properties& properties newProperties["autoBind"] = sn.second.get("autoBind", boost::any_cast(commonProperties.at("autoBind"))); LOG(trace) << "" << channelName << "[" << i << "]:"; - // TODO: make a loop out of this - LOG(trace) << "\ttype = " << boost::any_cast(newProperties.at("type")); - LOG(trace) << "\tmethod = " << boost::any_cast(newProperties.at("method")); - LOG(trace) << "\taddress = " << boost::any_cast(newProperties.at("address")); - LOG(trace) << "\ttransport = " << boost::any_cast(newProperties.at("transport")); - LOG(trace) << "\tsndBufSize = " << boost::any_cast(newProperties.at("sndBufSize")); - LOG(trace) << "\trcvBufSize = " << boost::any_cast(newProperties.at("rcvBufSize")); - LOG(trace) << "\tsndKernelSize = " << boost::any_cast(newProperties.at("sndKernelSize")); - LOG(trace) << "\trcvKernelSize = " << boost::any_cast(newProperties.at("rcvKernelSize")); - LOG(trace) << "\tlinger = " << boost::any_cast(newProperties.at("linger")); - LOG(trace) << "\trateLogging = " << boost::any_cast(newProperties.at("rateLogging")); - LOG(trace) << "\tportRangeMin = " << boost::any_cast(newProperties.at("portRangeMin")); - LOG(trace) << "\tportRangeMax = " << boost::any_cast(newProperties.at("portRangeMax")); - LOG(trace) << "\tautoBind = " << boost::any_cast(newProperties.at("autoBind")); + for (auto& p : newProperties) { + LOG(trace) << "\t" << setw(13) << left << p.first << " : " << p.second; + } for (const auto& p : newProperties) { properties.emplace(ToString("chans.", channelName, ".", i, ".", p.first), p.second); @@ -187,31 +160,21 @@ void SubChannelParser(const ptree& channelTree, fair::mq::Properties& properties ++i; } } - } // end socket loop + } if (i > 0) { LOG(trace) << "Found " << i << " socket(s) in channel."; } else { + // if no sockets are specified, apply common channel properties LOG(trace) << "" << channelName << ":"; LOG(trace) << "\tNo sockets specified,"; LOG(trace) << "\tapplying common settings to the channel:"; fair::mq::Properties newProperties(commonProperties); - // TODO: make a loop out of this - LOG(trace) << "\ttype = " << boost::any_cast(newProperties.at("type")); - LOG(trace) << "\tmethod = " << boost::any_cast(newProperties.at("method")); - LOG(trace) << "\taddress = " << boost::any_cast(newProperties.at("address")); - LOG(trace) << "\ttransport = " << boost::any_cast(newProperties.at("transport")); - LOG(trace) << "\tsndBufSize = " << boost::any_cast(newProperties.at("sndBufSize")); - LOG(trace) << "\trcvBufSize = " << boost::any_cast(newProperties.at("rcvBufSize")); - LOG(trace) << "\tsndKernelSize = " << boost::any_cast(newProperties.at("sndKernelSize")); - LOG(trace) << "\trcvKernelSize = " << boost::any_cast(newProperties.at("rcvKernelSize")); - LOG(trace) << "\tlinger = " << boost::any_cast(newProperties.at("linger")); - LOG(trace) << "\trateLogging = " << boost::any_cast(newProperties.at("rateLogging")); - LOG(trace) << "\tportRangeMin = " << boost::any_cast(newProperties.at("portRangeMin")); - LOG(trace) << "\tportRangeMax = " << boost::any_cast(newProperties.at("portRangeMax")); - LOG(trace) << "\tautoBind = " << boost::any_cast(newProperties.at("autoBind")); + for (auto& p : newProperties) { + LOG(trace) << "\t" << setw(13) << left << p.first << " : " << p.second; + } for (const auto& p : newProperties) { properties.emplace(ToString("chans.", channelName, ".0.", p.first), p.second); @@ -219,8 +182,6 @@ void SubChannelParser(const ptree& channelTree, fair::mq::Properties& properties } } -} // Helper namespace - -} // namespace parser +} // helper namespace } // namespace mq } // namespace fair diff --git a/fairmq/options/FairMQParser.h b/fairmq/JSONParser.h similarity index 77% rename from fairmq/options/FairMQParser.h rename to fairmq/JSONParser.h index f451bb4b..0770f8da 100644 --- a/fairmq/options/FairMQParser.h +++ b/fairmq/JSONParser.h @@ -12,8 +12,8 @@ * Created on May 14, 2015, 5:01 PM */ -#ifndef FAIRMQPARSER_H -#define FAIRMQPARSER_H +#ifndef FAIR_MQ_JSONPARSER_H +#define FAIR_MQ_JSONPARSER_H #include #include @@ -23,35 +23,29 @@ #include #include "FairMQChannel.h" -#include "Properties.h" +#include namespace fair { namespace mq { -namespace parser -{ struct ParserError : std::runtime_error { using std::runtime_error::runtime_error; }; -fair::mq::Properties ptreeToProperties(const boost::property_tree::ptree& pt, const std::string& deviceId); +fair::mq::Properties PtreeParser(const boost::property_tree::ptree& pt, const std::string& deviceId); -struct JSON -{ - fair::mq::Properties UserParser(const std::string& filename, const std::string& deviceId); -}; +fair::mq::Properties JSONParser(const std::string& filename, const std::string& deviceId); -namespace Helper +namespace helper { fair::mq::Properties DeviceParser(const boost::property_tree::ptree& tree, const std::string& deviceId); void ChannelParser(const boost::property_tree::ptree& tree, fair::mq::Properties& properties); void SubChannelParser(const boost::property_tree::ptree& tree, fair::mq::Properties& properties, const std::string& channelName, const fair::mq::Properties& commonProperties); -} // Helper namespace +} // helper namespace -} // namespace parser } // namespace mq } // namespace fair -#endif /* FAIRMQPARSER_H */ +#endif /* FAIR_MQ_JSONPARSER_H */ diff --git a/fairmq/Plugin.h b/fairmq/Plugin.h index 0984a38a..c3f12d0c 100644 --- a/fairmq/Plugin.h +++ b/fairmq/Plugin.h @@ -85,13 +85,25 @@ class Plugin // device config API // see for docs auto PropertyExists(const std::string& key) -> int { return fPluginServices->PropertyExists(key); } + template - auto SetProperty(const std::string& key, T val) -> void { fPluginServices->SetProperty(key, val); } + T GetProperty(const std::string& key) const { return fPluginServices->GetProperty(key); } template - auto GetProperty(const std::string& key) const -> T { return fPluginServices->GetProperty(key); } - auto GetPropertyAsString(const std::string& key) const -> std::string { return fPluginServices->GetPropertyAsString(key); } + T GetProperty(const std::string& key, const T& ifNotFound) const { return fPluginServices->GetProperty(key, ifNotFound); } + std::string GetPropertyAsString(const std::string& key) const { return fPluginServices->GetPropertyAsString(key); } + std::string GetPropertyAsString(const std::string& key, const std::string& ifNotFound) const { return fPluginServices->GetPropertyAsString(key, ifNotFound); } + fair::mq::Properties GetProperties(const std::string& q) const { return fPluginServices->GetProperties(q); } + fair::mq::Properties GetPropertiesStartingWith(const std::string& q) const { return fPluginServices->GetPropertiesStartingWith(q); }; + std::map GetPropertiesAsString(const std::string& q) const { return fPluginServices->GetPropertiesAsString(q); } + std::map GetPropertiesAsStringStartingWith(const std::string& q) const { return fPluginServices->GetPropertiesAsStringStartingWith(q); }; + auto GetChannelInfo() const -> std::unordered_map { return fPluginServices->GetChannelInfo(); } auto GetPropertyKeys() const -> std::vector { return fPluginServices->GetPropertyKeys(); } + + template + auto SetProperty(const std::string& key, T val) -> void { fPluginServices->SetProperty(key, val); } + void SetProperties(const fair::mq::Properties& props) { fPluginServices->SetProperties(props); } + template auto SubscribeToPropertyChange(std::function callback) -> void { fPluginServices->SubscribeToPropertyChange(fkName, callback); } template diff --git a/fairmq/PluginManager.cxx b/fairmq/PluginManager.cxx index 7efb0987..1c54ee06 100644 --- a/fairmq/PluginManager.cxx +++ b/fairmq/PluginManager.cxx @@ -49,13 +49,11 @@ fair::mq::PluginManager::PluginManager(const vector args) // Parse command line options auto options = ProgramOptions(); auto vm = po::variables_map{}; - try - { + 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) - { + } catch (const po::error& e) { throw ProgramOptionsParseError{ToString("Error occured while parsing the 'Plugin Manager' program options: ", e.what())}; } @@ -63,10 +61,8 @@ fair::mq::PluginManager::PluginManager(const vector args) auto append = vector{}; auto prepend = vector{}; auto searchPaths = vector{}; - if (vm.count("plugin-search-path")) - { - for (const auto& path : vm["plugin-search-path"].as>()) - { + if (vm.count("plugin-search-path")) { + for (const auto& path : vm["plugin-search-path"].as>()) { 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); } @@ -126,23 +122,16 @@ auto fair::mq::PluginManager::ProgramOptions() -> po::options_description auto fair::mq::PluginManager::LoadPlugin(const string& pluginName) -> void { - if (pluginName.substr(0,2) == "p:") - { + if (pluginName.substr(0,2) == "p:") { // Mechanism A: prelinked dynamic LoadPluginPrelinkedDynamic(pluginName.substr(2)); - } - else if (pluginName.substr(0,2) == "d:") - { + } else if (pluginName.substr(0,2) == "d:") { // Mechanism B: dynamic LoadPluginDynamic(pluginName.substr(2)); - } - else if (pluginName.substr(0,2) == "s:") - { + } else if (pluginName.substr(0,2) == "s:") { // Mechanism C: static (builtin) LoadPluginStatic(pluginName.substr(2)); - } - else - { + } else { // Mechanism B: dynamic (default) LoadPluginDynamic(pluginName); } @@ -151,15 +140,11 @@ auto fair::mq::PluginManager::LoadPlugin(const string& pluginName) -> void auto fair::mq::PluginManager::LoadPluginPrelinkedDynamic(const string& pluginName) -> void { // Load symbol - if (fPluginFactories.find(pluginName) == fPluginFactories.end()) - { - try - { + if (fPluginFactories.find(pluginName) == fPluginFactories.end()) { + try { LoadSymbols(pluginName, dll::program_location()); fPluginOrder.push_back(pluginName); - } - catch (boost::system::system_error& e) - { + } catch (boost::system::system_error& e) { throw PluginLoadError(ToString("An error occurred while loading prelinked dynamic plugin ", pluginName, ": ", e.what())); } } @@ -168,13 +153,11 @@ auto fair::mq::PluginManager::LoadPluginPrelinkedDynamic(const string& pluginNam auto fair::mq::PluginManager::LoadPluginDynamic(const string& pluginName) -> void { // Search plugin and load, if found - if (fPluginFactories.find(pluginName) == fPluginFactories.end()) - { + if (fPluginFactories.find(pluginName) == fPluginFactories.end()) { auto success = false; for (const auto& searchPath : SearchPaths()) { try { - LoadSymbols(pluginName, - searchPath / ToString(LibPrefix(), pluginName), + LoadSymbols(pluginName, searchPath / ToString(LibPrefix(), pluginName), dll::load_mode::append_decorations | dll::load_mode::rtld_global); fPluginOrder.push_back(pluginName); success = true; @@ -213,15 +196,11 @@ auto fair::mq::PluginManager::LoadPluginDynamic(const string& pluginName) -> voi auto fair::mq::PluginManager::LoadPluginStatic(const string& pluginName) -> void { // Load symbol - if (fPluginFactories.find(pluginName) == fPluginFactories.end()) - { - try - { + if (fPluginFactories.find(pluginName) == fPluginFactories.end()) { + try { LoadSymbols(pluginName, dll::program_location()); fPluginOrder.push_back(pluginName); - } - catch (boost::system::system_error& e) - { + } catch (boost::system::system_error& e) { throw PluginLoadError(ToString("An error occurred while loading static plugin ", pluginName, ": ", e.what())); } } @@ -229,22 +208,17 @@ auto fair::mq::PluginManager::LoadPluginStatic(const string& pluginName) -> void auto fair::mq::PluginManager::InstantiatePlugin(const string& pluginName) -> void { - if (fPlugins.find(pluginName) == fPlugins.end()) - { + if (fPlugins.find(pluginName) == fPlugins.end()) { fPlugins[pluginName] = fPluginFactories[pluginName](*fPluginServices); } } auto fair::mq::PluginManager::InstantiatePlugins() -> void { - for(const auto& pluginName : fPluginOrder) - { - try - { + for(const auto& pluginName : fPluginOrder) { + try { InstantiatePlugin(pluginName); - } - catch (std::exception& e) - { + } catch (std::exception& e) { throw PluginInstantiationError(ToString("An error occurred while instantiating plugin ", pluginName, ": ", e.what())); } } diff --git a/fairmq/PluginServices.cxx b/fairmq/PluginServices.cxx index 3bd3eb05..97145385 100644 --- a/fairmq/PluginServices.cxx +++ b/fairmq/PluginServices.cxx @@ -129,16 +129,11 @@ auto PluginServices::TakeDeviceControl(const std::string& controller) -> void { lock_guard lock{fDeviceControllerMutex}; - if (!fDeviceController) - { + if (!fDeviceController) { fDeviceController = controller; - } - else if (fDeviceController == controller) - { + } else if (fDeviceController == controller) { // nothing to do - } - else - { + } else { throw DeviceControlError{tools::ToString( "Plugin '", controller, "' is not allowed to take over control. ", "Currently, plugin '", *fDeviceController, "' has taken control." @@ -158,12 +153,9 @@ auto PluginServices::ReleaseDeviceControl(const std::string& controller) -> void { lock_guard lock{fDeviceControllerMutex}; - if (fDeviceController == controller) - { + if (fDeviceController == controller) { fDeviceController = boost::none; - } - else - { + } else { throw DeviceControlError{tools::ToString("Plugin '", controller, "' cannot release control because it has not taken over control.")}; } } @@ -182,8 +174,7 @@ auto PluginServices::WaitForReleaseDeviceControl() -> void { unique_lock lock{fDeviceControllerMutex}; - while (fDeviceController) - { + while (fDeviceController) { fReleaseDeviceControlCondition.wait(lock); } } diff --git a/fairmq/PluginServices.h b/fairmq/PluginServices.h index a3536fc8..42041899 100644 --- a/fairmq/PluginServices.h +++ b/fairmq/PluginServices.h @@ -11,7 +11,8 @@ #include #include -#include +#include +#include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -39,7 +41,7 @@ class PluginServices { public: PluginServices() = delete; - PluginServices(FairMQProgOptions& config, FairMQDevice& device) + PluginServices(ProgOptions& config, FairMQDevice& device) : fConfig(config) , fDevice(device) , fDeviceController() @@ -196,43 +198,76 @@ class PluginServices || (currentState == DeviceState::Binding) || (currentState == DeviceState::Bound) || (currentState == DeviceState::Connecting) - || (currentState == DeviceState::Ready) - || (currentState == DeviceState::Idle && key == "channel-config")) { - fConfig.SetValue(key, val); + || (currentState == DeviceState::Ready)) { + fConfig.SetProperty(key, val); } else { throw InvalidStateError{ tools::ToString("PluginServices::SetProperty is not supported in device state ", currentState, ". ", "Supported state is ", DeviceState::InitializingDevice, ".")}; } } + void SetProperties(const fair::mq::Properties& props) + { + fConfig.SetProperties(props); + } struct InvalidStateError : std::runtime_error { using std::runtime_error::runtime_error; }; /// @brief Read config property /// @param key - /// @return config property value + /// @return config property /// /// TODO Currently, if a non-existing key is requested and a default constructed object is returned. /// This behaviour will be changed in the future to throw an exception in that case to provide a proper sentinel. template - auto GetProperty(const std::string& key) const -> T { + auto GetProperty(const std::string& key) const -> T + { if (PropertyExists(key)) { - return fConfig.GetValue(key); + return fConfig.GetProperty(key); } throw PropertyNotFoundError(fair::mq::tools::ToString("Config has no key: ", key)); } + template + T GetProperty(const std::string& key, const T& ifNotFound) const + { + return fConfig.GetProperty(key, ifNotFound); + } + /// @brief Read config property as string /// @param key - /// @return config property value converted to string + /// @return config property converted to string /// /// 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 { + auto GetPropertyAsString(const std::string& key) const -> std::string + { if (PropertyExists(key)) { - return fConfig.GetStringValue(key); + return fConfig.GetPropertyAsString(key); } throw PropertyNotFoundError(fair::mq::tools::ToString("Config has no key: ", key)); } + auto GetPropertyAsString(const std::string& key, const std::string& ifNotFound) const -> std::string + { + return fConfig.GetPropertyAsString(key, ifNotFound); + } + + fair::mq::Properties GetProperties(const std::string& q) const + { + return fConfig.GetProperties(q); + } + fair::mq::Properties GetPropertiesStartingWith(const std::string& q) const + { + return fConfig.GetPropertiesStartingWith(q); + } + std::map GetPropertiesAsString(const std::string& q) const + { + return fConfig.GetPropertiesAsString(q); + } + std::map GetPropertiesAsStringStartingWith(const std::string& q) const + { + return fConfig.GetPropertiesAsStringStartingWith(q); + } + auto GetChannelInfo() const -> std::unordered_map { return fConfig.GetChannelInfo(); } /// @brief Discover the list of property keys @@ -282,7 +317,7 @@ class PluginServices static const std::unordered_map> fkDeviceStateTransitionMap; private: - FairMQProgOptions& fConfig; + fair::mq::ProgOptions& fConfig; FairMQDevice& fDevice; boost::optional fDeviceController; mutable std::mutex fDeviceControllerMutex; diff --git a/fairmq/ProgOptions.cxx b/fairmq/ProgOptions.cxx new file mode 100644 index 00000000..e6dea788 --- /dev/null +++ b/fairmq/ProgOptions.cxx @@ -0,0 +1,404 @@ +/******************************************************************************** + * 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" * + ********************************************************************************/ +/* + * File: ProgOptions.cxx + * Author: winckler + * + * Created on March 11, 2015, 10:20 PM + */ + +#include "FairMQLogger.h" +#include + +#include "tools/Unique.h" + +#include +#include + +#include +#include +#include +#include +#include // pair + +using namespace std; +using namespace fair::mq; + +namespace po = boost::program_options; + +struct ValInfo +{ + string value; + string type; + string origin; +}; + +namespace fair +{ +namespace mq +{ + +ValInfo ConvertVarValToValInfo(const po::variable_value& v) +{ + string origin; + + if (v.defaulted()) { + origin = "[default]"; + } else if (v.empty()) { + origin = "[empty]"; + } else { + origin = "[provided]"; + } + + try { + pair info = PropertyHelper::GetPropertyInfo(v.value()); + return {info.first, info.second, origin}; + } catch (out_of_range& oor) { + return {string("[unidentified_type]"), string("[unidentified_type]"), origin}; + } +}; + +string ConvertVarValToString(const po::variable_value& v) +{ + return ConvertVarValToValInfo(v).value; +} + +ProgOptions::ProgOptions() + : fVarMap() + , fAllOptions("FairMQ Command Line Options") + , fUnregisteredOptions() + , fEvents() + , fMtx() +{ + fAllOptions.add_options() + ("help,h", "Print help") + ("version,v", "Print version") + ("severity", po::value()->default_value("debug"), "Log severity level: trace, debug, info, state, warn, error, fatal, nolog") + ("verbosity", po::value()->default_value("medium"), "Log verbosity level: veryhigh, high, medium, low") + ("color", po::value()->default_value(true), "Log color (true/false)") + ("log-to-file", po::value()->default_value(""), "Log output to a file.") + ("print-options", po::value()->implicit_value(true), "Print options in machine-readable format (