00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 00027 #include "OgreDynLib.h" 00028 00029 #include "OgreException.h" 00030 #include "OgreLogManager.h" 00031 00032 #if OGRE_PLATFORM == PLATFORM_WIN32 00033 # define WIN32_LEAN_AND_MEAN 00034 # include <windows.h> 00035 #endif 00036 00037 #if OGRE_PLATFORM == PLATFORM_APPLE 00038 # include "macPlugins.h" 00039 #endif 00040 00041 00042 namespace Ogre { 00043 00044 //----------------------------------------------------------------------- 00045 DynLib::DynLib( const String& name ) 00046 { 00047 OgreGuard("DynLib::DynLib"); 00048 00049 mName = name; 00050 #if OGRE_PLATFORM == PLATFORM_LINUX 00051 // dlopen() does not add .so to the filename, like windows does for .dll 00052 if (mName.substr(mName.length() - 3, 3) != ".so") 00053 mName += ".so"; 00054 #endif 00055 mIsLoaded = false; 00056 m_hInst = NULL; 00057 00058 OgreUnguard(); 00059 } 00060 00061 //----------------------------------------------------------------------- 00062 DynLib::~DynLib() 00063 { 00064 if( mIsLoaded ) 00065 unload(); 00066 } 00067 00068 //----------------------------------------------------------------------- 00069 void DynLib::load() 00070 { 00071 OgreGuard("DynLib::load"); 00072 00073 // Log library load 00074 LogManager::getSingleton().logMessage("Loading library " + mName); 00075 00076 m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( mName.c_str() ); 00077 00078 if( !m_hInst ) 00079 Except( 00080 Exception::ERR_INTERNAL_ERROR, 00081 "Could not load dynamic library " + mName + 00082 ". System Error: " + DYNLIB_ERROR(), 00083 "DynLib::load" ); 00084 00085 mIsLoaded = true; 00086 00087 OgreUnguard(); 00088 } 00089 00090 //----------------------------------------------------------------------- 00091 void DynLib::unload() 00092 { 00093 OgreGuard("DynLib::unload"); 00094 00095 // Log library unload 00096 if (mIsLoaded) 00097 { 00098 LogManager::getSingleton().logMessage("Unloading library " + mName); 00099 00100 if( DYNLIB_UNLOAD( m_hInst ) ) 00101 Except( 00102 Exception::ERR_INTERNAL_ERROR, 00103 "Could not unload dynamic library " + mName + 00104 ". System Error: " + DYNLIB_ERROR(), 00105 "DynLib::unload"); 00106 } 00107 mIsLoaded = false; 00108 00109 OgreUnguard(); 00110 } 00111 00112 //----------------------------------------------------------------------- 00113 void* DynLib::getSymbol( const String& strName ) const throw() 00114 { 00115 return (void*)DYNLIB_GETSYM( m_hInst, strName.c_str() ); 00116 } 00117 }
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:22 2004