2
// Copyright � 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Implements CqPluginBase plugin loader/deloader for textures/riprocedural/shared objects for shaders
23
\author Michel Joron (joron@sympatico.ca)
34
#ifdef AQSIS_SYSTEM_WIN32
35
#include <Windows.h> /* LoadLibrary() */
36
#endif /* AQSIS_SYSTEM_WIN32 */
38
#ifdef AQSIS_SYSTEM_BEOS
39
#endif /* AQSIS_SYSTEM_BEOS */
41
#ifdef AQSIS_SYSTEM_MACOSX
44
// For Mac OS X, define MACOSX_NO_LIBDL if libdl not installed
45
#ifndef MACOSX_NO_LIBDL
46
#include <dlfcn.h> /* dlopen() */
49
#endif /* AQSIS_SYSTEM_MACOSX */
50
#ifdef AQSIS_SYSTEM_POSIX
53
// For Mac OS X, define MACOSX_NO_LIBDL if libdl not installed
54
#ifndef MACOSX_NO_LIBDL
55
#include <dlfcn.h> /* dlopen() */
58
#endif /* AQSIS_SYSTEM_POSIX */
64
START_NAMESPACE( Aqsis )
67
//---------------------------------------------------------------------
69
* These function abstract dlopen,dlsym and dlclose for win32, OS-X, BeOS
73
CqPluginBase::DLOpen( CqString *library )
78
#ifdef AQSIS_SYSTEM_WIN32
79
handle = ( void* ) LoadLibrary( library->c_str() );
80
#elif defined (AQSIS_SYSTEM_MACOSX)
81
# ifndef MACOSX_NO_LIBDL
82
handle = ( void * ) dlopen( library->c_str(), RTLD_NOW | RTLD_GLOBAL );
84
#elif defined (AQSIS_SYSTEM_BEOS)
85
// We probably need an interface for CFPlugins here
86
// But for now, we will not implement plugins
88
handle = ( void * ) dlopen( library->c_str(), RTLD_LAZY );
91
if ( handle ) m_activeHandles.push_back( handle );
96
CqPluginBase::DLSym( void *handle, CqString *symbol )
98
void * location = NULL;
104
#if defined (AQSIS_SYSTEM_WIN32) //Win32 LoadProc support
105
location = ( void * ) GetProcAddress( ( HINSTANCE ) handle, symbol->c_str() );
106
#elif defined (AQSIS_SYSTEM_MACOSX)
107
# ifndef MACOSX_NO_LIBDL
108
location = ( void * ) dlsym( handle, ( CqString( "_" ) + *symbol ).c_str() );
110
#elif defined (AQSIS_SYSTEM_BEOS)
111
// We probably need an interface for CFPlugins here
112
// But for now, we will not implement plugins
114
//this is the same as MacOS-X but we might aswell keep the same seperation for the moment
115
location = ( void * ) dlsym( handle, symbol->c_str() );
125
CqPluginBase::DLClose( void *handle )
131
#if defined (AQSIS_SYSTEM_WIN32) //Win32 LoadProc support
132
FreeLibrary( ( HINSTANCE ) handle );
133
#elif defined (AQSIS_SYSTEM_MACOSX)
134
# ifndef MACOSX_NO_LIBDL
137
#elif defined (AQSIS_SYSTEM_BEOS)
138
// We probably need an interface for CFPlugins here
139
// But for now, we will not implement plugins
141
//this is the same as MacOS-X but we might aswell keep the same seperation for the moment
146
m_activeHandles.remove( handle );
150
CqPluginBase::~CqPluginBase()
152
while ( !m_activeHandles.empty() )
154
if ( m_activeHandles.front() != NULL )
155
DLClose( m_activeHandles.front() );
161
CqPluginBase::DLError( void )
165
#ifdef AQSIS_SYSTEM_WIN32
168
FORMAT_MESSAGE_ALLOCATE_BUFFER |
169
FORMAT_MESSAGE_FROM_SYSTEM |
170
FORMAT_MESSAGE_IGNORE_INSERTS,
173
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
174
( LPTSTR ) & lpMsgBuf,
178
// Process any inserts in lpMsgBuf.
180
// Display the string.
181
errorlog = ( CqString ) ( LPCTSTR ) lpMsgBuf ;
184
LocalFree( lpMsgBuf );
186
errorlog = dlerror() ;
190
errorlog = "Aqsis was built without plugin support\n";
195
END_NAMESPACE( Aqsis )
196
//---------------------------------------------------------------------