MyGUI: MyGUI_DynLibManager.cpp Source File

MyGUI 3.4.3

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 mSingletonHolder(this)
19 {
20 }
21
22 void DynLibManager::initialise()
23 {
24 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
25 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
26
27 Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
28
29 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
30 mIsInitialise = true;
31 }
32
33 void DynLibManager::shutdown()
34 {
35 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
36 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
37
38 unloadAll();
39
40 Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
41 _unloadDelayDynLibs();
42
43 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
44 mIsInitialise = false;
45 }
46
47 DynLib* DynLibManager::load(std::string_view fileName)
48 {
49 StringDynLibMap::iterator it = mLibsMap.find(fileName);
50
51 if (it != mLibsMap.end())
52 {
53 return it->second;
54 }
55
56 DynLib* pLib = new DynLib(fileName);
57 if (!pLib->load())
58 {
59 delete pLib;
60 return nullptr;
61 }
62
63 mLibsMap[pLib->getName()] = pLib;
64 return pLib;
65 }
66
67 void DynLibManager::unload(DynLib* library)
68 {
69 StringDynLibMap::iterator it = mLibsMap.find(library->getName());
70
71 if (it != mLibsMap.end())
72 mLibsMap.erase(it);
73
74 mDelayDynLib.push_back(library);
75 }
76
77 void DynLibManager::unloadAll()
78 {
79 // unload and delete resources
80 for (const auto& it : mLibsMap)
81 {
82 mDelayDynLib.push_back(it.second);
83 }
84 // Empty the list
85 mLibsMap.clear();
86 }
87
88 void DynLibManager::notifyEventFrameStart(float _time)
89 {
90 _unloadDelayDynLibs();
91 }
92
93 void DynLibManager::_unloadDelayDynLibs()
94 {
95 if (!mDelayDynLib.empty())
96 {
97 WidgetManager* manager = WidgetManager::getInstancePtr();
98 if (manager != nullptr)
99 manager->_deleteDelayWidgets();
100
101 for (auto& entry : mDelayDynLib)
102 {
103 entry->unload();
104 delete entry;
105 }
106 mDelayDynLib.clear();
107 }
108 }
109
110} // namespace MyGUI
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
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:126
MyGUI_WidgetManager.h
MyGUI::DynLib
Resource holding data about a dynamic library.
Definition MyGUI_DynLib.h:35
MyGUI::DynLib::getName
const std::string & getName() const
Get the name of the library.
Definition MyGUI_DynLib.cpp:124
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:22
MyGUI::DynLibManager::_unloadDelayDynLibs
void _unloadDelayDynLibs()
Definition MyGUI_DynLibManager.cpp:93
MyGUI::DynLibManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::DynLibManager::unload
void unload(DynLib *library)
Unload library.
Definition MyGUI_DynLibManager.cpp:67
MyGUI::DynLibManager::unloadAll
void unloadAll()
Definition MyGUI_DynLibManager.cpp:77
MyGUI::DynLibManager::DynLibManager
DynLibManager()
Definition MyGUI_DynLibManager.cpp:17
MyGUI::DynLibManager::load
DynLib * load(std::string_view fileName)
Load library.
Definition MyGUI_DynLibManager.cpp:47
MyGUI::DynLibManager::shutdown
void shutdown()
Definition MyGUI_DynLibManager.cpp:33
MyGUI::Gui::getInstance
static Gui & getInstance()
Definition MyGUI_Gui.cpp:34
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition MyGUI_Gui.h:215
MyGUI::WidgetManager
Definition MyGUI_WidgetManager.h:21
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition MyGUI_WidgetManager.cpp:184
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:100