FairMQ: Implement GetPropertyKeys config API

This commit is contained in:
Dennis Klein 2017-09-27 21:37:51 +02:00 committed by Mohammad Al-Turany
parent 2589ca5ced
commit 8c8ee45914
4 changed files with 27 additions and 1 deletions

View File

@ -90,6 +90,7 @@ class Plugin
auto GetProperty(const std::string& key) const -> T { return fPluginServices->GetProperty<T>(key); } auto GetProperty(const std::string& key) const -> T { return fPluginServices->GetProperty<T>(key); }
auto GetPropertyAsString(const std::string& key) const -> std::string { return fPluginServices->GetPropertyAsString(key); } auto GetPropertyAsString(const std::string& key) const -> std::string { return fPluginServices->GetPropertyAsString(key); }
auto GetChannelInfo() const -> std::unordered_map<std::string, int> { return fPluginServices->GetChannelInfo(); } auto GetChannelInfo() const -> std::unordered_map<std::string, int> { return fPluginServices->GetChannelInfo(); }
auto GetPropertyKeys() const -> std::vector<std::string> { return fPluginServices->GetPropertyKeys(); }
// template<typename T> // template<typename T>
// auto SubscribeToPropertyChange(std::function<void(const std::string& [>key*/, const T /*newValue<])> callback) const -> void { fPluginServices.SubscribeToPropertyChange(fkName, callback); } // auto SubscribeToPropertyChange(std::function<void(const std::string& [>key*/, const T /*newValue<])> callback) const -> void { fPluginServices.SubscribeToPropertyChange(fkName, callback); }
// template<typename T> // template<typename T>

View File

@ -206,6 +206,8 @@ class PluginServices
auto GetChannelInfo() const -> std::unordered_map<std::string, int> { return fConfig->GetChannelInfo(); } auto GetChannelInfo() const -> std::unordered_map<std::string, int> { return fConfig->GetChannelInfo(); }
auto GetPropertyKeys() const -> std::vector<std::string> { return fConfig->GetPropertyKeys(); }
/// @brief Subscribe to property updates of type T /// @brief Subscribe to property updates of type T
/// @param subscriber /// @param subscriber
/// @param callback function /// @param callback function
@ -228,7 +230,6 @@ class PluginServices
// auto UnsubscribeFromPropertyChange(const std::string& subscriber) -> void { fConfig->Unsubscribe<T>(subscriber); } // auto UnsubscribeFromPropertyChange(const std::string& subscriber) -> void { fConfig->Unsubscribe<T>(subscriber); }
// //
// TODO Fix property subscription // TODO Fix property subscription
// TODO Property iterator
static const std::unordered_map<std::string, DeviceState> fkDeviceStateStrMap; static const std::unordered_map<std::string, DeviceState> fkDeviceStateStrMap;
static const std::unordered_map<DeviceState, std::string, tools::HashEnum<DeviceState>> fkStrDeviceStateMap; static const std::unordered_map<DeviceState, std::string, tools::HashEnum<DeviceState>> fkStrDeviceStateMap;

View File

@ -64,6 +64,20 @@ class FairProgOptions
FairProgOptions(); FairProgOptions();
virtual ~FairProgOptions(); virtual ~FairProgOptions();
auto GetPropertyKeys() const -> std::vector<std::string>
{
std::lock_guard<std::mutex> lock{fConfigMutex};
std::vector<std::string> result;
for (const auto& it : fVarMap)
{
result.push_back(it.first.c_str());
}
return result;
}
// add options_description // add options_description
int AddToCmdLineOptions(const po::options_description optDesc, bool visible = true); int AddToCmdLineOptions(const po::options_description optDesc, bool visible = true);
int AddToCfgFileOptions(const po::options_description optDesc, bool visible = true); int AddToCfgFileOptions(const po::options_description optDesc, bool visible = true);

View File

@ -8,6 +8,7 @@
#include "Fixture.h" #include "Fixture.h"
#include <fairmq/Tools.h> #include <fairmq/Tools.h>
#include <algorithm>
namespace 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 */ } /* namespace */