ADTF  3.18.2
kernel_timer.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "services/kernel_intf.h"
9 
10 namespace adtf
11 {
12 
13 namespace system
14 {
15 
20 {
21  private:
22  friend class cKernelTimerHelperRunnable;
23  struct ImplBase;
24  typedef std::shared_ptr<ImplBase> shared_base_type;
25 
26  struct ImplBase
27  {
29  inline virtual ~ImplBase() {}
30  virtual void Run() = 0;
31  };
32 
33  template<typename Callable>
34  struct Impl : public ImplBase
35  {
36  Callable pFunc;
37 
38  Impl(Callable&& pFunc) : pFunc(std::forward<Callable>(pFunc))
39  {
40  }
41 
42  void Run()
43  {
44  pFunc();
45  }
46  };
47 
48  template<typename Callable>
49  std::shared_ptr<Impl<Callable>> MakeCallable(Callable&& pFunc)
50  {
51  return std::make_shared<Impl<Callable>>(std::forward<Callable>(pFunc));
52  }
53 
54  shared_base_type m_pCallable;
55 
56  public:
61 
62  kernel_timer(const kernel_timer&) = delete;
63 
68 
72  template<typename Callable, typename ...Args>
75  const char* strName,
76  tTimeStamp tmPeriod, tTimeStamp tmInitialDelay,
77  Callable&& pFunc, Args&&... args): kernel_timer()
78  {
79  m_pCallable = MakeCallable(std::bind(std::forward<Callable>(pFunc),
80  std::forward<Args>(args)...));
81  Create(strName, sScheduling, eClock, tmPeriod, tmInitialDelay);
82  }
83 
87  template<typename Callable, typename ...Args>
88  kernel_timer(tTimeStamp tmMaximumExectionTime,
91  const char* strName,
92  tTimeStamp tmPeriod, tTimeStamp tmInitialDelay, uint32_t nFlags,
93  Callable&& pFunc, Args&&... args): kernel_timer()
94  {
95  m_pCallable = MakeCallable(std::bind(std::forward<Callable>(pFunc),
96  std::forward<Args>(args)...));
97  Create(strName, sScheduling, eClock, tmPeriod, tmInitialDelay, tmMaximumExectionTime, nFlags);
98  }
99 
103  template<typename Callable, typename ...Args>
104  kernel_timer(const char* strName, tTimeStamp tmPeriod, tTimeStamp tmInitialDelay,
105  Callable&& pFunc, Args&&... args):
106  kernel_timer(adtf::services::IKernel::tTimerClock::ADTF,
107  adtf::services::IKernel::tSchedulingInfo(), strName,
108  tmPeriod, tmInitialDelay,
109  std::forward<Callable>(pFunc),
110  std::forward<Args>(args)...)
111  {
112  }
113 
119 
126 
131  void Swap(kernel_timer& oOther);
132 
137  bool Stoppable() const;
138 
145 
152 
159 
160  private:
161  tResult Create(const char* strName, const adtf::services::IKernel::tSchedulingInfo& sScheduling,
163  tTimeStamp tmInitialDelay);
164 
165  tResult Create(const char* strName, const adtf::services::IKernel::tSchedulingInfo& sScheduling,
167  tTimeStamp tmInitialDelay, tTimeStamp tmMaximumExecutionTime, uint32_t nFlags);
168 };
169 
170 }
171 
172 }
tTimerClock
Enum for different time sources for timers.
Definition: kernel_intf.h:60
Class that wraps a kernel timer to call a method at specified intervals.
Definition: kernel_timer.h:20
kernel_timer(kernel_timer &&)
Move constructor.
tResult SetScheduling(const adtf::services::IKernel::tSchedulingInfo &sScheduling)
Changes the scheduling parameters of the timer.
bool Stoppable() const
Whether or not the timer is stoppable, i.e.
kernel_timer()
Default constructor.
kernel_timer(adtf::services::IKernel::tTimerClock eClock, const adtf::services::IKernel::tSchedulingInfo &sScheduling, const char *strName, tTimeStamp tmPeriod, tTimeStamp tmInitialDelay, Callable &&pFunc, Args &&... args)
Constructor that creates a new timer with a given clock and scheduling parameters.
Definition: kernel_timer.h:73
tResult Stop()
Stop the timer.
kernel_timer(tTimeStamp tmMaximumExectionTime, adtf::services::IKernel::tTimerClock eClock, const adtf::services::IKernel::tSchedulingInfo &sScheduling, const char *strName, tTimeStamp tmPeriod, tTimeStamp tmInitialDelay, uint32_t nFlags, Callable &&pFunc, Args &&... args)
Constructor that creates a new timer with a given clock, scheduling parameters and flags.
Definition: kernel_timer.h:88
tResult GetScheduling(adtf::services::IKernel::tSchedulingInfo &sScheduling) const
Retrieves the scheduling parameters of the thread.
void Swap(kernel_timer &oOther)
Swaps two timers.
kernel_timer & operator=(kernel_timer &&oOther)
Move assignment operator.
kernel_timer(const char *strName, tTimeStamp tmPeriod, tTimeStamp tmInitialDelay, Callable &&pFunc, Args &&... args)
Constructor that creates a new timer.
Definition: kernel_timer.h:104
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
Copyright © Audi Electronics Venture GmbH.
Namespace for entire ADTF SDK.
Struct for defining scheduling settings of a thread or timer.
Definition: kernel_intf.h:82