16 #ifndef FAIRMQPROGOPTIONS_H 17 #define FAIRMQPROGOPTIONS_H 19 #include <fairmq/EventManager.h> 21 #include "FairProgOptions.h" 22 #include "FairMQChannel.h" 24 #include <unordered_map> 44 using FairMQMap = std::unordered_map<std::string, std::vector<FairMQChannel>>;
50 int ParseAll(
const std::vector<std::string>& cmdLineArgs,
bool allowUnregistered);
53 int ParseAll(
const int argc,
char const*
const* argv,
bool allowUnregistered =
false)
override;
55 FairMQMap GetFairMQMap()
const 60 std::unordered_map<std::string, int> GetChannelInfo()
const 66 int UpdateValue(
const std::string& key, T val)
68 std::unique_lock<std::mutex> lock(fConfigMutex);
70 if (fVarMap.count(key))
73 UpdateVarMap<typename std::decay<T>::type>(key, val);
76 if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
78 if (fMQKeyMap.count(key))
80 UpdateChannelMap(fMQKeyMap.at(key).channel, fMQKeyMap.at(key).index, fMQKeyMap.at(key).member, val);
93 LOG(error) <<
"UpdateValue failed: key '" << key <<
"' not found in the variable map";
100 int SetValue(
const std::string& key, T val)
102 std::unique_lock<std::mutex> lock(fConfigMutex);
105 UpdateVarMap<typename std::decay<T>::type>(key, val);
108 if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
110 if (fMQKeyMap.count(key))
112 UpdateChannelMap(fMQKeyMap.at(key).channel, fMQKeyMap.at(key).index, fMQKeyMap.at(key).member, val);
125 template <
typename T>
126 void Subscribe(
const std::string& subscriber, std::function<
void(
typename fair::mq::PropertyChange::KeyType, T)> func)
128 std::unique_lock<std::mutex> lock(fConfigMutex);
130 static_assert(!std::is_same<T,const char*>::value || !std::is_same<T, char*>::value,
131 "In template member FairMQProgOptions::Subscribe<T>(key,Lambda) the types const char* or char* for the calback signatures are not supported.");
136 template <
typename T>
137 void Unsubscribe(
const std::string& subscriber)
139 std::unique_lock<std::mutex> lock(fConfigMutex);
144 void SubscribeAsString(
const std::string& subscriber, std::function<
void(
typename fair::mq::PropertyChange::KeyType, std::string)> func)
146 std::unique_lock<std::mutex> lock(fConfigMutex);
151 void UnsubscribeAsString(
const std::string& subscriber)
153 std::unique_lock<std::mutex> lock(fConfigMutex);
159 int UpdateChannelMap(
const FairMQMap& map);
169 po::options_description fMQCmdOptions;
170 po::options_description fMQParserOptions;
171 FairMQMap fFairMQMap;
174 std::unordered_map<std::string, int> fChannelInfo;
176 std::map<std::string, MQKey> fMQKeyMap;
178 int ImmediateOptions()
override;
179 void InitOptionDescription();
183 void UpdateMQValues();
184 int Store(
const FairMQMap& channels);
188 void EmitUpdate(
const std::string& key, T val)
191 static_assert(!std::is_same<T,const char*>::value || !std::is_same<T, char*>::value,
192 "In template member FairMQProgOptions::EmitUpdate<T>(key,val) the types const char* or char* for the calback signatures are not supported.");
197 int UpdateChannelMap(
const std::string& channelName,
int index,
const std::string& member,
const std::string& val);
198 int UpdateChannelMap(
const std::string& channelName,
int index,
const std::string& member,
int val);
201 int UpdateChannelMap(
const std::string& ,
int ,
const std::string& , T )
206 void UpdateChannelInfo();
Definition: FairMQProgOptions.h:162
Definition: EventManager.h:33
Definition: FairProgOptions.h:35
Manages event callbacks from different subscribers.
Definition: EventManager.h:53
Definition: FairMQProgOptions.h:41
Definition: FairMQProgOptions.h:36
Definition: DeviceRunner.h:23
Definition: FairMQProgOptions.h:35