ADTF  3.18.2
Source Code for Demo Data Load Generator Plugin
Location
./src/examples/src/adtf/streaming_services/sources/data_load_generator/
Namespace for entire ADTF SDK.
Build Environment
To see how to set up the build environment have a look at ADTF CMake Environment
this implementation shows:
Header
#pragma once
#include <optional>
class cDataLoadGenerator: public adtf::filter::cSampleStreamingSource
{
public:
ADTF_CLASS_ID_NAME(cDataLoadGenerator,
"demo_data_load_generator.streaming_source.adtf.cid",
"Demo Data Load Generator");
public:
cDataLoadGenerator();
tResult StartStreaming() override;
tResult StopStreaming() override;
private:
tResult GenerateData();
private:
adtf::streaming::ISampleWriter* m_pWriter = nullptr;
std::optional<adtf::base::tNanoSeconds> m_tmLastTrigger;
};
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define REQUIRE_INTERFACE(_interface)
Macro usable with ADTF_CLASS_DEPENDENCIES() to require mandatory interfaces.
#define ADTF_CLASS_DEPENDENCIES(...)
Add interface ids (string literals,.
#define ADTF_CLASS_ID_NAME(_class, _strcid, _strclabel)
Common macro to enable correct treatment of class identifier AND Class Name by IClassInfo.
Definition: class_id.h:33
Property Variable template for the given T.
Base class for ADTF sample streaming sources.
tResult StopStreaming() override
Stop your threads and timers in this method.
tResult StartStreaming() override
Start your threads and timers in this method.
This class is used to provide a fallback kernel thread/timer for a runner of a streaming service.
Kernel interface for thread, timer and signal handling.
Definition: kernel_intf.h:388
The IReferenceClock interface provides the reference time source for the filter graph.
Interface for sample writers that write to sample streams via output pins.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Copyright © Audi Electronics Venture GmbH.
Implementation
#include "demo_data_load_generator.h"
using namespace adtf::ucom;
using namespace adtf::streaming;
using namespace adtf::system;
ADTF_PLUGIN("Demo Data Load Generator Source Plugin",
cDataLoadGenerator);
cDataLoadGenerator::cDataLoadGenerator()
{
m_fDataRate.SetDescription("Count of bytes which should be generated per second.");
RegisterPropertyVariable("data_rate_bytes_per_second", m_fDataRate);
m_nDataInterval.SetDescription("Update interval in microseconds to generate random data. This is only used when no Timer Runner is connected to the 'generate_data' runner.");
RegisterPropertyVariable("data_interval_us", m_nDataInterval);
m_pWriter = CreateOutputPin("data");
SetDescription("data", "Provides the randomly generated data");
// For session compatibility reasons we use this fallback helper for the case where no active runner is connected to the runner.
// In your own implementations use a simple CreateRunner(...) instead!
m_oTimer = adtf::filter::cRunnerFallback(this, "generate_data", cTimerTriggerHint(*m_nDataInterval), [this]
{
auto oResult = GenerateData();
if (IS_FAILED(oResult))
{
m_pWriter->SetStreamError(oResult);
}
});
SetDescription("generate_data",
"Connect a Timer Runner that will trigger the data generation. In this case the property `data_interval_us` has no effect."
"If this is not connected, the source will create a timer on its own.");
// sets a short description for the component
SetDescription("Use this Streaming Source to generate random data load configured by 'data_rate_bytes_per_second' and 'data_interval_us' properties.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_data_load_generator.html");
}
tResult cDataLoadGenerator::StartStreaming()
{
RETURN_IF_FAILED(cSampleStreamingSource::StartStreaming());
m_tmLastTrigger = std::nullopt;
RETURN_IF_FAILED(m_oTimer.Activate(m_nDataInterval));
}
tResult cDataLoadGenerator::GenerateData()
{
auto tmNow = m_pClock->GetStreamTimeNs();
if (m_tmLastTrigger)
{
const auto tmInterval = tmNow - *m_tmLastTrigger;
auto nSampleSize = static_cast<size_t>(m_fDataRate * tmInterval.nCount / 1000000000);
object_ptr<ISample> pSample;
RETURN_IF_FAILED(alloc_sample(pSample, tmNow));
{
object_ptr_locked<ISampleBuffer> pBuffer;
RETURN_IF_FAILED(pSample->WriteLock(pBuffer, nSampleSize));
}
m_pWriter->Write(pSample);
m_pWriter->ManualTrigger(tmNow);
}
m_tmLastTrigger = tmNow;
}
tResult cDataLoadGenerator::StopStreaming()
{
m_oTimer.Deactivate();
return cSampleStreamingSource::StopStreaming();
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
Definition: adtf_plugin.h:22
#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.
virtual tResult GetObject(iobject_ptr< IObject > &pObject, const char *strNameOID) const =0
Get registered object from object registry.
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.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF System SDK.
Namespace for the ADTF uCOM3 SDK.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.