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 #include "MyGUI_Common.h" 00026 00027 namespace MyGUI 00028 { 00029 00030 MYGUI_INSTANCE_IMPLEMENT(DynLibManager); 00031 00032 void DynLibManager::initialise() 00033 { 00034 MYGUI_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice"); 00035 MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME); 00036 00037 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized"); 00038 mIsInitialise = true; 00039 } 00040 00041 void DynLibManager::shutdown() 00042 { 00043 if (false == mIsInitialise) return; 00044 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME); 00045 00046 StringDynLibMap::iterator it; 00047 00048 // unload and delete resources 00049 for (it = mLibsMap.begin(); it != mLibsMap.end(); it++) 00050 { 00051 it->second->unload(); 00052 delete it->second; 00053 } 00054 00055 // Empty the list 00056 mLibsMap.clear(); 00057 00058 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown"); 00059 mIsInitialise = false; 00060 } 00061 00062 DynLib* DynLibManager::load(const std::string &fileName) 00063 { 00064 StringDynLibMap::iterator it = mLibsMap.find(fileName); 00065 00066 if (it != mLibsMap.end()) 00067 { 00068 return it->second; 00069 } 00070 00071 DynLib *pLib = new DynLib(fileName); 00072 pLib->load(); 00073 mLibsMap[fileName] = pLib; 00074 return pLib; 00075 00076 } 00077 00078 void DynLibManager::unload(DynLib *library) 00079 { 00080 StringDynLibMap::iterator it = mLibsMap.find(library->getName()); 00081 00082 if (it != mLibsMap.end()) 00083 mLibsMap.erase(it); 00084 00085 library->unload(); 00086 delete library; 00087 } 00088 }