$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/DataProcessorPlugins/TCPDataListenerProducer.h" 00002 #include "otsdaq-core/Macros/CoutMacros.h" 00003 #include "otsdaq-core/Macros/ProcessorPluginMacros.h" 00004 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00005 #include "otsdaq-core/NetworkUtilities/NetworkConverters.h" 00006 00007 #include <string.h> 00008 #include <unistd.h> 00009 #include <cassert> 00010 #include <iostream> 00011 00012 using namespace ots; 00013 00014 //======================================================================================================================== 00015 TCPDataListenerProducer::TCPDataListenerProducer( 00016 std::string supervisorApplicationUID, 00017 std::string bufferUID, 00018 std::string processorUID, 00019 const ConfigurationTree& theXDAQContextConfigTree, 00020 const std::string& configurationPath) 00021 : WorkLoop(processorUID) 00022 //, Socket ("192.168.133.100", 40000) 00023 , DataProducer(supervisorApplicationUID, 00024 bufferUID, 00025 processorUID, 00026 theXDAQContextConfigTree.getNode(configurationPath) 00027 .getNode("BufferSize") 00028 .getValue<unsigned int>()) 00029 //, DataProducer (supervisorApplicationUID, bufferUID, processorUID, 100) 00030 , Configurable(theXDAQContextConfigTree, configurationPath) 00031 , TCPSocket( 00032 theXDAQContextConfigTree.getNode(configurationPath) 00033 .getNode("HostIPAddress") 00034 .getValue<std::string>(), 00035 theXDAQContextConfigTree.getNode(configurationPath) 00036 .getNode("HostPort") 00037 .getValue<unsigned int>(), 00038 0x10000 /*theXDAQContextConfigTree.getNode(configurationPath).getNode("SocketReceiveBufferSize").getValue<unsigned 00039 int>()*/ 00040 ) 00041 , dataP_(nullptr) 00042 , headerP_(nullptr) 00043 , ipAddress_(theXDAQContextConfigTree.getNode(configurationPath) 00044 .getNode("HostIPAddress") 00045 .getValue<std::string>()) 00046 , port_(theXDAQContextConfigTree.getNode(configurationPath) 00047 .getNode("HostPort") 00048 .getValue<unsigned int>()) 00049 { 00050 } 00051 00052 //======================================================================================================================== 00053 TCPDataListenerProducer::~TCPDataListenerProducer(void) {} 00054 00055 //======================================================================================================================== 00056 bool TCPDataListenerProducer::workLoopThread(toolbox::task::WorkLoop* workLoop) 00057 // bool TCPDataListenerProducer::getNextFragment(void) 00058 { 00059 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << DataProcessor::processorUID_ 00060 // << " running, because workloop: " << WorkLoop::continueWorkLoop_ << std::endl; 00061 fastWrite(); 00062 return WorkLoop::continueWorkLoop_; 00063 } 00064 00065 //======================================================================================================================== 00066 void TCPDataListenerProducer::slowWrite(void) 00067 { 00068 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << name_ << " running!" << 00069 // std::endl; 00070 00071 if(TCPSocket::receive(data_) != -1) 00072 { 00073 header_["IPAddress"] = ipAddress_; 00074 header_["Port"] = std::to_string(port_); 00075 00076 while(DataProducer::write(data_, header_) < 0) 00077 { 00078 __COUT__ << "There are no available buffers! Retrying...after waiting 10 " 00079 "milliseconds!" 00080 << std::endl; 00081 usleep(10000); 00082 return; 00083 } 00084 } 00085 } 00086 00087 //======================================================================================================================== 00088 void TCPDataListenerProducer::fastWrite(void) 00089 { 00090 // std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << name_ << " running!" << 00091 // std::endl; 00092 00093 if(DataProducer::attachToEmptySubBuffer(dataP_, headerP_) < 0) 00094 { 00095 __COUT__ 00096 << "There are no available buffers! Retrying...after waiting 10 milliseconds!" 00097 << std::endl; 00098 usleep(10000); 00099 return; 00100 } 00101 00102 if(TCPSocket::receive(*dataP_) != -1) 00103 { 00104 (*headerP_)["IPAddress"] = ipAddress_; 00105 (*headerP_)["Port"] = std::to_string(port_); 00106 00107 // if (port_ == 40005) 00108 //{ 00109 // __COUT__ << "Got data: " << dataP_->length() << std::endl; 00110 //} 00111 00112 DataProducer::setWrittenSubBuffer<std::string, 00113 std::map<std::string, std::string>>(); 00114 } 00115 } 00116 00117 DEFINE_OTS_PROCESSOR(TCPDataListenerProducer)