| 1 | /* | 
|---|
| 2 | ----------------------------------------------------------------------------- | 
|---|
| 3 | This source file is part of OGRE | 
|---|
| 4 |     (Object-oriented Graphics Rendering Engine) | 
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ | 
|---|
| 6 |  | 
|---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd | 
|---|
| 8 |  | 
|---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy | 
|---|
| 10 | of this software and associated documentation files (the "Software"), to deal | 
|---|
| 11 | in the Software without restriction, including without limitation the rights | 
|---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
|---|
| 13 | copies of the Software, and to permit persons to whom the Software is | 
|---|
| 14 | furnished to do so, subject to the following conditions: | 
|---|
| 15 |  | 
|---|
| 16 | The above copyright notice and this permission notice shall be included in | 
|---|
| 17 | all copies or substantial portions of the Software. | 
|---|
| 18 |  | 
|---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
|---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
|---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
|---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
|---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
|---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
|---|
| 25 | THE SOFTWARE. | 
|---|
| 26 | ----------------------------------------------------------------------------- | 
|---|
| 27 | */ | 
|---|
| 28 | #ifndef _DynLib_H__ | 
|---|
| 29 | #define _DynLib_H__ | 
|---|
| 30 |  | 
|---|
| 31 | #include "OgrePrerequisites.h" | 
|---|
| 32 | #include "OgreHeaderPrefix.h" | 
|---|
| 33 |  | 
|---|
| 34 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 | 
|---|
| 35 | #    define DYNLIB_HANDLE hInstance | 
|---|
| 36 | #    define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, 0 ) // we can not use LOAD_WITH_ALTERED_SEARCH_PATH with relative paths | 
|---|
| 37 | #    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b ) | 
|---|
| 38 | #    define DYNLIB_UNLOAD( a ) !FreeLibrary( a ) | 
|---|
| 39 |  | 
|---|
| 40 | struct HINSTANCE__; | 
|---|
| 41 | typedef struct HINSTANCE__* hInstance; | 
|---|
| 42 |  | 
|---|
| 43 | #elif OGRE_PLATFORM == OGRE_PLATFORM_WINRT | 
|---|
| 44 | #    define DYNLIB_HANDLE hInstance | 
|---|
| 45 | #    define DYNLIB_LOAD( a ) LoadPackagedLibrary( UTFString(a).asWStr_c_str(), 0 ) | 
|---|
| 46 | #    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b ) | 
|---|
| 47 | #    define DYNLIB_UNLOAD( a ) !FreeLibrary( a ) | 
|---|
| 48 |  | 
|---|
| 49 | struct HINSTANCE__; | 
|---|
| 50 | typedef struct HINSTANCE__* hInstance; | 
|---|
| 51 |  | 
|---|
| 52 | #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || OGRE_PLATFORM == OGRE_PLATFORM_NACL || OGRE_PLATFORM == OGRE_PLATFORM_FLASHCC | 
|---|
| 53 | #    define DYNLIB_HANDLE void* | 
|---|
| 54 | #    define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL) | 
|---|
| 55 | #    define DYNLIB_GETSYM( a, b ) dlsym( a, b ) | 
|---|
| 56 | #    define DYNLIB_UNLOAD( a ) dlclose( a ) | 
|---|
| 57 |  | 
|---|
| 58 | #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS | 
|---|
| 59 | #    define DYNLIB_HANDLE void* | 
|---|
| 60 | #    define DYNLIB_LOAD( a ) mac_loadDylib( a ) | 
|---|
| 61 | #    define FRAMEWORK_LOAD( a ) mac_loadFramework( a ) | 
|---|
| 62 | #    define DYNLIB_GETSYM( a, b ) dlsym( a, b ) | 
|---|
| 63 | #    define DYNLIB_UNLOAD( a ) dlclose( a ) | 
|---|
| 64 |  | 
|---|
| 65 | #endif | 
|---|
| 66 |  | 
|---|
| 67 | namespace Ogre { | 
|---|
| 68 |         /** \addtogroup Core | 
|---|
| 69 |         *  @{ | 
|---|
| 70 |         */ | 
|---|
| 71 |         /** \addtogroup General | 
|---|
| 72 |         *  @{ | 
|---|
| 73 |         */ | 
|---|
| 74 |  | 
|---|
| 75 |     /** Resource holding data about a dynamic library. | 
|---|
| 76 |         @remarks | 
|---|
| 77 |             This class holds the data required to get symbols from | 
|---|
| 78 |             libraries loaded at run-time (i.e. from DLL's for so's) | 
|---|
| 79 |         @author | 
|---|
| 80 |             Adrian Cearn„u (cearny@cearny.ro) | 
|---|
| 81 |         @since | 
|---|
| 82 |             27 January 2002 | 
|---|
| 83 |     */ | 
|---|
| 84 |         class _OgreExport DynLib : public DynLibAlloc | 
|---|
| 85 |     { | 
|---|
| 86 |         protected: | 
|---|
| 87 |                 String mName; | 
|---|
| 88 |         /// Gets the last loading error | 
|---|
| 89 |         String dynlibError(void); | 
|---|
| 90 |     public: | 
|---|
| 91 |         /** Default constructor - used by DynLibManager. | 
|---|
| 92 |             @warning | 
|---|
| 93 |                 Do not call directly | 
|---|
| 94 |         */ | 
|---|
| 95 |         DynLib( const String& name ); | 
|---|
| 96 |  | 
|---|
| 97 |         /** Default destructor. | 
|---|
| 98 |         */ | 
|---|
| 99 |         ~DynLib(); | 
|---|
| 100 |  | 
|---|
| 101 |         /** Load the library | 
|---|
| 102 |         */ | 
|---|
| 103 |         void load(); | 
|---|
| 104 |         /** Unload the library | 
|---|
| 105 |         */ | 
|---|
| 106 |         void unload(); | 
|---|
| 107 |                 /// Get the name of the library | 
|---|
| 108 |                 const String& getName(void) const { return mName; } | 
|---|
| 109 |  | 
|---|
| 110 |         /** | 
|---|
| 111 |             Returns the address of the given symbol from the loaded library. | 
|---|
| 112 |             @param | 
|---|
| 113 |                 strName The name of the symbol to search for | 
|---|
| 114 |             @return | 
|---|
| 115 |                 If the function succeeds, the returned value is a handle to | 
|---|
| 116 |                 the symbol. | 
|---|
| 117 |             @par | 
|---|
| 118 |                 If the function fails, the returned value is <b>NULL</b>. | 
|---|
| 119 |  | 
|---|
| 120 |         */ | 
|---|
| 121 |         void* getSymbol( const String& strName ) const throw(); | 
|---|
| 122 |  | 
|---|
| 123 |     protected: | 
|---|
| 124 |  | 
|---|
| 125 |         /// Handle to the loaded library. | 
|---|
| 126 |         DYNLIB_HANDLE mInst; | 
|---|
| 127 |     }; | 
|---|
| 128 |         /** @} */ | 
|---|
| 129 |         /** @} */ | 
|---|
| 130 |  | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | #include "OgreHeaderSuffix.h" | 
|---|
| 134 |  | 
|---|
| 135 | #endif | 
|---|