~ubuntu-branches/ubuntu/quantal/aqsis/quantal

« back to all changes in this revision

Viewing changes to aqsistypes/plugins.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-06 04:53:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806045326-z6xeaaao62idxcc6
Tags: 1.6.0-0ubuntu1
* New upstream release
* debian/control:
  - changed name of lib package to libaqsis1 instead of aqsis-libsc2a
  - changed name of dev package to libaqsis-dev instead of aqsis-libs-dev
  - Added aqsis-data package
  - Revised summary text according to that specified by the RISpec (Pixar)
* Moved examples installation from aqsis.install to aqsis-data.install
* debian/rules: 
  - added content to binary-indep target
* debian/rules: added explicit name of mime file to force dh_installmime
  to generate postinst and prerm scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Aqsis
2
 
// Copyright � 1997 - 2001, Paul C. Gregory
3
 
//
4
 
// Contact: pgregory@aqsis.org
5
 
//
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.
10
 
//
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.
15
 
//
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
19
 
 
20
 
 
21
 
/** \file
22
 
                \brief Implements CqPluginBase plugin loader/deloader for textures/riprocedural/shared objects for shaders
23
 
                \author Michel Joron (joron@sympatico.ca)
24
 
*/
25
 
 
26
 
 
27
 
#include <stdio.h>
28
 
#include <string.h>
29
 
 
30
 
 
31
 
 
32
 
#include "aqsis.h"
33
 
 
34
 
#ifdef AQSIS_SYSTEM_WIN32
35
 
#include <Windows.h>                /* LoadLibrary() */
36
 
#endif /* AQSIS_SYSTEM_WIN32 */
37
 
 
38
 
#ifdef AQSIS_SYSTEM_POSIX
39
 
extern "C"
40
 
{
41
 
        // For Mac OS X, define MACOSX_NO_LIBDL if libdl not installed
42
 
#ifndef MACOSX_NO_LIBDL
43
 
#include <dlfcn.h>                /* dlopen() */
44
 
#endif
45
 
}
46
 
#endif /* AQSIS_SYSTEM_POSIX */
47
 
 
48
 
 
49
 
#include "plugins.h"
50
 
#include "logging.h"
51
 
 
52
 
 
53
 
START_NAMESPACE( Aqsis )
54
 
 
55
 
 
56
 
//---------------------------------------------------------------------
57
 
/** dlfunc wrappers
58
 
 * These function abstract dlopen,dlsym and dlclose for win32, OS-X, BeOS 
59
 
 * and POSIX etc.
60
 
 */
61
 
void *
62
 
CqPluginBase::DLOpen( CqString *library )
63
 
{
64
 
        void * handle = NULL;
65
 
        Aqsis::log() << info << "Loading plugin \"" << library->c_str() << "\"" << std::endl;
66
 
 
67
 
#ifdef  PLUGINS
68
 
#ifdef AQSIS_SYSTEM_WIN32
69
 
 
70
 
        handle = ( void* ) LoadLibrary( library->c_str() );
71
 
#else
72
 
 
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 );
78
 
#endif
79
 
#endif
80
 
 
81
 
        if ( handle )
82
 
                m_activeHandles.push_back( handle );
83
 
        return handle;
84
 
}
85
 
 
86
 
void *
87
 
CqPluginBase::DLSym( void *handle, CqString *symbol )
88
 
{
89
 
        void * location = NULL;
90
 
 
91
 
#ifdef  PLUGINS
92
 
 
93
 
        if ( handle )
94
 
        {
95
 
 
96
 
#if   defined (AQSIS_SYSTEM_WIN32) //Win32 LoadProc support
97
 
                location = ( void * ) GetProcAddress( ( HINSTANCE ) handle, symbol->c_str() );
98
 
#else
99
 
 
100
 
                location = ( void * ) dlsym( handle, symbol->c_str() );
101
 
#endif
102
 
 
103
 
        };
104
 
 
105
 
#endif
106
 
 
107
 
        return location;
108
 
}
109
 
 
110
 
void
111
 
CqPluginBase::DLClose( void *handle )
112
 
{
113
 
#ifdef  PLUGINS
114
 
        if ( handle )
115
 
        {
116
 
 
117
 
#if   defined (AQSIS_SYSTEM_WIN32) //Win32 LoadProc support
118
 
                FreeLibrary( ( HINSTANCE ) handle );
119
 
#else
120
 
 
121
 
                dlclose( handle );
122
 
#endif
123
 
 
124
 
        };
125
 
        m_activeHandles.remove( handle );
126
 
#endif
127
 
}
128
 
 
129
 
CqPluginBase::~CqPluginBase()
130
 
{
131
 
        while ( !m_activeHandles.empty() )
132
 
        {
133
 
                if ( m_activeHandles.front() != NULL )
134
 
                        DLClose( m_activeHandles.front() );
135
 
        };
136
 
};
137
 
 
138
 
 
139
 
const CqString
140
 
CqPluginBase::DLError( void )
141
 
{
142
 
        CqString errorlog;
143
 
#ifdef  PLUGINS
144
 
#ifdef AQSIS_SYSTEM_WIN32
145
 
 
146
 
        LPVOID lpMsgBuf;
147
 
        FormatMessage(
148
 
            FORMAT_MESSAGE_ALLOCATE_BUFFER |
149
 
            FORMAT_MESSAGE_FROM_SYSTEM |
150
 
            FORMAT_MESSAGE_IGNORE_INSERTS,
151
 
            NULL,
152
 
            GetLastError(),
153
 
            MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),   // Default language
154
 
            ( LPTSTR ) & lpMsgBuf,
155
 
            0,
156
 
            NULL
157
 
        );
158
 
        // Process any inserts in lpMsgBuf.
159
 
        // ...
160
 
        // Display the string.
161
 
        errorlog = ( CqString ) ( LPCTSTR ) lpMsgBuf ;
162
 
 
163
 
        // Free the buffer.
164
 
        LocalFree( lpMsgBuf );
165
 
#elif not defined AQSIS_SYSTEM_MACOSX
166
 
 
167
 
        char* error = dlerror();
168
 
        if( error )
169
 
                errorlog = error;
170
 
#endif
171
 
 
172
 
#else
173
 
 
174
 
        errorlog = "Aqsis was built without plugin support\n";
175
 
#endif
176
 
 
177
 
        return errorlog;
178
 
}
179
 
 
180
 
END_NAMESPACE( Aqsis )
181
 
//---------------------------------------------------------------------
182