Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <algorithm>
23 : #include <cassert>
24 : #include <stdarg.h>
25 :
26 : #include <osl/mutex.hxx>
27 : #include <osl/interlck.h>
28 : #include <rtl/ustring.hxx>
29 : #include <rtl/ustrbuf.hxx>
30 : #include <rtl/instance.hxx>
31 :
32 : #include <typelib/typedescription.h>
33 :
34 :
35 : using namespace osl;
36 :
37 : using ::rtl::OUString;
38 : using ::rtl::OUStringBuffer;
39 :
40 : extern "C"
41 : {
42 :
43 : //------------------------------------------------------------------------
44 : sal_Int32 SAL_CALL typelib_typedescription_getAlignedUnoSize(
45 : const typelib_TypeDescription * pTypeDescription,
46 : sal_Int32 nOffset,
47 : sal_Int32 & rMaxIntegralTypeSize )
48 : SAL_THROW_EXTERN_C();
49 : //------------------------------------------------------------------------
50 : void SAL_CALL typelib_typedescription_newEmpty(
51 : typelib_TypeDescription ** ppRet,
52 : typelib_TypeClass eTypeClass,
53 : rtl_uString * pTypeName )
54 : SAL_THROW_EXTERN_C();
55 : //-----------------------------------------------------------------------------
56 : void SAL_CALL typelib_typedescriptionreference_getByName(
57 : typelib_TypeDescriptionReference ** ppRet,
58 : rtl_uString * pName )
59 : SAL_THROW_EXTERN_C();
60 :
61 : #ifdef SAL_W32
62 : #pragma pack(push, 8)
63 : #endif
64 :
65 : /**
66 : * The double member determin the alignment.
67 : * Under Os2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
68 : * The aligment of a strukture is min( 8, sizeof( max basic type ) ), the greatest basic type
69 : * determine the aligment.
70 : */
71 : struct AlignSize_Impl
72 : {
73 : sal_Int16 nInt16;
74 : #ifdef AIX
75 : //double: doubleword aligned if -qalign=natural/-malign=natural
76 : //which isn't the default ABI. Otherwise word aligned, While a long long int
77 : //is always doubleword aligned, so use that instead.
78 : sal_Int64 dDouble;
79 : #else
80 : double dDouble;
81 : #endif
82 : };
83 :
84 : #ifdef SAL_W32
85 : #pragma pack(pop)
86 : #endif
87 :
88 : // the value of the maximal alignment
89 : static sal_Int32 nMaxAlignment = (sal_Int32)( (sal_Size)(&((AlignSize_Impl *) 16)->dDouble) - 16);
90 :
91 4691 : static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
92 : SAL_THROW(())
93 : {
94 4691 : if( nRequestedAlignment > nMaxAlignment )
95 0 : nRequestedAlignment = nMaxAlignment;
96 4691 : return nRequestedAlignment;
97 : }
98 :
99 : /**
100 : * Calculate the new size of the struktur.
101 : */
102 514 : static inline sal_Int32 newAlignedSize(
103 : sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
104 : SAL_THROW(())
105 : {
106 514 : NeededAlignment = adjustAlignment( NeededAlignment );
107 514 : return (OldSize + NeededAlignment -1) / NeededAlignment * NeededAlignment + ElementSize;
108 : }
109 :
110 : //--------------------------------------------------------------------------------------------------
111 :
112 : namespace
113 : {
114 : struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {};
115 : }
116 :
117 : // !for NOT REALLY WEAK TYPES only!
118 18568 : static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
119 : SAL_THROW(())
120 : {
121 18568 : typelib_TypeDescriptionReference * pRef = 0;
122 18568 : ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
123 18568 : if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
124 : {
125 11382 : return pRef;
126 : }
127 : else
128 : {
129 7186 : return 0;
130 : }
131 : }
132 :
133 : extern "C"
134 : {
135 : //##################################################################################################
136 1900896 : CPPU_DLLPUBLIC typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass(
137 : typelib_TypeClass eTypeClass )
138 : SAL_THROW_EXTERN_C()
139 : {
140 : static typelib_TypeDescriptionReference * s_aTypes[] = {
141 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
142 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 : 0, 0, 0 };
144 :
145 1900896 : if (! s_aTypes[eTypeClass])
146 : {
147 1518 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
148 1518 : if (! s_aTypes[eTypeClass])
149 : {
150 : static const char * s_aTypeNames[] = {
151 : "void", "char", "boolean", "byte",
152 : "short", "unsigned short", "long", "unsigned long",
153 : "hyper", "unsigned hyper", "float", "double",
154 : "string", "type", "any" };
155 :
156 1518 : switch (eTypeClass)
157 : {
158 : case typelib_TypeClass_EXCEPTION:
159 : case typelib_TypeClass_INTERFACE:
160 : {
161 : // type
162 264 : if (! s_aTypes[typelib_TypeClass_TYPE])
163 : {
164 263 : OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
165 : ::typelib_typedescriptionreference_new(
166 263 : &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
167 : // another static ref:
168 263 : ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
169 : }
170 : // any
171 264 : if (! s_aTypes[typelib_TypeClass_ANY])
172 : {
173 263 : OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
174 : ::typelib_typedescriptionreference_new(
175 263 : &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
176 : // another static ref:
177 263 : ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
178 : }
179 : // string
180 264 : if (! s_aTypes[typelib_TypeClass_STRING])
181 : {
182 261 : OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
183 : ::typelib_typedescriptionreference_new(
184 261 : &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
185 : // another static ref:
186 261 : ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
187 : }
188 : // XInterface
189 264 : if (! s_aTypes[typelib_TypeClass_INTERFACE])
190 : {
191 264 : OUString sTypeName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
192 :
193 264 : typelib_InterfaceTypeDescription * pTD = 0;
194 :
195 264 : typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
196 264 : OUString sMethodName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::queryInterface") );
197 : ::typelib_typedescriptionreference_new(
198 264 : &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
199 264 : OUString sMethodName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::acquire") );
200 : ::typelib_typedescriptionreference_new(
201 264 : &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
202 264 : OUString sMethodName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface::release") );
203 : ::typelib_typedescriptionreference_new(
204 264 : &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
205 :
206 : ::typelib_typedescription_newInterface(
207 : &pTD, sTypeName.pData, 0xe227a391, 0x33d6, 0x11d1, 0xaabe00a0, 0x249d5590,
208 264 : 0, 3, pMembers );
209 :
210 264 : ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD );
211 : ::typelib_typedescriptionreference_acquire(
212 264 : s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef );
213 : // another static ref:
214 264 : ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
215 264 : ::typelib_typedescription_release( (typelib_TypeDescription*)pTD );
216 :
217 264 : ::typelib_typedescriptionreference_release( pMembers[0] );
218 264 : ::typelib_typedescriptionreference_release( pMembers[1] );
219 264 : ::typelib_typedescriptionreference_release( pMembers[2] );
220 : // Exception
221 : assert( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
222 : {
223 264 : typelib_TypeDescription * pTD1 = 0;
224 264 : OUString sTypeName1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception") );
225 :
226 : typelib_CompoundMember_Init aMembers[2];
227 264 : OUString sMemberType0( RTL_CONSTASCII_USTRINGPARAM("string") );
228 264 : OUString sMemberName0( RTL_CONSTASCII_USTRINGPARAM("Message") );
229 264 : aMembers[0].eTypeClass = typelib_TypeClass_STRING;
230 264 : aMembers[0].pTypeName = sMemberType0.pData;
231 264 : aMembers[0].pMemberName = sMemberName0.pData;
232 264 : OUString sMemberType1( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface") );
233 264 : OUString sMemberName1( RTL_CONSTASCII_USTRINGPARAM("Context") );
234 264 : aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
235 264 : aMembers[1].pTypeName = sMemberType1.pData;
236 264 : aMembers[1].pMemberName = sMemberName1.pData;
237 :
238 : ::typelib_typedescription_new(
239 264 : &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
240 264 : typelib_typedescription_register( &pTD1 );
241 : typelib_typedescriptionreference_acquire(
242 264 : s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
243 : // another static ref:
244 264 : ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
245 : // RuntimeException
246 264 : OUString sTypeName2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
247 : ::typelib_typedescription_new(
248 264 : &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
249 264 : ::typelib_typedescription_register( &pTD1 );
250 264 : ::typelib_typedescription_release( pTD1 );
251 : }
252 : // XInterface members
253 264 : typelib_InterfaceMethodTypeDescription * pMethod = 0;
254 : typelib_Parameter_Init aParameters[1];
255 264 : OUString sParamName0( RTL_CONSTASCII_USTRINGPARAM("aType") );
256 264 : OUString sParamType0( RTL_CONSTASCII_USTRINGPARAM("type") );
257 264 : aParameters[0].pParamName = sParamName0.pData;
258 264 : aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
259 264 : aParameters[0].pTypeName = sParamType0.pData;
260 264 : aParameters[0].bIn = sal_True;
261 264 : aParameters[0].bOut = sal_False;
262 : rtl_uString * pExceptions[1];
263 264 : OUString sExceptionName0( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException") );
264 264 : pExceptions[0] = sExceptionName0.pData;
265 264 : OUString sReturnType0( RTL_CONSTASCII_USTRINGPARAM("any") );
266 : typelib_typedescription_newInterfaceMethod(
267 : &pMethod, 0, sal_False, sMethodName0.pData,
268 : typelib_TypeClass_ANY, sReturnType0.pData,
269 264 : 1, aParameters, 1, pExceptions );
270 264 : ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
271 :
272 264 : OUString sReturnType1( RTL_CONSTASCII_USTRINGPARAM("void") );
273 : ::typelib_typedescription_newInterfaceMethod(
274 : &pMethod, 1, sal_True, sMethodName1.pData,
275 264 : typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
276 264 : ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
277 :
278 : ::typelib_typedescription_newInterfaceMethod(
279 : &pMethod, 2, sal_True, sMethodName2.pData,
280 : typelib_TypeClass_VOID, sReturnType1.pData,
281 264 : 0, 0, 0, 0 );
282 264 : ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
283 264 : ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
284 : }
285 264 : break;
286 : }
287 : default:
288 : {
289 1254 : OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
290 1254 : ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
291 : // another static ref:
292 1254 : ++s_aTypes[eTypeClass]->nStaticRefCount;
293 : }
294 : }
295 1518 : }
296 : }
297 1900896 : return &s_aTypes[eTypeClass];
298 : }
299 :
300 : //##################################################################################################
301 18521 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_type_init(
302 : typelib_TypeDescriptionReference ** ppRef,
303 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
304 : SAL_THROW_EXTERN_C()
305 : {
306 18521 : if (! *ppRef)
307 : {
308 18521 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
309 18521 : if (! *ppRef)
310 : {
311 18521 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
312 18521 : ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
313 :
314 : // another static ref:
315 18521 : ++((*ppRef)->nStaticRefCount);
316 18521 : }
317 : }
318 18521 : }
319 :
320 : //##################################################################################################
321 12817 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_sequence_type_init(
322 : typelib_TypeDescriptionReference ** ppRef,
323 : typelib_TypeDescriptionReference * pElementType )
324 : SAL_THROW_EXTERN_C()
325 : {
326 12817 : if (! *ppRef)
327 : {
328 12817 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
329 12817 : if (! *ppRef)
330 : {
331 12817 : OUStringBuffer aBuf( 32 );
332 12817 : aBuf.appendAscii( "[]" );
333 12817 : aBuf.append( pElementType->pTypeName );
334 12817 : OUString aTypeName( aBuf.makeStringAndClear() );
335 :
336 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
337 12817 : *ppRef = igetTypeByName( aTypeName.pData );
338 12817 : if (!*ppRef)
339 : {
340 3009 : typelib_TypeDescription * pReg = 0;
341 : ::typelib_typedescription_new(
342 : &pReg, typelib_TypeClass_SEQUENCE,
343 3009 : aTypeName.pData, pElementType, 0, 0 );
344 :
345 3009 : ::typelib_typedescription_register( &pReg );
346 3009 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
347 : assert( *ppRef == pReg->pWeakRef );
348 : }
349 : // another static ref:
350 12817 : ++((*ppRef)->nStaticRefCount);
351 12817 : }
352 : }
353 12817 : }
354 :
355 : //##################################################################################################
356 : namespace {
357 :
358 3116 : void init(
359 : typelib_TypeDescriptionReference ** ppRef,
360 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
361 : typelib_TypeDescriptionReference * pBaseType,
362 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
363 : sal_Bool const * pParameterizedTypes)
364 : {
365 : assert( eTypeClass == typelib_TypeClass_STRUCT || eTypeClass == typelib_TypeClass_EXCEPTION );
366 :
367 3116 : if (! *ppRef)
368 : {
369 3116 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
370 3116 : if (! *ppRef)
371 : {
372 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
373 3116 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
374 3116 : *ppRef = igetTypeByName( aTypeName.pData );
375 3116 : if (!*ppRef)
376 : {
377 2056 : typelib_CompoundTypeDescription * pComp = 0;
378 : ::typelib_typedescription_newEmpty(
379 2056 : (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData );
380 :
381 2056 : sal_Int32 nOffset = 0;
382 2056 : if (pBaseType)
383 : {
384 : ::typelib_typedescriptionreference_getDescription(
385 2056 : (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType );
386 : assert( pComp->pBaseTypeDescription );
387 2056 : nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize;
388 : assert( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize ); // unexpected offset
389 : }
390 :
391 2056 : if (nMembers)
392 : {
393 514 : pComp->nMembers = nMembers;
394 514 : pComp->pMemberOffsets = new sal_Int32[ nMembers ];
395 514 : pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
396 514 : if (pParameterizedTypes != 0) {
397 : reinterpret_cast< typelib_StructTypeDescription * >(
398 : pComp)->pParameterizedTypes
399 0 : = new sal_Bool[nMembers];
400 : }
401 1028 : for ( sal_Int32 i = 0 ; i < nMembers; ++i )
402 : {
403 : ::typelib_typedescriptionreference_acquire(
404 514 : pComp->ppTypeRefs[i] = ppMembers[i] );
405 : // write offset
406 514 : typelib_TypeDescription * pTD = 0;
407 514 : TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
408 : assert( pTD->nSize ); // void member?
409 514 : nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
410 514 : pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
411 514 : TYPELIB_DANGER_RELEASE( pTD );
412 :
413 514 : if (pParameterizedTypes != 0) {
414 : reinterpret_cast< typelib_StructTypeDescription * >(
415 0 : pComp)->pParameterizedTypes[i]
416 0 : = pParameterizedTypes[i];
417 : }
418 : }
419 : }
420 :
421 2056 : typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp;
422 2056 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
423 : // sizeof( void ) not allowed
424 2056 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
425 2056 : pReg->nAlignment = adjustAlignment( pReg->nAlignment );
426 2056 : pReg->bComplete = sal_False;
427 :
428 2056 : ::typelib_typedescription_register( &pReg );
429 2056 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
430 : assert( *ppRef == pReg->pWeakRef );
431 : }
432 : // another static ref:
433 3116 : ++((*ppRef)->nStaticRefCount);
434 3116 : }
435 : }
436 3116 : }
437 :
438 : }
439 :
440 2827 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_compound_type_init(
441 : typelib_TypeDescriptionReference ** ppRef,
442 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
443 : typelib_TypeDescriptionReference * pBaseType,
444 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
445 : SAL_THROW_EXTERN_C()
446 : {
447 2827 : init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
448 2827 : }
449 :
450 289 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_struct_type_init(
451 : typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
452 : typelib_TypeDescriptionReference * pBaseType,
453 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
454 : sal_Bool const * pParameterizedTypes )
455 : SAL_THROW_EXTERN_C()
456 : {
457 : init(
458 : ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
459 289 : ppMembers, pParameterizedTypes);
460 289 : }
461 :
462 : //##################################################################################################
463 0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_interface_type_init(
464 : typelib_TypeDescriptionReference ** ppRef,
465 : const sal_Char * pTypeName,
466 : typelib_TypeDescriptionReference * pBaseType )
467 : SAL_THROW_EXTERN_C()
468 : {
469 : typelib_static_mi_interface_type_init(
470 0 : ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
471 0 : }
472 :
473 : //##################################################################################################
474 1607 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_mi_interface_type_init(
475 : typelib_TypeDescriptionReference ** ppRef,
476 : const sal_Char * pTypeName,
477 : sal_Int32 nBaseTypes,
478 : typelib_TypeDescriptionReference ** ppBaseTypes )
479 : SAL_THROW_EXTERN_C()
480 : {
481 1607 : if (! *ppRef)
482 : {
483 1607 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
484 1607 : if (! *ppRef)
485 : {
486 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
487 1607 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
488 1607 : *ppRef = igetTypeByName( aTypeName.pData );
489 1607 : if (!*ppRef)
490 : {
491 1607 : typelib_InterfaceTypeDescription * pIface = 0;
492 : ::typelib_typedescription_newEmpty(
493 1607 : (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData );
494 :
495 1607 : pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
496 : pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
497 1607 : pIface->nBaseTypes];
498 1607 : if (nBaseTypes > 0)
499 : {
500 1606 : for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
501 803 : pIface->ppBaseTypes[i] = 0;
502 : ::typelib_typedescriptionreference_getDescription(
503 803 : (typelib_TypeDescription **)&pIface->ppBaseTypes[i], ppBaseTypes[i] );
504 : assert( pIface->ppBaseTypes[i] );
505 : }
506 : }
507 : else
508 : {
509 804 : pIface->ppBaseTypes[0] = 0;
510 : ::typelib_typedescriptionreference_getDescription(
511 : (typelib_TypeDescription **)&pIface->ppBaseTypes[0],
512 804 : * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
513 : assert( pIface->ppBaseTypes[0] );
514 : }
515 1607 : pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
516 : typelib_typedescription_acquire(
517 1607 : &pIface->pBaseTypeDescription->aBase);
518 :
519 1607 : typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface;
520 1607 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
521 : // sizeof( void ) not allowed
522 1607 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
523 :
524 1607 : pReg->nAlignment = adjustAlignment( pReg->nAlignment );
525 1607 : pReg->bComplete = sal_False;
526 :
527 1607 : ::typelib_typedescription_register( &pReg );
528 1607 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
529 : assert( *ppRef == pReg->pWeakRef );
530 : }
531 : // another static ref:
532 1607 : ++((*ppRef)->nStaticRefCount);
533 1607 : }
534 : }
535 1607 : }
536 :
537 : //##################################################################################################
538 1028 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_enum_type_init(
539 : typelib_TypeDescriptionReference ** ppRef,
540 : const sal_Char * pTypeName,
541 : sal_Int32 nDefaultValue )
542 : SAL_THROW_EXTERN_C()
543 : {
544 1028 : if (! *ppRef)
545 : {
546 1028 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
547 1028 : if (! *ppRef)
548 : {
549 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
550 1028 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
551 1028 : *ppRef = igetTypeByName( aTypeName.pData );
552 1028 : if (!*ppRef)
553 : {
554 514 : typelib_TypeDescription * pReg = 0;
555 : ::typelib_typedescription_newEmpty(
556 514 : &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
557 514 : typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg;
558 :
559 514 : pEnum->nDefaultEnumValue = nDefaultValue;
560 :
561 514 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
562 : // sizeof( void ) not allowed
563 514 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
564 514 : pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
565 514 : pReg->bComplete = sal_False;
566 :
567 514 : ::typelib_typedescription_register( &pReg );
568 514 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
569 : assert( *ppRef == pReg->pWeakRef );
570 : }
571 : // another static ref:
572 1028 : ++((*ppRef)->nStaticRefCount);
573 1028 : }
574 : }
575 1028 : }
576 :
577 : //##################################################################################################
578 0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_array_type_init(
579 : typelib_TypeDescriptionReference ** ppRef,
580 : typelib_TypeDescriptionReference * pElementTypeRef,
581 : sal_Int32 nDimensions, ... )
582 : SAL_THROW_EXTERN_C()
583 : {
584 0 : if (! *ppRef)
585 : {
586 0 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
587 0 : if (! *ppRef)
588 : {
589 0 : OUStringBuffer aBuf( 32 );
590 0 : aBuf.append( pElementTypeRef->pTypeName );
591 :
592 : va_list dimArgs;
593 0 : va_start( dimArgs, nDimensions );
594 0 : sal_Int32 dim = 0;
595 0 : sal_Int32 nElements = 1;
596 0 : sal_Int32* pDimensions = new sal_Int32[nDimensions];
597 0 : for (sal_Int32 i=0; i < nDimensions; i++)
598 : {
599 0 : dim = va_arg( dimArgs, int);
600 0 : pDimensions[i] = dim;
601 0 : aBuf.appendAscii("[");
602 0 : aBuf.append(dim);
603 0 : aBuf.appendAscii("]");
604 0 : nElements *= dim;
605 : }
606 0 : va_end( dimArgs );
607 0 : OUString aTypeName( aBuf.makeStringAndClear() );
608 :
609 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ARRAY) );
610 0 : *ppRef = igetTypeByName( aTypeName.pData );
611 0 : if (!*ppRef)
612 : {
613 0 : typelib_TypeDescription * pReg = 0;
614 : ::typelib_typedescription_newEmpty(
615 0 : &pReg, typelib_TypeClass_ARRAY, aTypeName.pData );
616 0 : typelib_ArrayTypeDescription * pArray = (typelib_ArrayTypeDescription *)pReg;
617 :
618 0 : pArray->nDimensions = nDimensions;
619 0 : pArray->nTotalElements = nElements;
620 0 : pArray->pDimensions = pDimensions;
621 :
622 0 : typelib_typedescriptionreference_acquire(pElementTypeRef);
623 0 : ((typelib_IndirectTypeDescription*)pArray)->pType = pElementTypeRef;
624 :
625 0 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
626 : // sizeof( void ) not allowed
627 0 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
628 0 : pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
629 0 : pReg->bComplete = sal_True;
630 :
631 0 : ::typelib_typedescription_register( &pReg );
632 0 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
633 : assert( *ppRef == pReg->pWeakRef );
634 : } else
635 0 : delete [] pDimensions;
636 : // another static ref:
637 0 : ++((*ppRef)->nStaticRefCount);
638 0 : }
639 : }
640 0 : }
641 :
642 : } // extern "C"
643 :
644 : }
645 :
646 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|