From 1bb77bf47b6d30719de5f8326f34338cc5dadfa3 Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Sun, 28 Jul 2019 19:20:11 +0200 Subject: [PATCH] DDS plugin: Automatically set session and device id if not provided Resolves #187 --- examples/dds/ex-dds-topology-infinite.xml | 6 +-- examples/dds/ex-dds-topology.xml | 6 +-- fairmq/DeviceRunner.cxx | 5 ++- fairmq/plugins/DDS/DDS.cxx | 49 ++++++++++++++--------- fairmq/plugins/DDS/DDS.h | 2 +- test/sdk/test_topo.xml | 4 +- 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/examples/dds/ex-dds-topology-infinite.xml b/examples/dds/ex-dds-topology-infinite.xml index cad744c7..46129bb5 100644 --- a/examples/dds/ex-dds-topology-infinite.xml +++ b/examples/dds/ex-dds-topology-infinite.xml @@ -8,8 +8,8 @@ + fairmq-ex-dds-sampler --color false --channel-config name=data1,type=push,method=bind --rate 100 -P dds fairmq-ex-dds-env.sh - fairmq-ex-dds-sampler --id sampler --color false --channel-config name=data1,type=push,method=bind --rate 100 -P dds SamplerWorker @@ -19,8 +19,8 @@ + fairmq-ex-dds-processor --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect -P dds fairmq-ex-dds-env.sh - fairmq-ex-dds-processor --id processor_%taskIndex% --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect -P dds ProcessorWorker @@ -31,8 +31,8 @@ + fairmq-ex-dds-sink --color false --channel-config name=data2,type=pull,method=bind -P dds fairmq-ex-dds-env.sh - fairmq-ex-dds-sink --id sink --color false --channel-config name=data2,type=pull,method=bind -P dds SinkWorker diff --git a/examples/dds/ex-dds-topology.xml b/examples/dds/ex-dds-topology.xml index 18870a47..a8c86e0e 100644 --- a/examples/dds/ex-dds-topology.xml +++ b/examples/dds/ex-dds-topology.xml @@ -8,8 +8,8 @@ + fairmq-ex-dds-sampler --color false --channel-config name=data1,type=push,method=bind -P dds --iterations 10 fairmq-ex-dds-env.sh - fairmq-ex-dds-sampler --id sampler --color false --channel-config name=data1,type=push,method=bind -P dds --iterations 10 SamplerWorker @@ -19,8 +19,8 @@ + fairmq-ex-dds-processor --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect -P dds fairmq-ex-dds-env.sh - fairmq-ex-dds-processor --id processor_%taskIndex% --color false --channel-config name=data1,type=pull,method=connect name=data2,type=push,method=connect -P dds ProcessorWorker @@ -31,8 +31,8 @@ + fairmq-ex-dds-sink --color false --channel-config name=data2,type=pull,method=bind -P dds --iterations 10 fairmq-ex-dds-env.sh - fairmq-ex-dds-sink --id sink --color false --channel-config name=data2,type=pull,method=bind -P dds --iterations 10 SinkWorker diff --git a/fairmq/DeviceRunner.cxx b/fairmq/DeviceRunner.cxx index 75fc5535..4ad26d05 100644 --- a/fairmq/DeviceRunner.cxx +++ b/fairmq/DeviceRunner.cxx @@ -63,8 +63,6 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo << " / __/ / /_/ / / / _ / / / / /_/ / " << FAIRMQ_REPO_URL << endl << " /_/ \\__,_/_/_/ /_/ /_/ \\___\\_\\ " << FAIRMQ_LICENSE << " © " << FAIRMQ_COPYRIGHT << endl; } - - config.PrintOptions(); } return true; @@ -169,6 +167,9 @@ auto DeviceRunner::Run() -> int // Instantiate and run plugins fPluginManager.InstantiatePlugins(); + // Log IDLE configuration + fConfig.PrintOptions(); + // Run the device fDevice->RunStateMachine(); diff --git a/fairmq/plugins/DDS/DDS.cxx b/fairmq/plugins/DDS/DDS.cxx index fe91ae09..a68e0306 100644 --- a/fairmq/plugins/DDS/DDS.cxx +++ b/fairmq/plugins/DDS/DDS.cxx @@ -55,18 +55,18 @@ DDS::DDS(const string& name, { try { TakeDeviceControl(); - fControllerThread = thread(&DDS::HandleControl, this); - fHeartbeatThread = thread(&DDS::HeartbeatSender, this); - } catch (PluginServices::DeviceControlError& e) { - LOG(debug) << e.what(); - } catch (exception& e) { - LOG(error) << "Error in plugin initialization: " << e.what(); - } -} -auto DDS::HandleControl() -> void -{ - try { + fHeartbeatThread = thread(&DDS::HeartbeatSender, this); + + std::string deviceId(GetProperty("id")); + if (deviceId.empty()) { + SetProperty("id", dds::env_prop()); + } + std::string sessionId(GetProperty("session")); + if (sessionId == "default") { + SetProperty("session", dds::env_prop()); + } + auto control = GetProperty("control"); bool staticMode(false); if (control == "static") { @@ -121,15 +121,26 @@ auto DDS::HandleControl() -> void }); if (staticMode) { - TransitionDeviceStateTo(DeviceState::Running); - - // wait until stop signal - unique_lock lock(fStopMutex); - while (!fDeviceTerminationRequested) { - fStopCondition.wait_for(lock, chrono::seconds(1)); - } - LOG(debug) << "Stopping DDS control plugin"; + fControllerThread = thread(&DDS::StaticControl, this); } + } catch (PluginServices::DeviceControlError& e) { + LOG(debug) << e.what(); + } catch (exception& e) { + LOG(error) << "Error in plugin initialization: " << e.what(); + } +} + +auto DDS::StaticControl() -> void +{ + try { + TransitionDeviceStateTo(DeviceState::Running); + + // wait until stop signal + unique_lock lock(fStopMutex); + while (!fDeviceTerminationRequested) { + fStopCondition.wait_for(lock, chrono::seconds(1)); + } + LOG(debug) << "Stopping DDS plugin static controller"; } catch (DeviceErrorState&) { ReleaseDeviceControl(); } catch (exception& e) { diff --git a/fairmq/plugins/DDS/DDS.h b/fairmq/plugins/DDS/DDS.h index c24726b2..60d3fb10 100644 --- a/fairmq/plugins/DDS/DDS.h +++ b/fairmq/plugins/DDS/DDS.h @@ -128,7 +128,7 @@ class DDS : public Plugin ~DDS(); private: - auto HandleControl() -> void; + auto StaticControl() -> void; auto FillChannelContainers() -> void; auto SubscribeForConnectingChannels() -> void; diff --git a/test/sdk/test_topo.xml b/test/sdk/test_topo.xml index 89ed0ac2..a36d9c70 100644 --- a/test/sdk/test_topo.xml +++ b/test/sdk/test_topo.xml @@ -6,7 +6,7 @@ - fairmq-bsampler --id sampler --color false --channel-config name=data,type=push,method=bind -P dds --msg-rate 10 + fairmq-bsampler --color false --channel-config name=data,type=push,method=bind -P dds --msg-rate 10 SamplerWorker @@ -16,7 +16,7 @@ - fairmq-sink --id sink_%taskIndex% --color false --channel-config name=data,type=pull,method=connect -P dds + fairmq-sink --color false --channel-config name=data,type=pull,method=connect -P dds SinkWorker