Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
ICommunicationController.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_COMMS_ICOMMUNICATIONCONTROLLER_HPP_
2#define IV_SRC_COMMS_ICOMMUNICATIONCONTROLLER_HPP_
3
6#include "threads/Thread.hpp"
9
10#include <map>
11#include <memory>
12#include <utility>
13
14namespace iv::channels
15{
16class AbstractChannel;
17}
18
19namespace iv::comms
20{
21
23{
24public:
26 ICommunicationController(const std::shared_ptr<iv::model::comms::NetworkData> &networkData,
27 std::unique_ptr<iv::comms::ICommunicationDriver> driver, std::shared_ptr<bool> isEnabled);
30
32 {
33 if (m_driver)
34 {
35 m_driver->stop();
36 m_driver->end();
37 }
38 }
39
42
43 virtual void addChannel(const std::shared_ptr<iv::channels::AbstractChannel> &channel) = 0;
44 virtual void initialize() = 0;
45 virtual bool frame() = 0;
46
47 void pause() const
48 {
49 if (auto fallBack = m_fallbackComm.lock())
50 {
51 iv::threads::WatchDog::pauseThread(fallBack->getNetworkId());
52 }
53 if (not*m_isEnabled)
54 {
55 return;
56 }
58 *m_isEnabled = false;
59 m_driver->stop();
60 }
61
62 void resume() const
63 {
64 if (*m_isEnabled)
65 {
66 return;
67 }
69 m_driver->start();
70 *m_isEnabled = true;
71 }
72
73 [[nodiscard]] iv::types::networkId getNetworkId() const
74 {
75 return m_networkId;
76 }
77
78 [[nodiscard]] std::shared_ptr<iv::model::comms::NetworkData> getCommConfig() const
79 {
80 return m_commConfig;
81 }
82
83 [[nodiscard]] std::shared_ptr<iv::comms::ICommunicationDriver> getDriver() const
84 {
85 return m_driver;
86 }
87
88 [[nodiscard]] bool hasChannel(const iv::types::channelId &channelId) const
89 {
90 return m_channels.contains(channelId);
91 }
92
93 [[nodiscard]] bool isEnabled()
94 {
95 return *m_isEnabled;
96 }
97
98protected:
100 std::shared_ptr<bool> m_isEnabled;
101
102 std::shared_ptr<iv::model::comms::NetworkData> m_commConfig;
103 std::shared_ptr<iv::comms::ICommunicationProtocol> m_protocol;
104 std::shared_ptr<iv::comms::ICommunicationDriver> m_driver;
105 std::map<iv::types::channelId, std::shared_ptr<iv::channels::AbstractChannel>> m_channels;
106 std::weak_ptr<iv::channels::AbstractChannel> m_errorChannel;
107 std::weak_ptr<iv::channels::AbstractChannel> m_heartbeatChannel;
108 std::weak_ptr<iv::comms::ICommunicationController> m_fallbackComm;
109
110 std::weak_ptr<iv::diamar::AppFailuresLoggerManager> m_appFailuresLoggerManager;
111};
112
113}// namespace iv::comms
114
115#endif//IV_SRC_COMMS_ICOMMUNICATIONCONTROLLER_HPP_
Definition ICommunicationController.hpp:23
virtual ~ICommunicationController()
Definition ICommunicationController.hpp:31
std::weak_ptr< iv::channels::AbstractChannel > m_errorChannel
Definition ICommunicationController.hpp:106
ICommunicationController(ICommunicationController &&other)=delete
std::shared_ptr< iv::comms::ICommunicationDriver > getDriver() const
Definition ICommunicationController.hpp:83
ICommunicationController(const ICommunicationController &other)=delete
std::shared_ptr< iv::model::comms::NetworkData > getCommConfig() const
Definition ICommunicationController.hpp:78
std::shared_ptr< bool > m_isEnabled
Definition ICommunicationController.hpp:100
std::shared_ptr< iv::comms::ICommunicationProtocol > m_protocol
Definition ICommunicationController.hpp:103
std::weak_ptr< iv::channels::AbstractChannel > m_heartbeatChannel
Definition ICommunicationController.hpp:107
ICommunicationController & operator=(ICommunicationController &&other)=delete
void pause() const
Definition ICommunicationController.hpp:47
std::map< iv::types::channelId, std::shared_ptr< iv::channels::AbstractChannel > > m_channels
Definition ICommunicationController.hpp:105
virtual void addChannel(const std::shared_ptr< iv::channels::AbstractChannel > &channel)=0
ICommunicationController & operator=(const ICommunicationController &other)=delete
std::shared_ptr< iv::model::comms::NetworkData > m_commConfig
Definition ICommunicationController.hpp:102
std::weak_ptr< iv::comms::ICommunicationController > m_fallbackComm
Definition ICommunicationController.hpp:108
bool hasChannel(const iv::types::channelId &channelId) const
Definition ICommunicationController.hpp:88
std::shared_ptr< iv::comms::ICommunicationDriver > m_driver
Definition ICommunicationController.hpp:104
iv::types::networkId m_networkId
Definition ICommunicationController.hpp:99
void resume() const
Definition ICommunicationController.hpp:62
iv::types::networkId getNetworkId() const
Definition ICommunicationController.hpp:73
std::weak_ptr< iv::diamar::AppFailuresLoggerManager > m_appFailuresLoggerManager
Definition ICommunicationController.hpp:110
bool isEnabled()
Definition ICommunicationController.hpp:93
static void resumeThread(const iv::types::threadName &name)
Definition WatchDog.cpp:347
static void pauseThread(const iv::types::threadName &name)
Definition WatchDog.cpp:324
Definition AlarmsManager.hpp:17
Definition ApiCommunicationController.cpp:12
std::string networkId
Definition types.hpp:43
std::string channelId
Definition types.hpp:66