mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Configuration and DDS example/tools updates
- Update DDS example command UI and extract it from example. - Unify address handling via DDS properties for dynamic deployment. - Update DDS docs with the new approach. - Allow `--config-key` to be used to access common config in JSON. - Allow common channel properties to be specified for all sockets. - Update MQ examples and Tuto3 with new config options. - Add start scripts to MQ examples for easier use.
This commit is contained in:
committed by
Mohammad Al-Turany
parent
8317d440db
commit
13453354c8
@@ -12,24 +12,13 @@
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <map>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
#include <boost/asio.hpp> // for DDS
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQDDSTools.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
#include "FairMQExample3Sink.h"
|
||||
#include "FairMQTools.h"
|
||||
|
||||
#include "dds_intercom.h" // DDS
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::program_options;
|
||||
using namespace dds::intercom_api;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@@ -40,94 +29,21 @@ int main(int argc, char** argv)
|
||||
|
||||
try
|
||||
{
|
||||
string interfaceName; // name of the network interface to use for communication.
|
||||
|
||||
options_description sinkOptions("Sink options");
|
||||
sinkOptions.add_options()
|
||||
("network-interface", value<string>(&interfaceName)->default_value("eth0"), "Name of the network interface to use (e.g. eth0, ib0, wlan0, en0...)");
|
||||
|
||||
config.AddToCmdLineOptions(sinkOptions);
|
||||
|
||||
if (config.ParseAll(argc, argv))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
string id = config.GetValue<string>("id");
|
||||
|
||||
LOG(INFO) << "PID: " << getpid();
|
||||
|
||||
sink.SetTransport(config.GetValue<std::string>("transport"));
|
||||
|
||||
sink.SetProperty(FairMQExample3Sink::Id, id);
|
||||
|
||||
// configure data output channel
|
||||
FairMQChannel dataInChannel("pull", "bind", "");
|
||||
dataInChannel.UpdateRateLogging(0);
|
||||
sink.fChannels["data2"].push_back(dataInChannel);
|
||||
|
||||
// Get the IP of the current host and store it for binding.
|
||||
map<string,string> IPs;
|
||||
FairMQ::tools::getHostIPs(IPs);
|
||||
stringstream ss;
|
||||
// Check if ib0 (infiniband) interface is available, otherwise try eth0 or wlan0.
|
||||
if (IPs.count(interfaceName))
|
||||
{
|
||||
ss << "tcp://" << IPs[interfaceName] << ":1";
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(INFO) << ss.str();
|
||||
LOG(ERROR) << "Could not find provided network interface: \"" << interfaceName << "\"!, exiting.";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
string initialInputAddress = ss.str();
|
||||
|
||||
// Configure the found host IP for the channel.
|
||||
// TCP port will be chosen randomly during the initialization (binding).
|
||||
sink.fChannels.at("data2").at(0).UpdateAddress(initialInputAddress);
|
||||
sink.SetConfig(config);
|
||||
|
||||
sink.ChangeState("INIT_DEVICE");
|
||||
sink.WaitForInitialValidation();
|
||||
|
||||
// Advertise the bound address via DDS property
|
||||
LOG(INFO) << "Giving sink input address to DDS.";
|
||||
CKeyValue ddsKeyValue;
|
||||
ddsKeyValue.putValue("SinkAddress", sink.fChannels.at("data2").at(0).GetAddress());
|
||||
|
||||
HandleConfigViaDDS(sink);
|
||||
sink.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
sink.ChangeState("INIT_TASK");
|
||||
sink.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
CCustomCmd ddsCustomCmd;
|
||||
|
||||
// Subscribe on custom commands
|
||||
ddsCustomCmd.subscribe([&](const string& command, const string& condition, uint64_t senderId)
|
||||
{
|
||||
LOG(INFO) << "Received custom command: " << command;
|
||||
if (command == "check-state")
|
||||
{
|
||||
ddsCustomCmd.send(id + ": " + sink.GetCurrentStateName(), to_string(senderId));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(WARN) << "Received unknown command: " << command;
|
||||
LOG(WARN) << "Origin: " << senderId;
|
||||
LOG(WARN) << "Destination: " << condition;
|
||||
}
|
||||
});
|
||||
|
||||
sink.ChangeState("RUN");
|
||||
sink.WaitForEndOfState("RUN");
|
||||
|
||||
sink.ChangeState("RESET_TASK");
|
||||
sink.WaitForEndOfState("RESET_TASK");
|
||||
|
||||
sink.ChangeState("RESET_DEVICE");
|
||||
sink.WaitForEndOfState("RESET_DEVICE");
|
||||
|
||||
sink.ChangeState("END");
|
||||
runDDSStateHandler(sink);
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user