ADTF  3.18.3
Source Code for Demo Signal Generator Plugin
Location
./src/examples/src/adtf/filters/standard_filters/signal_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 <unordered_set>
#include <mutex>
//*************************************************************************************************
#define CID_DEMO_SIGNAL_PROVIDER_FILTER "demo_signal_provider.filter.adtf.cid"
using namespace adtf::util;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::services;
class cCounterGenerator final : public cFilter,
public ISignalRegistry::ISignalProvider::IEnabledSignals
{
public:
ADTF_CLASS_ID_NAME(cCounterGenerator,
"demo_signal_provider.filter.adtf.cid",
"Demo Signal Generator");
);
cCounterGenerator();
virtual tResult Init(tInitStage eStage) override;
virtual tResult EnableSignal(ISignalRegistry::tSignalID nSignalID) override;
virtual tResult DisableSignal(ISignalRegistry::tSignalID nSignalID) override;
tResult Process(tNanoSeconds tmTimeOfTrigger,
IRunner* pRunner) override;
private:
uint64_t m_nCounter = 0;
ISignalRegistry::tSignalID m_nCounterID = 0;
std::mutex m_oEnabledSignalsMutex;
std::unordered_set<ISignalRegistry::tSignalID> m_oEnabledSignals;
// Reference to the provider must the *first* member to be destroyed.
// All methods from ISignalRegistry::ISignalProvider::IEnabledSignals can be called until destruction is complete!
object_ptr<ISignalRegistry::ISignalProvider> m_pProvider;
};
#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
Copyright © Audi Electronics Venture GmbH.
Namespace for the ADTF Base SDK.
Namespace for the ADTF Filter SDK.
Namespace for a summary of all service interfaces (System Service) provided by ADTF.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF uCOM3 SDK.
alias namespace for the A_UTILS Library.
Copyright © Audi Electronics Venture GmbH.
Implementation
#include "demo_signal_generator.h"
ADTF_PLUGIN("Demo Signal Generator Plugin", cCounterGenerator);
cCounterGenerator::cCounterGenerator()
{
CreateRunner("trigger", cTimerTriggerHint(std::chrono::seconds{1}));
SetDescription("trigger", "Runner to periodically trigger the function which increases the signal value");
// sets a short description for the component
SetDescription("Use this filter to provide monotonically increasing values for Signal Registry.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_signal_generator.html");
}
tResult cCounterGenerator::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cFilter::Init(eStage));
if (eStage == StageNormal)
{
// get a hold of the signal registry service
object_ptr<ISignalRegistry> pRegistry;
// create a new provider that we can add signals to
RETURN_IF_FAILED(pRegistry->CreateProvider(get_named_graph_object_full_name(*this),
m_pProvider));
// add our counter signal.
RETURN_IF_FAILED(m_pProvider->AddSignal({m_nCounterID, "counter", "calls", "counter that increases monotonically", 0, 0}, this));
}
}
tResult cCounterGenerator::EnableSignal(ISignalRegistry::tSignalID nSignalID)
{
// this is called when the first listener is interested in our signal.
std::lock_guard<std::mutex> oGuard(m_oEnabledSignalsMutex);
m_oEnabledSignals.insert(nSignalID);
}
tResult cCounterGenerator::DisableSignal(ISignalRegistry::tSignalID nSignalID)
{
// this is called when there is no longer a listener that is interested in our signal.
std::lock_guard<std::mutex> oGuard(m_oEnabledSignalsMutex);
m_oEnabledSignals.erase(nSignalID);
}
tResult cCounterGenerator::Process(tNanoSeconds tmTimeOfTrigger,
IRunner* /*pRunner*/)
{
++m_nCounter;
std::lock_guard<std::mutex> oGuard(m_oEnabledSignalsMutex);
if (m_oEnabledSignals.count(m_nCounterID))
{
// if enabled, update our signal value
m_pProvider->UpdateSignal(m_nCounterID, {tmTimeOfTrigger, static_cast<double>(m_nCounter)});
}
}
#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.
adtf_util::cString get_named_graph_object_full_name(const INamedGraphObject &oGraphObject)
Helper function to retrieve a full qualified unique name of an object registered in IFilterGraph.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.