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 determines the alignment.
67 : * Under OS2 and MS-Windows the Alignment is min( 8, sizeof( type ) ).
68 : * The alignment of a structure is min( 8, sizeof( max basic type ) ), the greatest basic type
69 : * determines the alignment.
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 9 : static inline sal_Int32 adjustAlignment( sal_Int32 nRequestedAlignment )
92 : SAL_THROW(())
93 : {
94 9 : if( nRequestedAlignment > nMaxAlignment )
95 0 : nRequestedAlignment = nMaxAlignment;
96 9 : return nRequestedAlignment;
97 : }
98 :
99 : /**
100 : * Calculate the new size of the struktur.
101 : */
102 0 : static inline sal_Int32 newAlignedSize(
103 : sal_Int32 OldSize, sal_Int32 ElementSize, sal_Int32 NeededAlignment )
104 : SAL_THROW(())
105 : {
106 0 : NeededAlignment = adjustAlignment( NeededAlignment );
107 0 : 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 26050 : static inline typelib_TypeDescriptionReference * igetTypeByName( rtl_uString * pTypeName )
119 : SAL_THROW(())
120 : {
121 26050 : typelib_TypeDescriptionReference * pRef = 0;
122 26050 : ::typelib_typedescriptionreference_getByName( &pRef, pTypeName );
123 26050 : if (pRef && pRef->pType && pRef->pType->pWeakRef) // found initialized td
124 : {
125 18992 : return pRef;
126 : }
127 : else
128 : {
129 7058 : return 0;
130 : }
131 : }
132 :
133 : extern "C"
134 : {
135 :
136 35120271 : 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 35120271 : if (! s_aTypes[eTypeClass])
146 : {
147 2344 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
148 2344 : 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 2344 : switch (eTypeClass)
157 : {
158 : case typelib_TypeClass_EXCEPTION:
159 : case typelib_TypeClass_INTERFACE:
160 : {
161 : // type
162 416 : if (! s_aTypes[typelib_TypeClass_TYPE])
163 : {
164 415 : OUString sTypeName("type");
165 : ::typelib_typedescriptionreference_new(
166 415 : &s_aTypes[typelib_TypeClass_TYPE], typelib_TypeClass_TYPE, sTypeName.pData );
167 : // another static ref:
168 415 : ++s_aTypes[typelib_TypeClass_TYPE]->nStaticRefCount;
169 : }
170 : // any
171 416 : if (! s_aTypes[typelib_TypeClass_ANY])
172 : {
173 415 : OUString sTypeName("any");
174 : ::typelib_typedescriptionreference_new(
175 415 : &s_aTypes[typelib_TypeClass_ANY], typelib_TypeClass_ANY, sTypeName.pData );
176 : // another static ref:
177 415 : ++s_aTypes[typelib_TypeClass_ANY]->nStaticRefCount;
178 : }
179 : // string
180 416 : if (! s_aTypes[typelib_TypeClass_STRING])
181 : {
182 412 : OUString sTypeName("string");
183 : ::typelib_typedescriptionreference_new(
184 412 : &s_aTypes[typelib_TypeClass_STRING], typelib_TypeClass_STRING, sTypeName.pData );
185 : // another static ref:
186 412 : ++s_aTypes[typelib_TypeClass_STRING]->nStaticRefCount;
187 : }
188 : // XInterface
189 416 : if (! s_aTypes[typelib_TypeClass_INTERFACE])
190 : {
191 416 : OUString sTypeName("com.sun.star.uno.XInterface");
192 :
193 416 : typelib_InterfaceTypeDescription * pTD = 0;
194 :
195 416 : typelib_TypeDescriptionReference * pMembers[3] = { 0,0,0 };
196 832 : OUString sMethodName0("com.sun.star.uno.XInterface::queryInterface");
197 : ::typelib_typedescriptionreference_new(
198 416 : &pMembers[0], typelib_TypeClass_INTERFACE_METHOD, sMethodName0.pData );
199 832 : OUString sMethodName1("com.sun.star.uno.XInterface::acquire");
200 : ::typelib_typedescriptionreference_new(
201 416 : &pMembers[1], typelib_TypeClass_INTERFACE_METHOD, sMethodName1.pData );
202 832 : OUString sMethodName2("com.sun.star.uno.XInterface::release");
203 : ::typelib_typedescriptionreference_new(
204 416 : &pMembers[2], typelib_TypeClass_INTERFACE_METHOD, sMethodName2.pData );
205 :
206 : ::typelib_typedescription_newInterface(
207 416 : &pTD, sTypeName.pData, 0, 0, 0, 0, 0, 0, 3, pMembers );
208 :
209 416 : ::typelib_typedescription_register( (typelib_TypeDescription **)&pTD );
210 : ::typelib_typedescriptionreference_acquire(
211 416 : s_aTypes[typelib_TypeClass_INTERFACE] = ((typelib_TypeDescription *)pTD)->pWeakRef );
212 : // another static ref:
213 416 : ++s_aTypes[typelib_TypeClass_INTERFACE]->nStaticRefCount;
214 416 : ::typelib_typedescription_release( (typelib_TypeDescription*)pTD );
215 :
216 416 : ::typelib_typedescriptionreference_release( pMembers[0] );
217 416 : ::typelib_typedescriptionreference_release( pMembers[1] );
218 416 : ::typelib_typedescriptionreference_release( pMembers[2] );
219 : // Exception
220 : assert( ! s_aTypes[typelib_TypeClass_EXCEPTION] );
221 : {
222 416 : typelib_TypeDescription * pTD1 = 0;
223 416 : OUString sTypeName1("com.sun.star.uno.Exception");
224 :
225 : typelib_CompoundMember_Init aMembers[2];
226 832 : OUString sMemberType0("string");
227 832 : OUString sMemberName0("Message");
228 416 : aMembers[0].eTypeClass = typelib_TypeClass_STRING;
229 416 : aMembers[0].pTypeName = sMemberType0.pData;
230 416 : aMembers[0].pMemberName = sMemberName0.pData;
231 832 : OUString sMemberType1("com.sun.star.uno.XInterface");
232 832 : OUString sMemberName1("Context");
233 416 : aMembers[1].eTypeClass = typelib_TypeClass_INTERFACE;
234 416 : aMembers[1].pTypeName = sMemberType1.pData;
235 416 : aMembers[1].pMemberName = sMemberName1.pData;
236 :
237 : ::typelib_typedescription_new(
238 416 : &pTD1, typelib_TypeClass_EXCEPTION, sTypeName1.pData, 0, 2, aMembers );
239 416 : typelib_typedescription_register( &pTD1 );
240 : typelib_typedescriptionreference_acquire(
241 416 : s_aTypes[typelib_TypeClass_EXCEPTION] = pTD1->pWeakRef );
242 : // another static ref:
243 416 : ++s_aTypes[typelib_TypeClass_EXCEPTION]->nStaticRefCount;
244 : // RuntimeException
245 832 : OUString sTypeName2("com.sun.star.uno.RuntimeException");
246 : ::typelib_typedescription_new(
247 416 : &pTD1, typelib_TypeClass_EXCEPTION, sTypeName2.pData, s_aTypes[typelib_TypeClass_EXCEPTION], 0, 0 );
248 416 : ::typelib_typedescription_register( &pTD1 );
249 832 : ::typelib_typedescription_release( pTD1 );
250 : }
251 : // XInterface members
252 416 : typelib_InterfaceMethodTypeDescription * pMethod = 0;
253 : typelib_Parameter_Init aParameters[1];
254 832 : OUString sParamName0("aType");
255 832 : OUString sParamType0("type");
256 416 : aParameters[0].pParamName = sParamName0.pData;
257 416 : aParameters[0].eTypeClass = typelib_TypeClass_TYPE;
258 416 : aParameters[0].pTypeName = sParamType0.pData;
259 416 : aParameters[0].bIn = sal_True;
260 416 : aParameters[0].bOut = sal_False;
261 : rtl_uString * pExceptions[1];
262 832 : OUString sExceptionName0("com.sun.star.uno.RuntimeException");
263 416 : pExceptions[0] = sExceptionName0.pData;
264 832 : OUString sReturnType0("any");
265 : typelib_typedescription_newInterfaceMethod(
266 : &pMethod, 0, sal_False, sMethodName0.pData,
267 : typelib_TypeClass_ANY, sReturnType0.pData,
268 416 : 1, aParameters, 1, pExceptions );
269 416 : ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
270 :
271 832 : OUString sReturnType1("void");
272 : ::typelib_typedescription_newInterfaceMethod(
273 : &pMethod, 1, sal_True, sMethodName1.pData,
274 416 : typelib_TypeClass_VOID, sReturnType1.pData, 0, 0, 0, 0 );
275 416 : ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
276 :
277 : ::typelib_typedescription_newInterfaceMethod(
278 : &pMethod, 2, sal_True, sMethodName2.pData,
279 : typelib_TypeClass_VOID, sReturnType1.pData,
280 416 : 0, 0, 0, 0 );
281 416 : ::typelib_typedescription_register( (typelib_TypeDescription**)&pMethod );
282 832 : ::typelib_typedescription_release( (typelib_TypeDescription*)pMethod );
283 : }
284 416 : break;
285 : }
286 : default:
287 : {
288 1928 : OUString aTypeName( OUString::createFromAscii( s_aTypeNames[eTypeClass] ) );
289 1928 : ::typelib_typedescriptionreference_new( &s_aTypes[eTypeClass], eTypeClass, aTypeName.pData );
290 : // another static ref:
291 1928 : ++s_aTypes[eTypeClass]->nStaticRefCount;
292 : }
293 : }
294 2344 : }
295 : }
296 35120271 : return &s_aTypes[eTypeClass];
297 : }
298 :
299 :
300 104991 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_type_init(
301 : typelib_TypeDescriptionReference ** ppRef,
302 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName )
303 : SAL_THROW_EXTERN_C()
304 : {
305 104991 : if (! *ppRef)
306 : {
307 104991 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
308 104991 : if (! *ppRef)
309 : {
310 104991 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
311 104991 : ::typelib_typedescriptionreference_new( ppRef, eTypeClass, aTypeName.pData );
312 :
313 : // another static ref:
314 104991 : ++((*ppRef)->nStaticRefCount);
315 104991 : }
316 : }
317 104991 : }
318 :
319 :
320 26011 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_sequence_type_init(
321 : typelib_TypeDescriptionReference ** ppRef,
322 : typelib_TypeDescriptionReference * pElementType )
323 : SAL_THROW_EXTERN_C()
324 : {
325 26011 : if (! *ppRef)
326 : {
327 26011 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
328 26011 : if (! *ppRef)
329 : {
330 26011 : OUStringBuffer aBuf( 32 );
331 26011 : aBuf.appendAscii( "[]" );
332 26011 : aBuf.append( pElementType->pTypeName );
333 52022 : OUString aTypeName( aBuf.makeStringAndClear() );
334 :
335 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) );
336 26011 : *ppRef = igetTypeByName( aTypeName.pData );
337 26011 : if (!*ppRef)
338 : {
339 7049 : typelib_TypeDescription * pReg = 0;
340 : ::typelib_typedescription_new(
341 : &pReg, typelib_TypeClass_SEQUENCE,
342 7049 : aTypeName.pData, pElementType, 0, 0 );
343 :
344 7049 : ::typelib_typedescription_register( &pReg );
345 7049 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
346 : assert( *ppRef == pReg->pWeakRef );
347 : }
348 : // another static ref:
349 52022 : ++((*ppRef)->nStaticRefCount);
350 26011 : }
351 : }
352 26011 : }
353 :
354 :
355 : namespace {
356 :
357 34 : void init(
358 : typelib_TypeDescriptionReference ** ppRef,
359 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
360 : typelib_TypeDescriptionReference * pBaseType,
361 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
362 : sal_Bool const * pParameterizedTypes)
363 : {
364 : assert( eTypeClass == typelib_TypeClass_STRUCT || eTypeClass == typelib_TypeClass_EXCEPTION );
365 :
366 34 : if (! *ppRef)
367 : {
368 34 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
369 34 : if (! *ppRef)
370 : {
371 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) );
372 34 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
373 34 : *ppRef = igetTypeByName( aTypeName.pData );
374 34 : if (!*ppRef)
375 : {
376 8 : typelib_CompoundTypeDescription * pComp = 0;
377 : ::typelib_typedescription_newEmpty(
378 8 : (typelib_TypeDescription **)&pComp, eTypeClass, aTypeName.pData );
379 :
380 8 : sal_Int32 nOffset = 0;
381 8 : if (pBaseType)
382 : {
383 : ::typelib_typedescriptionreference_getDescription(
384 8 : (typelib_TypeDescription **)&pComp->pBaseTypeDescription, pBaseType );
385 : assert( pComp->pBaseTypeDescription );
386 8 : nOffset = ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize;
387 : assert( newAlignedSize( 0, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize, ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nAlignment ) == ((typelib_TypeDescription *)pComp->pBaseTypeDescription)->nSize ); // unexpected offset
388 : }
389 :
390 8 : if (nMembers)
391 : {
392 0 : pComp->nMembers = nMembers;
393 0 : pComp->pMemberOffsets = new sal_Int32[ nMembers ];
394 0 : pComp->ppTypeRefs = new typelib_TypeDescriptionReference *[ nMembers ];
395 0 : if (pParameterizedTypes != 0) {
396 : reinterpret_cast< typelib_StructTypeDescription * >(
397 : pComp)->pParameterizedTypes
398 0 : = new sal_Bool[nMembers];
399 : }
400 0 : for ( sal_Int32 i = 0 ; i < nMembers; ++i )
401 : {
402 : ::typelib_typedescriptionreference_acquire(
403 0 : pComp->ppTypeRefs[i] = ppMembers[i] );
404 : // write offset
405 0 : typelib_TypeDescription * pTD = 0;
406 0 : TYPELIB_DANGER_GET( &pTD, pComp->ppTypeRefs[i] );
407 : assert( pTD->nSize ); // void member?
408 0 : nOffset = newAlignedSize( nOffset, pTD->nSize, pTD->nAlignment );
409 0 : pComp->pMemberOffsets[i] = nOffset - pTD->nSize;
410 0 : TYPELIB_DANGER_RELEASE( pTD );
411 :
412 0 : if (pParameterizedTypes != 0) {
413 : reinterpret_cast< typelib_StructTypeDescription * >(
414 0 : pComp)->pParameterizedTypes[i]
415 0 : = pParameterizedTypes[i];
416 : }
417 : }
418 : }
419 :
420 8 : typelib_TypeDescription * pReg = (typelib_TypeDescription *)pComp;
421 8 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
422 : // sizeof( void ) not allowed
423 8 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
424 8 : pReg->nAlignment = adjustAlignment( pReg->nAlignment );
425 8 : pReg->bComplete = sal_False;
426 :
427 8 : ::typelib_typedescription_register( &pReg );
428 8 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
429 : assert( *ppRef == pReg->pWeakRef );
430 : }
431 : // another static ref:
432 34 : ++((*ppRef)->nStaticRefCount);
433 34 : }
434 : }
435 34 : }
436 :
437 : }
438 :
439 34 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_compound_type_init(
440 : typelib_TypeDescriptionReference ** ppRef,
441 : typelib_TypeClass eTypeClass, const sal_Char * pTypeName,
442 : typelib_TypeDescriptionReference * pBaseType,
443 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers )
444 : SAL_THROW_EXTERN_C()
445 : {
446 34 : init(ppRef, eTypeClass, pTypeName, pBaseType, nMembers, ppMembers, 0);
447 34 : }
448 :
449 0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_struct_type_init(
450 : typelib_TypeDescriptionReference ** ppRef, const sal_Char * pTypeName,
451 : typelib_TypeDescriptionReference * pBaseType,
452 : sal_Int32 nMembers, typelib_TypeDescriptionReference ** ppMembers,
453 : sal_Bool const * pParameterizedTypes )
454 : SAL_THROW_EXTERN_C()
455 : {
456 : init(
457 : ppRef, typelib_TypeClass_STRUCT, pTypeName, pBaseType, nMembers,
458 0 : ppMembers, pParameterizedTypes);
459 0 : }
460 :
461 :
462 0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_interface_type_init(
463 : typelib_TypeDescriptionReference ** ppRef,
464 : const sal_Char * pTypeName,
465 : typelib_TypeDescriptionReference * pBaseType )
466 : SAL_THROW_EXTERN_C()
467 : {
468 : typelib_static_mi_interface_type_init(
469 0 : ppRef, pTypeName, pBaseType == 0 ? 0 : 1, &pBaseType);
470 0 : }
471 :
472 :
473 5 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_mi_interface_type_init(
474 : typelib_TypeDescriptionReference ** ppRef,
475 : const sal_Char * pTypeName,
476 : sal_Int32 nBaseTypes,
477 : typelib_TypeDescriptionReference ** ppBaseTypes )
478 : SAL_THROW_EXTERN_C()
479 : {
480 5 : if (! *ppRef)
481 : {
482 5 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
483 5 : if (! *ppRef)
484 : {
485 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) );
486 5 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
487 5 : *ppRef = igetTypeByName( aTypeName.pData );
488 5 : if (!*ppRef)
489 : {
490 1 : typelib_InterfaceTypeDescription * pIface = 0;
491 : ::typelib_typedescription_newEmpty(
492 1 : (typelib_TypeDescription **)&pIface, typelib_TypeClass_INTERFACE, aTypeName.pData );
493 :
494 1 : pIface->nBaseTypes = std::max< sal_Int32 >(nBaseTypes, 1);
495 : pIface->ppBaseTypes = new typelib_InterfaceTypeDescription *[
496 1 : pIface->nBaseTypes];
497 1 : if (nBaseTypes > 0)
498 : {
499 2 : for (sal_Int32 i = 0; i < nBaseTypes; ++i) {
500 1 : pIface->ppBaseTypes[i] = 0;
501 : ::typelib_typedescriptionreference_getDescription(
502 1 : (typelib_TypeDescription **)&pIface->ppBaseTypes[i], ppBaseTypes[i] );
503 : assert( pIface->ppBaseTypes[i] );
504 : }
505 : }
506 : else
507 : {
508 0 : pIface->ppBaseTypes[0] = 0;
509 : ::typelib_typedescriptionreference_getDescription(
510 : (typelib_TypeDescription **)&pIface->ppBaseTypes[0],
511 0 : * ::typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ) );
512 : assert( pIface->ppBaseTypes[0] );
513 : }
514 1 : pIface->pBaseTypeDescription = pIface->ppBaseTypes[0];
515 : typelib_typedescription_acquire(
516 1 : &pIface->pBaseTypeDescription->aBase);
517 :
518 1 : typelib_TypeDescription * pReg = (typelib_TypeDescription *)pIface;
519 1 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
520 : // sizeof( void ) not allowed
521 1 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
522 :
523 1 : pReg->nAlignment = adjustAlignment( pReg->nAlignment );
524 1 : pReg->bComplete = sal_False;
525 :
526 1 : ::typelib_typedescription_register( &pReg );
527 1 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
528 : assert( *ppRef == pReg->pWeakRef );
529 : }
530 : // another static ref:
531 5 : ++((*ppRef)->nStaticRefCount);
532 5 : }
533 : }
534 5 : }
535 :
536 :
537 0 : CPPU_DLLPUBLIC void SAL_CALL typelib_static_enum_type_init(
538 : typelib_TypeDescriptionReference ** ppRef,
539 : const sal_Char * pTypeName,
540 : sal_Int32 nDefaultValue )
541 : SAL_THROW_EXTERN_C()
542 : {
543 0 : if (! *ppRef)
544 : {
545 0 : MutexGuard aGuard( typelib_StaticInitMutex::get() );
546 0 : if (! *ppRef)
547 : {
548 : assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) );
549 0 : OUString aTypeName( OUString::createFromAscii( pTypeName ) );
550 0 : *ppRef = igetTypeByName( aTypeName.pData );
551 0 : if (!*ppRef)
552 : {
553 0 : typelib_TypeDescription * pReg = 0;
554 : ::typelib_typedescription_newEmpty(
555 0 : &pReg, typelib_TypeClass_ENUM, aTypeName.pData );
556 0 : typelib_EnumTypeDescription * pEnum = (typelib_EnumTypeDescription *)pReg;
557 :
558 0 : pEnum->nDefaultEnumValue = nDefaultValue;
559 :
560 0 : pReg->pWeakRef = (typelib_TypeDescriptionReference *)pReg;
561 : // sizeof( void ) not allowed
562 0 : pReg->nSize = ::typelib_typedescription_getAlignedUnoSize( pReg, 0, pReg->nAlignment );
563 0 : pReg->nAlignment = ::adjustAlignment( pReg->nAlignment );
564 0 : pReg->bComplete = sal_False;
565 :
566 0 : ::typelib_typedescription_register( &pReg );
567 0 : *ppRef = (typelib_TypeDescriptionReference *)pReg;
568 : assert( *ppRef == pReg->pWeakRef );
569 : }
570 : // another static ref:
571 0 : ++((*ppRef)->nStaticRefCount);
572 0 : }
573 : }
574 0 : }
575 :
576 : } // extern "C"
577 :
578 : }
579 :
580 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|