MyGUI_DynLibManager.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_DynLibManager.h"
#include "MyGUI_Gui.h"
#include "MyGUI_WidgetManager.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(DynLibManager);
DynLibManager::DynLibManager() :
mSingletonHolder(this)
{
}
void DynLibManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
Gui::getInstance().eventFrameStart += newDelegate(this, &DynLibManager::notifyEventFrameStart);
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void DynLibManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
unloadAll();
Gui::getInstance().eventFrameStart -= newDelegate(this, &DynLibManager::notifyEventFrameStart);
_unloadDelayDynLibs();
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
DynLib* DynLibManager::load(std::string_view fileName)
{
StringDynLibMap::iterator it = mLibsMap.find(fileName);
if (it != mLibsMap.end())
{
return it->second;
}
DynLib* pLib = new DynLib(fileName);
if (!pLib->load())
{
delete pLib;
return nullptr;
}
mLibsMap[pLib->getName()] = pLib;
return pLib;
}
void DynLibManager::unload(DynLib* library)
{
StringDynLibMap::iterator it = mLibsMap.find(library->getName());
if (it != mLibsMap.end())
mLibsMap.erase(it);
mDelayDynLib.push_back(library);
}
void DynLibManager::unloadAll()
{
// unload and delete resources
for (const auto& it : mLibsMap)
{
mDelayDynLib.push_back(it.second);
}
// Empty the list
mLibsMap.clear();
}
void DynLibManager::notifyEventFrameStart(float _time)
{
_unloadDelayDynLibs();
}
void DynLibManager::_unloadDelayDynLibs()
{
if (!mDelayDynLib.empty())
{
WidgetManager* manager = WidgetManager::getInstancePtr();
if (manager != nullptr)
manager->_deleteDelayWidgets();
for (auto& entry : mDelayDynLib)
{
entry->unload();
delete entry;
}
mDelayDynLib.clear();
}
}
} // 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