ADTF  3.18.3
Source Code for Demo String Handling Filters Plugin
Location
./src/examples/src/adtf/filters/standard_filters/demo_string_handling_filters/
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:
  • how to generate time triggered filter sending a string
  • how to use the adtf_memory template specialisations
  • how receive a sample containing a string
Generator Header
#pragma once
using namespace adtf::util;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
class cDemoStringSending : public cFilter
{
public:
ADTF_CLASS_ID_NAME(cDemoStringSending,
"demo_string_sending.filter.adtf.cid",
"Demo String Sending");
public:
cDemoStringSending();
tResult Process(tNanoSeconds tmTimeOfTrigger,
IRunner* pRunner) override;
private:
// writer to an output pin
pin_writer<std::string>* m_pWriterString = nullptr;
pin_writer<std::u16string>* m_pWriterU16String = nullptr;
};
#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 Streaming SDK.
Namespace for the ADTF uCOM3 SDK.
alias namespace for the A_UTILS Library.
Generator Implementation
#include "demo_string_sending_filter.h"
#include <codecvt>
#include <iostream>
#include <locale>
#include <sstream>
cDemoStringSending::cDemoStringSending()
{
SetDescription("This Filter shows how to send samples with string content via output pin. It uses the stream_type_string.");
// create the pin to send the content of a std::string
m_pWriterString = CreateOutputPin<pin_writer<std::string>>("out_string", stream_type_string<std::string>());
SetDescription("out_string", "Provides a string with the current time");
// create the pin to send the content of a std::wstring
m_pWriterU16String
= CreateOutputPin<pin_writer<std::u16string>>("out_16string", stream_type_string<std::u16string>());
SetDescription("out_16string", "Provides a u16string with the current time");
// create a trigger function that can be connected to an active runner.
CreateRunner("string_generator_function", cTimerTriggerHint(std::chrono::seconds {1}));
SetDescription("string_generator_function", "Runner to periodically trigger the function which generates the output data for all pins");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_string_handling_filters.html");
}
namespace
{
std::u16string convert_to_u16string(const std::string& strValue)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> oConverter;
return oConverter.from_bytes(strValue);
}
template<typename T>
std::u16string to_u16string(const T& value)
{
return convert_to_u16string(std::to_string(value));
}
} // namespace
//this function will be executed each time a trigger occured
tResult cDemoStringSending::Process(tNanoSeconds tmTimeOfTrigger,
IRunner* /*pRunner*/)
{
{
std::stringstream strTimeToSend;
strTimeToSend << "Hello, current trigger time is : " << tmTimeOfTrigger.nCount << " nanoseconds";
RETURN_IF_FAILED(m_pWriterString->Write(tmTimeOfTrigger, strTimeToSend.str()));
}
{
std::u16string strTimeToSend = u"Hello, current trigger time is : " + to_u16string(tmTimeOfTrigger.nCount) + u" nanoseconds"
+ u" with umlauts :" + u"\u00e4" + u" " + u"\u00f6" + u" " + u"\u00fc";
RETURN_IF_FAILED(m_pWriterU16String->Write(tmTimeOfTrigger, strTimeToSend));
}
}
#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.
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
Copyright © Audi Electronics Venture GmbH.
Accessor Header
#pragma once
using namespace adtf::util;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::filter;
class cDemoStringReceiving : public cFilter
{
public:
ADTF_CLASS_ID_NAME(cDemoStringReceiving,
"demo_string_receiving.filter.adtf.cid",
"Demo String Receiving");
public:
cDemoStringReceiving();
//override the process method to react on the data trigger
tResult ProcessInput(ISampleReader* pReader,
const iobject_ptr<const ISample>& pSample) override;
private:
// reader for an input string
ISampleReader* m_pReaderString = nullptr;
};
Accessor Implementation
#include "demo_string_receiving_filter.h"
cDemoStringReceiving::cDemoStringReceiving()
{
SetDescription("This Filter shows how to receive samples with string content via input pin. It used the stream_meta_type_string.");
// create a pin to receive the content of a std::string
m_pReaderString = CreateInputPin("in_string", stream_type_string<std::string>());
SetDescription("in_string", "Handles an incoming adtf/string type");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_string_handling_filters.html");
}
//this function will be executed each time a data trigger occured
tResult cDemoStringReceiving::ProcessInput(ISampleReader* pReader,
const iobject_ptr<const ISample>& pSample)
{
if (pReader == m_pReaderString)
{
LOG_INFO("Received string: %s", sample_data<std::string>(pSample)->c_str());
}
}