ADTF
Loading...
Searching...
No Matches
runnable.h
Go to the documentation of this file.
1
7#pragma once
8#include "runnable_intf.h"
10
11namespace adtf
12{
13namespace base
14{
15namespace 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
56template<IRunnable::tActivationType TYPE_OF_ACTIVATION = IRunnable::RUN_UNSPECIFIED, typename Interface = IRunnable>
57class runnable : public ucom::catwo::object<IRunnable, Interface>
58{
59protected:
62
63public:
69 {
70 m_fcRunOnceFunc = fcRunOnceFunc;
71 }
72
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;
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
111namespace flash
112{
113
114template<ant::IRunnable::tActivationType TYPE_OF_ACTIVATION = ant::IRunnable::RUN_UNSPECIFIED, typename AntInterface = ant::IRunnable, typename Interface = IRunnable>
115class runnable : public ucom::catwo::object<ant::IRunnable, AntInterface, IRunnable, Interface>
116{
117protected:
120
121public:
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
206using ant::cRunnable;
207using flash::runnable;
208
209
210} //namespace base
211} // namespace adtf
Copyright © Audi Electronics Venture GmbH.
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#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.
tActivationType
Enumeration of the possible activation types to set a component in running state.
@ RUN_UNSPECIFIED
unspecified Run activation type.
std::function< tResult(tTimeStamp)> tRunFunction
Type definition of the function used to implement Run.
cRunnable(cRunnable &&)=delete
no move CTOR
cRunnable & operator=(cRunnable &&)=delete
no move 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.
cRunnable & operator=(const cRunnable &)=delete
no copy operator
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
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 definition of the function used to implement Run.
~runnable() override=default
DTOR.
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:397
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
DestinationTimeStamp duration_cast(const SourceTimeStamp &)
Duration cast base template to converted between different time resolution.
Namespace for the ADTF Base SDK.
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.