ADTF  3.18.2
triggered_filter.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <adtffiltersdk/filter.h>
9 
10 #include <memory>
11 #include <functional>
12 
13 namespace adtf
14 {
15 namespace filter
16 {
17 namespace ant
18 {
26 template<typename TriggerFunctionImpl>
27 class triggered_filter : public cFilter
28 {
29  private:
30  triggered_filter(const triggered_filter&) = delete;
32  triggered_filter& operator=(const triggered_filter&) = delete;
33  triggered_filter& operator=(triggered_filter&&) = delete;
34 
35  TriggerFunctionImpl m_oTriggerFunc;
36 
37  protected:
39  {
40  adtf_util::cString strTriggerFuncName;
41  m_oTriggerFunc.GetName(adtf_string_intf(strTriggerFuncName));
42  if (strTriggerFuncName.IsEmpty())
43  {
44  strTriggerFuncName = "trigger";
45  m_oTriggerFunc.SetName(strTriggerFuncName);
46  }
47  m_oTriggerFunc.SetFilter(*this);
48  }
50  {
51  }
52  tResult Init(tInitStage eStage) override
53  {
55  if (eStage == tInitStage::StageFirst)
56  {
57  adtf_util::cString strTriggerFuncName;
58  m_oTriggerFunc.GetName(adtf_string_intf(strTriggerFuncName));
59  RETURN_IF_FAILED(RegisterRunner(strTriggerFuncName, m_oTriggerFunc));
60  RETURN_IF_FAILED(m_oTriggerFunc.ConnectReadersAndWriters(*this));
61  RETURN_IF_FAILED(m_oTriggerFunc.Configure());
62  RETURN_IF_FAILED(CreateDefaultTrigger(strTriggerFuncName));
63  }
65  }
66 
67  tResult SetParent(const adtf::ucom::ant::IObject* poParentObject) override
68  {
69  RETURN_IF_FAILED(cFilter::SetParent(poParentObject));
70  m_oTriggerFunc.SetParentFullName(adtf::streaming::ant::get_named_graph_object_full_name(*this));
72  }
73 
74  virtual tResult CreateDefaultTrigger(const char* strTriggerFuncName)
75  {
76  //no default defined here !!
78  }
79 
80 };
81 
82 
83 
84 } //namespace ant
85 
86 namespace devil
87 {
88 
90 {
91  public:
92  virtual adtf::util::cString GetTriggerFunctionName() = 0;
93 };
94 
102 template<typename TriggerFunctionImpl>
104 {
105  protected:
107 
108  private:
113 
114  std::function<tResult(cFilterWithTriggerFunction&)> m_fnCreateTrigger;
115  std::unique_ptr<TriggerFunctionImpl> m_pTriggerFunc;
116  tResult m_oTriggerFunctionCreationResult;
117 
118  protected:
119  filter_with_trigger_function(std::function<tResult(cFilterWithTriggerFunction&)> fnCreateTrigger):
120  m_fnCreateTrigger(fnCreateTrigger),
121  m_oTriggerFunctionCreationResult(CreateRunner())
122  {
123  }
124 
125  private:
126  tResult CreateRunner()
127  {
128  RETURN_IF_THROWS_DESC(m_pTriggerFunc.reset(new TriggerFunctionImpl),
129  "Unable to construct trigger function");
130 
131  if (GetTriggerFunctionName().IsEmpty())
132  {
133  m_pTriggerFunc->SetName("trigger");
134  }
135 
136  return m_pTriggerFunc->SetFilter(*this);
137  }
138 
139  public:
140  tResult Init(tInitStage eStage) override
141  {
143  if (eStage == tInitStage::StageFirst)
144  {
145  RETURN_IF_FAILED(m_oTriggerFunctionCreationResult);
146  RETURN_IF_FAILED(RegisterRunner(GetTriggerFunctionName(), *m_pTriggerFunc.get()));
147  RETURN_IF_FAILED(m_pTriggerFunc->Configure());
148  RETURN_IF_FAILED(m_pTriggerFunc->ConnectReadersAndWriters(*this));
149  RETURN_IF_FAILED(m_fnCreateTrigger(*this));
150  }
151 
153  }
154 
155  tResult Shutdown(tInitStage eStage) override
156  {
157  if (eStage == tInitStage::StageFirst)
158  {
159  m_pTriggerFunc.reset();
160  }
161 
162  return cFilter::Shutdown(eStage);
163  }
164 
165  adtf::util::cString GetTriggerFunctionName() override
166  {
167  adtf_util::cString strTriggerFuncName;
168  if (m_pTriggerFunc)
169  {
170  m_pTriggerFunc->GetName(adtf_string_intf(strTriggerFuncName));
171  }
172  return strTriggerFuncName;
173  }
174 };
175 
176 } //namespace devil
177 
178 namespace flash
179 {
180 
181 template<typename TriggerFunctionImpl, typename FilterClass = devil::cFilterWithTriggerFunction>
182 class filter_with_trigger_function: public FilterClass
183 {
184  protected:
186 
187  public:
192 
193  private:
194 
195  std::function<tResult(FilterClass&)> m_fnCreateTrigger;
196  std::unique_ptr<TriggerFunctionImpl> m_pTriggerFunc;
197  tResult m_oTriggerFunctionCreationResult;
198 
199  protected:
200  filter_with_trigger_function(std::function<tResult(FilterClass&)> fnCreateTrigger):
201  m_fnCreateTrigger(fnCreateTrigger),
202  m_oTriggerFunctionCreationResult(CreateRunner())
203  {
204  }
205 
207  {
209  }
210 
211  private:
212  tResult CreateRunner()
213  {
214  RETURN_IF_THROWS_DESC(m_pTriggerFunc.reset(new TriggerFunctionImpl),
215  "Unable to construct trigger function");
216 
217  if (GetTriggerFunctionName().IsEmpty())
218  {
219  m_pTriggerFunc->SetName("trigger");
220  }
221 
222  RETURN_IF_FAILED(m_pTriggerFunc->SetFilter(*this));
223 
224  return FilterClass::AttachConfiguration(GetTriggerFunctionName(), *m_pTriggerFunc);
225  }
226 
227  public:
228  tResult Init(typename FilterClass::tInitStage eStage) override
229  {
230  RETURN_IF_FAILED(FilterClass::Init(eStage));
231  if (eStage == FilterClass::tInitStage::StageFirst)
232  {
233  RETURN_IF_FAILED(m_oTriggerFunctionCreationResult);
234  RETURN_IF_FAILED(FilterClass::RegisterRunner(GetTriggerFunctionName(), *m_pTriggerFunc.get()));
235  RETURN_IF_FAILED(m_pTriggerFunc->Configure());
236  RETURN_IF_FAILED(m_pTriggerFunc->ConnectReadersAndWriters(*this));
237  RETURN_IF_FAILED(m_fnCreateTrigger(*this));
238  }
239 
241  }
242 
243  tResult Shutdown(typename FilterClass::tInitStage eStage) override
244  {
245  if (eStage == FilterClass::tInitStage::StageFirst)
246  {
247  m_pTriggerFunc.reset();
248  }
249 
250  return FilterClass::Shutdown(eStage);
251  }
252 
253  adtf::util::cString GetTriggerFunctionName() override
254  {
255  adtf_util::cString strTriggerFuncName;
256  if (m_pTriggerFunc)
257  {
258  m_pTriggerFunc->GetName(adtf_string_intf(strTriggerFuncName));
259  }
260  return strTriggerFuncName;
261  }
262 };
263 
264 }
265 
266 namespace hollow
267 {
268 
270 {
271 public:
272  virtual adtf::util::cString GetTriggerFunctionName() = 0;
273 };
274 
275 template<typename TriggerFunctionImpl, typename FilterClass = cFilterWithTriggerFunction>
277 
278 }
279 
282 
294 #define ADTF_TRIGGER_FUNCTION_FILTER(_class_identifier_,\
295  _class_name_,\
296  _triggerfilterclass_,\
297  _triggerfunction_,\
298  _trigger_configurator_,\
299  ...) \
300 class _triggerfilterclass_ : public adtf::filter::filter_with_trigger_function<_triggerfunction_> \
301 { \
302  public:\
303  ADTF_CLASS_ID_NAME(_triggerfilterclass_, _class_identifier_, _class_name_); \
304  __VA_ARGS__;\
305  public: \
306  _triggerfilterclass_():\
307  filter_type(_trigger_configurator_)\
308  {\
309  }\
310 }
311 
319 #define ADTF_TRIGGER_FUNCTION_FILTER_PLUGIN(_class_identifier_,\
320  _class_name_,\
321  _triggerfunction_,\
322  _trigger_configurator_,\
323  ...)\
324  ADTF_TRIGGER_FUNCTION_FILTER(_class_identifier_,\
325  _class_name_,\
326  _triggerfunction_##Filter,\
327  _triggerfunction_,\
328  _trigger_configurator_,\
329  __VA_ARGS__);\
330  ADTF_PLUGIN(_class_name_ " Plugin",\
331  _triggerfunction_##Filter)
332 
333 
334 } //namespace filter
335 } //namespace adtf
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#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.
Simple Filter for Registering One Triggerfunction to a filter.
Simple Filter for Registering One Triggerfunction to a filter.
tResult Shutdown(tInitStage eStage) override
Implements the default cFilterLevelmachine state machine call.
tResult Init(tInitStage eStage) override
Initializes the filter.
ucom::ant::object_ptr< streaming::ant::IRunner > RegisterRunner(const char *strName, std::function< tResult(base::flash::tNanoSeconds)> fnRunMethod)
Creates and registers a new Runner.
tResult Shutdown(tInitStage eStage) override
Implements the default cFilterLevelmachine state machine call.
tResult Init(tInitStage eStage) override
Initializes the filter.
@ State_Shutdown
Filter is New / Shutdown.
tInitStage
The Filters InitStages will be used for the cFilterLevelmachine::Init and cFilterLevelmachine::Shutdo...
Base class for every interface type within the uCOM.
Definition: object_intf.h:31
Copyright © Audi Electronics Venture GmbH.
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
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.
Namespace for entire ADTF SDK.
#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
#define RETURN_IF_THROWS_DESC(s,...)
if the expression throws an exception, returns a tResult containing the exception information and amm...