mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51: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
@@ -13,12 +13,13 @@
|
||||
*/
|
||||
|
||||
#include <memory> // unique_ptr
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <thread> // this_thread::sleep_for
|
||||
#include <chrono>
|
||||
|
||||
#include "FairMQExample6Sampler.h"
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -27,42 +28,39 @@ FairMQExample6Sampler::FairMQExample6Sampler()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQExample6Sampler::CustomCleanup(void* /*data*/, void *object)
|
||||
void FairMQExample6Sampler::InitTask()
|
||||
{
|
||||
delete static_cast<string*>(object);
|
||||
fText = fConfig->GetValue<string>("text");
|
||||
}
|
||||
|
||||
void FairMQExample6Sampler::Run()
|
||||
{
|
||||
std::unique_ptr<FairMQPoller> poller(fTransportFactory->CreatePoller(fChannels, { "data", "broadcast" }));
|
||||
unique_ptr<FairMQPoller> poller(fTransportFactory->CreatePoller(fChannels, { "data", "broadcast" }));
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
poller->Poll(-1);
|
||||
poller->Poll(100);
|
||||
|
||||
if (poller->CheckInput("broadcast", 0))
|
||||
{
|
||||
unique_ptr<FairMQMessage> msg(NewMessage());
|
||||
FairMQMessagePtr msg(NewMessage());
|
||||
|
||||
if (Receive(msg, "broadcast") > 0)
|
||||
{
|
||||
LOG(INFO) << "Received broadcast: \""
|
||||
<< string(static_cast<char*>(msg->GetData()), msg->GetSize())
|
||||
<< "\"";
|
||||
LOG(INFO) << "Received broadcast: \"" << string(static_cast<char*>(msg->GetData()), msg->GetSize()) << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
if (poller->CheckOutput("data", 0))
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
|
||||
string* text = new string(fText);
|
||||
FairMQMessagePtr msg(NewSimpleMessage(fText));
|
||||
|
||||
unique_ptr<FairMQMessage> msg(NewMessage(const_cast<char*>(text->c_str()), text->length(), CustomCleanup, text));
|
||||
|
||||
LOG(INFO) << "Sending \"" << fText << "\"";
|
||||
|
||||
Send(msg, "data");
|
||||
if (Send(msg, "data") > 0)
|
||||
{
|
||||
LOG(INFO) << "Sent \"" << fText << "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,47 +68,3 @@ void FairMQExample6Sampler::Run()
|
||||
FairMQExample6Sampler::~FairMQExample6Sampler()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQExample6Sampler::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Text:
|
||||
fText = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQExample6Sampler::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Text:
|
||||
return fText;
|
||||
break;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQExample6Sampler::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQExample6Sampler::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user