2
// Copyright � 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.org
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_POSIX
41
// For Mac OS X, define MACOSX_NO_LIBDL if libdl not installed
42
#ifndef MACOSX_NO_LIBDL
43
#include <dlfcn.h> /* dlopen() */
46
#endif /* AQSIS_SYSTEM_POSIX */
53
START_NAMESPACE( Aqsis )
56
//---------------------------------------------------------------------
58
* These function abstract dlopen,dlsym and dlclose for win32, OS-X, BeOS
62
CqPluginBase::DLOpen( CqString *library )
65
Aqsis::log() << info << "Loading plugin \"" << library->c_str() << "\"" << std::endl;
68
#ifdef AQSIS_SYSTEM_WIN32
70
handle = ( void* ) LoadLibrary( library->c_str() );
73
CqString tstring = *library;
74
CqString::size_type pos = tstring.find ("/");
75
if (pos == CqString::npos)
76
tstring = CqString("./") + *library;
77
handle = ( void * ) dlopen( tstring.c_str(), RTLD_NOW | RTLD_GLOBAL );
82
m_activeHandles.push_back( handle );
87
CqPluginBase::DLSym( void *handle, CqString *symbol )
89
void * location = NULL;
96
#if defined (AQSIS_SYSTEM_WIN32) //Win32 LoadProc support
97
location = ( void * ) GetProcAddress( ( HINSTANCE ) handle, symbol->c_str() );
100
location = ( void * ) dlsym( handle, symbol->c_str() );
111
CqPluginBase::DLClose( void *handle )
117
#if defined (AQSIS_SYSTEM_WIN32) //Win32 LoadProc support
118
FreeLibrary( ( HINSTANCE ) handle );
125
m_activeHandles.remove( handle );
129
CqPluginBase::~CqPluginBase()
131
while ( !m_activeHandles.empty() )
133
if ( m_activeHandles.front() != NULL )
134
DLClose( m_activeHandles.front() );
140
CqPluginBase::DLError( void )
144
#ifdef AQSIS_SYSTEM_WIN32
148
FORMAT_MESSAGE_ALLOCATE_BUFFER |
149
FORMAT_MESSAGE_FROM_SYSTEM |
150
FORMAT_MESSAGE_IGNORE_INSERTS,
153
MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
154
( LPTSTR ) & lpMsgBuf,
158
// Process any inserts in lpMsgBuf.
160
// Display the string.
161
errorlog = ( CqString ) ( LPCTSTR ) lpMsgBuf ;
164
LocalFree( lpMsgBuf );
165
#elif not defined AQSIS_SYSTEM_MACOSX
167
char* error = dlerror();
174
errorlog = "Aqsis was built without plugin support\n";
180
END_NAMESPACE( Aqsis )
181
//---------------------------------------------------------------------