MyGUI  3.2.1
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 
12 namespace MyGUI
13 {
14 
15  template <> DynLibManager* Singleton<DynLibManager>::msInstance = nullptr;
16  template <> const char* Singleton<DynLibManager>::mClassTypeName = "DynLibManager";
17 
19  mIsInitialise(false)
20  {
21  }
22 
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 
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);
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 0;
62  }
63 
64  mLibsMap[fileName] = pLib;
65  return pLib;
66  }
67 
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 
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  {
92  }
93 
95  {
96  if (!mDelayDynLib.empty())
97  {
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