diff --git a/fairmq/Plugin.h b/fairmq/Plugin.h index f83bf506..7dd5f680 100644 --- a/fairmq/Plugin.h +++ b/fairmq/Plugin.h @@ -90,6 +90,7 @@ class Plugin 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); } auto GetChannelInfo() const -> std::unordered_map { return fPluginServices->GetChannelInfo(); } + auto GetPropertyKeys() const -> std::vector { return fPluginServices->GetPropertyKeys(); } // template // auto SubscribeToPropertyChange(std::functionkey*/, const T /*newValue<])> callback) const -> void { fPluginServices.SubscribeToPropertyChange(fkName, callback); } // template diff --git a/fairmq/PluginServices.h b/fairmq/PluginServices.h index c3bf6b33..6333769c 100644 --- a/fairmq/PluginServices.h +++ b/fairmq/PluginServices.h @@ -206,6 +206,8 @@ class PluginServices auto GetChannelInfo() const -> std::unordered_map { return fConfig->GetChannelInfo(); } + auto GetPropertyKeys() const -> std::vector { return fConfig->GetPropertyKeys(); } + /// @brief Subscribe to property updates of type T /// @param subscriber /// @param callback function @@ -228,7 +230,6 @@ class PluginServices // auto UnsubscribeFromPropertyChange(const std::string& subscriber) -> void { fConfig->Unsubscribe(subscriber); } // // TODO Fix property subscription - // TODO Property iterator static const std::unordered_map fkDeviceStateStrMap; static const std::unordered_map> fkStrDeviceStateMap; diff --git a/fairmq/options/FairProgOptions.h b/fairmq/options/FairProgOptions.h index b76aa85a..469cdaf9 100644 --- a/fairmq/options/FairProgOptions.h +++ b/fairmq/options/FairProgOptions.h @@ -64,6 +64,20 @@ class FairProgOptions FairProgOptions(); virtual ~FairProgOptions(); + auto GetPropertyKeys() const -> std::vector + { + std::lock_guard lock{fConfigMutex}; + + std::vector result; + + for (const auto& it : fVarMap) + { + result.push_back(it.first.c_str()); + } + + return result; + } + // add options_description int AddToCmdLineOptions(const po::options_description optDesc, bool visible = true); int AddToCfgFileOptions(const po::options_description optDesc, bool visible = true); diff --git a/fairmq/test/plugin_services/_config.cxx b/fairmq/test/plugin_services/_config.cxx index 5f976523..b5920b9f 100644 --- a/fairmq/test/plugin_services/_config.cxx +++ b/fairmq/test/plugin_services/_config.cxx @@ -8,6 +8,7 @@ #include "Fixture.h" #include +#include namespace { @@ -47,4 +48,13 @@ TEST_F(PluginServices, ConfigInvalidStateError) }); } +TEST_F(PluginServices, KeyDiscovery) +{ + mConfig.SetValue("foo", 0); + + auto keys{mServices.GetPropertyKeys()}; + + EXPECT_TRUE(find(keys.begin(), keys.end(), "foo") != keys.end()); +} + } /* namespace */