ADTF
Loading...
Searching...
No Matches
Example Demo Data Load Generator

Description

Shows how to implement a streaming source to produce traffic.

Prebuilt Binaries

Source Code

./examples/demo_adtfplugins/demo_data_load_generator/

Streaming Source

demo_data_load_generator.h

#pragma once
#include <optional>
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
class cDataLoadGenerator final : public adtf::filter::cSampleStreamingSource
{
public:
ADTF_CLASS_ID_NAME(cDataLoadGenerator,
"demo_data_load_generator.streaming_source" ADTF_EXAMPLES_CID,
"Demo Data Load Generator");
public:
cDataLoadGenerator();
~cDataLoadGenerator() override;
tResult StartStreaming() override;
tResult StopStreaming() override;
private:
tResult GenerateData();
private:
adtf::streaming::ISampleWriter* m_pWriter = nullptr;
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
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

demo_data_load_generator.cpp

#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/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(alloc_sample(pSample, tmNow));
{
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