mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
134 lines
3.4 KiB
C++
134 lines
3.4 KiB
C++
/********************************************************************************
|
|
* Copyright (C) 2015-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
|
* *
|
|
* This software is distributed under the terms of the *
|
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
|
* copied verbatim in the file "LICENSE" *
|
|
********************************************************************************/
|
|
|
|
#include <FairMQDevice.h>
|
|
#include <FairMQLogger.h>
|
|
#include <options/FairMQProgOptions.h>
|
|
|
|
namespace fair
|
|
{
|
|
namespace mq
|
|
{
|
|
namespace test
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
class PollIn : public FairMQDevice
|
|
{
|
|
public:
|
|
PollIn()
|
|
: fPollType(0)
|
|
{}
|
|
|
|
protected:
|
|
auto Init() -> void override
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
}
|
|
|
|
auto Reset() -> void override
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
}
|
|
|
|
auto InitTask() -> void override
|
|
{
|
|
fPollType = fConfig->GetValue<int>("poll-type");
|
|
}
|
|
|
|
auto Run() -> void override
|
|
{
|
|
vector<const FairMQChannel*> chans;
|
|
|
|
chans.push_back(&fChannels.at("data1").at(0));
|
|
chans.push_back(&fChannels.at("data2").at(0));
|
|
|
|
FairMQPollerPtr poller = nullptr;
|
|
|
|
if (fPollType == 0)
|
|
{
|
|
poller = NewPoller(chans);
|
|
}
|
|
else if (fPollType == 1)
|
|
{
|
|
poller = NewPoller("data1", "data2");
|
|
}
|
|
else
|
|
{
|
|
LOG(ERROR) << "wrong poll type provided: " << fPollType;
|
|
}
|
|
|
|
bool arrived1 = false;
|
|
bool arrived2 = false;
|
|
bool bothArrived = false;
|
|
|
|
FairMQMessagePtr msg1(NewMessage());
|
|
FairMQMessagePtr msg2(NewMessage());
|
|
|
|
while (!bothArrived)
|
|
{
|
|
poller->Poll(100);
|
|
|
|
if (fPollType == 0)
|
|
{
|
|
if (poller->CheckInput(0))
|
|
{
|
|
LOG(DEBUG) << "CheckInput(0) triggered";
|
|
if (Receive(msg1, "data1", 0) >= 0)
|
|
{
|
|
arrived1 = true;
|
|
}
|
|
}
|
|
|
|
if (poller->CheckInput(1))
|
|
{
|
|
LOG(DEBUG) << "CheckInput(1) triggered";
|
|
if (Receive(msg2, "data2", 0) >= 0)
|
|
{
|
|
arrived2 = true;
|
|
}
|
|
}
|
|
}
|
|
else if (fPollType == 1)
|
|
{
|
|
if (poller->CheckInput("data1", 0))
|
|
{
|
|
LOG(DEBUG) << "CheckInput(\"data1\", 0) triggered";
|
|
if (Receive(msg1, "data1", 0) >= 0)
|
|
{
|
|
arrived1 = true;
|
|
}
|
|
}
|
|
|
|
if (poller->CheckInput("data2", 0))
|
|
{
|
|
LOG(DEBUG) << "CheckInput(\"data2\", 0) triggered";
|
|
if (Receive(msg2, "data2", 0) >= 0)
|
|
{
|
|
arrived2 = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (arrived1 && arrived2)
|
|
{
|
|
bothArrived = true;
|
|
LOG(INFO) << "POLL test successfull";
|
|
}
|
|
}
|
|
};
|
|
|
|
private:
|
|
int fPollType;
|
|
};
|
|
|
|
} // namespace test
|
|
} // namespace mq
|
|
} // namespace fair
|