From e0462adc80bd41a093689a54384453bfb84f2be0 Mon Sep 17 00:00:00 2001 From: Christoph Pohl <christoph.pohl@kit.edu> Date: Wed, 2 Nov 2022 14:02:39 +0100 Subject: [PATCH] Fix AronComponentConfigExample --- .../AronComponentConfigExample.cpp | 76 +++++++++++++++---- .../AronComponentConfigExample.h | 9 ++- .../aron/ComponentConfig.xml | 10 +++ .../aron_component_config/ComponentPlugin.h | 54 +------------ 4 files changed, 79 insertions(+), 70 deletions(-) diff --git a/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.cpp b/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.cpp index 7a3a07e6e..861964b43 100644 --- a/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.cpp +++ b/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.cpp @@ -28,43 +28,87 @@ namespace armarx { - void AronComponentConfigExample::onInitComponent() + void + AronComponentConfigExample::onInitComponent() { } - void AronComponentConfigExample::onConnectComponent() + void + AronComponentConfigExample::onConnectComponent() { + remote_gui_plugin_->createOrUpdateTab(aron_component_config_plugin_->buildRemoteGui("Config"), + [this](armarx::RemoteGui::TabProxy& prx) + { + prx.receiveUpdates(); + std::lock_guard lock(write_mutex); + if (aron_component_config_plugin_->updateRemoteGui(prx)) + { + remote_gui_plugin_->createOrUpdateTab("", + aron_component_config_plugin_ + ->buildRemoteGui( + "Config")); + } + prx.sendUpdates(); + }); + periodicTask = new SimplePeriodicTask<>([&, this] + { + std::lock_guard lock(write_mutex); + ARMARX_TRACE; + auto& config = + aron_component_config_plugin_->config_.getWriteBuffer(); + config.intMember--; + aron_component_config_plugin_->config_.commitWrite(); + }, 1000); + periodicTask->start(); } - void AronComponentConfigExample::onDisconnectComponent() + void + AronComponentConfigExample::onDisconnectComponent() { } - void AronComponentConfigExample::onExitComponent() + void + AronComponentConfigExample::onExitComponent() { } - armarx::PropertyDefinitionsPtr AronComponentConfigExample::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr + AronComponentConfigExample::createPropertyDefinitions() { armarx::PropertyDefinitionsPtr defs = new AronComponentConfigExamplePropertyDefinitions(getConfigIdentifier()); - auto& config = getConfigWriteBuffer(); - config.boolMember=true; - config.floatMember=100.0f; - config.intMember=1000; - config.stringMember="initial"; - config.longMember=0; - config.subMember.subsubMember.intListMember.insert(config.subMember.subsubMember.intListMember.end(), { 1, 2, 3, 4, 5, 6 }); - config.subMember.subsubMember.stringListMember.insert(config.subMember.subsubMember.stringListMember.end(), {"a", "b", "c", "d", "e"}); - commitConfigWriteBuffer(); + auto& config = aron_component_config_plugin_->config_.getWriteBuffer(); + config.boolMember = true; + config.floatMember = 100.0f; + config.intMember = 1000; + config.stringMember = "initial"; + config.longMember = 0; + config.subMember + .subsubMember + .intListMember + .insert(config.subMember.subsubMember.intListMember.end(), {1, 2, 3, 4, 5, 6}); + config.subMember + .subsubMember + .stringListMember + .insert(config.subMember.subsubMember.stringListMember.end(), {"a", "b", "c", "d", "e"}); + aron_component_config_plugin_->config_.commitWrite(); return defs; } - std::string AronComponentConfigExample::getDefaultName() const + std::string + AronComponentConfigExample::getDefaultName() const { return "ComponentConfigTest"; } + AronComponentConfigExample::AronComponentConfigExample() + { + addPlugin(remote_gui_plugin_, ""); + addPlugin(aron_component_config_plugin_, ""); + } + AronComponentConfigExamplePropertyDefinitions::AronComponentConfigExamplePropertyDefinitions(std::string prefix) : - armarx::ComponentPropertyDefinitions(std::move(prefix)) {} + armarx::ComponentPropertyDefinitions(std::move(prefix)) + { + } } \ No newline at end of file diff --git a/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.h b/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.h index d030e645b..e466b0a6a 100644 --- a/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.h +++ b/source/RobotAPI/components/AronComponentConfigExample/AronComponentConfigExample.h @@ -37,7 +37,6 @@ namespace armarx }; class AronComponentConfigExample : - virtual public armarx::AronComponentConfigPluginUser<armarx::component_config::aron::TestConfig>, virtual public armarx::Component { public: @@ -58,5 +57,13 @@ namespace armarx /// @see PropertyUser::createPropertyDefinitions() armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + AronComponentConfigExample(); + private: + SimplePeriodicTask<>::pointer_type periodicTask; + std::experimental::observer_ptr<plugins::RemoteGuiComponentPlugin> remote_gui_plugin_{nullptr}; + std::experimental::observer_ptr<plugins::AronComponentConfigPlugin<armarx::component_config::aron::TestConfig>> + aron_component_config_plugin_{nullptr}; + std::mutex write_mutex; + }; } \ No newline at end of file diff --git a/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml b/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml index e449a7616..56dc87b41 100644 --- a/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml +++ b/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml @@ -39,6 +39,16 @@ <int/> </List> </ObjectChild> + <ObjectChild key='stringDictMember'> + <Dict> + <string/> + </Dict> + </ObjectChild> + <ObjectChild key='intDictMember'> + <Dict> + <int/> + </Dict> + </ObjectChild> </Object> <Object name='armarx::component_config::aron::SubConfig'> diff --git a/source/RobotAPI/libraries/aron_component_config/ComponentPlugin.h b/source/RobotAPI/libraries/aron_component_config/ComponentPlugin.h index 568f62447..ae144f245 100644 --- a/source/RobotAPI/libraries/aron_component_config/ComponentPlugin.h +++ b/source/RobotAPI/libraries/aron_component_config/ComponentPlugin.h @@ -86,10 +86,9 @@ namespace armarx::plugins return RemoteGui::makeConfigGui(name, config_.getUpToDateReadBuffer()); } - bool updateRemoteGui(armarx::RemoteGui::TabProxy& prx) + bool updateRemoteGui(armarx::RemoteGui::TabProxy& prx) // prx has to be already updated; otherwise nothing will change { ARMARX_TRACE; - prx.receiveUpdates(); armarx::aron::component_config::GetValueFromMapVisitor vis(&prx); auto& cfg = config_.getWriteBuffer(); auto data = std::static_pointer_cast<armarx::aron::data::Variant>(cfg.toAron()); @@ -107,56 +106,5 @@ namespace armarx::plugins armarx::WriteBufferedTripleBuffer<AronStructT> config_; - }; -} - -namespace armarx -{ - template <typename AronStructT> - requires plugins::isAronGenerated<AronStructT> - class AronComponentConfigPluginUser : virtual public ManagedIceObject - { - public: - void onConnectComponent() override - { - remote_gui_plugin_->createOrUpdateTab(aron_component_config_plugin_->buildRemoteGui("Config"), - [this](armarx::RemoteGui::TabProxy& prx) - { - if (aron_component_config_plugin_->updateRemoteGui(prx)) - { - remote_gui_plugin_->createOrUpdateTab("", - aron_component_config_plugin_ - ->buildRemoteGui( - "Config")); - } - }); - } - - AronComponentConfigPluginUser() - { - addPlugin(remote_gui_plugin_, ""); - addPlugin(aron_component_config_plugin_, ""); - } - - AronStructT& getConfigWriteBuffer() - { - return aron_component_config_plugin_->config_.getWriteBuffer(); - } - - void commitConfigWriteBuffer() - { - aron_component_config_plugin_->config_.commitWrite(); - } - - const AronStructT& getUpToDateConfigReadBuffer() const - { - return aron_component_config_plugin_->config_.getUpToDateReadBuffer(); - } - - private: - std::experimental::observer_ptr<plugins::RemoteGuiComponentPlugin> remote_gui_plugin_{nullptr}; - std::experimental::observer_ptr<plugins::AronComponentConfigPlugin<AronStructT>> - aron_component_config_plugin_{nullptr}; - }; } \ No newline at end of file -- GitLab