mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
- Extend the multipart API to allow sending vectors of messages or helper thin wrapper FairMQParts. See example in examples/MQ/8-multipart. - NewMessage() can be used in devices instead of fTransportFactory->CreateMessage(). Possible arguments remain unchanged (no args, size or data+size). - Send()/Receive() methods can be used in devices instead of fChannels.at("chan").at(i).Send()/Receive(): Send(msg, "chan", i = 0), Receive(msg, "chan", i = 0). - Use the new methods in MQ examples and tests. - No breaking changes, but FAIRMQ_INTERFACE_VERSION is incremented to 3 to allow to check for new methods.
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
/********************************************************************************
|
|
* 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" *
|
|
********************************************************************************/
|
|
/**
|
|
* FairMQExample8Sampler.cpp
|
|
*
|
|
* @since 2014-10-10
|
|
* @author A. Rybalchenko
|
|
*/
|
|
|
|
#include <boost/thread.hpp>
|
|
#include <boost/bind.hpp>
|
|
|
|
#include "FairMQExample8Sampler.h"
|
|
#include "FairMQLogger.h"
|
|
|
|
using namespace std;
|
|
|
|
struct Ex8Header {
|
|
int32_t stopFlag;
|
|
};
|
|
|
|
FairMQExample8Sampler::FairMQExample8Sampler()
|
|
{
|
|
}
|
|
|
|
void FairMQExample8Sampler::Run()
|
|
{
|
|
int counter = 0;
|
|
|
|
// Check if we are still in the RUNNING state.
|
|
while (CheckCurrentState(RUNNING))
|
|
{
|
|
Ex8Header* header = new Ex8Header;
|
|
// Set stopFlag to 1 for the first 4 messages, and to 0 for the 5th.
|
|
counter < 5 ? header->stopFlag = 0 : header->stopFlag = 1;
|
|
|
|
FairMQParts parts;
|
|
parts.AddPart(NewMessage(header, sizeof(Ex8Header)));
|
|
parts.AddPart(NewMessage(1000));
|
|
|
|
LOG(INFO) << "Sending header with stopFlag: " << header->stopFlag;
|
|
LOG(INFO) << "Sending body of size: " << parts.At(1).GetSize();
|
|
|
|
Send(parts, "data-out");
|
|
|
|
// Go out of the sending loop if the stopFlag was sent.
|
|
if (counter == 5)
|
|
{
|
|
break;
|
|
}
|
|
|
|
counter++;
|
|
// Wait a second to keep the output readable.
|
|
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
|
}
|
|
|
|
LOG(INFO) << "Going out of RUNNING state.";
|
|
}
|
|
|
|
FairMQExample8Sampler::~FairMQExample8Sampler()
|
|
{
|
|
}
|