ADTF  3.18.2
Source Code for Demo Requestable Substream Generator Plugin
Location
./src/examples/src/adtf/filters/standard_filters/requestable_substream_filter/
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:
Implementation
#include <unordered_set>
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
class cDemoRequestableSubStreamGenerator: public cFilter
{
public:
ADTF_CLASS_ID_NAME(cDemoRequestableSubStreamGenerator,
"demo_request_substream_generator.filter.adtf.cid",
"Demo Requestable Substream Generator");
public:
cDemoRequestableSubStreamGenerator()
{
// sets a short description for the component
SetDescription("Use this filter to generate data of (requested) multiple substreams whenever a timer triggers");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_requestable_substream_generator.html");
CreateRunner("generate_samples");
SetDescription("generate_samples", "Runner to periodically trigger the function which generates samples for the substreams.");
// we use the helper class cSubStreamTypes to generate a stream type with the
// adtf::streaming::stream_meta_type_substreams meta type that contains
// multiple stream type definitions.
cSubStreamTypes oSubStreams;
oSubStreams.SetSubStream("stream1", 0, stream_type_plain<uint32_t>());
oSubStreams.SetSubStream("stream2", 1, stream_type_plain<uint32_t>());
oSubStreams.SetSubStream("stream3", 2, stream_type_plain<uint32_t>());
// now create our output pin with enabled streaming requests.
m_pWriter = CreateRequestableOutputPin("output", oSubStreams);
SetDescription("output", "Provides the generated substreams");
}
// to handle new requests we override this method.
tResult EnableSubStream(ISampleWriter* /*pWriter*/,
uint32_t nSubStreamId,
const IProperties* /*pRequestProperties*/) override
{
if (nSubStreamId > 2)
{
RETURN_ERROR_DESC(ERR_INVALID_ARG, "No substream with id %d available", nSubStreamId);
}
m_oEnabledSubStreams.insert(nSubStreamId);
LOG_INFO("Enabled substream %u", nSubStreamId);
}
// to handle closed requests we override this method.
void DisableSubStream(ISampleWriter* /*pWriter*/, uint32_t nSubStreamId) override
{
m_oEnabledSubStreams.erase(nSubStreamId);
LOG_INFO("Disabled substream %u", nSubStreamId);
}
tResult Process(tNanoSeconds tmTrigger, IRunner* /*pRunner*/) override
{
++m_nTriggerCounter;
for (const auto& nSubStreamId: m_oEnabledSubStreams)
{
// when generating samples we set the substream id.
// in this case we just pass it to the output_sample_data constructor.
// Otherwise take a look at adtf::streaming::set_sample_substream_id() and
// adtf::streaming::hollow::ISample::SetSubStreamId().
output_sample_data<uint32_t> oNewData(tmTrigger, m_nTriggerCounter + (nSubStreamId * 1000), nSubStreamId);
m_pWriter->Write(oNewData.Release());
}
}
private:
ISampleWriter* m_pWriter = nullptr;
std::unordered_set<uint32_t> m_oEnabledSubStreams;
uint32_t m_nTriggerCounter = 0;
};
// this creates the plugin entry methods and class factories
ADTF_PLUGIN("Demo Requestable Substream Generator Plugin", cDemoRequestableSubStreamGenerator);
#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
Copyright © Audi Electronics Venture GmbH.
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#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
Namespace for the ADTF Base SDK.
Namespace for the ADTF Filter SDK.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF uCOM3 SDK.