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-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | // 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau |
---|
31 | |
---|
32 | #ifndef _DynLib_H__ |
---|
33 | #define _DynLib_H__ |
---|
34 | |
---|
35 | #include "CorePrereqs.h" |
---|
36 | |
---|
37 | #include <string> |
---|
38 | |
---|
39 | #if defined(ORXONOX_PLATFORM_WINDOWS) |
---|
40 | # define DYNLIB_HANDLE hInstance |
---|
41 | # define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) |
---|
42 | # define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b ) |
---|
43 | # define DYNLIB_UNLOAD( a ) !FreeLibrary( a ) |
---|
44 | |
---|
45 | struct HINSTANCE__; |
---|
46 | typedef struct HINSTANCE__* hInstance; |
---|
47 | |
---|
48 | #elif defined(ORXONOX_PLATFORM_LINUX) |
---|
49 | # define DYNLIB_HANDLE void* |
---|
50 | # define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL) |
---|
51 | # define DYNLIB_GETSYM( a, b ) dlsym( a, b ) |
---|
52 | # define DYNLIB_UNLOAD( a ) dlclose( a ) |
---|
53 | |
---|
54 | #elif defined(ORXONOX_PLATFORM_APPLE) |
---|
55 | # define DYNLIB_HANDLE CFBundleRef |
---|
56 | # define DYNLIB_LOAD( a ) mac_loadExeBundle( a ) |
---|
57 | # define DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b ) |
---|
58 | # define DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a ) |
---|
59 | #endif |
---|
60 | |
---|
61 | namespace orxonox |
---|
62 | { |
---|
63 | /** Resource holding data about a dynamic library. |
---|
64 | @remarks |
---|
65 | This class holds the data required to get symbols from |
---|
66 | libraries loaded at run-time (i.e. from DLL's for so's) |
---|
67 | @author |
---|
68 | Adrian Cearnãu (cearny@cearny.ro) |
---|
69 | @since |
---|
70 | 27 January 2002 |
---|
71 | @see |
---|
72 | Resource |
---|
73 | */ |
---|
74 | class _CoreExport DynLib |
---|
75 | { |
---|
76 | protected: |
---|
77 | std::string mName; |
---|
78 | /// Gets the last loading error |
---|
79 | std::string dynlibError(void); |
---|
80 | public: |
---|
81 | /** Default constructor - used by DynLibManager. |
---|
82 | @warning |
---|
83 | Do not call directly |
---|
84 | */ |
---|
85 | DynLib( const std::string& name ); |
---|
86 | |
---|
87 | /** Default destructor. |
---|
88 | */ |
---|
89 | ~DynLib(); |
---|
90 | |
---|
91 | /** Load the library |
---|
92 | */ |
---|
93 | void load(); |
---|
94 | /** Unload the library |
---|
95 | */ |
---|
96 | void unload(); |
---|
97 | /// Get the name of the library |
---|
98 | const std::string& getName(void) const { return mName; } |
---|
99 | |
---|
100 | /** |
---|
101 | Returns the address of the given symbol from the loaded library. |
---|
102 | @param |
---|
103 | strName The name of the symbol to search for |
---|
104 | @returns |
---|
105 | If the function succeeds, the returned value is a handle to |
---|
106 | the symbol. |
---|
107 | @par |
---|
108 | If the function fails, the returned value is <b>NULL</b>. |
---|
109 | |
---|
110 | */ |
---|
111 | void* getSymbol( const std::string& strName ) const throw(); |
---|
112 | |
---|
113 | protected: |
---|
114 | |
---|
115 | /// Handle to the loaded library. |
---|
116 | DYNLIB_HANDLE m_hInst; |
---|
117 | }; |
---|
118 | |
---|
119 | } |
---|
120 | |
---|
121 | #endif |
---|