mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Enable new callback API
- OnData() channel data handler. - ConditionalRun() for devices without incoming data. - Header file with common main(), to be extended with getDevice/addCustomOptions. - Update examples (MQ/Tutorial3) to use the new API and config. - NewSimpleMessage() for simpler creation of small messages (additional copy). - Replace SetProperty/GetProperty with fConfig access. - Runtime configurable channel names for common devices. - Configurable logging interval per channel. - FairMQMultiplier for distributing same data to multiple outputs. - Cleanup state machine messages. - Cmd option to toggle signal handling. - Simpler API for send/receive timeouts. - Enable --log-to-file. - Fix coverity issues, warnings. - Various code cleanup and minor tweaks.
This commit is contained in:
67
fairmq/runFairMQDevice.h
Normal file
67
fairmq/runFairMQDevice.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/********************************************************************************
|
||||
* 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" *
|
||||
********************************************************************************/
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
#include "FairMQDevice.h"
|
||||
#include "runSimpleMQStateMachine.h"
|
||||
|
||||
template <typename R>
|
||||
class GenericFairMQDevice : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
GenericFairMQDevice(R func) : r(func) {}
|
||||
|
||||
protected:
|
||||
virtual bool ConditionalRun() { return r(*static_cast<FairMQDevice*>(this)); }
|
||||
|
||||
private:
|
||||
R r;
|
||||
};
|
||||
|
||||
template <typename R>
|
||||
FairMQDevice* makeDeviceWithConditionalRun(R r)
|
||||
{
|
||||
return new GenericFairMQDevice<R>(r);
|
||||
}
|
||||
|
||||
// to be implemented by the user to return a child class of FairMQDevice
|
||||
FairMQDevice* getDevice(const FairMQProgOptions& config);
|
||||
|
||||
// to be implemented by the user to add custom command line options (or just with empty body)
|
||||
void addCustomOptions(boost::program_options::options_description&);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::program_options::options_description customOptions("Custom options");
|
||||
addCustomOptions(customOptions);
|
||||
|
||||
FairMQProgOptions config;
|
||||
config.AddToCmdLineOptions(customOptions);
|
||||
config.ParseAll(argc, argv);
|
||||
|
||||
std::unique_ptr<FairMQDevice> device(getDevice(config));
|
||||
int result = runStateMachine(*device, config);
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG(ERROR) << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit";
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user