Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
ThreadRunnablePeriodic.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_THREADS_THREADRUNNABLEPERIODIC_HPP_
2#define IV_SRC_THREADS_THREADRUNNABLEPERIODIC_HPP_
3
6
7#include <chrono>
8#include <fmt/format.h>
9#include <iostream>
10
11namespace iv::threads
12{
13
15{
16public:
17 explicit ThreadRunnablePeriodic(const iv::types::pollTime sleepMs) : m_sleepMs(sleepMs)
18 {
19 }
20
21 ThreadRunnablePeriodic(const iv::types::pollTime sleepMs, const std::weak_ptr<bool> &isEnabledRef)
22 : ThreadRunnable(isEnabledRef), m_sleepMs(sleepMs)
23 {
24 }
25
26 ~ThreadRunnablePeriodic() override = default;
27
28 virtual void periodicTask() = 0;
29
30private:
31 void runFrame() override
32 {
33 try
34 {
37 }
38 catch (const std::exception &e)
39 {
40 auto errorMessage = fmt::format("ThreadRunnablePeriodic::runFrame() thread name: {} exception: {}",
41 m_taskName, e.what());
42#ifndef NDEBUG
44#else
45 std::cerr << errorMessage << std::endl;
46#endif
47 }
48 }
49
51};
52
53}// namespace iv::threads
54
55#endif /* IV_SRC_THREADS_THREADRUNNABLEPERIODIC_HPP_ */
static void showErrorDialog(std::string_view msg)
Show a zenity dialog with the message.
Definition CLoggerZenity.cpp:93
std::string_view m_taskName
Definition IRunnable.hpp:38
Definition ThreadRunnablePeriodic.hpp:15
iv::types::pollTime m_sleepMs
Definition ThreadRunnablePeriodic.hpp:50
void runFrame() override
Definition ThreadRunnablePeriodic.hpp:31
ThreadRunnablePeriodic(const iv::types::pollTime sleepMs, const std::weak_ptr< bool > &isEnabledRef)
Definition ThreadRunnablePeriodic.hpp:21
~ThreadRunnablePeriodic() override=default
ThreadRunnablePeriodic(const iv::types::pollTime sleepMs)
Definition ThreadRunnablePeriodic.hpp:17
Definition ThreadRunnable.hpp:14
void sleepFrame(iv::types::pollTime milliseconds)
Definition ThreadRunnable.cpp:118
Definition BackgroundTaskWithDialog.cpp:8
std::chrono::milliseconds pollTime
Definition types.hpp:44