FairMQ
1.4.33
C++ Message Queuing Library and Framework
|
9 #ifndef FAIR_MQ_PROGOPTIONS_H
10 #define FAIR_MQ_PROGOPTIONS_H
12 #include "FairMQChannel.h"
13 #include "FairMQLogger.h"
14 #include <fairmq/EventManager.h>
15 #include <fairmq/ProgOptionsFwd.h>
16 #include <fairmq/Properties.h>
17 #include <fairmq/tools/Strings.h>
19 #include <boost/program_options.hpp>
25 #include <unordered_map>
32 struct PropertyNotFoundError : std::runtime_error {
using std::runtime_error::runtime_error; };
40 void ParseAll(
const std::vector<std::string>& cmdArgs,
bool allowUnregistered);
41 void ParseAll(
const int argc,
char const*
const* argv,
bool allowUnregistered =
true);
44 void AddToCmdLineOptions(
const boost::program_options::options_description optDesc,
bool visible =
true);
45 boost::program_options::options_description& GetCmdLineOptions();
50 int Count(
const std::string& key)
const;
65 std::lock_guard<std::mutex> lock(fMtx);
66 if (fVarMap.count(key)) {
67 return fVarMap[key].as<T>();
78 T
GetProperty(
const std::string& key,
const T& ifNotFound)
const
80 std::lock_guard<std::mutex> lock(fMtx);
81 if (fVarMap.count(key)) {
82 return fVarMap[key].as<T>();
103 std::string
GetPropertyAsString(
const std::string& key,
const std::string& ifNotFound)
const;
108 fair::mq::Properties
GetProperties(
const std::string& q)
const;
132 std::unique_lock<std::mutex> lock(fMtx);
134 SetVarMapValue<typename std::decay<T>::type>(key, val);
148 std::unique_lock<std::mutex> lock(fMtx);
150 if (fVarMap.count(key)) {
151 SetVarMapValue<typename std::decay<T>::type>(key, val);
159 LOG(debug) <<
"UpdateProperty failed, no property found with key '" << key <<
"'";
185 void Subscribe(
const std::string& subscriber, std::function<
void(
typename fair::mq::PropertyChange::KeyType, T)> func)
const
187 std::lock_guard<std::mutex> lock(fMtx);
188 static_assert(!std::is_same<T,const char*>::value || !std::is_same<T, char*>::value,
189 "In template member ProgOptions::Subscribe<T>(key,Lambda) the types const char* or char* for the calback signatures are not supported.");
196 void Unsubscribe(
const std::string& subscriber)
const
198 std::lock_guard<std::mutex> lock(fMtx);
207 void SubscribeAsString(
const std::string& subscriber, std::function<
void(
typename fair::mq::PropertyChange::KeyType, std::string)> func)
const
209 std::lock_guard<std::mutex> lock(fMtx);
217 std::lock_guard<std::mutex> lock(fMtx);
229 const boost::program_options::variables_map&
GetVarMap()
const {
return fVarMap; }
237 std::lock_guard<std::mutex> lock(fMtx);
238 if (fVarMap.count(key)) {
239 return fVarMap[key].as<T>();
241 LOG(warn) <<
"Config has no key: " << key <<
". Returning default constructed object.";
246 int SetValue(
const std::string& key, T val) {
SetProperty(key, val);
return 0; }
253 void ParseDefaults();
254 std::unordered_map<std::string, int> GetChannelInfoImpl()
const;
257 void SetVarMapValue(
const std::string& key,
const T& val)
259 std::map<std::string, boost::program_options::variable_value>& vm = fVarMap;
260 vm[key].value() = boost::any(val);
263 boost::program_options::variables_map fVarMap;
264 boost::program_options::options_description fAllOptions;
265 std::vector<std::string> fUnregisteredOptions;
268 mutable std::mutex fMtx;
Definition: ProgOptions.h:41
std::vector< std::string > GetPropertyKeys() const
Discover the list of property keys.
Definition: ProgOptions.cxx:189
const boost::program_options::variables_map & GetVarMap() const
returns the property container
Definition: ProgOptions.h:235
fair::mq::Properties GetPropertiesStartingWith(const std::string &q) const
Read several config properties whose keys start with the provided string.
Definition: ProgOptions.cxx:256
bool UpdateProperty(const std::string &key, T val)
Updates an existing config property (or fails if it doesn't exist)
Definition: ProgOptions.h:152
void Unsubscribe(const std::string &subscriber) const
Unsubscribe from property updates of type T.
Definition: ProgOptions.h:202
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
void AddChannel(const std::string &name, const FairMQChannel &channel)
Takes the provided channel and creates properties based on it.
Definition: ProgOptions.cxx:357
T GetProperty(const std::string &key) const
Read config property, throw if no property with this key exists.
Definition: ProgOptions.h:69
std::string GetPropertyAsString(const std::string &key) const
Read config property as string, throw if no property with this key exists.
void SetProperty(const std::string &key, T val)
Set config property.
Definition: ProgOptions.h:136
std::map< std::string, std::string > GetPropertiesAsString(const std::string &q) const
Read several config properties as string whose keys match the provided regular expression.
Definition: ProgOptions.cxx:271
void PrintHelp() const
prints full options description
Definition: ProgOptions.cxx:383
Definition: Properties.h:37
void SubscribeAsString(const std::string &subscriber, std::function< void(typename fair::mq::PropertyChange::KeyType, std::string)> func) const
Subscribe to property updates, with values converted to string.
Definition: ProgOptions.h:213
Definition: ProgOptions.h:38
Manages event callbacks from different subscribers.
Definition: EventManager.h:56
bool UpdateProperties(const fair::mq::Properties &input)
Updates multiple existing config properties (or fails of any of then do not exist,...
Definition: ProgOptions.cxx:323
void Subscribe(const std::string &subscriber, std::function< void(typename fair::mq::PropertyChange::KeyType, T)> func) const
Subscribe to property updates of type T.
Definition: ProgOptions.h:191
void UnsubscribeAsString(const std::string &subscriber) const
Unsubscribe from property updates that convert to string.
Definition: ProgOptions.h:221
Wrapper class for FairMQSocket and related methods.
Definition: FairMQChannel.h:35
std::map< std::string, std::string > GetPropertiesAsStringStartingWith(const std::string &q) const
Read several config properties as string whose keys start with the provided string.
Definition: ProgOptions.cxx:291
void PrintOptionsRaw() const
prints full options description in a compact machine-readable format
Definition: ProgOptions.cxx:432
void SetProperties(const fair::mq::Properties &input)
Set multiple config properties.
Definition: ProgOptions.cxx:306
fair::mq::Properties GetProperties(const std::string &q) const
Read several config properties whose keys match the provided regular expression.
Definition: ProgOptions.cxx:236
int Count(const std::string &key) const
Checks a property with the given key exist in the configuration.
Definition: ProgOptions.cxx:155
void DeleteProperty(const std::string &key)
Deletes a property with the given key from the config store.
Definition: ProgOptions.cxx:349
Definition: Properties.h:38
std::string GetStringValue(const std::string &key) const
Read config property as string, return default-constructed object if key doesn't exist.
Definition: ProgOptions.cxx:213
T GetValue(const std::string &key) const
Read config property, return default-constructed object if key doesn't exist.
Definition: ProgOptions.h:241
void PrintOptions() const
prints properties stored in the property container
Definition: ProgOptions.cxx:388
std::unordered_map< std::string, int > GetChannelInfo() const
Retrieve current channel information.
Definition: ProgOptions.cxx:161
privacy