/
MsvDllModuleAdapter.h
135 lines (107 loc) · 6.5 KB
/
MsvDllModuleAdapter.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
/**************************************************************************************************//**
* @addtogroup MMODULE
* @{
******************************************************************************************************/
/**************************************************************************************************//**
* @file
* @brief MarsTech DLL Module Adapter Implementation
* @details Contains implementation @ref MsvDllModuleAdapter of @ref IMsvModule 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_DLLMODULEADAPTER_H
#define MARSTECH_DLLMODULEADAPTER_H
#include "IMsvDllModule.h"
#include "mlogging/mlogging.h"
/**************************************************************************************************//**
* @brief MarsTech DLL Module Adapter.
* @details DLL module adapter which loads, initializes, starts, stops and uninitializes module
* in dynamic/shared library.
* @note This class is usefull for modules stored in dynamic/shared libraries.
******************************************************************************************************/
class MsvDllModuleAdapter:
public IMsvModule
{
public:
/**************************************************************************************************//**
* @brief Constructor.
* @param[in] moduleId DLL module ID (ID to get module from DLL factory).
* @param[in] spDllFactory Shared pointer to DLL factory.
* @param[in] spLogger Shared pointer to logger for logging.
******************************************************************************************************/
MsvDllModuleAdapter(const char* moduleId, std::shared_ptr<IMsvDllFactory> spDllFactory, std::shared_ptr<MsvLogger> spLogger = nullptr);
/**************************************************************************************************//**
* @brief Virtual destructor.
******************************************************************************************************/
virtual ~MsvDllModuleAdapter();
/*-----------------------------------------------------------------------------------------------------
** IMsvModule public methods
**---------------------------------------------------------------------------------------------------*/
public:
/**************************************************************************************************//**
* @copydoc IMsvModule::Initialize()
******************************************************************************************************/
virtual MsvErrorCode Initialize() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Uninitialize()
******************************************************************************************************/
virtual MsvErrorCode Uninitialize() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Initialized() const
******************************************************************************************************/
virtual bool Initialized() const override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Start()
******************************************************************************************************/
virtual MsvErrorCode Start() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Stop()
******************************************************************************************************/
virtual MsvErrorCode Stop() override;
/**************************************************************************************************//**
* @copydoc IMsvModule::Running() const
******************************************************************************************************/
virtual bool Running() const override;
protected:
/**************************************************************************************************//**
* @brief Module manager mutex.
* @details Locks this object for thread safety access.
******************************************************************************************************/
mutable std::recursive_mutex m_lock;
/**************************************************************************************************//**
* @brief Module ID.
* @details DLL module ID (ID to get module from DLL factory).
******************************************************************************************************/
std::string m_moduleId;
/**************************************************************************************************//**
* @brief DLL factory.
* @details DLL factory used for loading DLLs and theirs objects. Used to get DLL module.
******************************************************************************************************/
std::shared_ptr<IMsvDllFactory> m_spDllFactory;
/**************************************************************************************************//**
* @brief DLL module.
* @details Real DLL module loaded from DLL.
******************************************************************************************************/
std::shared_ptr<IMsvDllModule> m_spModule;
/**************************************************************************************************//**
* @brief Logger.
* @details Shared pointer to logger for logging.
******************************************************************************************************/
std::shared_ptr<MsvLogger> m_spLogger;
};
#endif // !MARSTECH_DLLMODULEADAPTER_H
/** @} */ //End of group MMODULE.