mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Tests for MQ examples
This commit is contained in:
committed by
Mohammad Al-Turany
parent
984eed1a89
commit
319bdc91a1
@@ -14,21 +14,36 @@
|
||||
|
||||
#include "FairMQExample1Sink.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h" // device->fConfig
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQExample1Sink::FairMQExample1Sink()
|
||||
: fMaxIterations(0)
|
||||
, fNumIterations(0)
|
||||
{
|
||||
// register a handler for data arriving on "data" channel
|
||||
OnData("data", &FairMQExample1Sink::HandleData);
|
||||
}
|
||||
|
||||
void FairMQExample1Sink::InitTask()
|
||||
{
|
||||
// Get the fMaxIterations value from the command line options (via fConfig)
|
||||
fMaxIterations = fConfig->GetValue<uint64_t>("max-iterations");
|
||||
}
|
||||
|
||||
// handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
|
||||
bool FairMQExample1Sink::HandleData(FairMQMessagePtr& msg, int /*index*/)
|
||||
{
|
||||
LOG(INFO) << "Received: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
|
||||
// return true if want to be called again (otherwise go to IDLE state)
|
||||
if (fMaxIterations > 0 && ++fNumIterations >= fMaxIterations)
|
||||
{
|
||||
LOG(INFO) << "Configured maximum number of iterations reached. Leaving RUNNING state.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// return true if want to be called again (otherwise return false go to IDLE state)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user