MyGUI
3.0.3
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #include "MyGUI_Precompiled.h" 00024 #include "MyGUI_DynLibManager.h" 00025 00026 namespace MyGUI 00027 { 00028 00029 MYGUI_INSTANCE_IMPLEMENT( DynLibManager ) 00030 00031 void DynLibManager::initialise() 00032 { 00033 MYGUI_ASSERT(!mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice"); 00034 MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME); 00035 00036 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized"); 00037 mIsInitialise = true; 00038 } 00039 00040 void DynLibManager::shutdown() 00041 { 00042 if (!mIsInitialise) return; 00043 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME); 00044 00045 StringDynLibMap::iterator it; 00046 00047 // unload and delete resources 00048 for (it = mLibsMap.begin(); it != mLibsMap.end(); ++it) 00049 { 00050 it->second->unload(); 00051 delete it->second; 00052 } 00053 00054 // Empty the list 00055 mLibsMap.clear(); 00056 00057 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown"); 00058 mIsInitialise = false; 00059 } 00060 00061 DynLib* DynLibManager::load(const std::string &fileName) 00062 { 00063 StringDynLibMap::iterator it = mLibsMap.find(fileName); 00064 00065 if (it != mLibsMap.end()) 00066 { 00067 return it->second; 00068 } 00069 00070 DynLib *pLib = new DynLib(fileName); 00071 if (!pLib->load()) 00072 { 00073 delete pLib; 00074 return 0; 00075 } 00076 00077 mLibsMap[fileName] = pLib; 00078 return pLib; 00079 } 00080 00081 void DynLibManager::unload(DynLib *library) 00082 { 00083 StringDynLibMap::iterator it = mLibsMap.find(library->getName()); 00084 00085 if (it != mLibsMap.end()) 00086 mLibsMap.erase(it); 00087 00088 library->unload(); 00089 delete library; 00090 } 00091 }