ADTF  3.18.3
Source Code for Demo Thread Trigger Plugin
Location
./src/examples/src/adtf/filters/standard_filters/thread_triggered_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:
Header
#pragma once
#include <condition_variable>
#include <mutex>
using namespace adtf::util;
using namespace ddl;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::mediadescription;
using namespace adtf::filter;
class cAsynchronousDataPrinter : public cFilter
{
public:
ADTF_CLASS_ID_NAME(cAsynchronousDataPrinter,
"demo_thread_trigger.filter.adtf.cid",
"Demo Thread Trigger");
public:
cAsynchronousDataPrinter();
tResult ProcessInput(tNanoSeconds tmTrigger,
ISampleReader* pReader) override;
private:
tResult PrintData();
private:
// reader for our input pin
ISampleReader* m_pReader = nullptr;
// this is used to signal the thread that executes our trigger function
std::mutex m_oSamplesAvailableMutex;
std::condition_variable m_oSamplesAvailable;
size_t m_nSampleCounter = 0;
};
#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
Copyright © Audi Electronics Venture GmbH.
Namespace for the ADTF Base SDK.
Namespace for the ADTF Filter SDK.
Namespace for the ADTF Media Description SDK.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF uCOM3 SDK.
alias namespace for the A_UTILS Library.
Implementation
#include "demo_thread_trigger_function.h"
// this creates the plugin entry methods and class factories
ADTF_PLUGIN("Demo Thread Trigger Plugin", cAsynchronousDataPrinter);
cAsynchronousDataPrinter::cAsynchronousDataPrinter()
{
// create our input pin with a data-in trigger that calls our overridden Process method.
m_pReader = CreateInputPin("in", stream_type_plain<float>(), true);
SetDescription("in", "Input value for printing");
// create a trigger function that can be connected to an active runner.
CreateRunner("print_data",
std::bind(&cAsynchronousDataPrinter::PrintData, this),
cThreadTriggerHint());
SetDescription("print_data", "Runner to cyclically trigger the function which prints the data");
// sets a short description for the component
SetDescription("Use this filter to print asynchronously the received values with a defined Thread Runner.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_thread_triggered_filter.html");
}
// this is called when a data trigger is received at the input pin.
tResult cAsynchronousDataPrinter::ProcessInput(tNanoSeconds /*tmTrigger*/,
ISampleReader* /*pReader*/)
{
// all we do is notify the trigger function that there might be some samples available.
m_oSamplesAvailable.notify_all();
}
// this method is called repeatedly by an active thread runner
tResult cAsynchronousDataPrinter::PrintData()
{
object_ptr<const ISample> pSample;
// wait until a sample should be available to read.
// we use a timeout to ensure that this method finishes eventually.
std::unique_lock<std::mutex> oGuard(m_oSamplesAvailableMutex);
if (m_oSamplesAvailable.wait_for(oGuard, std::chrono::milliseconds(10), [&]
{
return IS_OK(m_pReader->GetNextSample(pSample));
}))
{
float fValue = sample_data<float>(pSample);
LOG_INFO("value number %ld: %f", ++m_nSampleCounter, fValue);
}
}
#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_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.