Shows how to implement a streaming source to produce traffic.
#pragma once
#include <optional>
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
{
public:
"demo_data_load_generator.streaming_source" ADTF_EXAMPLES_CID,
"Demo Data Load Generator");
public:
cDataLoadGenerator();
~cDataLoadGenerator() override;
private:
private:
std::optional<adtf::base::tNanoSeconds> m_tmLastTrigger;
};
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define REQUIRE_INTERFACE(_interface)
Macro usable with ADTF_CLASS_DEPENDENCIES() to require mandatory interfaces.
Definition class_dependencies.h:36
#define ADTF_CLASS_DEPENDENCIES(...)
Add interface ids (string literals,.
Definition class_dependencies.h:61
#define ADTF_CLASS_ID_NAME(_class, _strcid, _strclabel)
Definition class_id.h:33
Property Variable template for the given T. A Property Variable will store a copy of a property value...
Definition configuration.h:808
Definition sample_streaming_source.h:50
tResult StopStreaming() override
tResult StartStreaming() override
Definition runner_fallback.h:25
Definition kernel_intf.h:390
Definition reference_clock_intf.h:782
Definition samplestreamer_intf.h:234
Definition object_ptr.h:384
#include "demo_data_load_generator.h"
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");
{
auto oResult = GenerateData();
{
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.");
SetDescription("Use this streaming source to generate random data load configured by 'data_rate_bytes_per_second' and 'data_interval_us' properties.");
SetHelpLink("$(ADTF_DIR)/doc/html/page_demo_data_load_generator.html");
}
cDataLoadGenerator::~cDataLoadGenerator() = default;
tResult cDataLoadGenerator::StartStreaming()
{
RETURN_IF_FAILED(cSampleStreamingSource::StartStreaming());
RETURN_IF_FAILED(_runtime->GetObject(m_pClock));
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);
{
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,...)
Definition adtf_plugin.h:29
#define IS_FAILED(s)
Check if result is failed.
Definition result.h:20
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
Definition lockedobject_intf.h:207
Namespace for the ADTF Streaming SDK.
Definition bindingproxyinport.h:14
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSample)
Namespace for the ADTF System SDK.
Definition adtf_service.h:14
Namespace for the ADTF uCOM SDK.
Definition adtf_system.h:324