MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_DynLibManager.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_DynLibManager.h"
24 #include "MyGUI_Gui.h"
25 #include "MyGUI_WidgetManager.h"
26
27 namespace MyGUI
28 {
29
30 template <> DynLibManager* Singleton<DynLibManager>::msInstance = nullptr;
31 template <> const char* Singleton<DynLibManager>::mClassTypeName("DynLibManager");
32
33 DynLibManager::DynLibManager() :
34 mIsInitialise(false)
35 {
36 }
37
38 void DynLibManager::initialise()
39 {
40 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
41 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
42
43 Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
44
45 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
46 mIsInitialise = true;
47 }
48
49 void DynLibManager::shutdown()
50 {
51 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
52 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
53
54 unloadAll();
55
56 Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
57 _unloadDelayDynLibs();
58
59 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
60 mIsInitialise = false;
61 }
62
63 DynLib* DynLibManager::load(const std::string& fileName)
64 {
65 StringDynLibMap::iterator it = mLibsMap.find(fileName);
66
67 if (it != mLibsMap.end())
68 {
69 return it->second;
70 }
71
72 DynLib* pLib = new DynLib(fileName);
73 if (!pLib->load())
74 {
75 delete pLib;
76 return 0;
77 }
78
79 mLibsMap[fileName] = pLib;
80 return pLib;
81 }
82
83 void DynLibManager::unload(DynLib* library)
84 {
85 StringDynLibMap::iterator it = mLibsMap.find(library->getName());
86
87 if (it != mLibsMap.end())
88 mLibsMap.erase(it);
89
90 mDelayDynLib.push_back(library);
91 }
92
93 void DynLibManager::unloadAll()
94 {
95 // unload and delete resources
96 for (StringDynLibMap::iterator it = mLibsMap.begin(); it != mLibsMap.end(); ++it)
97 {
98 mDelayDynLib.push_back(it->second);
99 }
100 // Empty the list
101 mLibsMap.clear();
102 }
103
104 void DynLibManager::notifyEventFrameStart(float _time)
105 {
106 _unloadDelayDynLibs();
107 }
108
109 void DynLibManager::_unloadDelayDynLibs()
110 {
111 if (!mDelayDynLib.empty())
112 {
113 WidgetManager* manager = WidgetManager::getInstancePtr();
114 if (manager != nullptr)
115 manager->_deleteDelayWidgets();
116
117 for (VectorDynLib::iterator entry = mDelayDynLib.begin(); entry != mDelayDynLib.end(); ++entry)
118 {
119 (*entry)->unload();
120 delete (*entry);
121 }
122 mDelayDynLib.clear();
123 }
124 }
125
126 } // namespace MyGUI
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition: MyGUI_WidgetManager.cpp:197
MyGUI::DynLibManager::unload
void unload(DynLib *library)
Unload library.
Definition: MyGUI_DynLibManager.cpp:83
MyGUI_Precompiled.h
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:150
MyGUI::Singleton< Gui >::getInstance
static Gui & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI_WidgetManager.h
MyGUI::DynLib
Resource holding data about a dynamic library.
Definition: MyGUI_DynLib.h:63
MyGUI::WidgetManager
Definition: MyGUI_WidgetManager.h:35
MyGUI::Singleton< DynLibManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
MyGUI::DynLibManager::DynLibManager
DynLibManager()
Definition: MyGUI_DynLibManager.cpp:33
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI::DynLibManager::_unloadDelayDynLibs
void _unloadDelayDynLibs()
Definition: MyGUI_DynLibManager.cpp:109
MyGUI::DynLibManager::unloadAll
void unloadAll()
Definition: MyGUI_DynLibManager.cpp:93
MyGUI::Singleton< WidgetManager >::getInstancePtr
static WidgetManager * getInstancePtr()
Definition: MyGUI_Singleton.h:59
MyGUI::DynLib::load
bool load()
Definition: MyGUI_DynLib.cpp:46
MyGUI::DynLibManager::initialise
void initialise()
Definition: MyGUI_DynLibManager.cpp:38
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::DynLib::getName
std::string getName(void) const
Get the name of the library.
Definition: MyGUI_DynLib.cpp:109
MyGUI::DynLibManager::load
DynLib * load(const std::string &fileName)
Load library.
Definition: MyGUI_DynLibManager.cpp:63
MyGUI::DynLibManager::shutdown
void shutdown()
Definition: MyGUI_DynLibManager.cpp:49
MyGUI_Gui.h
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI_DynLibManager.h