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:
committed by
Mohammad Al-Turany
parent
d5b98567db
commit
da10c64800
@@ -12,11 +12,12 @@
|
||||
* @author A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <thread> // this_thread::sleep_for
|
||||
#include <chrono>
|
||||
|
||||
#include "FairMQExample3Sampler.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h" // device->fConfig
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -24,25 +25,24 @@ FairMQExample3Sampler::FairMQExample3Sampler()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQExample3Sampler::CustomCleanup(void *data, void *object)
|
||||
bool FairMQExample3Sampler::ConditionalRun()
|
||||
{
|
||||
delete static_cast<string*>(object);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
void FairMQExample3Sampler::Run()
|
||||
{
|
||||
while (CheckCurrentState(RUNNING))
|
||||
// NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
|
||||
// Should only be used for small data because of the cost of an additional copy
|
||||
FairMQMessagePtr msg(NewSimpleMessage("Data"));
|
||||
|
||||
LOG(INFO) << "Sending \"Data\"";
|
||||
|
||||
// in case of error or transfer interruption, return false to go to IDLE state
|
||||
// successfull transfer will return number of bytes transfered (can be 0 if sending an empty message).
|
||||
if (Send(msg, "data1") < 0)
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
|
||||
string* text = new string("Data");
|
||||
|
||||
unique_ptr<FairMQMessage> msg(NewMessage(const_cast<char*>(text->c_str()), text->length(), CustomCleanup, text));
|
||||
|
||||
LOG(INFO) << "Sending \"Data\"";
|
||||
|
||||
Send(msg, "data1");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FairMQExample3Sampler::~FairMQExample3Sampler()
|
||||
|
Reference in New Issue
Block a user