ADTF  3.18.2
Source Code for Demo Signal Listener Plugin
Location
./src/examples/src/adtf/system_services/signal_listening/signal_listener/
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
#ifndef _DEMO_SDL_APP_SERVICE_HEADER_
#define _DEMO_SDL_APP_SERVICE_HEADER_
#define CID_DEMO_ADTF_SIGNAL_LISTENER "demo_signal_listener.service.adtf.cid"
class cSignalDumper;
class cDemoSignalListener : public cADTFService, public ISignalListening::ISignalsListener
{
public:
ADTF_CLASS_ID_NAME(cDemoSignalListener, CID_DEMO_ADTF_SIGNAL_LISTENER, "Demo Signal Listener");
cDemoSignalListener();
public: // overrides cService
virtual tResult ServiceInit() override;
virtual tResult ServiceShutdown() override;
public:
virtual void SignalAdded(const ISignalRegistry::tSignalAttributes& sSignalAttributes) override;
virtual void SignalRemoved(const ISignalRegistry::tSignalAttributes& sSignalAttributes) override;
private:
object_ptr<ISignalListening> m_pSignalListening;
std::unordered_map<ISignalRegistry::tSignalID, std::unique_ptr<cSignalDumper>> m_oDumper;
};
#endif // _DEMO_SERVICE_HEADER_
#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
Implementation
#include "stdafx.h"
#include "demo_signal_listener_service.h"
#include <cinttypes>
ADTF_PLUGIN("Demo Signal Listener",
cDemoSignalListener);
class cSignalDumper: public ISignalListening::ISignalListener
{
public:
cSignalDumper(const char* strSignalName):
m_strSignalName(strSignalName)
{
}
public:
virtual void SignalUpdated(ISignalRegistry::tSignalID /* nSignalID */, const ISignalRegistry::tSignalValueNs& sValue) override
{
LOG_INFO("%s @ %" PRIi64 ": %f", m_strSignalName.GetPtr(), sValue.nTimeStamp.nCount, sValue.f64Value);
}
private:
cString m_strSignalName;
};
cDemoSignalListener::cDemoSignalListener()
{
SetDefaultRunlevel(tADTFRunLevel::RL_Session);
// sets a short description for the component
SetDescription("Use this System Service to print signal updates (e.g. send by 'Demo Signal Provider', see Filters.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_signal_listener.html");
}
tResult cDemoSignalListener::ServiceInit()
{
RETURN_IF_FAILED(_runtime->GetObject(m_pSignalListening));
RETURN_IF_FAILED(m_pSignalListening->RegisterSignalsListener(*this));
}
tResult cDemoSignalListener::ServiceShutdown()
{
for (auto& oDumper: m_oDumper)
{
m_pSignalListening->CancelSignalUpdates(oDumper.first, *oDumper.second.get());
}
RETURN_IF_FAILED(m_pSignalListening->UnregisterSignalsListener(*this));
m_pSignalListening.Reset();
}
void cDemoSignalListener::SignalAdded(const ISignalRegistry::tSignalAttributes& sSignalAttributes)
{
std::unique_ptr<cSignalDumper> pDumper(new cSignalDumper(sSignalAttributes.strName));
if (IS_OK(m_pSignalListening->RequestSignalUpdates(sSignalAttributes.nSignalID, *pDumper.get())))
{
m_oDumper.emplace(sSignalAttributes.nSignalID, std::move(pDumper));
}
}
void cDemoSignalListener::SignalRemoved(const ISignalRegistry::tSignalAttributes& sSignalAttributes)
{
m_oDumper.erase(sSignalAttributes.nSignalID);
}
#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.
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
@ RL_Session
The session level.
Definition: adtf_runtime.h:30
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.