mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Add PluginServices::DeleteProperty, test for property accessors
This commit is contained in:
committed by
Dennis Klein
parent
5271d4236e
commit
7bea2bc0e6
@@ -107,6 +107,8 @@ class Plugin
|
||||
bool UpdateProperty(const std::string& key, T val) { return fPluginServices->UpdateProperty(key, val); }
|
||||
bool UpdateProperties(const fair::mq::Properties& input) { return fPluginServices->UpdateProperties(input); }
|
||||
|
||||
void DeleteProperty(const std::string& key) { fPluginServices->DeleteProperty(key); }
|
||||
|
||||
template<typename T>
|
||||
auto SubscribeToPropertyChange(std::function<void(const std::string& key, T newValue)> callback) -> void { fPluginServices->SubscribeToPropertyChange<T>(fkName, callback); }
|
||||
template<typename T>
|
||||
|
@@ -185,33 +185,20 @@ class PluginServices
|
||||
/// @brief Set config property
|
||||
/// @param key
|
||||
/// @param val
|
||||
/// @throws fair::mq::PluginServices::InvalidStateError if method is called in unsupported device states
|
||||
///
|
||||
/// Setting a config property will store the value in the FairMQ internal config store and notify any subscribers about the update.
|
||||
/// It is property dependent, if the call to this method will have an immediate, delayed or any effect at all.
|
||||
template<typename T>
|
||||
auto SetProperty(const std::string& key, T val) -> void
|
||||
{
|
||||
auto currentState = GetCurrentDeviceState();
|
||||
if ( (currentState == DeviceState::InitializingDevice)
|
||||
|| (currentState == DeviceState::Initialized)
|
||||
|| (currentState == DeviceState::Binding)
|
||||
|| (currentState == DeviceState::Bound)
|
||||
|| (currentState == DeviceState::Connecting)
|
||||
|| (currentState == DeviceState::Ready)) {
|
||||
fConfig.SetProperty(key, val);
|
||||
} else {
|
||||
throw InvalidStateError{
|
||||
tools::ToString("PluginServices::SetProperty is not supported in device state ", currentState, ". ",
|
||||
"Supported state is ", DeviceState::InitializingDevice, ".")};
|
||||
}
|
||||
fConfig.SetProperty(key, val);
|
||||
}
|
||||
void SetProperties(const fair::mq::Properties& props) { fConfig.SetProperties(props); }
|
||||
template<typename T>
|
||||
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; };
|
||||
void DeleteProperty(const std::string& key) { fConfig.DeleteProperty(key); }
|
||||
|
||||
/// @brief Read config property
|
||||
/// @param key
|
||||
|
@@ -50,6 +50,7 @@ pair<string, string> getStringPair(const boost::any& v, const string& label)
|
||||
unordered_map<type_index, function<pair<string, string>(const Property&)>> PropertyHelper::fTypeInfos = {
|
||||
{ type_index(typeid(char)), [](const Property& p) { return pair<string, string>{ string(1, any_cast<char>(p)), "char" }; } },
|
||||
{ type_index(typeid(unsigned char)), [](const Property& p) { return pair<string, string>{ string(1, any_cast<unsigned char>(p)), "unsigned char" }; } },
|
||||
{ type_index(typeid(const char*)), [](const Property& p) { return pair<string, string>{ string(any_cast<const char*>(p)), "string" }; } },
|
||||
{ type_index(typeid(string)), [](const Property& p) { return pair<string, string>{ any_cast<string>(p), "string" }; } },
|
||||
{ type_index(typeid(int)), [](const Property& p) { return getString<int>(p, "int"); } },
|
||||
{ type_index(typeid(size_t)), [](const Property& p) { return getString<size_t>(p, "size_t"); } },
|
||||
@@ -87,6 +88,7 @@ unordered_map<type_index, function<pair<string, string>(const Property&)>> Prope
|
||||
unordered_map<type_index, void(*)(const EventManager&, const string&, const Property&)> PropertyHelper::fEventEmitters = {
|
||||
{ type_index(typeid(char)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, char>(k, any_cast<char>(p)); } },
|
||||
{ type_index(typeid(unsigned char)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, unsigned char>(k, any_cast<unsigned char>(p)); } },
|
||||
{ type_index(typeid(const char*)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, string>(k, string(any_cast<const char*>(p))); } },
|
||||
{ type_index(typeid(string)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, string>(k, any_cast<string>(p)); } },
|
||||
{ type_index(typeid(int)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, int>(k, any_cast<int>(p)); } },
|
||||
{ type_index(typeid(size_t)), [](const EventManager& em, const string& k, const Property& p) { em.Emit<PropertyChange, size_t>(k, any_cast<size_t>(p)); } },
|
||||
|
Reference in New Issue
Block a user