16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_TIMING_TIMER_H_ 17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_TIMING_TIMER_H_ 20 #include <condition_variable> 73 const std::shared_ptr<sdkInterfaces::timing::TimerDelegateFactoryInterface>& timerDelegateFactory =
114 template <
typename Delay,
typename Period,
typename Task,
typename...
Args>
147 template <
typename Period,
typename Task,
typename...
Args>
171 template <
typename Delay,
typename Task,
typename...
Args>
172 auto start(Delay&& delay, Task&& task,
Args&&...
args) noexcept -> std::future<decltype(task(
args...))>;
184 void stop() noexcept;
201 static constexpr
size_t ONCE = 1u;
208 bool activate() noexcept;
222 const std::chrono::nanoseconds& delayNano,
223 const std::chrono::nanoseconds& periodNano,
226 std::function<
void()>&& task) noexcept;
242 template <
typename Delay,
typename Period>
243 bool adaptTypesAndCallTask(
244 const Delay& delayNano,
245 const Period& periodNano,
248 std::function<
void()>&& task) noexcept;
251 std::unique_ptr<sdkInterfaces::timing::TimerDelegateInterface> m_timer;
254 std::thread m_thread;
257 template <
typename Delay,
typename Period,
typename Task,
typename...
Args>
266 auto boundTask = std::bind(std::forward<Task>(task), std::forward<Args>(
args)...);
269 return adaptTypesAndCallTask(
270 std::forward<Delay>(delay), std::forward<Period>(period), periodType, maxCount,
std::move(boundTask));
273 template <
typename Period,
typename Task,
typename...
Args>
276 auto boundTask = std::bind(std::forward<Task>(task), std::forward<Args>(
args)...);
279 return adaptTypesAndCallTask(
280 std::forward<Period>(period), std::forward<Period>(period), periodType, maxCount,
std::move(boundTask));
283 template <
typename Delay,
typename Task,
typename...
Args>
289 auto boundTask = std::bind(std::forward<Task>(task), std::forward<Args>(
args)...);
295 auto packagedTask = std::make_shared<std::packaged_task<Value()>>(
std::move(boundTask));
297 auto packagedTaskFuture = packagedTask->get_future();
300 auto translatedTask = std::bind(&std::packaged_task<
Value()>::
operator(),
std::move(packagedTask));
303 if (!adaptTypesAndCallTask(
304 std::forward<Delay>(delay),
305 std::forward<Delay>(delay),
309 return std::future<Value>();
312 return packagedTaskFuture;
315 template <
typename Delay,
typename Period>
316 bool Timer::adaptTypesAndCallTask(
318 const Period& period,
321 std::function<
void()>&& task) noexcept {
322 return callTask(delay, period, periodType, maxCount,
std::move(task));
326 extern template bool Timer::adaptTypesAndCallTask(
327 const std::chrono::milliseconds&,
328 const std::chrono::milliseconds&,
331 std::function<
void()>&&) noexcept;
332 extern template bool Timer::adaptTypesAndCallTask(
333 const std::chrono::nanoseconds&,
334 const std::chrono::nanoseconds&,
337 std::function<
void()>&&) noexcept;
344 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_TIMING_TIMER_H_ ~Timer() noexcept
Destructs a Timer.
def args
Definition: android_test.py:111
PeriodType
Specifies different ways to apply the period of a recurring task.
Definition: Timer.h:48
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
Definition: gmock-generated-matchers.h:481
static size_t getForever() noexcept
Static member function to get FOREVER.
Definition: Timer.h:82
bool start(Delay &&delay, Period &&period, PeriodType periodType, size_t maxCount, Task &&task, Args &&... args) noexcept
Submit a callable type for periodic execution.
Definition: Timer.h:258
void stop() noexcept
Stop the timer.
bool Value(const T &value, M matcher)
Definition: gmock-matchers.h:4347
Timer to schedule task for delayed and periodic execution.
Definition: Timer.h:39
static constexpr size_t FOREVER
Definition: Timer.h:45
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::shared_ptr< SDKPrimitivesProvider > getInstance()
Timer(const std::shared_ptr< sdkInterfaces::timing::TimerDelegateFactoryInterface > &timerDelegateFactory=avs::initialization::SDKPrimitivesProvider::getInstance() ->getTimerDelegateFactory()) noexcept
Constructs a Timer.
const T & move(const T &t)
Definition: gtest-port.h:1317
bool isActive() const noexcept
Check if timer is active.