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

« back to all changes in this revision

Viewing changes to .pc/bug#624504_ftbfs-boost_1.46/libs/shadervm/dsoshadeops.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-05-28 14:47:48 UTC
  • mfrom: (2.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110528144748-zqd2v88cakc9pm1u
Tags: 1.6.0-5ubuntu1
* Merge from debian unstable.  Remaining changes:
  - added transitional package aqsis-data to install aqsis-examples
  - bump Replaces and Breaks version on aqsis-data in aqsis-examples package,
    to avoid having aqsis-data ans aqsis-examples on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright (C) 1997 - 2001, Paul C. Gregory // // Contact: pgregory@aqsis.org //
 
3
// This library is free software; you can redistribute it and/or
 
4
// modify it under the terms of the GNU General Public
 
5
// License as published by the Free Software Foundation; either
 
6
// version 2 of the License, or (at your option) any later version.
 
7
//
 
8
// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
10
// General Public License for more details.
 
11
//
 
12
// You should have received a copy of the GNU General Public
 
13
// License along with this library; if not, write to the Free Software
 
14
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
 
 
16
/** \file
 
17
                \brief Implements the classes and support structures for DSO shadeops
 
18
                \author Tristan Colgate <tristan@inuxtech.co.uk>
 
19
*/
 
20
 
 
21
#include <aqsis/aqsis.h>
 
22
 
 
23
#include <cstring>
 
24
 
 
25
#include <boost/filesystem.hpp>
 
26
 
 
27
#include "dsoshadeops.h"
 
28
#include <aqsis/util/file.h>
 
29
#include <aqsis/util/logging.h>
 
30
 
 
31
namespace Aqsis {
 
32
 
 
33
//---------------------------------------------------------------------
 
34
CqString
 
35
CqDSORepository::strPrototype(CqString *strFuncName, SqDSOExternalCall *pExtCall)
 
36
{
 
37
        CqString strProt;
 
38
        EqVariableType type;
 
39
 
 
40
        type = pExtCall->return_type;
 
41
        m_itTypeNameMap = m_TypeNameMap.begin();
 
42
        while (m_itTypeNameMap != m_TypeNameMap.end() &&
 
43
                (*m_itTypeNameMap).second != type)
 
44
        {
 
45
                m_itTypeNameMap++ ;
 
46
        };
 
47
        if(m_itTypeNameMap != m_TypeNameMap.end())
 
48
        {
 
49
                strProt = (*m_itTypeNameMap).first + " ";
 
50
        }
 
51
        else
 
52
        {
 
53
                strProt += "Unkown ";
 
54
        };
 
55
 
 
56
        strProt += *strFuncName + " ( ";
 
57
 
 
58
        std::list<EqVariableType>::iterator it = pExtCall->arg_types.begin();
 
59
        while( it != pExtCall->arg_types.end())
 
60
        {
 
61
                type = (*it);
 
62
                m_itTypeNameMap = m_TypeNameMap.begin();
 
63
                while (m_itTypeNameMap != m_TypeNameMap.end() &&
 
64
                        (*m_itTypeNameMap).second != type)
 
65
                {
 
66
                        m_itTypeNameMap++ ;
 
67
                };
 
68
                if(m_itTypeNameMap != m_TypeNameMap.end())
 
69
                {
 
70
                        strProt += (*m_itTypeNameMap).first + " ";
 
71
                }
 
72
                else
 
73
                {
 
74
                        strProt += "Unkown ";
 
75
                };
 
76
 
 
77
                it++ ;
 
78
        };
 
79
 
 
80
        strProt += ")";
 
81
 
 
82
        return strProt;
 
83
};
 
84
 
 
85
//---------------------------------------------------------------------
 
86
void CqDSORepository::SetDSOPath(const char* pathStr)
 
87
{
 
88
        if ( pathStr == NULL )
 
89
                return;
 
90
 
 
91
        // Scan through all the paths in the search path
 
92
        std::string pathString = pathStr;
 
93
        TqPathsTokenizer paths(pathString);
 
94
        for(TqPathsTokenizer::iterator path = paths.begin(), end = paths.end();
 
95
                        path != end; ++path)
 
96
        {
 
97
                try
 
98
                {
 
99
                        if(boost::filesystem::is_directory(*path))
 
100
                        {
 
101
                                // If the path points to a directory, we add each library in the
 
102
                                // named directory to the list of DSO candidates.
 
103
                                std::vector<std::string> files = Glob(
 
104
                                                ((*path)/"*" SHARED_LIBRARY_SUFFIX).file_string() );
 
105
                                m_DSOPathList.insert(m_DSOPathList.end(), files.begin(), files.end());
 
106
                        }
 
107
                        else
 
108
                        {
 
109
                                // else add the file itself.
 
110
                                m_DSOPathList.push_back(path->file_string());
 
111
                        }
 
112
                }
 
113
                catch(boost::filesystem::filesystem_error& /*e*/)
 
114
                {
 
115
                        // ignore any errors.
 
116
                }
 
117
        }
 
118
}
 
119
 
 
120
 
 
121
//---------------------------------------------------------------------
 
122
/**  This returns a list of descriptors of calls to external DSO functions that
 
123
 * implement a named shadeop, entries are returned for each polymorphic function
 
124
 */
 
125
std::list<SqDSOExternalCall*>*
 
126
CqDSORepository::getShadeOpMethods(CqString* pShadeOpName)
 
127
{
 
128
        CqString strTableSymbol = *pShadeOpName + "_shadeops" ;
 
129
 
 
130
        std::list<SqDSOExternalCall*>* oplist = new (std::list<SqDSOExternalCall*>);
 
131
        std::list<CqString>::iterator itPathEntry;
 
132
        SqShadeOp *pTableSymbol = NULL;
 
133
 
 
134
        Aqsis::log() << debug << "Looking for DSO candidates for shadeop \"" << pShadeOpName->c_str() << "\"" << std::endl;
 
135
        for ( itPathEntry = m_DSOPathList.begin() ; itPathEntry != m_DSOPathList.end() ; itPathEntry++ )
 
136
        {
 
137
                Aqsis::log() << debug << "Looking in shared library : " << itPathEntry->c_str() << std::endl;
 
138
                void *handle = DLOpen( &(*itPathEntry) );
 
139
 
 
140
                if( handle != NULL )
 
141
                {
 
142
                        pTableSymbol = (SqShadeOp*) DLSym( handle, &strTableSymbol );
 
143
 
 
144
                        if ( pTableSymbol != NULL )
 
145
                        {
 
146
                                //We have an appropriate named shadeop table
 
147
                                SqShadeOp *pShadeOp = (SqShadeOp*) pTableSymbol;
 
148
                                while( ( pShadeOp->m_opspec )[0] != (char) NULL )
 
149
                                {
 
150
                                        SqDSOExternalCall *pDSOCall = NULL;
 
151
                                        pDSOCall = parseShadeOpTableEntry( handle, pShadeOp );
 
152
                                        if ( pDSOCall != NULL )
 
153
                                                oplist->push_back( pDSOCall );
 
154
 
 
155
                                        pShadeOp++;
 
156
                                };
 
157
                        };
 
158
 
 
159
                        // Failure here does not neccesarily mean anything since
 
160
                }
 
161
                else
 
162
                {
 
163
                        CqString strError = DLError();
 
164
                        Aqsis::log() << error << "DLOpen: " << strError.c_str() << std::endl;
 
165
                };
 
166
        };
 
167
        std::stringstream resultStr;
 
168
        if(oplist->empty())
 
169
                resultStr << "(none found)";
 
170
        else
 
171
                resultStr << "(found " << oplist->size() << " possibilities)";
 
172
        Aqsis::log() << debug << "Finished looking for DSO candidates "<< resultStr.str().c_str() << std::endl;
 
173
        return ( oplist->empty() ? NULL : oplist );
 
174
};
 
175
 
 
176
//---------------------------------------------------------------------
 
177
/** We have found a plugins with the desried shadeop table in it
 
178
 * For each shaeop table entry we parse the prototype and validate all
 
179
 * symbols that are named by the shadeop entry.
 
180
 */
 
181
 
 
182
SqDSOExternalCall*
 
183
CqDSORepository::parseShadeOpTableEntry(void* handle, SqShadeOp* pShadeOpEntry)
 
184
{
 
185
 
 
186
        TqInt length = strlen(pShadeOpEntry->m_opspec)+1;
 
187
        char temp[1024];
 
188
        strncpy(temp, pShadeOpEntry->m_opspec,length);
 
189
 
 
190
        // We remove all the '(),' charachters, so we are left with
 
191
        //   returntype name argtype ...
 
192
        for (int x = 0; x < length; x++)
 
193
                if(temp[x]=='('||temp[x]==')'||temp[x]==',')
 
194
                        temp[x]=' ';
 
195
 
 
196
        CqString strSpec(temp);
 
197
 
 
198
        // Get the return type of the function
 
199
        std::string strRetType;
 
200
 
 
201
 
 
202
        strRetType = strtok(temp, " ");
 
203
        m_itTypeNameMap = m_TypeNameMap.find(strRetType.c_str());
 
204
 
 
205
        // ERROR if we cant find this types name;
 
206
        if (m_itTypeNameMap == m_TypeNameMap.end())
 
207
        {
 
208
                Aqsis::log() << warning << "Discarding DSO Table entry due to unsupported return type: \"" << strRetType.c_str() << "\"" << std::endl;
 
209
                return NULL;
 
210
        }
 
211
        EqVariableType rettype = (*m_itTypeNameMap).second;
 
212
 
 
213
 
 
214
        // Get function name
 
215
        std::string strMethodName;
 
216
 
 
217
        strMethodName = strtok(NULL, " ");
 
218
        CqString s = strMethodName.c_str();
 
219
        DSOMethod method = (DSOMethod) DLSym (handle,&s);
 
220
        if(method == NULL)
 
221
        {
 
222
                Aqsis::log() << warning << "Discarding DSO Table entry due to unknown symbol for method: \"" << strMethodName.c_str() << "\"" << std::endl;
 
223
                return NULL;
 
224
        };
 
225
 
 
226
 
 
227
        // Parse each arg type, presumably we need to handle arrays here
 
228
        std::list<EqVariableType> arglist;
 
229
        char *nextarg = NULL;
 
230
        do
 
231
        {
 
232
                // Get the next arguments type
 
233
                std::string strArgType;
 
234
 
 
235
                nextarg = strtok(NULL, " ");
 
236
                if (nextarg == NULL)
 
237
                        break;
 
238
                strArgType = nextarg;
 
239
                m_itTypeNameMap = m_TypeNameMap.find(strArgType.c_str());
 
240
 
 
241
                // ERROR if we cant find this arguments type name;
 
242
                if (m_itTypeNameMap == m_TypeNameMap.end())
 
243
                {
 
244
                        Aqsis::log() << warning << "Discarding DSO Table entry due to unsupported argument type: \"" << strArgType.c_str() << "\"" << std::endl;
 
245
                        return NULL;
 
246
                };
 
247
                arglist.push_back((*m_itTypeNameMap).second);
 
248
 
 
249
        }
 
250
        while(nextarg);
 
251
 
 
252
        // Check if there is a valid init function
 
253
        CqString strInit = pShadeOpEntry->m_init;
 
254
        DSOInit initfunc = NULL;
 
255
        if (strcmp(pShadeOpEntry->m_init,""))
 
256
        {
 
257
                initfunc = (DSOInit) DLSym(handle,&strInit);
 
258
                if (initfunc == NULL)
 
259
                {
 
260
                        Aqsis::log() << warning << "Discarding DSO Table entry due to unknown symbol for init: \"" << strInit.c_str() << "\"" << std::endl;
 
261
                        return NULL; // ERROR ;
 
262
                };
 
263
        }
 
264
 
 
265
        // Check if there is a valid shutdown function
 
266
        CqString strShutdown = pShadeOpEntry->m_shutdown;
 
267
        DSOShutdown shutdownfunc = NULL;
 
268
        if (strcmp(pShadeOpEntry->m_shutdown,""))
 
269
        {
 
270
                shutdownfunc = (DSOShutdown) DLSym(handle,&strShutdown);
 
271
                if (shutdownfunc == NULL)
 
272
                {
 
273
                        Aqsis::log() << warning << "Discarding DSO Table entry due to unknown symbol for shutdown: \"" << strShutdown.c_str() << "\"" << std::endl;
 
274
                        return NULL; // ERROR ;
 
275
                };
 
276
        };
 
277
 
 
278
 
 
279
        // We have a valid shadeop implementation
 
280
        SqDSOExternalCall *ret = new SqDSOExternalCall;
 
281
        ret->method = method;
 
282
        ret->init = initfunc;
 
283
        ret->shutdown = shutdownfunc;
 
284
        ret->return_type = rettype;
 
285
        ret->arg_types = arglist;
 
286
        ret->initData = NULL;
 
287
        ret->initialised = false;
 
288
 
 
289
        return ret;
 
290
};
 
291
 
 
292
 
 
293
} // namespace Aqsis
 
294
//---------------------------------------------------------------------