This repository has been archived by the owner on May 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModuleManager.cpp
116 lines (90 loc) · 2.45 KB
/
ModuleManager.cpp
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
/*
This file is part of MasterServer.
MasterServer is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MasterServer 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with MasterServer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ModuleManager.h"
#include <MDK/Utility.h>
CModuleManager::CModuleManager()
{
}
CModuleManager::~CModuleManager()
{
size_t i = 0;
// Free memory of the modules
for (; i < m_vModules.size(); i++)
delete m_vModules.at(i);
m_vModules.clear();
}
bool CModuleManager::LoadMSModule(const char *name)
{
CModule *module = new CModule();
// Get the module
//module = m_vModules.at(m_vModules.size() - 1);
// Try to load the module
if (!module->Load(name))
{
delete module;
// Remove the module from the array
//m_vModules.erase(m_vModules.begin()+(m_vModules.size()-1));
return false;
}
// Add the pointer into the vector
m_vModules.push_back(module);
return true;
}
bool CModuleManager::LoadMSModule(const char *name, ModuleConfigMap cfg)
{
CModule *module = new CModule();
// Get the module
//module = m_vModules.at(m_vModules.size() - 1);
// Try to load the module
if (!module->Load(name, cfg))
{
delete module;
// Remove the module from the array
//m_vModules.erase(m_vModules.begin()+(m_vModules.size()-1));
return false;
}
// Add the pointer into the vector
m_vModules.push_back(module);
return true;
}
void CModuleManager::Start(CDatabase* db)
{
size_t i = 0;
for (; i < m_vModules.size(); i++)
{
LOG_INFO("Module", "Starting %s...", m_vModules.at(i)->GetName());
if (!m_vModules.at(i)->Start(db))
{
LOG_ERROR("Module", "Unable to start module %s!", m_vModules.at(i)->GetName());
}
}
}
void CModuleManager::Stop()
{
size_t i = 0;
for (; i < m_vModules.size(); i++)
{
m_vModules.at(i)->Stop();
}
}
size_t CModuleManager::GetModuleSize()
{
return m_vModules.size();
}
CModule* CModuleManager::GetModule(size_t index)
{
if (GetModuleSize() < index)
return NULL;
return m_vModules.at(index);
}