1 /* NAME:
2 E3Extension.c
3
4 DESCRIPTION:
5 Implementation of Quesa API calls.
6
7 COPYRIGHT:
8 Copyright (c) 1999-2004, Quesa Developers. All rights reserved.
9
10 For the current release of Quesa, please see:
11
12 <http://www.quesa.org/>
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions
16 are met:
17
18 o Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20
21 o Redistributions in binary form must reproduce the above
22 copyright notice, this list of conditions and the following
23 disclaimer in the documentation and/or other materials provided
24 with the distribution.
25
26 o Neither the name of Quesa nor the names of its contributors
27 may be used to endorse or promote products derived from this
28 software without specific prior written permission.
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
36 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ___________________________________________________________________________
42 */
43 //=============================================================================
44 // Include files
45 //-----------------------------------------------------------------------------
46 #include "E3Prefix.h"
47 #include "E3Extension.h"
48
49
50
51
52
53 //=============================================================================
54 // Public functions
55 //-----------------------------------------------------------------------------
56 // E3XObjectHierarchy_RegisterClass : Register a new object class.
57 //-----------------------------------------------------------------------------
58 // Note : The Quesa class implementation does not support virtual
59 // methods, as methods are inherited from the parent metahandler.
60 //
61 // If you are using the virtual metahandler parameter, you will
62 // probably need to update the class tree to support this: please
63 // contact dair@refnum.com about this.
64 //
65 // In addition, we do not use the methodsSize parameter: if you
66 // understand how this parameter is used, please let me know - the
67 // comments in QD3DExtension.h seem to indicate that it's used to
68 // provide class specific private data, however the routine to
69 // access it (Q3ObjectClass_GetClassPrivate), does't actually
70 // exist (and so we don't support it).
71 //-----------------------------------------------------------------------------
72 TQ3XObjectClass
E3XObjectHierarchy_RegisterClass(TQ3ObjectType parentType,TQ3ObjectType * objectType,const char * objectName,TQ3XMetaHandler metaHandler,TQ3XMetaHandler virtualMetaHandler,TQ3Uns32 methodsSize,TQ3Uns32 instanceSize)73 E3XObjectHierarchy_RegisterClass(TQ3ObjectType parentType, TQ3ObjectType *objectType,
74 const char *objectName, TQ3XMetaHandler metaHandler,
75 TQ3XMetaHandler virtualMetaHandler, TQ3Uns32 methodsSize, TQ3Uns32 instanceSize)
76 { TQ3Status qd3dStatus;
77 E3ClassInfoPtr theClass;
78 #pragma unused(virtualMetaHandler)
79 #pragma unused(methodsSize)
80
81
82
83 // Make sure this class hasn't been registered
84 if ( E3ClassTree::GetClass ( objectName ) != NULL )
85 return(NULL);
86
87
88
89 // If parentType is kQ3ObjectTypeInvalid, use the root object as the parent
90 if (parentType == kQ3ObjectTypeInvalid)
91 parentType = kQ3ObjectTypeRoot;
92
93
94
95 // Allocate a unique type for this class
96 *objectType = E3ClassTree::GetNextClassType () ;
97
98
99
100 // Register the class
101 qd3dStatus = E3ClassTree::RegisterExternalClass(parentType,
102 *objectType,
103 objectName,
104 metaHandler,
105 instanceSize);
106 if (qd3dStatus != kQ3Success)
107 return(NULL);
108
109
110
111 // Find the class
112 theClass = E3ClassTree::GetClass ( *objectType ) ;
113
114 return((TQ3XObjectClass) theClass);
115 }
116
117
118
119
120
121 //=============================================================================
122 // E3XObjectHierarchy_UnregisterClass : Unregister a class.
123 //-----------------------------------------------------------------------------
124 // Note : We're not required to unregister the class, and so we allow
125 // the call to fail if there are still instances of the object.
126 //-----------------------------------------------------------------------------
127 TQ3Status
E3XObjectHierarchy_UnregisterClass(TQ3XObjectClass objectClass)128 E3XObjectHierarchy_UnregisterClass(TQ3XObjectClass objectClass)
129 { E3ClassInfoPtr theClass = (E3ClassInfoPtr) objectClass;
130 TQ3Status qd3dStatus;
131 TQ3ObjectType classType;
132
133
134
135 // Get the type of the class, and try and unregister it
136 classType = theClass->GetType () ;
137 qd3dStatus = E3ClassTree::UnregisterClass(classType, kQ3False);
138
139 return(qd3dStatus);
140 }
141
142
143
144
145
146 //=============================================================================
147 // E3XObjectHierarchy_NewObject : Instantiate a new object.
148 //-----------------------------------------------------------------------------
149 // Note : By passing true for the sharedParams parameter, we make sure
150 // that parent objects of the class are instantiaed with the same
151 // parameter data as the leaf class.
152 //
153 // This is the same behaviour as QD3D, although it's different
154 // from the normal Quesa scheme.
155 //-----------------------------------------------------------------------------
156 TQ3Object
E3XObjectHierarchy_NewObject(TQ3XObjectClass objectClass,void * parameters)157 E3XObjectHierarchy_NewObject(TQ3XObjectClass objectClass, void *parameters)
158 {
159 E3ClassInfoPtr theClass = (E3ClassInfoPtr) objectClass ;
160
161
162
163 // Get the type of the class, and instantiate it
164 return E3ClassTree::CreateInstance ( theClass->GetType (), kQ3True, parameters ) ;
165 }
166
167
168
169
170
171 //=============================================================================
172 // E3XObjectHierarchy_GetClassVersion : Get the version of a class.
173 //-----------------------------------------------------------------------------
174 TQ3Status
E3XObjectHierarchy_GetClassVersion(TQ3ObjectType objectClassType,TQ3XObjectClassVersion * version)175 E3XObjectHierarchy_GetClassVersion(TQ3ObjectType objectClassType, TQ3XObjectClassVersion *version)
176 {
177 // Initialise a return value
178 *version = 0 ;
179
180
181
182 // Find the class
183 E3ClassInfoPtr theClass = E3ClassTree::GetClass ( objectClassType ) ;
184 if ( theClass == NULL )
185 return kQ3Failure ;
186
187
188
189 // Get the version for the class
190 *version = (TQ3XObjectClassVersion) (long)theClass->GetMethod ( kQ3XMethodTypeObjectClassVersion );
191
192 return kQ3Success ;
193 }
194
195
196
197
198
199 //=============================================================================
200 // E3XObjectHierarchy_FindClassByType : Find a class.
201 //-----------------------------------------------------------------------------
202 TQ3XObjectClass
E3XObjectHierarchy_FindClassByType(TQ3ObjectType theType)203 E3XObjectHierarchy_FindClassByType(TQ3ObjectType theType)
204 {
205 // Find the class
206 return (TQ3XObjectClass) E3ClassTree::GetClass ( theType ) ;
207 }
208
209
210
211
212
213 //=============================================================================
214 // E3XObjectClass_GetMethod : Find a method for a class.
215 //-----------------------------------------------------------------------------
216 #pragma mark -
217 TQ3XFunctionPointer
E3XObjectClass_GetMethod(TQ3XObjectClass objectClass,TQ3XMethodType methodType)218 E3XObjectClass_GetMethod(TQ3XObjectClass objectClass, TQ3XMethodType methodType)
219 {
220 E3ClassInfoPtr theClass = (E3ClassInfoPtr) objectClass ;
221
222 // Get the method for the class
223 return theClass->GetMethod ( methodType ) ;
224 }
225
226
227
228
229
230 //=============================================================================
231 // E3XObjectClass_GetLeafType : Get the leaf type for a class.
232 //-----------------------------------------------------------------------------
233 TQ3ObjectType
E3XObjectClass_GetLeafType(TQ3XObjectClass objectClass)234 E3XObjectClass_GetLeafType(TQ3XObjectClass objectClass)
235 {
236 E3ClassInfoPtr theClass = (E3ClassInfoPtr) objectClass ;
237
238
239
240 // Get the type of the class
241 return theClass->GetType () ;
242 }
243
244
245
246
247
248 //=============================================================================
249 // E3XObjectClass_GetType : Get the type for a class.
250 //-----------------------------------------------------------------------------
251 // Note : It's not clear how the type of a class differs from the leaf
252 // type of the class (since, by definition, a class is a leaf
253 // unto itself - if the class has children, which type should
254 // be returned?), so we just return the type of the class.
255 //-----------------------------------------------------------------------------
256 TQ3Status
E3XObjectClass_GetType(TQ3XObjectClass objectClass,TQ3ObjectType * theType)257 E3XObjectClass_GetType(TQ3XObjectClass objectClass, TQ3ObjectType *theType)
258 {
259 E3ClassInfoPtr theClass = (E3ClassInfoPtr) objectClass ;
260
261
262
263 // Get the type of the class
264 *theType = theClass->GetType () ;
265
266 return kQ3Success ;
267 }
268
269
270
271
272
273 //=============================================================================
274 // E3XObjectClass_GetPrivate : Get the instance data for an object.
275 //-----------------------------------------------------------------------------
276 void *
E3XObjectClass_GetPrivate(TQ3XObjectClass objectClass,TQ3Object targetObject)277 E3XObjectClass_GetPrivate(TQ3XObjectClass objectClass, TQ3Object targetObject)
278 {
279 // Return the instance data
280 return targetObject->FindLeafInstanceData () ;
281 }
282
283
284
285
286
287 //=============================================================================
288 // E3XObject_GetClass : Get the class for an object.
289 //-----------------------------------------------------------------------------
290 TQ3XObjectClass
E3XObject_GetClass(TQ3Object object)291 E3XObject_GetClass(TQ3Object object)
292 {
293 // Return the class
294 return (TQ3XObjectClass) object->GetClass () ;
295 }
296
297
298
299
300
301 //=============================================================================
302 // E3XSharedLibrary_Register : Register a shared library.
303 //-----------------------------------------------------------------------------
304 // Note : Called during E3System_LoadPlugins, as plug-ins register their
305 // shared library details with Quesa.
306 //
307 // We simply save the library details in the global state, since
308 // E3System_LoadPlugins may need to impose some order on the
309 // actual plug-in registration.
310 //-----------------------------------------------------------------------------
311 #pragma mark -
312 TQ3Status
E3XSharedLibrary_Register(TQ3XSharedLibraryInfo * sharedLibraryInfo)313 E3XSharedLibrary_Register(TQ3XSharedLibraryInfo *sharedLibraryInfo)
314 { E3GlobalsPtr theGlobals = E3Globals_Get();
315 TQ3Status qd3dStatus;
316
317
318
319 // Try and allocate some space to save the library info
320 qd3dStatus = Q3Memory_Reallocate(&theGlobals->sharedLibraryInfo,
321 sizeof(TQ3XSharedLibraryInfo) *
322 (theGlobals->sharedLibraryCount+1));
323 if (qd3dStatus != kQ3Success)
324 return(qd3dStatus);
325
326
327
328 // Save the library info
329 theGlobals->sharedLibraryInfo[theGlobals->sharedLibraryCount] = *sharedLibraryInfo;
330 theGlobals->sharedLibraryCount++;
331
332 return(kQ3Success);
333 }
334
335
336
337
338
339 //=============================================================================
340 // E3XSharedLibrary_Unregister : Unregister a shared library.
341 //-----------------------------------------------------------------------------
342 // Note : Does nothing at the moment.
343 //-----------------------------------------------------------------------------
344 TQ3Status
E3XSharedLibrary_Unregister(TQ3Uns32 sharedLibrary)345 E3XSharedLibrary_Unregister(TQ3Uns32 sharedLibrary)
346 {
347
348
349 // Do nothing for now
350 return(kQ3Success);
351 }
352
353
354
355
356
357 //=============================================================================
358 // E3XError_Post : Post an error.
359 //-----------------------------------------------------------------------------
360 void
E3XError_Post(TQ3Error theError)361 E3XError_Post(TQ3Error theError)
362 { TQ3Boolean isFatal;
363
364
365
366 // Post the error
367 isFatal = (TQ3Boolean) (theError == kQ3ErrorInternalError || theError == kQ3ErrorNoRecovery);
368 E3ErrorManager_PostError(theError, isFatal);
369 }
370
371
372
373
374
375 //=============================================================================
376 // E3XWarning_Post : Post a warning.
377 //-----------------------------------------------------------------------------
378 void
E3XWarning_Post(TQ3Warning theWarning)379 E3XWarning_Post(TQ3Warning theWarning)
380 {
381
382
383 // Post the warning
384 E3ErrorManager_PostWarning(theWarning);
385 }
386
387
388
389
390
391 //=============================================================================
392 // E3XNotice_Post : Post a notice.
393 //-----------------------------------------------------------------------------
394 void
E3XNotice_Post(TQ3Notice theNotice)395 E3XNotice_Post(TQ3Notice theNotice)
396 {
397
398
399 // Post the notice
400 E3ErrorManager_PostNotice(theNotice);
401 }
402