Add new Send/Receive methods with smart pointers and no flag checks.

This commit is contained in:
Alexey Rybalchenko
2015-08-17 14:45:31 +02:00
committed by Mohammad Al-Turany
parent 105e734808
commit a7ab33a10e
22 changed files with 204 additions and 121 deletions

View File

@@ -33,21 +33,18 @@ void base_GenericSampler<T,U,K,L>::InitTask()
BindingSendPart();
BindingGetSocketNumber();
BindingGetCurrentIndex();
source_type::InitSampler();
fNumEvents = source_type::GetNumberOfEvent();
}
template <typename T, typename U, typename K, typename L>
void base_GenericSampler<T,U,K,L>::Run()
{
// boost::thread resetEventCounter(boost::bind(&GenericSampler::ResetEventCounter, this));
int sentMsgs = 0;
boost::timer::auto_cpu_timer timer;
LOG(INFO) << "Number of events to process: " << fNumEvents;
@@ -56,32 +53,36 @@ void base_GenericSampler<T,U,K,L>::Run()
{
for (fCurrentIdx = 0; fCurrentIdx < fNumEvents; fCurrentIdx++)
{
for(auto& p : fChannels[fOutChanName])
for (auto& p : fChannels[fOutChanName])
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
serialization_type::SetMessage(msg);
std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
serialization_type::SetMessage(msg.get());
source_type::SetIndex(fCurrentIdx);
ExecuteTasks();
p.Send(serialization_type::SerializeMsg(source_type::GetOutData()));
if (msg)
msg->CloseMessage();
sentMsgs++;
if(fChannels[fOutChanName].size()>1)
if (fChannels[fOutChanName].size() > 1)
{
fCurrentIdx++;
}
// Optional event rate limiting
// --fEventCounter;
// while (fEventCounter == 0) {
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
// }
if (!CheckCurrentState(RUNNING))
{
break;
}
}
// if more than one socket, remove the last incrementation
if(fChannels[fOutChanName].size()>1)
if (fChannels[fOutChanName].size() > 1)
{
fCurrentIdx--;
}
}
}
while (CheckCurrentState(RUNNING) && fContinuous);
@@ -96,14 +97,12 @@ template <typename T, typename U, typename K, typename L>
void base_GenericSampler<T,U,K,L>::SendPart(int socketIdx)
{
fCurrentIdx++;
if(fCurrentIdx<fNumEvents)
if (fCurrentIdx < fNumEvents)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
serialization_type::SetMessage(msg);
std::unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
serialization_type::SetMessage(msg.get());
source_type::SetIndex(fCurrentIdx);
fChannels[fOutChanName].at(socketIdx).Send(serialization_type::SerializeMsg(source_type::GetOutData()), "snd-more");
if (msg)
msg->CloseMessage();
}
}
@@ -129,7 +128,7 @@ void base_GenericSampler<T,U,K,L>::SetContinuous(bool flag)
template <typename T, typename U, typename K, typename L>
void base_GenericSampler<T,U,K,L>::ResetEventCounter()
{
while (GetCurrentState() == RUNNING)
while (CheckCurrentState(RUNNING))
{
try
{
@@ -197,8 +196,6 @@ std::string base_GenericSampler<T,U,K,L>::GetProperty(const int key, const std::
}
}
template<typename T, typename U>
using GenericSampler = base_GenericSampler<T,U,int,std::function<void()> >;
typedef std::map<int, std::function<void()> > SamplerTasksMap;