diff --git a/fairmq/Plugin.h b/fairmq/Plugin.h index 8d1eeece..bf3b9e0f 100644 --- a/fairmq/Plugin.h +++ b/fairmq/Plugin.h @@ -95,6 +95,8 @@ class Plugin auto SubscribeToPropertyChange(std::function callback) -> void { fPluginServices->SubscribeToPropertyChange(fkName, callback); } template auto UnsubscribeFromPropertyChange() -> void { fPluginServices->UnsubscribeFromPropertyChange(fkName); } + auto SubscribeToPropertyChangeAsString(std::function callback) -> void { fPluginServices->SubscribeToPropertyChangeAsString(fkName, callback); } + auto UnsubscribeFromPropertyChangeAsString() -> void { fPluginServices->UnsubscribeFromPropertyChangeAsString(fkName); } private: const std::string fkName; diff --git a/fairmq/PluginServices.h b/fairmq/PluginServices.h index 65f76260..11450955 100644 --- a/fairmq/PluginServices.h +++ b/fairmq/PluginServices.h @@ -226,6 +226,21 @@ class PluginServices template auto UnsubscribeFromPropertyChange(const std::string& subscriber) -> void { fConfig->Unsubscribe(subscriber); } + /// @brief Subscribe to property updates + /// @param subscriber + /// @param callback function + /// + /// Subscribe to property changes with a callback to monitor property changes in an event based fashion. Will convert the property to string. + auto SubscribeToPropertyChangeAsString(const std::string& subscriber, std::function callback) const -> void + { + fConfig->SubscribeAsString(subscriber, callback); + } + + /// @brief Unsubscribe from property updates that convert to string + /// @param subscriber + auto UnsubscribeFromPropertyChangeAsString(const std::string& subscriber) -> void { fConfig->UnsubscribeAsString(subscriber); } + + static const std::unordered_map fkDeviceStateStrMap; static const std::unordered_map> fkStrDeviceStateMap; static const std::unordered_map fkDeviceStateTransitionStrMap; diff --git a/fairmq/options/FairMQProgOptions.h b/fairmq/options/FairMQProgOptions.h index 923b9715..bc184685 100644 --- a/fairmq/options/FairMQProgOptions.h +++ b/fairmq/options/FairMQProgOptions.h @@ -34,6 +34,7 @@ namespace mq { struct PropertyChange : Event {}; +struct PropertyChangeAsString : Event {}; } /* namespace mq */ } /* namespace fair */ @@ -204,8 +205,10 @@ class FairMQProgOptions : public FairProgOptions } } + lock.unlock(); //if (std::is_same::value || std::is_same::value)//if one wants to restrict type fEvents.Emit::type>(key, val); + fEvents.Emit(key, GetStringValue(key)); return 0; } @@ -240,8 +243,11 @@ class FairMQProgOptions : public FairProgOptions } } + lock.unlock(); + //if (std::is_same::value || std::is_same::value)//if one wants to restrict type fEvents.Emit::type>(key, val); + fEvents.Emit(key, GetStringValue(key)); return 0; } @@ -265,6 +271,19 @@ class FairMQProgOptions : public FairProgOptions fEvents.Unsubscribe(subscriber); } + void SubscribeAsString(const std::string& subscriber, std::function func) + { + std::unique_lock lock(fConfigMutex); + + fEvents.Subscribe(subscriber, func); + } + + void UnsubscribeAsString(const std::string& subscriber) + { + std::unique_lock lock(fConfigMutex); + + fEvents.Unsubscribe(subscriber); + } /* template void Subscribe(const std::string& key, F&& func) @@ -328,6 +347,7 @@ class FairMQProgOptions : public FairProgOptions static_assert(!std::is_same::value || !std::is_same::value, "In template member FairMQProgOptions::EmitUpdate(key,val) the types const char* or char* for the calback signatures are not supported."); fEvents.Emit(key, val); + fEvents.Emit(key, GetStringValue(key)); } int UpdateChannelMap(const std::string& channelName, int index, const std::string& member, const std::string& val);