MyGUI: MyGUI_DynLibManager.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

MyGUI_DynLibManager.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_DynLibManager.h"
9#include "MyGUI_Gui.h"
10#include "MyGUI_WidgetManager.h"
11
12namespace MyGUI
13{
14
15 MYGUI_SINGLETON_DEFINITION(DynLibManager);
16
17 DynLibManager::DynLibManager() :
18 mIsInitialise(false),
19 mSingletonHolder(this)
20 {
21 }
22
23 void DynLibManager::initialise()
24 {
25 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
26 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
27
28 Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
29
30 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
31 mIsInitialise = true;
32 }
33
34 void DynLibManager::shutdown()
35 {
36 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
37 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
38
39 unloadAll();
40
41 Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
42 _unloadDelayDynLibs();
43
44 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
45 mIsInitialise = false;
46 }
47
48 DynLib* DynLibManager::load(const std::string& fileName)
49 {
50 StringDynLibMap::iterator it = mLibsMap.find(fileName);
51
52 if (it != mLibsMap.end())
53 {
54 return it->second;
55 }
56
57 DynLib* pLib = new DynLib(fileName);
58 if (!pLib->load())
59 {
60 delete pLib;
61 return nullptr;
62 }
63
64 mLibsMap[fileName] = pLib;
65 return pLib;
66 }
67
68 void DynLibManager::unload(DynLib* library)
69 {
70 StringDynLibMap::iterator it = mLibsMap.find(library->getName());
71
72 if (it != mLibsMap.end())
73 mLibsMap.erase(it);
74
75 mDelayDynLib.push_back(library);
76 }
77
78 void DynLibManager::unloadAll()
79 {
80 // unload and delete resources
81 for (StringDynLibMap::iterator it = mLibsMap.begin(); it != mLibsMap.end(); ++it)
82 {
83 mDelayDynLib.push_back(it->second);
84 }
85 // Empty the list
86 mLibsMap.clear();
87 }
88
89 void DynLibManager::notifyEventFrameStart(float _time)
90 {
91 _unloadDelayDynLibs();
92 }
93
94 void DynLibManager::_unloadDelayDynLibs()
95 {
96 if (!mDelayDynLib.empty())
97 {
98 WidgetManager* manager = WidgetManager::getInstancePtr();
99 if (manager != nullptr)
100 manager->_deleteDelayWidgets();
101
102 for (VectorDynLib::iterator entry = mDelayDynLib.begin(); entry != mDelayDynLib.end(); ++entry)
103 {
104 (*entry)->unload();
105 delete (*entry);
106 }
107 mDelayDynLib.clear();
108 }
109 }
110
111} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:29
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_DynLibManager.h
MyGUI_Gui.h
MyGUI_Precompiled.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:123
MyGUI_WidgetManager.h
MyGUI::DynLib
Resource holding data about a dynamic library.
Definition MyGUI_DynLib.h:35
MyGUI::DynLib::getName
std::string getName(void) const
Get the name of the library.
Definition MyGUI_DynLib.cpp:126
MyGUI::DynLib::load
bool load()
Definition MyGUI_DynLib.cpp:36
MyGUI::DynLibManager
Manager of dynamic libraries.
Definition MyGUI_DynLibManager.h:21
MyGUI::DynLibManager::initialise
void initialise()
Definition MyGUI_DynLibManager.cpp:23
MyGUI::DynLibManager::_unloadDelayDynLibs
void _unloadDelayDynLibs()
Definition MyGUI_DynLibManager.cpp:94
MyGUI::DynLibManager::unload
void unload(DynLib *library)
Unload library.
Definition MyGUI_DynLibManager.cpp:68
MyGUI::DynLibManager::unloadAll
void unloadAll()
Definition MyGUI_DynLibManager.cpp:78
MyGUI::DynLibManager::DynLibManager
DynLibManager()
Definition MyGUI_DynLibManager.cpp:17
MyGUI::DynLibManager::getClassTypeName
static const char * getClassTypeName()
MyGUI::DynLibManager::load
DynLib * load(const std::string &fileName)
Load library.
Definition MyGUI_DynLibManager.cpp:48
MyGUI::DynLibManager::shutdown
void shutdown()
Definition MyGUI_DynLibManager.cpp:34
MyGUI::Gui::getInstance
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:150
MyGUI::WidgetManager
Definition MyGUI_WidgetManager.h:22
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition MyGUI_WidgetManager.cpp:183
MyGUI::WidgetManager::getInstancePtr
static WidgetManager * getInstancePtr()
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:99