mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
Several FairMQ fixes and improvements:
- FairMQ: add possibility to poll on multiple channels. - FairMQ: include command channel when polling on blocking calls (for unblocking without termination). - FairMQ: move signal handler inside of FairMQDevice class (call FairMQDevice::CatchSignals() in the main function). - FairMQ: add 'bool CheckCurrentState(statename)' (instead of 'GetCurrentState() == statename' that cannot be thread safe). - FairMQDevice: add 'InteractiveStateLoop()' method that can be used to change states from the command line. - FairMQDevice: add automatic transition to IDLE state if Run() exits without an external event. - FairMQDevice: implement device reset. - FairMQDevice: use unordered_map for device channels. - FairMQChannel: improve address validation for channels. - FairMQChannel: add ExpectsAnotherPart() method to check if another msg part is expected (old approach still works). - FairMQ: remove invalid transition from the run files. - FairMQFileSink: disable ROOT termination signal handler. - Tutorial3: spawn xterm windows from start scripts without overlapping for better visibility. - FairMQ Examples: update protobuf test and move its files to a common directory. - FairMQStateMachine: improve feedback on invalid transitions (more readable).
This commit is contained in:
committed by
Mohammad Al-Turany
parent
d1bba61939
commit
1302e77a16
@@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
@@ -32,31 +31,10 @@ using namespace std;
|
||||
using namespace FairMQParser;
|
||||
using namespace boost::program_options;
|
||||
|
||||
FairMQBenchmarkSampler sampler;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
||||
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
FairMQBenchmarkSampler sampler;
|
||||
sampler.CatchSignals();
|
||||
|
||||
FairMQProgOptions config;
|
||||
|
||||
@@ -79,7 +57,7 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
string filename = config.GetValue<string>("config-json-filename");
|
||||
string filename = config.GetValue<string>("config-json-file");
|
||||
string id = config.GetValue<string>("id");
|
||||
|
||||
config.UserParser<JSON>(filename, id);
|
||||
@@ -101,25 +79,14 @@ int main(int argc, char** argv)
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::EventRate, eventRate);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, ioThreads);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::INIT_DEVICE);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_DEVICE);
|
||||
sampler.ChangeState("INIT_DEVICE");
|
||||
sampler.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::INIT_TASK);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_TASK);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::RUN);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RUN);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::STOP);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::RESET_TASK);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RESET_TASK);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::RESET_DEVICE);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RESET_DEVICE);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
||||
sampler.ChangeState("INIT_TASK");
|
||||
sampler.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
sampler.ChangeState("RUN");
|
||||
sampler.InteractiveStateLoop();
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
@@ -1,186 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* runBenchmarkSampler.cxx
|
||||
*
|
||||
* @since 2013-04-23
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQBinSampler.h"
|
||||
|
||||
#ifdef NANOMSG
|
||||
#include "FairMQTransportFactoryNN.h"
|
||||
#else
|
||||
#include "FairMQTransportFactoryZMQ.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQBinSampler sampler;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
|
||||
sampler.ChangeState(FairMQBinSampler::STOP);
|
||||
sampler.ChangeState(FairMQBinSampler::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
id(), eventSize(0), eventRate(0), ioThreads(0),
|
||||
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress() {}
|
||||
|
||||
string id;
|
||||
int eventSize;
|
||||
int eventRate;
|
||||
int ioThreads;
|
||||
string outputSocketType;
|
||||
int outputBufSize;
|
||||
string outputMethod;
|
||||
string outputAddress;
|
||||
} DeviceOptions_t;
|
||||
|
||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
{
|
||||
if (_options == NULL)
|
||||
throw runtime_error("Internal error: options' container is empty.");
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
bpo::options_description desc("Options");
|
||||
desc.add_options()
|
||||
("id", bpo::value<string>()->required(), "Device ID")
|
||||
("event-size", bpo::value<int>()->default_value(1000), "Event size in bytes")
|
||||
("event-rate", bpo::value<int>()->default_value(0), "Event rate limit in maximum number of events per second")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
|
||||
("output-buff-size", bpo::value<int>()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
|
||||
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://*:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
||||
bpo::variables_map vm;
|
||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
||||
|
||||
if ( vm.count("help") )
|
||||
{
|
||||
LOG(INFO) << "FairMQ Bin Sampler" << endl << desc;
|
||||
return false;
|
||||
}
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
if ( vm.count("id") )
|
||||
_options->id = vm["id"].as<string>();
|
||||
|
||||
if ( vm.count("event-size") )
|
||||
_options->eventSize = vm["event-size"].as<int>();
|
||||
|
||||
if ( vm.count("event-rate") )
|
||||
_options->eventRate = vm["event-rate"].as<int>();
|
||||
|
||||
if ( vm.count("io-threads") )
|
||||
_options->ioThreads = vm["io-threads"].as<int>();
|
||||
|
||||
if ( vm.count("output-socket-type") )
|
||||
_options->outputSocketType = vm["output-socket-type"].as<string>();
|
||||
|
||||
if ( vm.count("output-buff-size") )
|
||||
_options->outputBufSize = vm["output-buff-size"].as<int>();
|
||||
|
||||
if ( vm.count("output-method") )
|
||||
_options->outputMethod = vm["output-method"].as<string>();
|
||||
|
||||
if ( vm.count("output-address") )
|
||||
_options->outputAddress = vm["output-address"].as<string>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
{
|
||||
if (!parse_cmd_line(argc, argv, &options))
|
||||
return 0;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
LOG(INFO) << "PID: " << getpid();
|
||||
LOG(INFO) << "CONFIG: " << "id: " << options.id << ", event size: " << options.eventSize << ", event rate: " << options.eventRate << ", I/O threads: " << options.ioThreads;
|
||||
LOG(INFO) << "OUTPUT: " << options.outputSocketType << " " << options.outputBufSize << " " << options.outputMethod << " " << options.outputAddress;
|
||||
|
||||
#ifdef NANOMSG
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||
#else
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||
#endif
|
||||
|
||||
sampler.SetTransport(transportFactory);
|
||||
|
||||
sampler.SetProperty(FairMQBinSampler::Id, options.id);
|
||||
sampler.SetProperty(FairMQBinSampler::EventSize, options.eventSize);
|
||||
sampler.SetProperty(FairMQBinSampler::EventRate, options.eventRate);
|
||||
sampler.SetProperty(FairMQBinSampler::NumIoThreads, options.ioThreads);
|
||||
|
||||
sampler.SetProperty(FairMQBinSampler::NumInputs, 0);
|
||||
sampler.SetProperty(FairMQBinSampler::NumOutputs, 1);
|
||||
|
||||
sampler.ChangeState(FairMQBinSampler::INIT);
|
||||
|
||||
sampler.SetProperty(FairMQBinSampler::OutputSocketType, options.outputSocketType);
|
||||
sampler.SetProperty(FairMQBinSampler::OutputSndBufSize, options.outputBufSize);
|
||||
sampler.SetProperty(FairMQBinSampler::OutputMethod, options.outputMethod);
|
||||
sampler.SetProperty(FairMQBinSampler::OutputAddress, options.outputAddress);
|
||||
|
||||
sampler.ChangeState(FairMQBinSampler::SETOUTPUT);
|
||||
sampler.ChangeState(FairMQBinSampler::SETINPUT);
|
||||
sampler.ChangeState(FairMQBinSampler::BIND);
|
||||
sampler.ChangeState(FairMQBinSampler::CONNECT);
|
||||
sampler.ChangeState(FairMQBinSampler::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(sampler.fRunningMutex);
|
||||
while (!sampler.fRunningFinished)
|
||||
{
|
||||
sampler.fRunningCondition.wait(lock);
|
||||
}
|
||||
|
||||
sampler.ChangeState(FairMQBinSampler::STOP);
|
||||
sampler.ChangeState(FairMQBinSampler::END);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,172 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* runSink.cxx
|
||||
*
|
||||
* @since 2013-01-21
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQBinSink.h"
|
||||
|
||||
#ifdef NANOMSG
|
||||
#include "FairMQTransportFactoryNN.h"
|
||||
#else
|
||||
#include "FairMQTransportFactoryZMQ.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQBinSink sink;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
|
||||
sink.ChangeState(FairMQBinSink::STOP);
|
||||
sink.ChangeState(FairMQBinSink::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
id(), ioThreads(0),
|
||||
inputSocketType(), inputBufSize(0), inputMethod(), inputAddress() {}
|
||||
|
||||
string id;
|
||||
int ioThreads;
|
||||
string inputSocketType;
|
||||
int inputBufSize;
|
||||
string inputMethod;
|
||||
string inputAddress;
|
||||
} DeviceOptions_t;
|
||||
|
||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
{
|
||||
if (_options == NULL)
|
||||
throw runtime_error("Internal error: options' container is empty.");
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
bpo::options_description desc("Options");
|
||||
desc.add_options()
|
||||
("id", bpo::value<string>()->required(), "Device ID")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
||||
("input-buff-size", bpo::value<int>()->required(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://*:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
||||
bpo::variables_map vm;
|
||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
||||
|
||||
if ( vm.count("help") )
|
||||
{
|
||||
LOG(INFO) << "FairMQ Bin Sink" << endl << desc;
|
||||
return false;
|
||||
}
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
if ( vm.count("id") )
|
||||
_options->id = vm["id"].as<string>();
|
||||
|
||||
if ( vm.count("io-threads") )
|
||||
_options->ioThreads = vm["io-threads"].as<int>();
|
||||
|
||||
if ( vm.count("input-socket-type") )
|
||||
_options->inputSocketType = vm["input-socket-type"].as<string>();
|
||||
|
||||
if ( vm.count("input-buff-size") )
|
||||
_options->inputBufSize = vm["input-buff-size"].as<int>();
|
||||
|
||||
if ( vm.count("input-method") )
|
||||
_options->inputMethod = vm["input-method"].as<string>();
|
||||
|
||||
if ( vm.count("input-address") )
|
||||
_options->inputAddress = vm["input-address"].as<string>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
{
|
||||
if (!parse_cmd_line(argc, argv, &options))
|
||||
return 0;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
LOG(INFO) << "PID: " << getpid();
|
||||
|
||||
#ifdef NANOMSG
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||
#else
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||
#endif
|
||||
|
||||
sink.SetTransport(transportFactory);
|
||||
|
||||
sink.SetProperty(FairMQBinSink::Id, options.id);
|
||||
sink.SetProperty(FairMQBinSink::NumIoThreads, options.ioThreads);
|
||||
|
||||
sink.SetProperty(FairMQBinSink::NumInputs, 1);
|
||||
sink.SetProperty(FairMQBinSink::NumOutputs, 0);
|
||||
|
||||
sink.ChangeState(FairMQBinSink::INIT);
|
||||
|
||||
sink.SetProperty(FairMQBinSink::InputSocketType, options.inputSocketType);
|
||||
sink.SetProperty(FairMQBinSink::InputRcvBufSize, options.inputBufSize);
|
||||
sink.SetProperty(FairMQBinSink::InputMethod, options.inputMethod);
|
||||
sink.SetProperty(FairMQBinSink::InputAddress, options.inputAddress);
|
||||
|
||||
sink.ChangeState(FairMQBinSink::SETOUTPUT);
|
||||
sink.ChangeState(FairMQBinSink::SETINPUT);
|
||||
sink.ChangeState(FairMQBinSink::BIND);
|
||||
sink.ChangeState(FairMQBinSink::CONNECT);
|
||||
sink.ChangeState(FairMQBinSink::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(sink.fRunningMutex);
|
||||
while (!sink.fRunningFinished)
|
||||
{
|
||||
sink.fRunningCondition.wait(lock);
|
||||
}
|
||||
|
||||
sink.ChangeState(FairMQBinSink::STOP);
|
||||
sink.ChangeState(FairMQBinSink::END);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -9,11 +9,10 @@
|
||||
* runBuffer.cxx
|
||||
*
|
||||
* @since 2012-10-26
|
||||
* @author: D. Klein, A. Rybalchenko
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
@@ -28,28 +27,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQBuffer buffer;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::END);
|
||||
|
||||
LOG(INFO) << "Shutdown complete";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
@@ -135,7 +112,8 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
FairMQBuffer buffer;
|
||||
buffer.CatchSignals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
@@ -176,24 +154,14 @@ int main(int argc, char** argv)
|
||||
buffer.SetProperty(FairMQBuffer::Id, options.id);
|
||||
buffer.SetProperty(FairMQBuffer::NumIoThreads, options.ioThreads);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::INIT_DEVICE);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::INIT_DEVICE);
|
||||
buffer.ChangeState("INIT_DEVICE");
|
||||
buffer.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::INIT_TASK);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::INIT_TASK);
|
||||
buffer.ChangeState("INIT_TASK");
|
||||
buffer.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::RUN);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::RUN);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::STOP);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::RESET_TASK);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::RESET_TASK);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::RESET_DEVICE);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::RESET_DEVICE);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::END);
|
||||
buffer.ChangeState("RUN");
|
||||
buffer.InteractiveStateLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
@@ -28,28 +27,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQMerger merger;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
merger.ChangeState(FairMQMerger::END);
|
||||
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
@@ -94,7 +71,7 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
bpo::variables_map vm;
|
||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
||||
|
||||
if ( vm.count("help") )
|
||||
if (vm.count("help"))
|
||||
{
|
||||
LOG(INFO) << "FairMQ Merger" << endl << desc;
|
||||
return false;
|
||||
@@ -102,37 +79,37 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
if ( vm.count("id") )
|
||||
if (vm.count("id"))
|
||||
_options->id = vm["id"].as<string>();
|
||||
|
||||
if ( vm.count("io-threads") )
|
||||
if (vm.count("io-threads"))
|
||||
_options->ioThreads = vm["io-threads"].as<int>();
|
||||
|
||||
if ( vm.count("num-inputs") )
|
||||
if (vm.count("num-inputs"))
|
||||
_options->numInputs = vm["num-inputs"].as<int>();
|
||||
|
||||
if ( vm.count("input-socket-type") )
|
||||
if (vm.count("input-socket-type"))
|
||||
_options->inputSocketType = vm["input-socket-type"].as< vector<string> >();
|
||||
|
||||
if ( vm.count("input-buff-size") )
|
||||
if (vm.count("input-buff-size"))
|
||||
_options->inputBufSize = vm["input-buff-size"].as< vector<int> >();
|
||||
|
||||
if ( vm.count("input-method") )
|
||||
if (vm.count("input-method"))
|
||||
_options->inputMethod = vm["input-method"].as< vector<string> >();
|
||||
|
||||
if ( vm.count("input-address") )
|
||||
if (vm.count("input-address"))
|
||||
_options->inputAddress = vm["input-address"].as< vector<string> >();
|
||||
|
||||
if ( vm.count("output-socket-type") )
|
||||
if (vm.count("output-socket-type"))
|
||||
_options->outputSocketType = vm["output-socket-type"].as<string>();
|
||||
|
||||
if ( vm.count("output-buff-size") )
|
||||
if (vm.count("output-buff-size"))
|
||||
_options->outputBufSize = vm["output-buff-size"].as<int>();
|
||||
|
||||
if ( vm.count("output-method") )
|
||||
if (vm.count("output-method"))
|
||||
_options->outputMethod = vm["output-method"].as<string>();
|
||||
|
||||
if ( vm.count("output-address") )
|
||||
if (vm.count("output-address"))
|
||||
_options->outputAddress = vm["output-address"].as<string>();
|
||||
|
||||
return true;
|
||||
@@ -140,7 +117,8 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
FairMQMerger merger;
|
||||
merger.CatchSignals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
@@ -184,24 +162,14 @@ int main(int argc, char** argv)
|
||||
merger.SetProperty(FairMQMerger::Id, options.id);
|
||||
merger.SetProperty(FairMQMerger::NumIoThreads, options.ioThreads);
|
||||
|
||||
merger.ChangeState(FairMQMerger::INIT_DEVICE);
|
||||
merger.WaitForEndOfState(FairMQMerger::INIT_DEVICE);
|
||||
merger.ChangeState("INIT_DEVICE");
|
||||
merger.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
merger.ChangeState(FairMQMerger::INIT_TASK);
|
||||
merger.WaitForEndOfState(FairMQMerger::INIT_TASK);
|
||||
merger.ChangeState("INIT_TASK");
|
||||
merger.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
merger.ChangeState(FairMQMerger::RUN);
|
||||
merger.WaitForEndOfState(FairMQMerger::RUN);
|
||||
|
||||
merger.ChangeState(FairMQMerger::STOP);
|
||||
|
||||
merger.ChangeState(FairMQMerger::RESET_TASK);
|
||||
merger.WaitForEndOfState(FairMQMerger::RESET_TASK);
|
||||
|
||||
merger.ChangeState(FairMQMerger::RESET_DEVICE);
|
||||
merger.WaitForEndOfState(FairMQMerger::RESET_DEVICE);
|
||||
|
||||
merger.ChangeState(FairMQMerger::END);
|
||||
merger.ChangeState("RUN");
|
||||
merger.InteractiveStateLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,186 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* runBenchmarkSampler.cxx
|
||||
*
|
||||
* @since 2013-04-23
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProtoSampler.h"
|
||||
|
||||
#ifdef NANOMSG
|
||||
#include "FairMQTransportFactoryNN.h"
|
||||
#else
|
||||
#include "FairMQTransportFactoryZMQ.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQProtoSampler sampler;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
|
||||
sampler.ChangeState(FairMQProtoSampler::STOP);
|
||||
sampler.ChangeState(FairMQProtoSampler::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
id(), eventSize(0), eventRate(0), ioThreads(0),
|
||||
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress() {}
|
||||
|
||||
string id;
|
||||
int eventSize;
|
||||
int eventRate;
|
||||
int ioThreads;
|
||||
string outputSocketType;
|
||||
int outputBufSize;
|
||||
string outputMethod;
|
||||
string outputAddress;
|
||||
} DeviceOptions_t;
|
||||
|
||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
{
|
||||
if (_options == NULL)
|
||||
throw runtime_error("Internal error: options' container is empty.");
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
bpo::options_description desc("Options");
|
||||
desc.add_options()
|
||||
("id", bpo::value<string>()->required(), "Device ID")
|
||||
("event-size", bpo::value<int>()->default_value(1000), "Event size in bytes")
|
||||
("event-rate", bpo::value<int>()->default_value(0), "Event rate limit in maximum number of events per second")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
|
||||
("output-buff-size", bpo::value<int>()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
|
||||
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://*:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
||||
bpo::variables_map vm;
|
||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
||||
|
||||
if ( vm.count("help") )
|
||||
{
|
||||
LOG(INFO) << "FairMQ Proto Sampler" << endl << desc;
|
||||
return false;
|
||||
}
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
if ( vm.count("id") )
|
||||
_options->id = vm["id"].as<string>();
|
||||
|
||||
if ( vm.count("event-size") )
|
||||
_options->eventSize = vm["event-size"].as<int>();
|
||||
|
||||
if ( vm.count("event-rate") )
|
||||
_options->eventRate = vm["event-rate"].as<int>();
|
||||
|
||||
if ( vm.count("io-threads") )
|
||||
_options->ioThreads = vm["io-threads"].as<int>();
|
||||
|
||||
if ( vm.count("output-socket-type") )
|
||||
_options->outputSocketType = vm["output-socket-type"].as<string>();
|
||||
|
||||
if ( vm.count("output-buff-size") )
|
||||
_options->outputBufSize = vm["output-buff-size"].as<int>();
|
||||
|
||||
if ( vm.count("output-method") )
|
||||
_options->outputMethod = vm["output-method"].as<string>();
|
||||
|
||||
if ( vm.count("output-address") )
|
||||
_options->outputAddress = vm["output-address"].as<string>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
{
|
||||
if (!parse_cmd_line(argc, argv, &options))
|
||||
return 0;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
LOG(INFO) << "PID: " << getpid();
|
||||
LOG(INFO) << "CONFIG: " << "id: " << options.id << ", event size: " << options.eventSize << ", event rate: " << options.eventRate << ", I/O threads: " << options.ioThreads;
|
||||
LOG(INFO) << "OUTPUT: " << options.outputSocketType << " " << options.outputBufSize << " " << options.outputMethod << " " << options.outputAddress;
|
||||
|
||||
#ifdef NANOMSG
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||
#else
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||
#endif
|
||||
|
||||
sampler.SetTransport(transportFactory);
|
||||
|
||||
sampler.SetProperty(FairMQProtoSampler::Id, options.id);
|
||||
sampler.SetProperty(FairMQProtoSampler::EventSize, options.eventSize);
|
||||
sampler.SetProperty(FairMQProtoSampler::EventRate, options.eventRate);
|
||||
sampler.SetProperty(FairMQProtoSampler::NumIoThreads, options.ioThreads);
|
||||
|
||||
sampler.SetProperty(FairMQProtoSampler::NumInputs, 0);
|
||||
sampler.SetProperty(FairMQProtoSampler::NumOutputs, 1);
|
||||
|
||||
sampler.ChangeState(FairMQProtoSampler::INIT);
|
||||
|
||||
sampler.SetProperty(FairMQProtoSampler::OutputSocketType, options.outputSocketType);
|
||||
sampler.SetProperty(FairMQProtoSampler::OutputSndBufSize, options.outputBufSize);
|
||||
sampler.SetProperty(FairMQProtoSampler::OutputMethod, options.outputMethod);
|
||||
sampler.SetProperty(FairMQProtoSampler::OutputAddress, options.outputAddress);
|
||||
|
||||
sampler.ChangeState(FairMQProtoSampler::SETOUTPUT);
|
||||
sampler.ChangeState(FairMQProtoSampler::SETINPUT);
|
||||
sampler.ChangeState(FairMQProtoSampler::BIND);
|
||||
sampler.ChangeState(FairMQProtoSampler::CONNECT);
|
||||
sampler.ChangeState(FairMQProtoSampler::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(sampler.fRunningMutex);
|
||||
while (!sampler.fRunningFinished)
|
||||
{
|
||||
sampler.fRunningCondition.wait(lock);
|
||||
}
|
||||
|
||||
sampler.ChangeState(FairMQProtoSampler::STOP);
|
||||
sampler.ChangeState(FairMQProtoSampler::END);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,172 +0,0 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* runSink.cxx
|
||||
*
|
||||
* @since 2013-01-21
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProtoSink.h"
|
||||
|
||||
#ifdef NANOMSG
|
||||
#include "FairMQTransportFactoryNN.h"
|
||||
#else
|
||||
#include "FairMQTransportFactoryZMQ.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQProtoSink sink;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
|
||||
sink.ChangeState(FairMQProtoSink::STOP);
|
||||
sink.ChangeState(FairMQProtoSink::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
id(), ioThreads(0),
|
||||
inputSocketType(), inputBufSize(0), inputMethod(), inputAddress() {}
|
||||
|
||||
string id;
|
||||
int ioThreads;
|
||||
string inputSocketType;
|
||||
int inputBufSize;
|
||||
string inputMethod;
|
||||
string inputAddress;
|
||||
} DeviceOptions_t;
|
||||
|
||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
{
|
||||
if (_options == NULL)
|
||||
throw runtime_error("Internal error: options' container is empty.");
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
bpo::options_description desc("Options");
|
||||
desc.add_options()
|
||||
("id", bpo::value<string>()->required(), "Device ID")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
||||
("input-buff-size", bpo::value<int>()->required(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://*:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
||||
bpo::variables_map vm;
|
||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
||||
|
||||
if ( vm.count("help") )
|
||||
{
|
||||
LOG(INFO) << "FairMQ Proto Sink" << endl << desc;
|
||||
return false;
|
||||
}
|
||||
|
||||
bpo::notify(vm);
|
||||
|
||||
if ( vm.count("id") )
|
||||
_options->id = vm["id"].as<string>();
|
||||
|
||||
if ( vm.count("io-threads") )
|
||||
_options->ioThreads = vm["io-threads"].as<int>();
|
||||
|
||||
if ( vm.count("input-socket-type") )
|
||||
_options->inputSocketType = vm["input-socket-type"].as<string>();
|
||||
|
||||
if ( vm.count("input-buff-size") )
|
||||
_options->inputBufSize = vm["input-buff-size"].as<int>();
|
||||
|
||||
if ( vm.count("input-method") )
|
||||
_options->inputMethod = vm["input-method"].as<string>();
|
||||
|
||||
if ( vm.count("input-address") )
|
||||
_options->inputAddress = vm["input-address"].as<string>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
{
|
||||
if (!parse_cmd_line(argc, argv, &options))
|
||||
return 0;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
LOG(INFO) << "PID: " << getpid();
|
||||
|
||||
#ifdef NANOMSG
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||
#else
|
||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||
#endif
|
||||
|
||||
sink.SetTransport(transportFactory);
|
||||
|
||||
sink.SetProperty(FairMQProtoSink::Id, options.id);
|
||||
sink.SetProperty(FairMQProtoSink::NumIoThreads, options.ioThreads);
|
||||
|
||||
sink.SetProperty(FairMQProtoSink::NumInputs, 1);
|
||||
sink.SetProperty(FairMQProtoSink::NumOutputs, 0);
|
||||
|
||||
sink.ChangeState(FairMQProtoSink::INIT);
|
||||
|
||||
sink.SetProperty(FairMQProtoSink::InputSocketType, options.inputSocketType);
|
||||
sink.SetProperty(FairMQProtoSink::InputRcvBufSize, options.inputBufSize);
|
||||
sink.SetProperty(FairMQProtoSink::InputMethod, options.inputMethod);
|
||||
sink.SetProperty(FairMQProtoSink::InputAddress, options.inputAddress);
|
||||
|
||||
sink.ChangeState(FairMQProtoSink::SETOUTPUT);
|
||||
sink.ChangeState(FairMQProtoSink::SETINPUT);
|
||||
sink.ChangeState(FairMQProtoSink::BIND);
|
||||
sink.ChangeState(FairMQProtoSink::CONNECT);
|
||||
sink.ChangeState(FairMQProtoSink::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(sink.fRunningMutex);
|
||||
while (!sink.fRunningFinished)
|
||||
{
|
||||
sink.fRunningCondition.wait(lock);
|
||||
}
|
||||
|
||||
sink.ChangeState(FairMQProtoSink::STOP);
|
||||
sink.ChangeState(FairMQProtoSink::END);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
@@ -28,28 +27,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQProxy proxy;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
proxy.ChangeState(FairMQProxy::END);
|
||||
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
@@ -135,7 +112,8 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
FairMQProxy proxy;
|
||||
proxy.CatchSignals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
@@ -176,24 +154,14 @@ int main(int argc, char** argv)
|
||||
proxy.SetProperty(FairMQProxy::Id, options.id);
|
||||
proxy.SetProperty(FairMQProxy::NumIoThreads, options.ioThreads);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::INIT_DEVICE);
|
||||
proxy.WaitForEndOfState(FairMQProxy::INIT_DEVICE);
|
||||
proxy.ChangeState("INIT_DEVICE");
|
||||
proxy.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
proxy.ChangeState(FairMQProxy::INIT_TASK);
|
||||
proxy.WaitForEndOfState(FairMQProxy::INIT_TASK);
|
||||
proxy.ChangeState("INIT_TASK");
|
||||
proxy.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
proxy.ChangeState(FairMQProxy::RUN);
|
||||
proxy.WaitForEndOfState(FairMQProxy::RUN);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::STOP);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::RESET_TASK);
|
||||
proxy.WaitForEndOfState(FairMQProxy::RESET_TASK);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::RESET_DEVICE);
|
||||
proxy.WaitForEndOfState(FairMQProxy::RESET_DEVICE);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::END);
|
||||
proxy.ChangeState("RUN");
|
||||
proxy.InteractiveStateLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
@@ -32,31 +31,10 @@ using namespace std;
|
||||
using namespace FairMQParser;
|
||||
using namespace boost::program_options;
|
||||
|
||||
FairMQSink sink;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
sink.ChangeState(FairMQSink::END);
|
||||
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
FairMQSink sink;
|
||||
sink.CatchSignals();
|
||||
|
||||
FairMQProgOptions config;
|
||||
|
||||
@@ -75,7 +53,7 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
string filename = config.GetValue<string>("config-json-filename");
|
||||
string filename = config.GetValue<string>("config-json-file");
|
||||
string id = config.GetValue<string>("id");
|
||||
|
||||
config.UserParser<JSON>(filename, id);
|
||||
@@ -95,25 +73,14 @@ int main(int argc, char** argv)
|
||||
sink.SetProperty(FairMQSink::Id, id);
|
||||
sink.SetProperty(FairMQSink::NumIoThreads, ioThreads);
|
||||
|
||||
sink.ChangeState(FairMQSink::INIT_DEVICE);
|
||||
sink.WaitForEndOfState(FairMQSink::INIT_DEVICE);
|
||||
sink.ChangeState("INIT_DEVICE");
|
||||
sink.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
sink.ChangeState(FairMQSink::INIT_TASK);
|
||||
sink.WaitForEndOfState(FairMQSink::INIT_TASK);
|
||||
|
||||
sink.ChangeState(FairMQSink::RUN);
|
||||
sink.WaitForEndOfState(FairMQSink::RUN);
|
||||
|
||||
sink.ChangeState(FairMQSink::STOP);
|
||||
|
||||
sink.ChangeState(FairMQSink::RESET_TASK);
|
||||
sink.WaitForEndOfState(FairMQSink::RESET_TASK);
|
||||
|
||||
sink.ChangeState(FairMQSink::RESET_DEVICE);
|
||||
sink.WaitForEndOfState(FairMQSink::RESET_DEVICE);
|
||||
|
||||
sink.ChangeState(FairMQSink::END);
|
||||
sink.ChangeState("INIT_TASK");
|
||||
sink.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
sink.ChangeState("RUN");
|
||||
sink.InteractiveStateLoop();
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
@@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
@@ -28,28 +27,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQSplitter splitter;
|
||||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::END);
|
||||
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void s_catch_signals(void)
|
||||
{
|
||||
struct sigaction action;
|
||||
action.sa_handler = s_signal_handler;
|
||||
action.sa_flags = 0;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
|
||||
typedef struct DeviceOptions
|
||||
{
|
||||
DeviceOptions() :
|
||||
@@ -141,7 +118,8 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
s_catch_signals();
|
||||
FairMQSplitter splitter;
|
||||
splitter.CatchSignals();
|
||||
|
||||
DeviceOptions_t options;
|
||||
try
|
||||
@@ -185,24 +163,14 @@ int main(int argc, char** argv)
|
||||
splitter.SetProperty(FairMQSplitter::Id, options.id);
|
||||
splitter.SetProperty(FairMQSplitter::NumIoThreads, options.ioThreads);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::INIT_DEVICE);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::INIT_DEVICE);
|
||||
splitter.ChangeState("INIT_DEVICE");
|
||||
splitter.WaitForEndOfState("INIT_DEVICE");
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::INIT_TASK);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::INIT_TASK);
|
||||
splitter.ChangeState("INIT_TASK");
|
||||
splitter.WaitForEndOfState("INIT_TASK");
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::RUN);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::RUN);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::STOP);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::RESET_TASK);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::RESET_TASK);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::RESET_DEVICE);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::RESET_DEVICE);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::END);
|
||||
splitter.ChangeState("RUN");
|
||||
splitter.InteractiveStateLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user