/
MsvModuleManager.h
161 lines (129 loc) · 7.89 KB
/
MsvModuleManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**************************************************************************************************//**
* @addtogroup MMODULE
* @{
******************************************************************************************************/
/**************************************************************************************************//**
* @file
* @brief MarsTech Module Manager Implementation
* @details Contains implementation @ref MsvModuleManager of @ref IMsvModuleManager interface.
* @author Martin Svoboda
* @date 19.05.2019
* @copyright GNU General Public License (GPLv3).
******************************************************************************************************/
/*
This file is part of MarsTech Module Library.
MarsTech Dependency Injection is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MarsTech Promise Like Syntax is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MARSTECH_MODULEMANAGER_H
#define MARSTECH_MODULEMANAGER_H
#include "IMsvModuleManager.h"
#include "IMsvModuleConfigurator.h"
#include "mlogging/mlogging.h"
MSV_DISABLE_ALL_WARNINGS
#include <map>
#include <mutex>
MSV_ENABLE_WARNINGS
/**************************************************************************************************//**
* @brief MarsTech Module Manager Implementation.
* @details Module manager implementation which can manage all modules.
******************************************************************************************************/
class MsvModuleManager:
public IMsvModuleManager
{
public:
/**************************************************************************************************//**
* @brief Constructor.
* @param[in] spLogger Shared pointer to logger for logging.
******************************************************************************************************/
MsvModuleManager(std::shared_ptr<MsvLogger> spLogger);
/**************************************************************************************************//**
* @brief Virtual destructor.
******************************************************************************************************/
virtual ~MsvModuleManager();
/*-----------------------------------------------------------------------------------------------------
** IMsvModule public methods
**---------------------------------------------------------------------------------------------------*/
public:
/**************************************************************************************************//**
* @copydoc IMsvModule::Initialize()
* @retval MSV_ALREADY_INITIALIZED_INFO When module manager has been already initialized (this is info, not error).
******************************************************************************************************/
virtual MsvErrorCode Initialize() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Uninitialize()
* @retval MSV_NOT_INITIALIZED_INFO When module manager has not been initialized (this is info, not error).
* @retval MSV_STILL_RUNNING_ERROR When module manager is still running. Must be stopped before.
******************************************************************************************************/
virtual MsvErrorCode Uninitialize() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Initialized() const
******************************************************************************************************/
virtual bool Initialized() const override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Start()
* @retval MSV_NOT_INITIALIZED_ERROR When module manager has not been initialized before. Must be initialized before.
* @retval MSV_ALREADY_RUNNING_INFO When module manager is already running (this is info, not error).
******************************************************************************************************/
virtual MsvErrorCode Start() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Stop()
* @retval MSV_NOT_RUNNING_INFO When module manager is not running (this is info, not error).
******************************************************************************************************/
virtual MsvErrorCode Stop() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Running() const
******************************************************************************************************/
virtual bool Running() const override;
/*-----------------------------------------------------------------------------------------------------
** IMsvModuleManager public methods
**---------------------------------------------------------------------------------------------------*/
public:
/**************************************************************************************************//**
* @copydoc IMsvModuleManager::AddModule(int32_t moduleId, std::shared_ptr<IMsvModule> spModule, std::shared_ptr<IMsvModuleConfigurator> spModuleConfigurator)
******************************************************************************************************/
virtual MsvErrorCode AddModule(int32_t moduleId, std::shared_ptr<IMsvModule> spModule, std::shared_ptr<IMsvModuleConfigurator> spModuleConfigurator) override;
protected:
/**************************************************************************************************//**
* @brief Module manager mutex.
* @details Locks this object for thread safety access.
******************************************************************************************************/
mutable std::recursive_mutex m_lock;
/**************************************************************************************************//**
* @brief Initialize flag.
* @details Flag if module manager is initialized (true) or not (false).
* @see Initialize
* @see Uninitialize
* @see Initialized
******************************************************************************************************/
bool m_initialized;
/**************************************************************************************************//**
* @brief Registered modules.
* @details Map of registered modules to module manager. These modules are managed by module manager.
* @see AddModule
******************************************************************************************************/
std::map<int32_t, std::pair<std::shared_ptr<IMsvModuleConfigurator>, std::shared_ptr<IMsvModule>>> m_modules;
/**************************************************************************************************//**
* @brief Logger.
* @details Shared pointer to logger for logging.
******************************************************************************************************/
std::shared_ptr<MsvLogger> m_spLogger;
/**************************************************************************************************//**
* @brief Running flag.
* @details Flag if module manager is running (true) or not (false).
* @see Start
* @see Stop
* @see Running
******************************************************************************************************/
bool m_running;
};
#endif // !MARSTECH_MODULEMANAGER_H
/** @} */ //End of group MMODULE.