mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Add UpdateProperty/ies()
This commit is contained in:
parent
b905f517cc
commit
7c9744760e
|
@ -38,8 +38,7 @@ auto DeviceRunner::Run() -> int
|
||||||
fEvents.Emit<hooks::SetCustomCmdLineOptions>(*this);
|
fEvents.Emit<hooks::SetCustomCmdLineOptions>(*this);
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
fPluginManager.ForEachPluginProgOptions(
|
fPluginManager.ForEachPluginProgOptions([&](boost::program_options::options_description options) {
|
||||||
[&](boost::program_options::options_description options) {
|
|
||||||
fConfig.AddToCmdLineOptions(options);
|
fConfig.AddToCmdLineOptions(options);
|
||||||
});
|
});
|
||||||
fConfig.AddToCmdLineOptions(fPluginManager.ProgramOptions());
|
fConfig.AddToCmdLineOptions(fPluginManager.ProgramOptions());
|
||||||
|
|
|
@ -103,6 +103,9 @@ class Plugin
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto SetProperty(const std::string& key, T val) -> void { fPluginServices->SetProperty(key, val); }
|
auto SetProperty(const std::string& key, T val) -> void { fPluginServices->SetProperty(key, val); }
|
||||||
void SetProperties(const fair::mq::Properties& props) { fPluginServices->SetProperties(props); }
|
void SetProperties(const fair::mq::Properties& props) { fPluginServices->SetProperties(props); }
|
||||||
|
template<typename T>
|
||||||
|
bool UpdateProperty(const std::string& key, T val) { return fPluginServices->UpdateProperty(key, val); }
|
||||||
|
bool UpdateProperties(const fair::mq::Properties& input) { return fPluginServices->UpdateProperties(input); }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto SubscribeToPropertyChange(std::function<void(const std::string& key, T newValue)> callback) -> void { fPluginServices->SubscribeToPropertyChange<T>(fkName, callback); }
|
auto SubscribeToPropertyChange(std::function<void(const std::string& key, T newValue)> callback) -> void { fPluginServices->SubscribeToPropertyChange<T>(fkName, callback); }
|
||||||
|
|
|
@ -206,10 +206,11 @@ class PluginServices
|
||||||
"Supported state is ", DeviceState::InitializingDevice, ".")};
|
"Supported state is ", DeviceState::InitializingDevice, ".")};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void SetProperties(const fair::mq::Properties& props)
|
void SetProperties(const fair::mq::Properties& props) { fConfig.SetProperties(props); }
|
||||||
{
|
template<typename T>
|
||||||
fConfig.SetProperties(props);
|
bool UpdateProperty(const std::string& key, T val) { return fConfig.UpdateProperty(key, val); }
|
||||||
}
|
bool UpdateProperties(const fair::mq::Properties& input) { return fConfig.UpdateProperties(input); }
|
||||||
|
|
||||||
struct InvalidStateError : std::runtime_error { using std::runtime_error::runtime_error; };
|
struct InvalidStateError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||||
|
|
||||||
/// @brief Read config property
|
/// @brief Read config property
|
||||||
|
|
|
@ -21,9 +21,10 @@
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <exception>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <exception>
|
#include <sstream>
|
||||||
#include <utility> // pair
|
#include <utility> // pair
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -111,6 +112,7 @@ void ProgOptions::ParseAll(const vector<string>& cmdArgs, bool allowUnregistered
|
||||||
|
|
||||||
void ProgOptions::ParseAll(const int argc, char const* const* argv, bool allowUnregistered)
|
void ProgOptions::ParseAll(const int argc, char const* const* argv, bool allowUnregistered)
|
||||||
{
|
{
|
||||||
|
lock_guard<mutex> lock(fMtx);
|
||||||
// clear the container because it was filled with default values and subsequent calls to store() do not overwrite the existing values
|
// clear the container because it was filled with default values and subsequent calls to store() do not overwrite the existing values
|
||||||
fVarMap.clear();
|
fVarMap.clear();
|
||||||
|
|
||||||
|
@ -128,11 +130,13 @@ void ProgOptions::ParseAll(const int argc, char const* const* argv, bool allowUn
|
||||||
|
|
||||||
void ProgOptions::Notify()
|
void ProgOptions::Notify()
|
||||||
{
|
{
|
||||||
|
lock_guard<mutex> lock(fMtx);
|
||||||
po::notify(fVarMap);
|
po::notify(fVarMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgOptions::AddToCmdLineOptions(const po::options_description optDesc, bool /* visible */)
|
void ProgOptions::AddToCmdLineOptions(const po::options_description optDesc, bool /* visible */)
|
||||||
{
|
{
|
||||||
|
lock_guard<mutex> lock(fMtx);
|
||||||
fAllOptions.add(optDesc);
|
fAllOptions.add(optDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +302,32 @@ void ProgOptions::SetProperties(const Properties& input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProgOptions::UpdateProperties(const Properties& input)
|
||||||
|
{
|
||||||
|
unique_lock<mutex> lock(fMtx);
|
||||||
|
|
||||||
|
for (const auto& m : input) {
|
||||||
|
if (fVarMap.count(m.first) == 0) {
|
||||||
|
LOG(debug) << "UpdateProperties failed, no property found with key '" << m.first << "'";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
map<string, boost::program_options::variable_value>& vm = fVarMap;
|
||||||
|
for (const auto& m : input) {
|
||||||
|
vm[m.first].value() = m.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
for (const auto& m : input) {
|
||||||
|
PropertyHelper::fEventEmitters.at(m.second.type())(fEvents, m.first, m.second);
|
||||||
|
fEvents.Emit<PropertyChangeAsString, string>(m.first, PropertyHelper::ConvertPropertyToString(m.second));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void ProgOptions::DeleteProperty(const string& key)
|
void ProgOptions::DeleteProperty(const string& key)
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(fMtx);
|
lock_guard<mutex> lock(fMtx);
|
||||||
|
|
|
@ -9,23 +9,21 @@
|
||||||
#ifndef FAIR_MQ_PROGOPTIONS_H
|
#ifndef FAIR_MQ_PROGOPTIONS_H
|
||||||
#define FAIR_MQ_PROGOPTIONS_H
|
#define FAIR_MQ_PROGOPTIONS_H
|
||||||
|
|
||||||
#include <fairmq/EventManager.h>
|
|
||||||
#include "FairMQLogger.h"
|
|
||||||
#include "FairMQChannel.h"
|
#include "FairMQChannel.h"
|
||||||
|
#include "FairMQLogger.h"
|
||||||
|
#include <fairmq/EventManager.h>
|
||||||
|
#include <fairmq/ProgOptionsFwd.h>
|
||||||
#include <fairmq/Properties.h>
|
#include <fairmq/Properties.h>
|
||||||
#include <fairmq/Tools.h>
|
#include <fairmq/Tools.h>
|
||||||
#include <fairmq/ProgOptionsFwd.h>
|
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <map>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <map>
|
||||||
#include <vector>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sstream>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace fair
|
namespace fair
|
||||||
{
|
{
|
||||||
|
@ -90,10 +88,30 @@ class ProgOptions
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
fEvents.Emit<fair::mq::PropertyChange, typename std::decay<T>::type>(key, val);
|
fEvents.Emit<fair::mq::PropertyChange, typename std::decay<T>::type>(key, val);
|
||||||
fEvents.Emit<fair::mq::PropertyChangeAsString, std::string>(key, GetStringValue(key));
|
fEvents.Emit<fair::mq::PropertyChangeAsString, std::string>(key, GetPropertyAsString(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool UpdateProperty(const std::string& key, T val)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(fMtx);
|
||||||
|
|
||||||
|
if (fVarMap.count(key)) {
|
||||||
|
SetVarMapValue<typename std::decay<T>::type>(key, val);
|
||||||
|
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
fEvents.Emit<fair::mq::PropertyChange, typename std::decay<T>::type>(key, val);
|
||||||
|
fEvents.Emit<fair::mq::PropertyChangeAsString, std::string>(key, GetPropertyAsString(key));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
LOG(debug) << "UpdateProperty failed, no property found with key '" << key << "'";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetProperties(const fair::mq::Properties& input);
|
void SetProperties(const fair::mq::Properties& input);
|
||||||
|
bool UpdateProperties(const fair::mq::Properties& input);
|
||||||
void DeleteProperty(const std::string& key);
|
void DeleteProperty(const std::string& key);
|
||||||
|
|
||||||
void AddChannel(const std::string& name, const FairMQChannel& channel);
|
void AddChannel(const std::string& name, const FairMQChannel& channel);
|
||||||
|
|
|
@ -19,5 +19,4 @@ class ProgOptions;
|
||||||
|
|
||||||
using FairMQProgOptions = fair::mq::ProgOptions;
|
using FairMQProgOptions = fair::mq::ProgOptions;
|
||||||
|
|
||||||
#endif
|
#endif /* FAIR_MQ_PROGOPTIONSFWD_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user