#include "stdafx.h"
#include "demo_legacy_udp_receiver.h"
cDemoUDPReceiver::cDemoUDPReceiver()
{
set_description(*
this,
"Use this legacy Streaming Source to receive sample data from another ADTF System using UDP protocol.");
}
cDemoUDPReceiver::~cDemoUDPReceiver()
{
}
tResult cDemoUDPReceiver::Init(tInitStage eStage)
{
if (eStage == tInitStage::StageFirst)
{
object_ptr<IStreamType> pType = make_object_ptr<cStreamType>(stream_meta_type_anonymous());
}
else if (eStage == tInitStage::StageNormal)
{
m_oSocket.SetTimeout(10000);
}
}
{
m_oThread = kernel_thread_looper(OIGetInstanceName() + "::recieve_thread",
&cDemoUDPReceiver::ThreadLoopFunc,
this);
if (!m_oThread.Joinable())
{
}
}
{
m_oThread = kernel_thread_looper();
return cLegacyStreamingSource::Stop();
}
tResult cDemoUDPReceiver::Shutdown(tInitStage eStage)
{
if (eStage == tInitStage::StageNormal)
{
m_oSocket.Close();
}
return cLegacyStreamingSource::Shutdown(eStage);
}
void cDemoUDPReceiver::ThreadLoopFunc()
{
tResult nResult = TransmitPacket();
{
m_oOutputPin.SetStreamError(nResult);
}
}
tResult cDemoUDPReceiver::TransmitPacket()
{
uint8_t aBuffer[0xFFFF];
int nBytes = 0xFFFF;
if (
IS_OK(m_oSocket.Read(aBuffer, nBytes, &nBytes)))
{
object_ptr<ISample> pSample;
{
object_ptr_locked<ISampleBuffer> pBuffer;
RETURN_IF_FAILED(pBuffer->Write(adtf_memory_buffer<const uint8_t>(aBuffer, nBytes)));
}
}
}
#define IS_FAILED(s)
Check if result is failed.
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define IS_OK(s)
Check if result is OK.
A common result class usable as return value throughout.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSampleObject, const char *strSampleCID)
Helper Function to get a Sample Instance through the adtf::ucom::ant::IRuntime.
void set_description(base::ant::IConfiguration &oConfig, const char *strDescription)
Sets description information.