00001 #include "otsdaq-core/DataProcessorPlugins/UDPDataStreamerConsumer.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutMacros.h"
00004 #include "otsdaq-core/Macros/ProcessorPluginMacros.h"
00005
00006 #include <iostream>
00007 #include <cassert>
00008 #include <unistd.h>
00009
00010 using namespace ots;
00011
00012
00013 UDPDataStreamerConsumer::UDPDataStreamerConsumer(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID, const ConfigurationTree& theXDAQContextConfigTree, const std::string& configurationPath)
00014 : Socket (theXDAQContextConfigTree.getNode(configurationPath).getNode("HostIPAddress").getValue<std::string>(),
00015 theXDAQContextConfigTree.getNode(configurationPath).getNode("HostPort").getValue<unsigned int>())
00016 , WorkLoop (processorUID)
00017 , UDPDataStreamerBase(
00018 theXDAQContextConfigTree.getNode(configurationPath).getNode("HostIPAddress").getValue<std::string>(),
00019 theXDAQContextConfigTree.getNode(configurationPath).getNode("HostPort").getValue<unsigned int>(),
00020 theXDAQContextConfigTree.getNode(configurationPath).getNode("StreamToIPAddress").getValue<std::string>(),
00021 theXDAQContextConfigTree.getNode(configurationPath).getNode("StreamToPort").getValue<unsigned int>()
00022 )
00023 , DataConsumer (supervisorApplicationUID, bufferUID, processorUID, HighConsumerPriority)
00024 , Configurable (theXDAQContextConfigTree, configurationPath)
00025
00026
00027
00028 {
00029 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
00030 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
00031 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
00032 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
00033 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
00034 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
00035
00036 std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "done!" << std::endl;
00037 }
00038
00039
00040 UDPDataStreamerConsumer::~UDPDataStreamerConsumer(void)
00041 {
00042 }
00043
00044
00045 bool UDPDataStreamerConsumer::workLoopThread(toolbox::task::WorkLoop* workLoop)
00046 {
00047 fastRead();
00048 return WorkLoop::continueWorkLoop_;
00049 }
00050
00051
00052 void UDPDataStreamerConsumer::fastRead(void)
00053 {
00054
00055 if(DataConsumer::read(dataP_, headerP_) < 0)
00056 {
00057 usleep(100);
00058 return;
00059 }
00060
00061
00062
00063
00064 TransmitterSocket::send(streamToSocket_, *dataP_);
00065 DataConsumer::setReadSubBuffer<std::string, std::map<std::string, std::string>>();
00066 }
00067
00068
00069 void UDPDataStreamerConsumer::slowRead(void)
00070 {
00071
00072
00073 if(DataConsumer::read(data_, header_) < 0)
00074 {
00075 usleep(1000);
00076 return;
00077 }
00078
00079
00080
00081 TransmitterSocket::send(streamToSocket_, data_);
00082 }
00083
00084 DEFINE_OTS_PROCESSOR(UDPDataStreamerConsumer)