MyGUI  3.2.0
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 
34  mIsInitialise(false)
35  {
36  }
37 
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 
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);
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 
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 
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  {
107  }
108 
110  {
111  if (!mDelayDynLib.empty())
112  {
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
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
void unload(DynLib *library)
Unload library.
delegates::IDelegate0 * newDelegate(void(*_func)())
static Gui & getInstance()
Resource holding data about a dynamic library.
Definition: MyGUI_DynLib.h:63
static const char * getClassTypeName()
#define MYGUI_LOG(level, text)
static WidgetManager * getInstancePtr()
#define MYGUI_ASSERT(exp, dest)
std::string getName(void) const
Get the name of the library.
DynLib * load(const std::string &fileName)
Load library.
static const char * mClassTypeName