MyGUI  3.2.2
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
MyGUI::Singleton< Gui >::getInstance
static Gui & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:150
MyGUI_Gui.h
MyGUI_DynLibManager.h
MyGUI::WidgetManager
Definition: MyGUI_WidgetManager.h:20
MyGUI::DynLibManager::unload
void unload(DynLib *library)
Unload library.
Definition: MyGUI_DynLibManager.cpp:68
MyGUI::DynLibManager::DynLibManager
DynLibManager()
Definition: MyGUI_DynLibManager.cpp:18
MyGUI::Singleton< DynLibManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:49
MyGUI::DynLib::getName
std::string getName(void) const
Get the name of the library.
Definition: MyGUI_DynLib.cpp:102
MyGUI::DynLib
Resource holding data about a dynamic library.
Definition: MyGUI_DynLib.h:46
MyGUI::DynLibManager::unloadAll
void unloadAll()
Definition: MyGUI_DynLibManager.cpp:78
MyGUI::DynLib::load
bool load()
Definition: MyGUI_DynLib.cpp:28
MyGUI_Precompiled.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MyGUI_WidgetManager.h
MyGUI::DynLibManager::initialise
void initialise()
Definition: MyGUI_DynLibManager.cpp:23
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition: MyGUI_WidgetManager.cpp:183
MyGUI::DynLibManager::_unloadDelayDynLibs
void _unloadDelayDynLibs()
Definition: MyGUI_DynLibManager.cpp:94
MyGUI::Singleton< WidgetManager >::getInstancePtr
static WidgetManager * getInstancePtr()
Definition: MyGUI_Singleton.h:44
MyGUI::DynLibManager::load
DynLib * load(const std::string &fileName)
Load library.
Definition: MyGUI_DynLibManager.cpp:48
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI
Definition: MyGUI_ActionController.h:14
newDelegate
MYGUI_TEMPLATE MYGUI_TEMPLATE_PARAMS delegates::IDelegateMYGUI_SUFFIX MYGUI_TEMPLATE_ARGS * newDelegate(void(*_func)(MYGUI_PARAMS))
Definition: MyGUI_DelegateImplement.h:117
MyGUI::DynLibManager::shutdown
void shutdown()
Definition: MyGUI_DynLibManager.cpp:34