Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
WatchDog.hpp
Go to the documentation of this file.
1#ifndef SRC_IV_THREADS_WATCHDOG_HPP
2#define SRC_IV_THREADS_WATCHDOG_HPP
3
4#include "core/defines.hpp"
7#include "threads/Thread.hpp"
9
10#include <map>
11#include <optional>
12#include <string>
13#include <thread>
14
15namespace iv::threads
16{
17
24
33
35{
36public:
37 WatchDog();
38 ~WatchDog() override = default;
39
40 static bool startMonitoring();
41 static bool stopMonitoring();
42
43 static void addThread(const iv::types::threadName &name, ThreadRunnablePeriodic *runnable, eThreadType type);
44 static void removeThread(const iv::types::threadName &name);
45
46 static void startThreads(eThreadType type, const std::optional<std::shared_ptr<AbstractProgress>> &progress);
47 static void restartThreads(eThreadType type, const std::optional<std::shared_ptr<AbstractProgress>> &progress);
48 static void stopThreads(eThreadType type, const std::optional<std::shared_ptr<AbstractProgress>> &progress);
49
50 static bool startThread(const iv::types::threadName &name);
51 static bool restartThread(const iv::types::threadName &name);
52 static bool stopThread(const iv::types::threadName &name);
53
54 static void pauseThread(const iv::types::threadName &name);
55 static void resumeThread(const iv::types::threadName &name);
56 static std::optional<ThreadData> getThreadData(const iv::types::threadName &name);
57
58 static std::map<std::thread::id, std::atomic<bool>> haveThreadsCrashed;
59
60private:
61 static std::map<iv::types::threadName, ThreadData> m_threads;
62 static std::mutex m_mutex;
63 void periodicTask() override;
64
66
67 // Diamar Threads
68 // iv::threads::RunManageOfflineUnitAndStation m_runManageOfflineUnitAndStation;
69 // iv::threads::RunReconnect m_runReconnect;
70 // iv::threads::RunSendHeartbeatStation m_runSendHeartbeatStation;
71 // iv::threads::RunSendRedundancy m_runSendRedundancy;
72 // iv::threads::RunSendStationValuesToLoms m_runSendStationValuesToLoms;
73 // //iv::threads::RunSendUpdateGroupAlarms m_runSendUpdateGroupAlarms; // TODO: Problematico
74 // iv::threads::RunStationLogics m_runStationLogics;
75 // iv::threads::RunTanks m_runTanks;
76 // iv::threads::RunUpdateChannels m_runUpdateChannels;
77 //
78 // // Edit Diamar Threads
79 // //iv::threads::RunReceiveEditorComms m_runReceiveEditorComms;
80 // //iv::threads::RunUpdateInfoUnit m_runUpdateInfoUnit;
81};
82
83}// namespace iv::threads
84
85#endif//SRC_IV_THREADS_WATCHDOG_HPP
Definition IRunnable.hpp:10
Definition ThreadRunnablePeriodic.hpp:15
Definition Thread.hpp:14
Definition WatchDog.hpp:35
static bool stopMonitoring()
Definition WatchDog.cpp:64
static void addThread(const iv::types::threadName &name, ThreadRunnablePeriodic *runnable, eThreadType type)
Definition WatchDog.cpp:97
static std::map< iv::types::threadName, ThreadData > m_threads
Definition WatchDog.hpp:61
static void resumeThread(const iv::types::threadName &name)
Definition WatchDog.cpp:347
static std::mutex m_mutex
Definition WatchDog.hpp:62
static void pauseThread(const iv::types::threadName &name)
Definition WatchDog.cpp:324
void periodicTask() override
Definition WatchDog.cpp:28
static bool startThread(const iv::types::threadName &name)
Definition WatchDog.cpp:241
~WatchDog() override=default
static bool restartThread(const iv::types::threadName &name)
Definition WatchDog.cpp:271
static void removeThread(const iv::types::threadName &name)
Definition WatchDog.cpp:108
static void restartThreads(eThreadType type, const std::optional< std::shared_ptr< AbstractProgress > > &progress)
Definition WatchDog.cpp:165
iv::types::timestamp startTime
Definition WatchDog.hpp:65
static bool startMonitoring()
Definition WatchDog.cpp:51
static void stopThreads(eThreadType type, const std::optional< std::shared_ptr< AbstractProgress > > &progress)
Definition WatchDog.cpp:206
WatchDog()
Definition WatchDog.cpp:23
static void startThreads(eThreadType type, const std::optional< std::shared_ptr< AbstractProgress > > &progress)
Definition WatchDog.cpp:130
static bool stopThread(const iv::types::threadName &name)
Definition WatchDog.cpp:279
static std::map< std::thread::id, std::atomic< bool > > haveThreadsCrashed
Definition WatchDog.hpp:58
static std::optional< ThreadData > getThreadData(const iv::types::threadName &name)
Definition WatchDog.cpp:315
Definition BackgroundTaskWithDialog.cpp:8
eThreadType
Definition WatchDog.hpp:19
@ Editor
Definition WatchDog.hpp:21
@ Internal
Definition WatchDog.hpp:22
@ Communication
Definition WatchDog.hpp:20
uint64_t timestamp
Definition types.hpp:21
std::string threadName
Definition types.hpp:26
Definition WatchDog.hpp:26
iv::threads::Thread * thread
Definition WatchDog.hpp:29
eThreadType type
Definition WatchDog.hpp:31
iv::threads::IRunnable * runnable
Definition WatchDog.hpp:30
iv::types::threadName name
Definition WatchDog.hpp:27
iv::types::timestamp lastTimeRunning
Definition WatchDog.hpp:28