1 #include "otsdaq-core/DataProcessorPlugins/TCPDataListenerProducer.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutMacros.h"
4 #include "otsdaq-core/NetworkUtilities/NetworkConverters.h"
5 #include "otsdaq-core/Macros/ProcessorPluginMacros.h"
16 TCPDataListenerProducer::TCPDataListenerProducer(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID,
17 const ConfigurationTree& theXDAQContextConfigTree,
const std::string& configurationPath)
22 supervisorApplicationUID,
25 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"BufferSize").getValue<unsigned int>()
28 ,
Configurable(theXDAQContextConfigTree, configurationPath)
31 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"HostIPAddress").getValue<std::string>(),
32 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"HostPort").getValue<unsigned int>(),
33 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"SocketReceiveBufferSize").getValue<unsigned int>()
37 , ipAddress_(theXDAQContextConfigTree.getNode(configurationPath).getNode(
"HostIPAddress").getValue<std::string>())
38 , port_(theXDAQContextConfigTree.getNode(configurationPath).getNode(
"HostPort").getValue<unsigned int>())
43 TCPDataListenerProducer::~TCPDataListenerProducer(
void)
47 bool TCPDataListenerProducer::workLoopThread(toolbox::task::WorkLoop* workLoop)
52 return WorkLoop::continueWorkLoop_;
56 void TCPDataListenerProducer::slowWrite(
void)
60 if (TCPSocket::receive(data_) != -1)
62 header_[
"IPAddress"] = ipAddress_;
63 header_[
"Port"] = std::to_string(port_);
65 while (DataProducer::write(data_, header_) < 0)
67 __COUT__ <<
"There are no available buffers! Retrying...after waiting 10 milliseconds!" << std::endl;
75 void TCPDataListenerProducer::fastWrite(
void)
79 if (DataProducer::attachToEmptySubBuffer(dataP_, headerP_) < 0)
81 __COUT__ <<
"There are no available buffers! Retrying...after waiting 10 milliseconds!" << std::endl;
86 if (TCPSocket::receive(*dataP_) != -1)
88 (*headerP_)[
"IPAddress"] = ipAddress_;
89 (*headerP_)[
"Port"] = std::to_string(port_);
96 DataProducer::setWrittenSubBuffer<std::string, std::map<std::string, std::string>>();