ADTF  3.18.2
legacy_filter.h
Go to the documentation of this file.
1 
7 #ifndef _ADTF_ADTF2_LEGACY_FILTER_HEADER_
8 #define _ADTF_ADTF2_LEGACY_FILTER_HEADER_
9 
10 #ifdef GetObject
11 #undef GetObject
12 #endif
13 
14 namespace adtf
15 {
16 namespace adtf2
17 {
18 namespace ant
19 {
20 
26  public adtf::streaming::ant::sample_reader<adtf::streaming::ant::cDynamicSampleReaderQueue, false>
27 {
28  public:
35  tResult Create(const char* strName,
37  {
38  SetName(strName);
39  return SetType(pStreamType);
40  }
41 
48  tResult Create(const char* strName,
50  {
52  return Create(strName, pConstHelper);
53  }
54 };
55 
61 {
62  private:
64  bool m_bManualTriggerRequired = false;
65 
66  public:
73  tResult Create(const char* strName,
75  {
76  SetName(strName);
77  return SetType(pStreamType);
78  }
79 
86  tResult Create(const char* strName,
88  {
90  return Create(strName, pConstHelper);
91  }
92 
97  void SetManualTriggerRequired(bool bManualTriggerRequired)
98  {
99  m_bManualTriggerRequired = bManualTriggerRequired;
100  }
101 
108  {
110 
111  if (m_bManualTriggerRequired)
112  {
114  }
115 
117  }
118 };
119 
124 {
125  protected:
130 
131  protected:
137  {
140  }
141 };
142 
146 template<typename Child>
148 {
149  protected:
155  void SetPropertyBool(const char* strName, bool bValue)
156  {
157  adtf::base::set_property(*static_cast<Child*>(this), strName, bValue);
158  }
159 
165  void SetPropertyInt(const char* strName, int nValue)
166  {
167  adtf::base::set_property(*static_cast<Child*>(this), strName, nValue);
168  }
169 
175  void SetPropertyFloat(const char* strName, double fValue)
176  {
177  adtf::base::set_property(*static_cast<Child*>(this), strName, fValue);
178  }
179 
185  void SetPropertyStr(const char* strName, const char* strValue)
186  {
187  adtf::base::set_property(*static_cast<Child*>(this), strName, strValue);
188  }
189 
197  bool GetPropertyBool(const char* strName, bool bDefault = false)
198  {
199  return adtf::base::get_property<bool>(*static_cast<Child*>(this), strName, bDefault);
200  }
201 
209  int GetPropertyInt(const char* strName, int nDefault = 0)
210  {
211  return adtf::base::get_property<int>(*static_cast<Child*>(this), strName, nDefault);
212  }
213 
221  double GetPropertyFloat(const char* strName, double fDefault = 0.0)
222  {
223  return adtf::base::get_property<double>(*static_cast<Child*>(this), strName,
224  fDefault);
225  }
226 
234  adtf_util::cString GetPropertyStr(const tChar* strName, const tChar* strDefault = "")
235  {
236  return adtf::base::get_property<adtf_util::cString>(*static_cast<Child*>(this),
237  strName, strDefault);
238  }
239 };
240 
246 {
247  protected:
256  {
258  }
259 
269  {
270  // by default we do the same that the reader would do.
272  RETURN_IF_FAILED(pPin->GetType(pCurrentType));
274  RETURN_IF_FAILED(pCurrentType->GetMetaType(pMetaType));
275  return pMetaType->IsCompatible(*pType.Get(), *pCurrentType.Get());
276  }
277 };
278 
283 {
284  public:
289  {
290  StageFirst = 0,
291  StageNormal = 1,
292  StageGraphReady = 2,
293  };
294 
295  protected:
301  virtual tResult Init(tInitStage /* eStage */)
302  {
304  }
305 
310  virtual tResult Start()
311  {
313  }
314 
319  virtual tResult Stop()
320  {
322  }
323 
329  virtual tResult Shutdown(tInitStage /* eStage */)
330  {
332  }
333 };
334 
343  public cKernelAndClockHelper,
344  public cConfigurationHelper<cLegacyFilter>,
345  public cLegacyPinEvents,
346  public cLegacyStateHandler
347 {
348  public:
354  tResult Process(tTimeStamp /* tmTimeOfTrigger */) override
355  {
356  bool bSamplesFound;
357  do
358  {
359  bSamplesFound = false;
360  for (auto& pReader: m_vecOfReaders)
361  {
363  if (IS_OK(pReader->GetNextSample(pSample)))
364  {
365  RETURN_IF_FAILED(OnSampleReceived(static_cast<cLegacyInputPin*>(pReader),
366  pSample));
367  bSamplesFound = true;
368  }
369  }
370  }
371  while (bSamplesFound);
372 
374  }
375 
382  {
383  for (auto& itReader : m_vecOfReaders)
384  {
385  adtf_util::cString strNameOfReader;
386  itReader->GetName(adtf_string_intf(strNameOfReader));
387  RETURN_IF_FAILED(filter_create_pin(oFilter, *itReader));
388  RETURN_IF_FAILED(oFilter.ConfigureDataInTrigger(m_strName, strNameOfReader));
389  }
390  for (auto& itWriter : m_vecOfWriters)
391  {
392  adtf_util::cString strNameOfWriter;
393  itWriter->GetName(adtf_string_intf(strNameOfWriter));
394  RETURN_IF_FAILED(filter_create_pin(oFilter, *itWriter));
395  RETURN_IF_FAILED(oFilter.ConfigureDataOutTrigger(m_strName, strNameOfWriter));
396  }
398  }
399 
400  protected:
408  {
409  oInput.SetAcceptTypeCallback(
411  {
412  return OnTypeChanged(&oInput, pStreamType);
413  });
414  return Register(oInput);
415  }
416 
424  {
425  return Register(oOutput);
426  }
427 
433  {
434  adtf_util::cString strName;
435  GetName(adtf_string_intf(strName));
436  return strName;
437  }
438 };
439 
444 template<typename TriggerFunctionImpl>
446 {
447  private:
448  legacy_filter(const legacy_filter&) = delete;
449  legacy_filter(legacy_filter&&) = delete;
450  legacy_filter& operator=(const legacy_filter&) = delete;
451  legacy_filter& operator=(legacy_filter&&) = delete;
452 
453  TriggerFunctionImpl m_oTriggerFunc;
454 
455  protected:
460  {
461  adtf_util::cString strTriggerFuncName;
462  m_oTriggerFunc.GetName(adtf_string_intf(strTriggerFuncName));
463  if (strTriggerFuncName.IsEmpty())
464  {
465  strTriggerFuncName = "trigger";
466  m_oTriggerFunc.SetName(strTriggerFuncName);
467  }
468  m_oTriggerFunc.SetFilter(*this);
469  }
470 
474  tResult Init(tInitStage eStage) override
475  {
476  RETURN_IF_FAILED(cFilter::Init(eStage));
477  if (eStage == tInitStage::StageFirst)
478  {
479  RETURN_IF_FAILED(m_oTriggerFunc.Init(cLegacyStateHandler::StageFirst));
480 
481  adtf_util::cString strTriggerFuncName;
482  m_oTriggerFunc.GetName(adtf_string_intf(strTriggerFuncName));
483  RETURN_IF_FAILED(RegisterRunner(strTriggerFuncName, m_oTriggerFunc));
484  RETURN_IF_FAILED(m_oTriggerFunc.ConnectReadersAndWriters(*this));
485  RETURN_IF_FAILED(m_oTriggerFunc.Configure());
486  }
487  else if (eStage == tInitStage::StageNormal)
488  {
489  RETURN_IF_FAILED(m_oTriggerFunc.Init(cLegacyStateHandler::StageNormal));
490  }
491  else if(eStage == tInitStage::StageGraphReady)
492  {
493  RETURN_IF_FAILED(m_oTriggerFunc.Init(cLegacyStateHandler::StageGraphReady));
494  }
496  }
497 
501  tResult Start() override
502  {
503  return m_oTriggerFunc.Start();
504  }
505 
509  tResult Stop() override
510  {
511  return m_oTriggerFunc.Stop();
512  }
513 
517  tResult Shutdown(tInitStage eStage) override
518  {
519  if (eStage == tInitStage::StageFirst)
520  {
521  RETURN_IF_FAILED(m_oTriggerFunc.Shutdown(cLegacyStateHandler::StageFirst));
522  }
523  else if(eStage == tInitStage::StageNormal)
524  {
525  RETURN_IF_FAILED(m_oTriggerFunc.Shutdown(cLegacyStateHandler::StageNormal));
526  }
527  else if(eStage == tInitStage::StageGraphReady)
528  {
529  RETURN_IF_FAILED(m_oTriggerFunc.Shutdown(cLegacyStateHandler::StageGraphReady));
530  }
531 
532  return cFilter::Shutdown(eStage);
533  }
534 };
535 
536 }
537 
538 using ant::cLegacyInputPin;
539 using ant::cLegacyOutputPin;
540 using ant::cLegacyFilter;
541 
542 }
543 }
544 
546 #define __sample_read_lock(__sample, __type, __variable) \
547  adtf::ucom::object_ptr_shared_locked<const adtf::streaming::ISampleBuffer> __variable##Buffer; \
548  RETURN_IF_FAILED(__sample->Lock(__variable##Buffer)); \
549  const __type* __variable = reinterpret_cast<const __type*>(__variable##Buffer->GetPtr());
550 
552 #define __sample_write_lock(__sample, __type, __variable) \
553  adtf::ucom::object_ptr_locked<adtf::streaming::ISampleBuffer> __variable##Buffer; \
554  RETURN_IF_FAILED(__sample->WriteLock(__variable##Buffer, sizeof(__type))); \
555  __type* __variable = reinterpret_cast<__type*>(__variable##Buffer->GetPtr());
556 
558 #define ADTF_LEGACY_FILTER_NAME(_class_identifier_, \
559  _class_name_, \
560  _legacyfilterclass_, \
561  _triggerfunction_) \
562 class _legacyfilterclass_ : public adtf::adtf2::ant::legacy_filter<_triggerfunction_> \
563 { \
564  public:\
565  ADTF_CLASS_ID_NAME(_legacyfilterclass_, _class_identifier_, _class_name_); \
566  public: \
567  _legacyfilterclass_() = default; \
568  virtual ~_legacyfilterclass_() = default; \
569 };
570 
572 #define ADTF_LEGACY_FILTER_PLUGIN(_class_identifier_, \
573  _class_name_,\
574  _triggerfunction_)\
575  ADTF_LEGACY_FILTER_NAME(_class_identifier_,\
576  _class_name_,\
577  _triggerfunction_##filter,\
578  _triggerfunction_)\
579  ADTF_PLUGIN(_class_name_ " Plugin", \
580  _triggerfunction_##filter);
581 
582 #endif
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
#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.
Common base class for all legacy filter classes that emulates the old configuration interface.
void SetPropertyInt(const char *strName, int nValue)
Sets a Property value.
double GetPropertyFloat(const char *strName, double fDefault=0.0)
Gets a Property value.
void SetPropertyBool(const char *strName, bool bValue)
Sets a Property value.
adtf_util::cString GetPropertyStr(const tChar *strName, const tChar *strDefault="")
Gets a Property value.
bool GetPropertyBool(const char *strName, bool bDefault=false)
Gets a Property value.
int GetPropertyInt(const char *strName, int nDefault=0)
Gets a Property value.
void SetPropertyStr(const char *strName, const char *strValue)
Sets a Property value.
void SetPropertyFloat(const char *strName, double fValue)
Sets a Property value.
Common base class for all legacy filter classes.
adtf::ucom::object_ptr< adtf::services::IKernel > _kernel
pointer to the kernel service
adtf::ucom::object_ptr< adtf::services::IReferenceClock > _clock
pointer to the current reference clock
Class that helps with porting old ADTF 2 Filters to ADTF 3.
tResult RegisterPin(cLegacyOutputPin &oOutput)
Compatibility method to register Pins.
tResult ConnectReadersAndWriters(adtf::filter::ant::cFilter &oFilter) override
Used internally to construct the same trigger model as used in ADTF 2.
adtf_util::cString OIGetInstanceName()
Compatibility method to retrieve the name of the current filter instance.
tResult RegisterPin(cLegacyInputPin &oInput)
Compatibility method to register Pins.
tResult Process(tTimeStamp) override
Used internally to emulate to old IPinEventSink interface.
This class helps when porting ADTF 2 Filters to ADTF 3.
Definition: legacy_filter.h:27
tResult Create(const char *strName, const ucom::iobject_ptr< adtf::streaming::IStreamType > &pStreamType)
Initializes an instance of an Input Pin.
Definition: legacy_filter.h:48
tResult Create(const char *strName, const ucom::iobject_ptr< const adtf::streaming::IStreamType > &pStreamType)
Initializes an instance of an Input Pin.
Definition: legacy_filter.h:35
This class helps when porting ADTF 2 Filters to ADTF 3.
Definition: legacy_filter.h:61
tResult Create(const char *strName, const ucom::iobject_ptr< adtf::streaming::IStreamType > &pStreamType)
Initializes an instance of an Output Pin.
Definition: legacy_filter.h:86
tResult Create(const char *strName, const ucom::iobject_ptr< const adtf::streaming::IStreamType > &pStreamType)
Initializes an instance of an Output Pin.
Definition: legacy_filter.h:73
void SetManualTriggerRequired(bool bManualTriggerRequired)
For internal use only.
Definition: legacy_filter.h:97
tResult Transmit(const ucom::iobject_ptr< const adtf::streaming::ISample > &pSample) override
Transmits a sample via an Output Pin.
Common base class for all legacy filter classes that emulates the old IPinEventHandler interface.
virtual tResult OnSampleReceived(cLegacyInputPin *, const adtf::ucom::iobject_ptr< const adtf::streaming::ISample > &)
This is called whenever a sample is received via one of the input Pins.
virtual tResult OnTypeChanged(cLegacyInputPin *pPin, const adtf::ucom::iobject_ptr< const adtf::streaming::IStreamType > &pType)
This is called whenever a type has been changed/received on one of the input Pins.
Common base class for all legacy filter classes that emulates the old state maschine of cFilter.
virtual tResult Stop()
Emulates the old Stop method.
virtual tResult Shutdown(tInitStage)
Emulates the old Shutdown method.
virtual tResult Start()
Emulates the old Start method.
virtual tResult Init(tInitStage)
Emulates the old Init method.
Internal class that is the glue between the cLegacyFilter and ADTF 3.
legacy_filter()
Internal use only.
tResult Shutdown(tInitStage eStage) override
Internal use only.
tResult Init(tInitStage eStage) override
Internal use only.
tResult Stop() override
Internal use only.
tResult Start() override
Internal use only.
tResult ConfigureDataInTrigger(const char *strRunnerName, const char *strPinName)
Creates an internal trigger pipe for the given pin.
tResult ConfigureDataOutTrigger(const char *strRunnerName, const char *strPinName)
Creates an internal trigger pipe for the given pin.
adtf_util::cString m_strName
Name of the TriggerFunction used to create the IRunner.
tInitStage
The Filters InitStages will be used for the cFilterLevelmachine::Init and cFilterLevelmachine::Shutdo...
This base implementation of a sample writer is able to write to one Sample Stream which is connected ...
Definition: samplewriter.h:35
virtual tResult Transmit(const ucom::ant::iobject_ptr< const ISample > &pSample)
Transmits and writes a sample reference to the opened ISampleOutStream.
Definition: samplewriter.h:95
tResult ManualTrigger()
This is to Run a trigger call manually.
Definition: samplewriter.h:164
A Possible Sample Reader of a Trigger Function! Sample reader with a internal queue,...
Definition: samplereader.h:778
void SetName(const char *strName)
Sets the name of the streamer.
Definition: samplereader.h:84
tResult SetType(const ucom::ant::iobject_ptr< const IStreamType > &pStreamType)
Sets the StreamType of the streamer.
Definition: samplereader.h:140
virtual tResult GetObject(iobject_ptr< IObject > &pObject, const char *strNameOID) const =0
Get registered object from object registry.
virtual T * Get() const =0
Get raw pointer to shared object.
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
virtual T * Get() const
Get pointer to shared object.
Definition: object_ptr.h:381
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
tResult set_property(IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oValue)
Set the property.
Namespace for entire ADTF SDK.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.
#define adtf_string_intf(__string__)
The adtf_string_intf Macro helps to easily create a rvalue reference of a adtf::util::cString.
Definition: string_intf.h:371