mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-12-14 15:00:17 +00:00
FairMQ: Implement PluginServices - Config
This commit is contained in:
committed by
Mohammad Al-Turany
parent
739460b2fe
commit
ad0f050c99
@@ -16,6 +16,8 @@
|
||||
#ifndef FAIRMQEVENTMANAGER_H
|
||||
#define FAIRMQEVENTMANAGER_H
|
||||
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
@@ -97,7 +99,7 @@ class FairMQEventManager
|
||||
}
|
||||
|
||||
template <EventId event, typename... ValueType>
|
||||
void Disonnect(const std::string& key)
|
||||
void Disconnect(const std::string& key)
|
||||
{
|
||||
GetSlot<event, ValueType...>(key).disconnect();
|
||||
}
|
||||
@@ -111,14 +113,7 @@ class FairMQEventManager
|
||||
template <EventId event>
|
||||
bool EventKeyFound(const std::string& key)
|
||||
{
|
||||
if (fEventMap.find(std::pair<EventId, std::string>(event, key)) != fEventMap.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return fEventMap.find(std::pair<EventId, std::string>(event, key)) != fEventMap.end();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -205,6 +205,37 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SetValue(const std::string& key, T val)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
// update variable map
|
||||
UpdateVarMap<typename std::decay<T>::type>(key, val);
|
||||
|
||||
// update FairMQChannel map, check first if data are int or string
|
||||
if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
|
||||
{
|
||||
if (fMQKeyMap.count(key))
|
||||
{
|
||||
std::string channelName;
|
||||
int index = 0;
|
||||
std::string member;
|
||||
std::tie(channelName, index, member) = fMQKeyMap.at(key);
|
||||
UpdateChannelMap(channelName, index, member, val);
|
||||
}
|
||||
}
|
||||
|
||||
// execute stored function of a given key if exist
|
||||
//if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)//if one wants to restrict type
|
||||
if (EventKeyFound(key))
|
||||
{
|
||||
EmitUpdate<typename std::decay<T>::type>(key, val);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T, typename F>
|
||||
void Subscribe(const std::string& key, F&& func) const
|
||||
{
|
||||
@@ -215,10 +246,19 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
FairMQEventManager::Connect<EventId::UpdateParam, T>(key, std::forward<F>(func));
|
||||
Connect<EventId::UpdateParam, T>(key, std::forward<F>(func));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Unsubscribe(const std::string& key) const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
Disconnect<EventId::UpdateParam, T>(key);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
template <typename F>
|
||||
void Subscribe(const std::string& key, F&& func)
|
||||
|
||||
@@ -59,7 +59,7 @@ FairProgOptions::~FairProgOptions()
|
||||
|
||||
/// //////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Add option descriptions
|
||||
int FairProgOptions::AddToCmdLineOptions(const po::options_description& optDesc, bool visible)
|
||||
int FairProgOptions::AddToCmdLineOptions(const po::options_description optDesc, bool visible)
|
||||
{
|
||||
fCmdLineOptions.add(optDesc);
|
||||
if (visible)
|
||||
@@ -69,7 +69,7 @@ int FairProgOptions::AddToCmdLineOptions(const po::options_description& optDesc,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FairProgOptions::AddToCfgFileOptions(const po::options_description& optDesc, bool visible)
|
||||
int FairProgOptions::AddToCfgFileOptions(const po::options_description optDesc, bool visible)
|
||||
{
|
||||
//if UseConfigFile() not yet called, then enable it with required file name to be provided by command line
|
||||
if (!fUseConfigFile)
|
||||
@@ -100,7 +100,7 @@ po::options_description& FairProgOptions::GetEnvironmentOptions()
|
||||
return fEnvironmentDesc;
|
||||
}
|
||||
|
||||
int FairProgOptions::AddToEnvironmentOptions(const po::options_description& optDesc)
|
||||
int FairProgOptions::AddToEnvironmentOptions(const po::options_description optDesc)
|
||||
{
|
||||
fEnvironmentDesc.add(optDesc);
|
||||
return 0;
|
||||
|
||||
@@ -65,9 +65,9 @@ class FairProgOptions
|
||||
virtual ~FairProgOptions();
|
||||
|
||||
// add options_description
|
||||
int AddToCmdLineOptions(const po::options_description& optDesc, bool visible = true);
|
||||
int AddToCfgFileOptions(const po::options_description& optDesc, bool visible = true);
|
||||
int AddToEnvironmentOptions(const po::options_description& optDesc);
|
||||
int AddToCmdLineOptions(const po::options_description optDesc, bool visible = true);
|
||||
int AddToCfgFileOptions(const po::options_description optDesc, bool visible = true);
|
||||
int AddToEnvironmentOptions(const po::options_description optDesc);
|
||||
po::options_description& GetCmdLineOptions();
|
||||
po::options_description& GetCfgFileOptions();
|
||||
po::options_description& GetEnvironmentOptions();
|
||||
|
||||
Reference in New Issue
Block a user