Move config & control DDS functionality into plugins.

This commit is contained in:
Alexey Rybalchenko
2016-10-19 16:20:40 +02:00
parent 16fd63cd5b
commit da3010b20c
22 changed files with 868 additions and 567 deletions

View File

@@ -36,15 +36,38 @@ enum class EventId : uint32_t
namespace Events
{
template <EventId,typename ...Args> struct Traits;
template <typename T> struct Traits<EventId::UpdateParam, T> { using signal_type = boost::signals2::signal<void(const std::string&, T)>; } ;
template <typename T> struct Traits<EventId::UpdateParam, std::vector<T> > { using signal_type = boost::signals2::signal<void(const std::string&, const std::vector<T>& )>; } ;
template <EventId,typename ...Args>
struct Traits;
template <> struct Traits<EventId::UpdateParam, std::string> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
template <typename T>
struct Traits<EventId::UpdateParam, T>
{
using signal_type = boost::signals2::signal<void(const std::string&, T)>;
};
template<std::size_t N> struct Traits<EventId::UpdateParam, const char[N]> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
template <typename T>
struct Traits<EventId::UpdateParam, std::vector<T>>
{
using signal_type = boost::signals2::signal<void(const std::string&, const std::vector<T>& )>;
};
template <typename ...T> struct Traits<EventId::Custom,T...> { using signal_type = boost::signals2::signal<void(T...)>; } ;
template <>
struct Traits<EventId::UpdateParam, std::string>
{
using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>;
};
template<std::size_t N>
struct Traits<EventId::UpdateParam, const char[N]>
{
using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>;
};
template <typename ...T>
struct Traits<EventId::Custom,T...>
{
using signal_type = boost::signals2::signal<void(T...)>;
};
/*
template <EventId, typename ...Args> struct Traits2;
@@ -58,54 +81,61 @@ template <> struct Traits2<EventId::UpdateParamInt> { using signal_type = boo
class FairMQEventManager
{
public:
typedef std::pair<EventId,std::string> EventKey;
FairMQEventManager() : fEventMap() {}
virtual ~FairMQEventManager(){}
typedef std::pair<EventId, std::string> EventKey;
FairMQEventManager() :
fEventMap()
{}
virtual ~FairMQEventManager()
{}
template <EventId event, typename... ValueType, typename F>
void Connect(const std::string& key, F&& func)
void Connect(const std::string& key, F&& func)
{
GetSlot<event,ValueType...>(key).connect(std::forward<F>(func));
}
template <EventId event, typename... ValueType>
void Disonnect(const std::string& key)
{
GetSlot<event,ValueType...>(key).disconnect();
GetSlot<event, ValueType...>(key).connect(std::forward<F>(func));
}
template <EventId event, typename... ValueType>
void Disonnect(const std::string& key)
{
GetSlot<event, ValueType...>(key).disconnect();
}
template <EventId event, typename... ValueType, typename... Args>
void Emit(const std::string& key, Args&&... args)
void Emit(const std::string& key, Args&&... args)
{
GetSlot<event,ValueType...>(key)(std::forward<Args>(args)...);
}
template <EventId event>
bool EventKeyFound(const std::string& key)
{
if (fEventMap.find(std::pair<EventId,std::string>(event,key) ) != fEventMap.end())
if (fEventMap.find(std::pair<EventId, std::string>(event, key) ) != fEventMap.end())
{
return true;
}
else
{
return false;
}
}
private:
std::map<EventKey, boost::any> fEventMap;
template <EventId event, typename... T, typename Slot = typename Events::Traits<event,T...>::signal_type,
typename SlotPtr = boost::shared_ptr<Slot> >
template <EventId event, typename... T, typename Slot = typename Events::Traits<event,T...>::signal_type,
typename SlotPtr = boost::shared_ptr<Slot>>
Slot& GetSlot(const std::string& key)
{
try
{
EventKey eventKey = std::make_pair(event,key);
EventKey eventKey = std::make_pair(event, key);
//static_assert(std::is_same<decltype(boost::make_shared<Slot>()),SlotPtr>::value, "");
if (fEventMap.find(eventKey) == fEventMap.end())
{
fEventMap.emplace(eventKey, boost::make_shared<Slot>());
}
return *boost::any_cast<SlotPtr>(fEventMap.at(eventKey));
// auto &&tmp = boost::any_cast<SlotPtr>(fEventMap.at(eventKey));

View File

@@ -228,7 +228,6 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMa
commonChannel.UpdateType(q.second.get<string>("type", commonChannel.GetType()));
commonChannel.UpdateMethod(q.second.get<string>("method", commonChannel.GetMethod()));
commonChannel.UpdateAddress(q.second.get<string>("address", commonChannel.GetAddress()));
commonChannel.UpdateProperty(q.second.get<string>("property", commonChannel.GetProperty()));
commonChannel.UpdateSndBufSize(q.second.get<int>("sndBufSize", commonChannel.GetSndBufSize()));
commonChannel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
@@ -245,7 +244,6 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMa
LOG(DEBUG) << "\ttype = " << commonChannel.GetType();
LOG(DEBUG) << "\tmethod = " << commonChannel.GetMethod();
LOG(DEBUG) << "\taddress = " << commonChannel.GetAddress();
LOG(DEBUG) << "\tproperty = " << commonChannel.GetProperty();
LOG(DEBUG) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
LOG(DEBUG) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
LOG(DEBUG) << "\trateLogging = " << commonChannel.GetRateLogging();
@@ -287,7 +285,6 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMa
commonChannel.UpdateType(p.second.get<string>("type", commonChannel.GetType()));
commonChannel.UpdateMethod(p.second.get<string>("method", commonChannel.GetMethod()));
commonChannel.UpdateAddress(p.second.get<string>("address", commonChannel.GetAddress()));
commonChannel.UpdateProperty(p.second.get<string>("property", commonChannel.GetProperty()));
commonChannel.UpdateSndBufSize(p.second.get<int>("sndBufSize", commonChannel.GetSndBufSize()));
commonChannel.UpdateRcvBufSize(p.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
commonChannel.UpdateRateLogging(p.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
@@ -305,7 +302,6 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMa
LOG(DEBUG) << "\ttype = " << commonChannel.GetType();
LOG(DEBUG) << "\tmethod = " << commonChannel.GetMethod();
LOG(DEBUG) << "\taddress = " << commonChannel.GetAddress();
LOG(DEBUG) << "\tproperty = " << commonChannel.GetProperty();
LOG(DEBUG) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
LOG(DEBUG) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
LOG(DEBUG) << "\trateLogging = " << commonChannel.GetRateLogging();
@@ -344,7 +340,6 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
channel.UpdateType(q.second.get<string>("type", channel.GetType()));
channel.UpdateMethod(q.second.get<string>("method", channel.GetMethod()));
channel.UpdateAddress(q.second.get<string>("address", channel.GetAddress()));
channel.UpdateProperty(q.second.get<string>("property", channel.GetProperty()));
channel.UpdateSndBufSize(q.second.get<int>("sndBufSize", channel.GetSndBufSize()));
channel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging()));
@@ -353,7 +348,6 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
LOG(DEBUG) << "\ttype = " << channel.GetType();
LOG(DEBUG) << "\tmethod = " << channel.GetMethod();
LOG(DEBUG) << "\taddress = " << channel.GetAddress();
LOG(DEBUG) << "\tproperty = " << channel.GetProperty();
LOG(DEBUG) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(DEBUG) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(DEBUG) << "\trateLogging = " << channel.GetRateLogging();
@@ -372,7 +366,6 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
channel.UpdateType(p.second.get<string>("type", channel.GetType()));
channel.UpdateMethod(p.second.get<string>("method", channel.GetMethod()));
channel.UpdateAddress(p.second.get<string>("address", channel.GetAddress()));
channel.UpdateProperty(p.second.get<string>("property", channel.GetProperty()));
channel.UpdateSndBufSize(p.second.get<int>("sndBufSize", channel.GetSndBufSize()));
channel.UpdateRcvBufSize(p.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
channel.UpdateRateLogging(p.second.get<int>("rateLogging", channel.GetRateLogging()));
@@ -381,7 +374,6 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
LOG(DEBUG) << "\ttype = " << channel.GetType();
LOG(DEBUG) << "\tmethod = " << channel.GetMethod();
LOG(DEBUG) << "\taddress = " << channel.GetAddress();
LOG(DEBUG) << "\tproperty = " << channel.GetProperty();
LOG(DEBUG) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(DEBUG) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(DEBUG) << "\trateLogging = " << channel.GetRateLogging();
@@ -406,7 +398,6 @@ void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>
LOG(DEBUG) << "\ttype = " << channel.GetType();
LOG(DEBUG) << "\tmethod = " << channel.GetMethod();
LOG(DEBUG) << "\taddress = " << channel.GetAddress();
LOG(DEBUG) << "\tproperty = " << channel.GetProperty();
LOG(DEBUG) << "\tsndBufSize = " << channel.GetSndBufSize();
LOG(DEBUG) << "\trcvBufSize = " << channel.GetRcvBufSize();
LOG(DEBUG) << "\trateLogging = " << channel.GetRateLogging();

View File

@@ -32,14 +32,10 @@ FairMQProgOptions::FairMQProgOptions()
{
}
// ----------------------------------------------------------------------------------
FairMQProgOptions::~FairMQProgOptions()
{
}
// ----------------------------------------------------------------------------------
void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregistered)
{
// init description
@@ -209,9 +205,6 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
FairProgOptions::PrintOptions();
}
// ----------------------------------------------------------------------------------
int FairMQProgOptions::Store(const FairMQMap& channels)
{
fFairMQMap = channels;
@@ -219,9 +212,6 @@ int FairMQProgOptions::Store(const FairMQMap& channels)
return 0;
}
// ----------------------------------------------------------------------------------
// replace FairMQChannelMap, and update variable map accordingly
int FairMQProgOptions::UpdateChannelMap(const FairMQMap& channels)
{
@@ -230,8 +220,6 @@ int FairMQProgOptions::UpdateChannelMap(const FairMQMap& channels)
return 0;
}
// ----------------------------------------------------------------------------------
// read FairMQChannelMap and insert/update corresponding values in variable map
// create key for variable map as follow : channelName.index.memberName
void FairMQProgOptions::UpdateMQValues()
@@ -244,23 +232,20 @@ void FairMQProgOptions::UpdateMQValues()
std::string typeKey = p.first + "." + std::to_string(index) + ".type";
std::string methodKey = p.first + "." + std::to_string(index) + ".method";
std::string addressKey = p.first + "." + std::to_string(index) + ".address";
std::string propertyKey = p.first + "." + std::to_string(index) + ".property";
std::string sndBufSizeKey = p.first + "." + std::to_string(index) + ".sndBufSize";
std::string rcvBufSizeKey = p.first + "." + std::to_string(index) + ".rcvBufSize";
std::string rateLoggingKey = p.first + "." + std::to_string(index) + ".rateLogging";
fMQKeyMap[typeKey] = std::make_tuple(p.first,index,"type");
fMQKeyMap[methodKey] = std::make_tuple(p.first,index,"method");
fMQKeyMap[addressKey] = std::make_tuple(p.first,index,"address");
fMQKeyMap[propertyKey] = std::make_tuple(p.first,index,"property");
fMQKeyMap[sndBufSizeKey] = std::make_tuple(p.first,index,"sndBufSize");
fMQKeyMap[rcvBufSizeKey] = std::make_tuple(p.first,index,"rcvBufSize");
fMQKeyMap[rateLoggingKey] = std::make_tuple(p.first,index,"rateLogging");
UpdateVarMap<std::string>(typeKey,channel.GetType());
UpdateVarMap<std::string>(methodKey,channel.GetMethod());
UpdateVarMap<std::string>(addressKey,channel.GetAddress());
UpdateVarMap<std::string>(propertyKey,channel.GetProperty());
//UpdateVarMap<std::string>(sndBufSizeKey, std::to_string(channel.GetSndBufSize()));// string API
@@ -277,21 +262,15 @@ void FairMQProgOptions::UpdateMQValues()
LOG(DEBUG) << "key = " << typeKey <<"\t value = " << GetValue<std::string>(typeKey);
LOG(DEBUG) << "key = " << methodKey <<"\t value = " << GetValue<std::string>(methodKey);
LOG(DEBUG) << "key = " << addressKey <<"\t value = " << GetValue<std::string>(addressKey);
LOG(DEBUG) << "key = " << propertyKey <<"\t value = " << GetValue<std::string>(propertyKey);
LOG(DEBUG) << "key = " << sndBufSizeKey << "\t value = " << GetValue<int>(sndBufSizeKey);
LOG(DEBUG) << "key = " << rcvBufSizeKey <<"\t value = " << GetValue<int>(rcvBufSizeKey);
LOG(DEBUG) << "key = " << rateLoggingKey <<"\t value = " << GetValue<int>(rateLoggingKey);
*/
index++;
}
}
}
// ----------------------------------------------------------------------------------
int FairMQProgOptions::NotifySwitchOption()
{
if (fVarMap.count("help"))
@@ -309,8 +288,6 @@ int FairMQProgOptions::NotifySwitchOption()
return 0;
}
// ----------------------------------------------------------------------------------
void FairMQProgOptions::InitOptionDescription()
{
// Id required in command line if config txt file not enabled
@@ -320,8 +297,8 @@ void FairMQProgOptions::InitOptionDescription()
("id", po::value<string>(), "Device ID (required argument).")
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').")
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/<control library filename>).")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file")
("catch-signals", po::value<int >()->default_value(1), "Enable signal handling (1/0)")
@@ -332,8 +309,8 @@ void FairMQProgOptions::InitOptionDescription()
("id", po::value<string>()->required(), "Device ID (required argument).")
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').")
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/<control library filename>).")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file")
("catch-signals", po::value<int >()->default_value(1), "Enable signal handling (1/0)")
@@ -346,8 +323,8 @@ void FairMQProgOptions::InitOptionDescription()
("id", po::value<string>()->required(), "Device ID (required argument)")
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads")
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
("deployment", po::value<string>()->default_value("static"), "Deployment ('static'/'dds').")
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/<control library filename>).")
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file")
("catch-signals", po::value<int >()->default_value(1), "Enable signal handling (1/0)")
@@ -374,33 +351,25 @@ void FairMQProgOptions::InitOptionDescription()
}
}
// ----------------------------------------------------------------------------------
int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int index, const std::string& member, const std::string& val)
{
if(member == "type")
if (member == "type")
{
fFairMQMap.at(channelName).at(index).UpdateType(val);
return 0;
}
if(member == "method")
if (member == "method")
{
fFairMQMap.at(channelName).at(index).UpdateMethod(val);
return 0;
}
if(member == "address")
if (member == "address")
{
fFairMQMap.at(channelName).at(index).UpdateAddress(val);
return 0;
}
if(member == "property")
{
fFairMQMap.at(channelName).at(index).UpdateProperty(val);
return 0;
}
else
{
//if we get there it means something is wrong
@@ -408,39 +377,32 @@ int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int inde
<< channelName<<"."<<index<<"."<<member;
return 1;
}
}
/*
// string API
int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int index, const std::string& member, const std::string& val)
{
if(member == "type")
if (member == "type")
{
fFairMQMap.at(channelName).at(index).UpdateType(val);
return 0;
}
if(member == "method")
if (member == "method")
{
fFairMQMap.at(channelName).at(index).UpdateMethod(val);
return 0;
}
if(member == "address")
if (member == "address")
{
fFairMQMap.at(channelName).at(index).UpdateAddress(val);
return 0;
}
if(member == "property")
{
fFairMQMap.at(channelName).at(index).UpdateProperty(val);
return 0;
}
else
{
if(member == "sndBufSize" || member == "rcvBufSize" || member == "rateLogging")
if (member == "sndBufSize" || member == "rcvBufSize" || member == "rateLogging")
{
UpdateChannelMap(channelName,index,member,ConvertTo<int>(val));
}
@@ -458,20 +420,19 @@ int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int inde
int FairMQProgOptions::UpdateChannelMap(const std::string& channelName, int index, const std::string& member, int val)
{
if(member == "sndBufSize")
if (member == "sndBufSize")
{
fFairMQMap.at(channelName).at(index).UpdateSndBufSize(val);
return 0;
}
if(member == "rcvBufSize")
if (member == "rcvBufSize")
{
fFairMQMap.at(channelName).at(index).UpdateRcvBufSize(val);
return 0;
}
if(member == "rateLogging")
if (member == "rateLogging")
{
fFairMQMap.at(channelName).at(index).UpdateRateLogging(val);
return 0;

View File

@@ -84,6 +84,10 @@ class FairProgOptions
{
val = fVarMap[key].as<T>();
}
else
{
LOG(ERROR) << "Config has no key: " << key;
}
}
catch(std::exception& e)
{

View File

@@ -10,208 +10,181 @@
* Author: winckler
*/
// FairRoot - FairMQ
#include "FairMQLogger.h"
#include "FairMQProgOptions.h"
#include "FairMQDevice.h"
typedef std::unordered_map<std::string, std::vector<FairMQChannel>> FairMQMap;
#include <exception>
#include <string>
#include <vector>
#include <unordered_map>
class MyDevice : public FairMQDevice
using namespace std;
typedef unordered_map<string, vector<FairMQChannel>> FairMQMap;
class MyDevice : public FairMQDevice
{
public:
MyDevice() : rate(0.5) {}
virtual ~MyDevice() {}
void SetRate(double r){rate=r;}
void Print(){LOG(INFO)<<"[MyDevice] rate = "<<rate;}
MyDevice()
: fRate(0.5)
{}
virtual ~MyDevice()
{}
void SetRate(double r)
{
fRate = r;
}
double GetRate()
{
return fRate;
}
void Print()
{
LOG(INFO) << "[MyDevice] rate = " << fRate;
}
private:
double rate;
double fRate;
};
void MyCallBack(MyDevice& d, double val)
{
d.SetRate(val);
d.Print();
}
{
d.SetRate(val);
d.Print();
}
void PrintMQParam(const FairMQMap& channels, const FairMQProgOptions& config)
{
for(const auto& p : channels)
for (const auto& p : channels)
{
int index = 0;
for(const auto& channel : p.second)
for (const auto& channel : p.second)
{
std::string typeKey = p.first + "." + std::to_string(index) + ".type";
std::string methodKey = p.first + "." + std::to_string(index) + ".method";
std::string addressKey = p.first + "." + std::to_string(index) + ".address";
std::string propertyKey = p.first + "." + std::to_string(index) + ".property";
std::string sndBufSizeKey = p.first + "." + std::to_string(index) + ".sndBufSize";
std::string rcvBufSizeKey = p.first + "." + std::to_string(index) + ".rcvBufSize";
std::string rateLoggingKey = p.first + "." + std::to_string(index) + ".rateLogging";
LOG(DEBUG) << "Channel name = "<<p.first;
LOG(DEBUG) << "key = " << typeKey <<"\t value = " << config.GetValue<std::string>(typeKey);
LOG(DEBUG) << "key = " << methodKey <<"\t value = " << config.GetValue<std::string>(methodKey);
LOG(DEBUG) << "key = " << addressKey <<"\t value = " << config.GetValue<std::string>(addressKey);
LOG(DEBUG) << "key = " << propertyKey <<"\t value = " << config.GetValue<std::string>(propertyKey);
LOG(DEBUG) << "key = " << sndBufSizeKey << "\t value = " << config.GetValue<int>(sndBufSizeKey);
LOG(DEBUG) << "key = " << rcvBufSizeKey <<"\t value = " << config.GetValue<int>(rcvBufSizeKey);
LOG(DEBUG) << "key = " << rateLoggingKey <<"\t value = " << config.GetValue<int>(rateLoggingKey);
string typeKey = p.first + "." + to_string(index) + ".type";
string methodKey = p.first + "." + to_string(index) + ".method";
string addressKey = p.first + "." + to_string(index) + ".address";
string propertyKey = p.first + "." + to_string(index) + ".property";
string sndBufSizeKey = p.first + "." + to_string(index) + ".sndBufSize";
string rcvBufSizeKey = p.first + "." + to_string(index) + ".rcvBufSize";
string rateLoggingKey = p.first + "." + to_string(index) + ".rateLogging";
LOG(INFO) << "Channel name = " << p.first;
LOG(INFO) << "key = " << typeKey <<"\t value = " << config.GetValue<string>(typeKey);
LOG(INFO) << "key = " << methodKey <<"\t value = " << config.GetValue<string>(methodKey);
LOG(INFO) << "key = " << addressKey <<"\t value = " << config.GetValue<string>(addressKey);
LOG(INFO) << "key = " << propertyKey <<"\t value = " << config.GetValue<string>(propertyKey);
LOG(INFO) << "key = " << sndBufSizeKey << "\t value = " << config.GetValue<int>(sndBufSizeKey);
LOG(INFO) << "key = " << rcvBufSizeKey <<"\t value = " << config.GetValue<int>(rcvBufSizeKey);
LOG(INFO) << "key = " << rateLoggingKey <<"\t value = " << config.GetValue<int>(rateLoggingKey);
}
}
}
int main(int argc, char** argv)
{
try
{
// create option manager object
FairMQProgOptions config;
// add key description to cmd line options
config.GetCmdLineOptions().add_options()
("data-rate", po::value<double>()->default_value(0.5), "Data rate");
("data-rate", po::value<double>()->default_value(0.5), "Data rate");
// parse command lines, parse json file and init FairMQMap
config.ParseAll(argc, argv);
// get FairMQMap
auto map1 = config.GetFairMQMap();
// form keys from map1 and print the value stored in variable map
PrintMQParam(map1,config);
// // get FairMQMap
// auto map1 = config.GetFairMQMap();
// update value in variable map, and propagate the update to the FairMQMap
config.UpdateValue("data.0.address","tcp://localhost:1234");
// get the updated FairMQMap
auto map2 = config.GetFairMQMap();
// // form keys from map1 and print the value stored in variable map
// PrintMQParam(map1, config);
// modify one channel value
map2.at("data").at(0).UpdateSndBufSize(500);
// // update value in variable map, and propagate the update to the FairMQMap
// config.UpdateValue<string>("data.0.address","tcp://localhost:1234");
// update the FairMQMap and propagate the change in variable map
config.UpdateChannelMap(map2);
// // get the updated FairMQMap
// auto map2 = config.GetFairMQMap();
// print values stored in variable map
PrintMQParam(map2,config);
// // modify one channel value
// map2.at("data").at(0).UpdateSndBufSize(500);
// // update the FairMQMap and propagate the change in variable map
// config.UpdateChannelMap(map2);
// // print values stored in variable map
// PrintMQParam(map2, config);
MyDevice device;
device.CatchSignals();
device.SetConfig(config);
// getting as string and conversion helpers
std::string blah = config.GetStringValue("data-rate");
double blah2 = config.ConvertTo<double>(blah);
LOG(INFO)<<"blah2 "<<blah2;
// string dataRateStr = config.GetStringValue("data-rate");
// double dataRate = config.ConvertTo<double>(dataRateStr);
// LOG(INFO) << "dataRate: " << dataRate;
LOG(INFO) << "Subscribing: <string>(data.0.address)";
config.Subscribe<string>("data.0.address", [&device](const string& key, const string& value)
{
LOG(INFO) << "[callback] Updating device parameter " << key << " = " << value;
device.fChannels.at("data").at(0).UpdateAddress(value);
});
LOG(INFO)<<"---- Connect 1";
config.Subscribe<std::string >("data.0.address",[&device](const std::string& key, const std::string& value)
{
LOG(INFO) << "[Lambda] Update parameter (0) " << key << " = " << value;
device.fChannels.at("data").at(0).UpdateAddress(value);
});
LOG(INFO) << "Subscribing: <int>(data.0.rcvBufSize)";
config.Subscribe<int>("data.0.rcvBufSize", [&device](const string& key, int value)
{
LOG(INFO) << "[callback] Updating device parameter " << key << " = " << value;
device.fChannels.at("data").at(0).UpdateRcvBufSize(value);
});
LOG(INFO) << "Subscribing: <double>(data-rate)";
config.Subscribe<double>("data-rate", [&device](const string& key, double value)
{
LOG(INFO) << "[callback] Updating device parameter " << key << " = " << value;
device.SetRate(value);
});
std::string key1("data.0.address");
std::string value1("tcp://localhost:4321");
config.UpdateValue(key1,value1);
LOG(INFO) << "Starting value updates...\n";
LOG(INFO)<<"device.fChannels.GetAddress = "<<device.fChannels.at("data").at(0).GetAddress();
LOG(INFO)<<"config.GetValue = "<<config.GetValue<std::string>(key1);
config.UpdateValue<string>("data.0.address", "tcp://localhost:4321");
LOG(INFO) << "config: " << config.GetValue<string>("data.0.address");
LOG(INFO) << "device: " << device.fChannels.at("data").at(0).GetAddress() << endl;
config.UpdateValue<int>("data.0.rcvBufSize", 100);
LOG(INFO) << "config: " << config.GetValue<int>("data.0.rcvBufSize");
LOG(INFO) << "device: " << device.fChannels.at("data").at(0).GetRcvBufSize() << endl;
LOG(INFO)<<"---- Connect 2";
config.Subscribe<std::string>("data.0.method",[&device](const std::string& key, const std::string& value)
{
//value="abcd";
LOG(INFO) << "[Lambda] Update parameter " << key << " = " << value;
device.fChannels.at("data").at(0).UpdateMethod(value);
});
LOG(INFO)<<"---- Connect 3";
config.Subscribe<int>("data.0.rcvBufSize",[&device](const std::string& key, int value)
{
LOG(INFO) << "[Lambda] Update parameter " << key << " = " << value;
device.fChannels.at("data").at(0).UpdateRcvBufSize(value);
});
LOG(INFO)<<"---- Connect 4";
config.Subscribe<double>("data-rate",[&device](const std::string& key, double value)
{
LOG(INFO) << "[Lambda] Update parameter " << key << " = " << value;
device.SetRate(value);
});
std::string key2("data.0.rcvBufSize");
int value2(100);
std::string key3("data.0.method");
std::string value3("bind");
LOG(INFO)<<"-------------------- start update";
//config.EmitUpdate(key,value);
config.UpdateValue(key1,value1);
LOG(INFO)<<"device.fChannels.GetAddress = "<<device.fChannels.at("data").at(0).GetAddress();
LOG(INFO)<<"config.GetValue = "<<config.GetValue<std::string>(key1);
config.UpdateValue(key2,value2);
LOG(INFO)<<"device.fChannels.GetRcvBufSize = "<<device.fChannels.at("data").at(0).GetRcvBufSize();
LOG(INFO)<<"config.GetValue = "<<config.GetValue<int>(key2);
config.UpdateValue(key3,value3);
LOG(INFO)<<"device.fChannels.Method = "<<device.fChannels.at("data").at(0).GetMethod();
LOG(INFO)<<"config.GetValue = "<<config.GetValue<std::string>(key3);
device.Print();
double rate=0.9;
config.UpdateValue<double>("data-rate",rate);
LOG(INFO)<<"config.GetValue = "<<config.GetValue<double>("data-rate");
device.Print();
LOG(INFO)<<" double rate = " <<rate;
config.UpdateValue<double>("data-rate", 0.9);
LOG(INFO) << "config: " << config.GetValue<double>("data-rate");
LOG(INFO) << "device: " << device.GetRate() << endl;
// device.Print();
// advanced commands
LOG(INFO)<<"-------------------- start custom 1";
config.Connect<EventId::Custom, MyDevice&, double>("myNewKey",[](MyDevice& d, double val)
{
d.SetRate(val);
d.Print();
});
double value4=0.123;
config.Emit<EventId::Custom, MyDevice&, double>("myNewKey",device,value4);
LOG(INFO)<<"-------------------- start custom 2 with function";
config.Connect<EventId::Custom, MyDevice&, double>("function example",&MyCallBack);
value4=6.66;
config.Emit<EventId::Custom, MyDevice&, double>("function example",device,value4);
// LOG(INFO) << "-------------------- start custom 1";
// config.Connect<EventId::Custom, MyDevice&, double>("myNewKey", [](MyDevice& d, double val)
// {
// d.SetRate(val);
// d.Print();
// });
// config.Emit<EventId::Custom, MyDevice&, double>("myNewKey", device, 0.123);
// LOG(INFO) << "-------------------- start custom 2 with function";
// config.Connect<EventId::Custom, MyDevice&, double>("function example", &MyCallBack);
// config.Emit<EventId::Custom, MyDevice&, double>("function example", device, 6.66);
}
catch (std::exception& e)
catch (exception& e)
{
LOG(ERROR) << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit";
@@ -219,5 +192,3 @@ int main(int argc, char** argv)
}
return 0;
}