ADTF  3.18.2
runnable.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "runnable_intf.h"
9 #include <adtfucom3/adtf_ucom3.h>
10 
11 namespace adtf
12 {
13 namespace base
14 {
15 namespace ant
16 {
17 
18 
23 {
24 
25  protected:
27  cRunnable(const cRunnable&) = delete;
29  cRunnable(cRunnable&&) = delete;
31  cRunnable& operator=(const cRunnable&) = delete;
34 
35  public:
39  virtual ~cRunnable();
40 
41  public:
42  tResult Run(tTimeStamp tmTimeofActivation,
43  tActivationType ui32ActivationType,
44  const void* pvUserData,
45  size_t nUserDataSize) override;
46 };
47 
56 template<IRunnable::tActivationType TYPE_OF_ACTIVATION = IRunnable::RUN_UNSPECIFIED, typename Interface = IRunnable>
57 class runnable : public ucom::catwo::object<IRunnable, Interface>
58 {
59 protected:
62 
63 public:
65  runnable() {}
69  {
70  m_fcRunOnceFunc = fcRunOnceFunc;
71  }
73  virtual ~runnable() = default;
74 
82  tResult Run(tTimeStamp tmTimeofActivation,
83  IRunnable::tActivationType ui32ActivationType,
84  const void* /* pvUserData */,
85  size_t /* nUserDataSize */) override
86  {
87  if (ui32ActivationType == TYPE_OF_ACTIVATION
88  || TYPE_OF_ACTIVATION == IRunnable::RUN_UNSPECIFIED)
89  {
90  tResult nErrorCode = ERR_NOT_INITIALIZED;
91  if (m_fcRunOnceFunc)
92  {
93  nErrorCode = m_fcRunOnceFunc(tmTimeofActivation);
94  }
95 
96  return nErrorCode;
97  }
98  RETURN_ERROR(ERR_INVALID_ARG);
99  }
100 
104  {
105  return TYPE_OF_ACTIVATION;
106  }
107 };
108 
109 } //namespace ant
110 
111 namespace flash
112 {
113 
114 template<ant::IRunnable::tActivationType TYPE_OF_ACTIVATION = ant::IRunnable::RUN_UNSPECIFIED, typename AntInterface = ant::IRunnable, typename Interface = IRunnable>
115 class runnable : public ucom::catwo::object<ant::IRunnable, AntInterface, IRunnable, Interface>
116 {
117 protected:
120 
121 public:
123  runnable() = default;
127  {
128  m_fcRunOnceFunc = fcRunOnceFunc;
129  }
130 
134  {
135  m_fcRunOnceFunc = [fcRunOnceFunc](tNanoSeconds tmTimeofActivation) -> tResult
136  {
137  return fcRunOnceFunc(duration_cast<tTimeStamp>(tmTimeofActivation));
138  };
139  }
140 
142  ~runnable() override = default;
143 
144  tResult Run(tTimeStamp tmTimeofActivation,
145  ant::IRunnable::tActivationType ui32ActivationType,
146  const void* pvUserData,
147  size_t nUserDataSize) override
148  {
149  return Run(duration_cast<tNanoSeconds>(tmTimeofActivation),
150  ui32ActivationType,
151  pvUserData,
152  nUserDataSize);
153  }
154 
162  tResult Run(tNanoSeconds tmTimeofActivation,
163  ant::IRunnable::tActivationType ui32ActivationType,
164  const void* /* pvUserData */,
165  size_t /* nUserDataSize */) override
166  {
167  if (ui32ActivationType == TYPE_OF_ACTIVATION
168  || TYPE_OF_ACTIVATION == ant::IRunnable::RUN_UNSPECIFIED)
169  {
170  tResult nErrorCode = ERR_NOT_INITIALIZED;
171  if (m_fcRunOnceFunc)
172  {
173  nErrorCode = m_fcRunOnceFunc(tmTimeofActivation);
174  }
175 
176  return nErrorCode;
177  }
178  RETURN_ERROR(ERR_INVALID_ARG);
179  }
180 
184  {
185  return TYPE_OF_ACTIVATION;
186  }
187 };
188 
189 }
190 
196 #define ADTF_RUN_FUNCTION(_fcName_) [this](tTimeStamp tmTime) -> tResult { return _fcName_(tmTime); }
197 
203 #define ADTF_RUN_FUNCTION_NS(_fcName_) [this](adtf::base::flash::tNanoSeconds tmTime) -> tResult { return _fcName_(tmTime); }
204 
205 
206 using ant::cRunnable;
207 using flash::runnable;
208 
209 
210 } //namespace base
211 } // namespace adtf
Copyright © Audi Electronics Venture GmbH.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
The Runnable interface defines common methods for a running component.
Definition: runnable_intf.h:26
tActivationType
Enumeration of the possible activation types to set a component in running state.
Definition: runnable_intf.h:44
@ RUN_UNSPECIFIED
unspecified Run activation type.
Definition: runnable_intf.h:46
std::function< tResult(tTimeStamp)> tRunFunction
Type defintion of the function used to implement Run.
Definition: runnable_intf.h:37
Empty Runnable helper implementation.
Definition: runnable.h:23
cRunnable(cRunnable &&)=delete
no move CTOR
cRunnable & operator=(cRunnable &&)=delete
no move operator
cRunnable & operator=(const cRunnable &)=delete
no copy operator
cRunnable(const cRunnable &)=delete
no copy CTOR
tResult Run(tTimeStamp tmTimeofActivation, tActivationType ui32ActivationType, const void *pvUserData, size_t nUserDataSize) override
The Run method to set the component in running state.
Runnable helper implementaton template.
Definition: runnable.h:58
virtual ~runnable()=default
DTOR.
virtual IRunnable::tActivationType GetActivationType() const
Returns the type of activation implemented.
Definition: runnable.h:103
runnable(IRunnable::tRunFunction fcRunOnceFunc)
Main CTOR with callable function.
Definition: runnable.h:68
IRunnable::tRunFunction m_fcRunOnceFunc
given function to call on Run
Definition: runnable.h:61
tResult Run(tTimeStamp tmTimeofActivation, IRunnable::tActivationType ui32ActivationType, const void *, size_t) override
IRunnable::Run implementation which will call m_fcRunOnceFunc if ui32ActivationType is TYPE_OF_ACTIVA...
Definition: runnable.h:82
std::function< tResult(tNanoSeconds)> tRunFunction
Type defintion of the function used to implement Run.
~runnable() override=default
DTOR.
adtf::base::flash::IRunnable::tRunFunction m_fcRunOnceFunc
given function to call on Run
Definition: runnable.h:119
runnable(adtf::base::flash::IRunnable::tRunFunction fcRunOnceFunc)
Main CTOR with callable function.
Definition: runnable.h:126
ant::IRunnable::tActivationType GetActivationType() const override
Returns the type of activation implemented.
Definition: runnable.h:183
runnable(ant::IRunnable::tRunFunction fcRunOnceFunc)
Compatibility CTOR with callable function.
Definition: runnable.h:133
tResult Run(tNanoSeconds tmTimeofActivation, ant::IRunnable::tActivationType ui32ActivationType, const void *, size_t) override
IRunnable::Run implementation which will call m_fcRunOnceFunc if ui32ActivationType is TYPE_OF_ACTIVA...
Definition: runnable.h:162
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
Definition: object.h:379
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.