FairMQ/fairmq/tools/runSimpleMQStateMachine.h
Alexey Rybalchenko f1abb9ecdd Remove compile time transport interface switch
- Remove the compile time check of the transport implementation.
  The transport (zeromq/nanomsg) can be chosen at run time with:
  `device.SetTransport("zeromq"); // possible values are "zeromq" and "nanomsg"`.

  For devices that use FairMQProgOptions, the transport can be configured via cmd option:
  `--transport zeromq` or `--transport nanomsg`. Default values is "zeromq".
  The device receives the configured value with:
  `device.SetTransport(config.GetValue<std::string>("transport"));`

  Old method of setting transport still works. But the NANOMSG constant is not defined.

- Remove old `fairmq/prototest` directory. It was only used as a test for protobuf.
  The protobuf part of Tutorial3 does the same (with different values).

- Fix a bug in FairMQPollerNN, where the `revents` value was not initialized.
  This caused the `poller->CheckOutput()` to trigger when it should not.
2016-01-14 15:19:30 +01:00

97 lines
2.6 KiB
C++

/*
* File: runSimpleMQStateMachine.h
* Author: winckler
*
* Created on July 2, 2015, 2:07 PM
*/
#ifndef RUNSIMPLEMQSTATEMACHINE_H
#define RUNSIMPLEMQSTATEMACHINE_H
/// std
#include <iostream>
#include <type_traits>
#include <string>
/// boost
#include "boost/program_options.hpp"
/// FairRoot - FairMQ
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
// template function that take any device,
// and run a simple MQ state machine configured from a JSON file
template<typename TMQDevice>
inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
{
device.CatchSignals();
std::string jsonfile = config.GetValue<std::string>("config-json-file");
std::string id = config.GetValue<std::string>("id");
int ioThreads = config.GetValue<int>("io-threads");
config.UserParser<FairMQParser::JSON>(jsonfile, id);
device.fChannels = config.GetFairMQMap();
device.SetProperty(TMQDevice::Id, id);
device.SetProperty(TMQDevice::NumIoThreads, ioThreads);
LOG(INFO) << "PID: " << getpid();
device.SetTransport(config.GetValue<std::string>("transport"));
device.ChangeState(TMQDevice::INIT_DEVICE);
device.WaitForEndOfState(TMQDevice::INIT_DEVICE);
device.ChangeState(TMQDevice::INIT_TASK);
device.WaitForEndOfState(TMQDevice::INIT_TASK);
device.ChangeState(TMQDevice::RUN);
device.InteractiveStateLoop();
return 0;
}
template<typename TMQDevice>
inline int runNonInteractiveStateMachine(TMQDevice& device, FairMQProgOptions& config)
{
device.CatchSignals();
std::string jsonfile = config.GetValue<std::string>("config-json-file");
std::string id = config.GetValue<std::string>("id");
int ioThreads = config.GetValue<int>("io-threads");
config.UserParser<FairMQParser::JSON>(jsonfile, id);
device.fChannels = config.GetFairMQMap();
device.SetProperty(TMQDevice::Id, id);
device.SetProperty(TMQDevice::NumIoThreads, ioThreads);
LOG(INFO) << "PID: " << getpid();
device.SetTransport(config.GetValue<std::string>("transport"));
device.ChangeState(TMQDevice::INIT_DEVICE);
device.WaitForEndOfState(TMQDevice::INIT_DEVICE);
device.ChangeState(TMQDevice::INIT_TASK);
device.WaitForEndOfState(TMQDevice::INIT_TASK);
device.ChangeState(TMQDevice::RUN);
device.WaitForEndOfState(TMQDevice::RUN);
device.ChangeState(TMQDevice::RESET_TASK);
device.WaitForEndOfState(TMQDevice::RESET_TASK);
device.ChangeState(TMQDevice::RESET_DEVICE);
device.WaitForEndOfState(TMQDevice::RESET_DEVICE);
device.ChangeState(TMQDevice::END);
return 0;
}
#endif /* RUNSIMPLEMQSTATEMACHINE_H */