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 :
21 : #include <sal/config.h>
22 : #ifdef SAL_UNX
23 : #include <sal/alloca.h>
24 : #endif
25 : #if !(defined(MACOSX) || defined(IOS) || defined(FREEBSD))
26 : #include <malloc.h>
27 : #endif
28 : #include <rtl/alloc.h>
29 : #include <typelib/typedescription.hxx>
30 : #include <uno/data.h>
31 :
32 : #include "base.hxx"
33 :
34 : #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
35 : #include "com/sun/star/uno/RuntimeException.hpp"
36 : #include "cppuhelper/exc_hlp.hxx"
37 :
38 : namespace stoc_corefl
39 : {
40 :
41 :
42 5122 : class IdlAttributeFieldImpl
43 : : public IdlMemberImpl
44 : , public XIdlField
45 : , public XIdlField2
46 : {
47 : public:
48 8291 : typelib_InterfaceAttributeTypeDescription * getAttributeTypeDescr()
49 8291 : { return (typelib_InterfaceAttributeTypeDescription *)getTypeDescr(); }
50 :
51 3052 : IdlAttributeFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
52 : typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr )
53 3052 : : IdlMemberImpl( pReflection, rName, pTypeDescr, pDeclTypeDescr )
54 3052 : {}
55 :
56 : // XInterface
57 : virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
58 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
59 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
60 :
61 : // XTypeProvider
62 : virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 :
65 : // XIdlMember
66 : virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
67 : virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
68 : // XIdlField
69 : virtual Reference< XIdlClass > SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
70 : virtual FieldAccessMode SAL_CALL getAccessMode() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
71 : virtual Any SAL_CALL get( const Any & rObj ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
72 : virtual void SAL_CALL set( const Any & rObj, const Any & rValue ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
73 : // XIdlField2: getType, getAccessMode and get are equal to XIdlField
74 : virtual void SAL_CALL set( Any & rObj, const Any & rValue ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
75 :
76 : private:
77 : void checkException(
78 : uno_Any * exception, Reference< XInterface > const & context);
79 : };
80 :
81 : // XInterface
82 :
83 3152 : Any IdlAttributeFieldImpl::queryInterface( const Type & rType )
84 : throw(::com::sun::star::uno::RuntimeException, std::exception)
85 : {
86 : Any aRet( ::cppu::queryInterface( rType,
87 : static_cast< XIdlField * >( this ),
88 3152 : static_cast< XIdlField2 * >( this ) ) );
89 3152 : return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
90 : }
91 :
92 15054 : void IdlAttributeFieldImpl::acquire() throw()
93 : {
94 15054 : IdlMemberImpl::acquire();
95 15054 : }
96 :
97 14563 : void IdlAttributeFieldImpl::release() throw()
98 : {
99 14563 : IdlMemberImpl::release();
100 14563 : }
101 :
102 : // XTypeProvider
103 :
104 0 : Sequence< Type > IdlAttributeFieldImpl::getTypes()
105 : throw (::com::sun::star::uno::RuntimeException, std::exception)
106 : {
107 : static OTypeCollection * s_pTypes = 0;
108 0 : if (! s_pTypes)
109 : {
110 0 : MutexGuard aGuard( getMutexAccess() );
111 0 : if (! s_pTypes)
112 : {
113 : static OTypeCollection s_aTypes(
114 0 : ::getCppuType( (const Reference< XIdlField2 > *)0 ),
115 0 : ::getCppuType( (const Reference< XIdlField > *)0 ),
116 0 : IdlMemberImpl::getTypes() );
117 0 : s_pTypes = &s_aTypes;
118 0 : }
119 : }
120 0 : return s_pTypes->getTypes();
121 : }
122 :
123 0 : Sequence< sal_Int8 > IdlAttributeFieldImpl::getImplementationId()
124 : throw (::com::sun::star::uno::RuntimeException, std::exception)
125 : {
126 0 : return css::uno::Sequence<sal_Int8>();
127 : }
128 :
129 : // XIdlMember
130 :
131 0 : Reference< XIdlClass > IdlAttributeFieldImpl::getDeclaringClass()
132 : throw(::com::sun::star::uno::RuntimeException, std::exception)
133 : {
134 0 : if (! _xDeclClass.is())
135 : {
136 0 : MutexGuard aGuard( getMutexAccess() );
137 0 : if (! _xDeclClass.is())
138 : {
139 0 : OUString aName(getAttributeTypeDescr()->aBase.aBase.pTypeName);
140 0 : sal_Int32 i = aName.indexOf(':');
141 : OSL_ASSERT(i >= 0);
142 0 : _xDeclClass = getReflection()->forName(aName.copy(0, i));
143 0 : }
144 : }
145 0 : return _xDeclClass;
146 : }
147 :
148 2156 : OUString IdlAttributeFieldImpl::getName()
149 : throw(::com::sun::star::uno::RuntimeException, std::exception)
150 : {
151 2156 : return IdlMemberImpl::getName();
152 : }
153 :
154 : // XIdlField
155 :
156 2604 : Reference< XIdlClass > IdlAttributeFieldImpl::getType()
157 : throw(::com::sun::star::uno::RuntimeException, std::exception)
158 : {
159 : return getReflection()->forType(
160 2604 : getAttributeTypeDescr()->pAttributeTypeRef );
161 : }
162 :
163 2156 : FieldAccessMode IdlAttributeFieldImpl::getAccessMode()
164 : throw(::com::sun::star::uno::RuntimeException, std::exception)
165 : {
166 2156 : return (((typelib_InterfaceAttributeTypeDescription *)getAttributeTypeDescr())->bReadOnly
167 2156 : ? FieldAccessMode_READONLY : FieldAccessMode_READWRITE);
168 : }
169 :
170 1707 : Any IdlAttributeFieldImpl::get( const Any & rObj )
171 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
172 : {
173 : uno_Interface * pUnoI = getReflection()->mapToUno(
174 1707 : rObj, (typelib_InterfaceTypeDescription *)getDeclTypeDescr() );
175 : OSL_ENSURE( pUnoI, "### illegal destination object given!" );
176 1707 : if (pUnoI)
177 : {
178 1707 : TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
179 1707 : typelib_TypeDescription * pTD = aTD.get();
180 :
181 : uno_Any aExc;
182 1707 : uno_Any * pExc = &aExc;
183 1707 : void * pReturn = alloca( pTD->nSize );
184 :
185 1707 : (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), pReturn, 0, &pExc );
186 1707 : (*pUnoI->release)( pUnoI );
187 :
188 : checkException(
189 : pExc,
190 1707 : *static_cast< Reference< XInterface > const * >(rObj.getValue()));
191 3414 : Any aRet;
192 : uno_any_destruct(
193 1707 : &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
194 1707 : uno_any_constructAndConvert( &aRet, pReturn, pTD, getReflection()->getUno2Cpp().get() );
195 1707 : uno_destructData( pReturn, pTD, 0 );
196 5121 : return aRet;
197 : }
198 : throw IllegalArgumentException(
199 : OUString("illegal object given!"),
200 0 : (XWeak *)(OWeakObject *)this, 0 );
201 : }
202 :
203 912 : void IdlAttributeFieldImpl::set( Any & rObj, const Any & rValue )
204 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException, std::exception)
205 : {
206 912 : if (getAttributeTypeDescr()->bReadOnly)
207 : {
208 : throw IllegalAccessException(
209 : OUString("cannot set readonly attribute!"),
210 0 : (XWeak *)(OWeakObject *)this );
211 : }
212 :
213 : uno_Interface * pUnoI = getReflection()->mapToUno(
214 912 : rObj, (typelib_InterfaceTypeDescription *)getDeclTypeDescr() );
215 : OSL_ENSURE( pUnoI, "### illegal destination object given!" );
216 912 : if (pUnoI)
217 : {
218 912 : TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
219 912 : typelib_TypeDescription * pTD = aTD.get();
220 :
221 : // construct uno value to be set
222 : void * pArgs[1];
223 912 : void * pArg = pArgs[0] = alloca( pTD->nSize );
224 :
225 : sal_Bool bAssign;
226 912 : if (pTD->eTypeClass == typelib_TypeClass_ANY)
227 : {
228 : uno_copyAndConvertData( pArg, (const_cast< Any * >(&rValue)),
229 311 : pTD, getReflection()->getCpp2Uno().get() );
230 311 : bAssign = sal_True;
231 : }
232 601 : else if (typelib_typedescriptionreference_equals( rValue.getValueTypeRef(), pTD->pWeakRef ))
233 : {
234 601 : uno_copyAndConvertData( pArg, (const_cast< void * >(rValue.getValue()) ),
235 1202 : pTD, getReflection()->getCpp2Uno().get() );
236 601 : bAssign = sal_True;
237 : }
238 0 : else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
239 : {
240 0 : Reference< XInterface > xObj;
241 : bAssign = extract(
242 : rValue, (typelib_InterfaceTypeDescription *)pTD, xObj,
243 0 : getReflection() );
244 0 : if (bAssign)
245 : {
246 0 : *(void **)pArg = getReflection()->getCpp2Uno().mapInterface(
247 0 : xObj.get(), (typelib_InterfaceTypeDescription *)pTD );
248 0 : }
249 : }
250 : else
251 : {
252 0 : typelib_TypeDescription * pValueTD = 0;
253 0 : TYPELIB_DANGER_GET( &pValueTD, rValue.getValueTypeRef() );
254 : // construct temp uno val to do proper assignment: todo opt
255 0 : void * pTemp = alloca( pValueTD->nSize );
256 : uno_copyAndConvertData(
257 0 : pTemp, (void *)rValue.getValue(), pValueTD, getReflection()->getCpp2Uno().get() );
258 : uno_constructData(
259 0 : pArg, pTD );
260 : // assignment does simple conversion
261 : bAssign = uno_assignData(
262 0 : pArg, pTD, pTemp, pValueTD, 0, 0, 0 );
263 : uno_destructData(
264 0 : pTemp, pValueTD, 0 );
265 0 : TYPELIB_DANGER_RELEASE( pValueTD );
266 : }
267 :
268 912 : if (bAssign)
269 : {
270 : uno_Any aExc;
271 912 : uno_Any * pExc = &aExc;
272 912 : (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), 0, pArgs, &pExc );
273 912 : (*pUnoI->release)( pUnoI );
274 :
275 912 : uno_destructData( pArg, pTD, 0 );
276 : checkException(
277 : pExc,
278 : *static_cast< Reference< XInterface > const * >(
279 912 : rObj.getValue()));
280 1824 : return;
281 : }
282 0 : (*pUnoI->release)( pUnoI );
283 :
284 : throw IllegalArgumentException(
285 : OUString("illegal value given!"),
286 912 : *(const Reference< XInterface > *)rObj.getValue(), 1 );
287 : }
288 : throw IllegalArgumentException(
289 : OUString("illegal destination object given!"),
290 0 : (XWeak *)(OWeakObject *)this, 0 );
291 : }
292 :
293 0 : void IdlAttributeFieldImpl::set( const Any & rObj, const Any & rValue )
294 : throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException, std::exception)
295 : {
296 0 : IdlAttributeFieldImpl::set( const_cast< Any & >( rObj ), rValue );
297 0 : }
298 :
299 2619 : void IdlAttributeFieldImpl::checkException(
300 : uno_Any * exception, Reference< XInterface > const & context)
301 : {
302 2619 : if (exception != 0) {
303 0 : Any e;
304 0 : uno_any_destruct(&e, reinterpret_cast< uno_ReleaseFunc >(cpp_release));
305 : uno_type_any_constructAndConvert(
306 : &e, exception->pData, exception->pType,
307 0 : getReflection()->getUno2Cpp().get());
308 0 : uno_any_destruct(exception, 0);
309 0 : if (e.isExtractableTo(
310 0 : getCppuType(static_cast< RuntimeException const * >(0))))
311 : {
312 0 : cppu::throwException(e);
313 : } else {
314 : throw WrappedTargetRuntimeException(
315 : OUString(
316 : "non-RuntimeException occurred when accessing an"
317 : " interface type attribute"),
318 0 : context, e);
319 0 : }
320 : }
321 2619 : }
322 :
323 :
324 :
325 :
326 :
327 :
328 :
329 : class IdlInterfaceMethodImpl
330 : : public IdlMemberImpl
331 : , public XIdlMethod
332 : {
333 : Sequence< Reference< XIdlClass > > * _pExceptionTypes;
334 : Sequence< Reference< XIdlClass > > * _pParamTypes;
335 : Sequence< ParamInfo > * _pParamInfos;
336 :
337 : public:
338 130721 : typelib_InterfaceMethodTypeDescription * getMethodTypeDescr()
339 130721 : { return (typelib_InterfaceMethodTypeDescription *)getTypeDescr(); }
340 :
341 70739 : IdlInterfaceMethodImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
342 : typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr )
343 : : IdlMemberImpl( pReflection, rName, pTypeDescr, pDeclTypeDescr )
344 : , _pExceptionTypes( 0 )
345 : , _pParamTypes( 0 )
346 70739 : , _pParamInfos( 0 )
347 70739 : {}
348 : virtual ~IdlInterfaceMethodImpl();
349 :
350 : // XInterface
351 : virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
352 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
353 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
354 :
355 : // XTypeProvider
356 : virtual Sequence< Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
357 : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
358 :
359 : // XIdlMember
360 : virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
361 : virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
362 : // XIdlMethod
363 : virtual Reference< XIdlClass > SAL_CALL getReturnType() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
364 : virtual Sequence< Reference< XIdlClass > > SAL_CALL getParameterTypes() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
365 : virtual Sequence< ParamInfo > SAL_CALL getParameterInfos() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
366 : virtual Sequence< Reference< XIdlClass > > SAL_CALL getExceptionTypes() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
367 : virtual MethodMode SAL_CALL getMode() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
368 : virtual Any SAL_CALL invoke( const Any & rObj, Sequence< Any > & rArgs ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
369 : };
370 :
371 194895 : IdlInterfaceMethodImpl::~IdlInterfaceMethodImpl()
372 : {
373 64965 : delete _pParamInfos;
374 64965 : delete _pParamTypes;
375 64965 : delete _pExceptionTypes;
376 129930 : }
377 :
378 : // XInterface
379 :
380 19 : Any IdlInterfaceMethodImpl::queryInterface( const Type & rType )
381 : throw(::com::sun::star::uno::RuntimeException, std::exception)
382 : {
383 19 : Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlMethod * >( this ) ) );
384 19 : return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
385 : }
386 :
387 128433 : void IdlInterfaceMethodImpl::acquire() throw()
388 : {
389 128433 : IdlMemberImpl::acquire();
390 128433 : }
391 :
392 121093 : void IdlInterfaceMethodImpl::release() throw()
393 : {
394 121093 : IdlMemberImpl::release();
395 121093 : }
396 :
397 : // XTypeProvider
398 :
399 0 : Sequence< Type > IdlInterfaceMethodImpl::getTypes()
400 : throw (::com::sun::star::uno::RuntimeException, std::exception)
401 : {
402 : static OTypeCollection * s_pTypes = 0;
403 0 : if (! s_pTypes)
404 : {
405 0 : MutexGuard aGuard( getMutexAccess() );
406 0 : if (! s_pTypes)
407 : {
408 : static OTypeCollection s_aTypes(
409 0 : ::getCppuType( (const Reference< XIdlMethod > *)0 ),
410 0 : IdlMemberImpl::getTypes() );
411 0 : s_pTypes = &s_aTypes;
412 0 : }
413 : }
414 0 : return s_pTypes->getTypes();
415 : }
416 :
417 0 : Sequence< sal_Int8 > IdlInterfaceMethodImpl::getImplementationId()
418 : throw (::com::sun::star::uno::RuntimeException, std::exception)
419 : {
420 0 : return css::uno::Sequence<sal_Int8>();
421 : }
422 :
423 : // XIdlMember
424 :
425 89665 : Reference< XIdlClass > IdlInterfaceMethodImpl::getDeclaringClass()
426 : throw(::com::sun::star::uno::RuntimeException, std::exception)
427 : {
428 89665 : if (! _xDeclClass.is())
429 : {
430 70720 : MutexGuard aGuard( getMutexAccess() );
431 70720 : if (! _xDeclClass.is())
432 : {
433 70720 : OUString aName(getMethodTypeDescr()->aBase.aBase.pTypeName);
434 70720 : sal_Int32 i = aName.indexOf(':');
435 : OSL_ASSERT(i >= 0);
436 70720 : _xDeclClass = getReflection()->forName(aName.copy(0, i));
437 70720 : }
438 : }
439 89665 : return _xDeclClass;
440 : }
441 :
442 187910 : OUString IdlInterfaceMethodImpl::getName()
443 : throw(::com::sun::star::uno::RuntimeException, std::exception)
444 : {
445 187910 : return IdlMemberImpl::getName();
446 : }
447 :
448 : // XIdlMethod
449 :
450 12342 : Reference< XIdlClass > SAL_CALL IdlInterfaceMethodImpl::getReturnType()
451 : throw(::com::sun::star::uno::RuntimeException, std::exception)
452 : {
453 12342 : return getReflection()->forType( getMethodTypeDescr()->pReturnTypeRef );
454 : }
455 :
456 19 : Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes()
457 : throw(::com::sun::star::uno::RuntimeException, std::exception)
458 : {
459 19 : if (! _pExceptionTypes)
460 : {
461 19 : MutexGuard aGuard( getMutexAccess() );
462 19 : if (! _pExceptionTypes)
463 : {
464 19 : sal_Int32 nExc = getMethodTypeDescr()->nExceptions;
465 : Sequence< Reference< XIdlClass > > * pTempExceptionTypes =
466 19 : new Sequence< Reference< XIdlClass > >( nExc );
467 19 : Reference< XIdlClass > * pExceptionTypes = pTempExceptionTypes->getArray();
468 :
469 : typelib_TypeDescriptionReference ** ppExc =
470 19 : getMethodTypeDescr()->ppExceptions;
471 19 : IdlReflectionServiceImpl * pRefl = getReflection();
472 :
473 50 : while (nExc--)
474 12 : pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] );
475 :
476 19 : _pExceptionTypes = pTempExceptionTypes;
477 19 : }
478 : }
479 19 : return *_pExceptionTypes;
480 : }
481 :
482 18337 : Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes()
483 : throw(::com::sun::star::uno::RuntimeException, std::exception)
484 : {
485 18337 : if (! _pParamTypes)
486 : {
487 18196 : MutexGuard aGuard( getMutexAccess() );
488 18196 : if (! _pParamTypes)
489 : {
490 18196 : sal_Int32 nParams = getMethodTypeDescr()->nParams;
491 : Sequence< Reference< XIdlClass > > * pTempParamTypes =
492 18196 : new Sequence< Reference< XIdlClass > >( nParams );
493 18196 : Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray();
494 :
495 : typelib_MethodParameter * pTypelibParams =
496 18196 : getMethodTypeDescr()->pParams;
497 18196 : IdlReflectionServiceImpl * pRefl = getReflection();
498 :
499 50494 : while (nParams--)
500 14102 : pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef );
501 :
502 18196 : _pParamTypes = pTempParamTypes;
503 18196 : }
504 : }
505 18337 : return *_pParamTypes;
506 : }
507 :
508 2366 : Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
509 : throw(::com::sun::star::uno::RuntimeException, std::exception)
510 : {
511 2366 : if (! _pParamInfos)
512 : {
513 1257 : MutexGuard aGuard( getMutexAccess() );
514 1257 : if (! _pParamInfos)
515 : {
516 1257 : sal_Int32 nParams = getMethodTypeDescr()->nParams;
517 1257 : Sequence< ParamInfo > * pTempParamInfos = new Sequence< ParamInfo >( nParams );
518 1257 : ParamInfo * pParamInfos = pTempParamInfos->getArray();
519 :
520 : typelib_MethodParameter * pTypelibParams =
521 1257 : getMethodTypeDescr()->pParams;
522 :
523 1257 : if (_pParamTypes) // use param types
524 : {
525 1052 : const Reference< XIdlClass > * pParamTypes = _pParamTypes->getConstArray();
526 :
527 5577 : while (nParams--)
528 : {
529 3473 : const typelib_MethodParameter & rParam = pTypelibParams[nParams];
530 3473 : ParamInfo & rInfo = pParamInfos[nParams];
531 3473 : rInfo.aName = rParam.pName;
532 3473 : if (rParam.bIn)
533 3473 : rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
534 : else
535 0 : rInfo.aMode = ParamMode_OUT;
536 3473 : rInfo.aType = pParamTypes[nParams];
537 : }
538 : }
539 : else // make also param types sequence if not already initialized
540 : {
541 : Sequence< Reference< XIdlClass > > * pTempParamTypes =
542 205 : new Sequence< Reference< XIdlClass > >( nParams );
543 205 : Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray();
544 :
545 205 : IdlReflectionServiceImpl * pRefl = getReflection();
546 :
547 725 : while (nParams--)
548 : {
549 315 : const typelib_MethodParameter & rParam = pTypelibParams[nParams];
550 315 : ParamInfo & rInfo = pParamInfos[nParams];
551 315 : rInfo.aName = rParam.pName;
552 315 : if (rParam.bIn)
553 315 : rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
554 : else
555 0 : rInfo.aMode = ParamMode_OUT;
556 315 : rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef );
557 : }
558 :
559 205 : _pParamTypes = pTempParamTypes;
560 : }
561 :
562 1257 : _pParamInfos = pTempParamInfos;
563 1257 : }
564 : }
565 2366 : return *_pParamInfos;
566 : }
567 :
568 0 : MethodMode SAL_CALL IdlInterfaceMethodImpl::getMode()
569 : throw(::com::sun::star::uno::RuntimeException, std::exception)
570 : {
571 : return
572 0 : getMethodTypeDescr()->bOneWay ? MethodMode_ONEWAY : MethodMode_TWOWAY;
573 : }
574 :
575 2905 : Any SAL_CALL IdlInterfaceMethodImpl::invoke( const Any & rObj, Sequence< Any > & rArgs )
576 : throw(::com::sun::star::lang::IllegalArgumentException,
577 : ::com::sun::star::reflection::InvocationTargetException,
578 : ::com::sun::star::uno::RuntimeException, std::exception)
579 : {
580 2905 : if (rObj.getValueTypeClass() == TypeClass_INTERFACE)
581 : {
582 : // acquire()/ release()
583 5810 : if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
584 2905 : "com.sun.star.uno.XInterface::acquire" ) == 0)
585 : {
586 0 : (*(const Reference< XInterface > *)rObj.getValue())->acquire();
587 0 : return Any();
588 : }
589 5810 : else if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
590 2905 : "com.sun.star.uno.XInterface::release" ) == 0)
591 : {
592 0 : (*(const Reference< XInterface > *)rObj.getValue())->release();
593 0 : return Any();
594 : }
595 : }
596 :
597 : uno_Interface * pUnoI = getReflection()->mapToUno(
598 2905 : rObj, (typelib_InterfaceTypeDescription *)getDeclTypeDescr() );
599 : OSL_ENSURE( pUnoI, "### illegal destination object given!" );
600 2905 : if (pUnoI)
601 : {
602 2905 : sal_Int32 nParams = getMethodTypeDescr()->nParams;
603 2905 : if (rArgs.getLength() != nParams)
604 : {
605 0 : (*pUnoI->release)( pUnoI );
606 : throw IllegalArgumentException(
607 : OUString("arguments len differ!"),
608 0 : *(const Reference< XInterface > *)rObj.getValue(), 1 );
609 : }
610 :
611 2905 : Any * pCppArgs = rArgs.getArray();
612 2905 : typelib_MethodParameter * pParams = getMethodTypeDescr()->pParams;
613 2905 : typelib_TypeDescription * pReturnType = 0;
614 : TYPELIB_DANGER_GET(
615 2905 : &pReturnType, getMethodTypeDescr()->pReturnTypeRef );
616 :
617 2905 : void * pUnoReturn = alloca( pReturnType->nSize );
618 2905 : void ** ppUnoArgs = (void **)alloca( sizeof(void *) * nParams *2 );
619 2905 : typelib_TypeDescription ** ppParamTypes = (typelib_TypeDescription **)(ppUnoArgs + nParams);
620 :
621 : // convert arguments
622 7895 : for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
623 : {
624 4990 : ppParamTypes[nPos] = 0;
625 4990 : TYPELIB_DANGER_GET( ppParamTypes + nPos, pParams[nPos].pTypeRef );
626 4990 : typelib_TypeDescription * pTD = ppParamTypes[nPos];
627 :
628 4990 : ppUnoArgs[nPos] = alloca( pTD->nSize );
629 4990 : if (pParams[nPos].bIn)
630 : {
631 : sal_Bool bAssign;
632 4990 : if (typelib_typedescriptionreference_equals(
633 4990 : pCppArgs[nPos].getValueTypeRef(), pTD->pWeakRef ))
634 : {
635 : uno_type_copyAndConvertData(
636 690 : ppUnoArgs[nPos], (void *)pCppArgs[nPos].getValue(),
637 1380 : pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
638 690 : bAssign = sal_True;
639 : }
640 4300 : else if (pTD->eTypeClass == typelib_TypeClass_ANY)
641 : {
642 : uno_type_any_constructAndConvert(
643 4122 : (uno_Any *)ppUnoArgs[nPos], (void *)pCppArgs[nPos].getValue(),
644 8244 : pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
645 4122 : bAssign = sal_True;
646 : }
647 178 : else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
648 : {
649 161 : Reference< XInterface > xDest;
650 : bAssign = extract(
651 : pCppArgs[nPos], (typelib_InterfaceTypeDescription *)pTD,
652 161 : xDest, getReflection() );
653 161 : if (bAssign)
654 : {
655 322 : *(void **)ppUnoArgs[nPos] = getReflection()->getCpp2Uno().mapInterface(
656 322 : xDest.get(), (typelib_InterfaceTypeDescription *)pTD );
657 161 : }
658 : }
659 : else
660 : {
661 17 : typelib_TypeDescription * pValueTD = 0;
662 17 : TYPELIB_DANGER_GET( &pValueTD, pCppArgs[nPos].getValueTypeRef() );
663 : // construct temp uno val to do proper assignment: todo opt
664 17 : void * pTemp = alloca( pValueTD->nSize );
665 : uno_copyAndConvertData(
666 17 : pTemp, (void *)pCppArgs[nPos].getValue(), pValueTD,
667 34 : getReflection()->getCpp2Uno().get() );
668 : uno_constructData(
669 17 : ppUnoArgs[nPos], pTD );
670 : // assignment does simple conversion
671 : bAssign = uno_assignData(
672 17 : ppUnoArgs[nPos], pTD, pTemp, pValueTD, 0, 0, 0 );
673 : uno_destructData(
674 17 : pTemp, pValueTD, 0 );
675 17 : TYPELIB_DANGER_RELEASE( pValueTD );
676 : }
677 :
678 4990 : if (! bAssign)
679 : {
680 : IllegalArgumentException aExc(
681 : OUString("cannot coerce argument type during corereflection call!"),
682 0 : *(const Reference< XInterface > *)rObj.getValue(), (sal_Int16)nPos );
683 :
684 : // cleanup
685 0 : while (nPos--)
686 : {
687 0 : if (pParams[nPos].bIn)
688 0 : uno_destructData( ppUnoArgs[nPos], ppParamTypes[nPos], 0 );
689 0 : TYPELIB_DANGER_RELEASE( ppParamTypes[nPos] );
690 : }
691 0 : TYPELIB_DANGER_RELEASE( pReturnType );
692 0 : (*pUnoI->release)( pUnoI );
693 :
694 0 : throw aExc;
695 : }
696 : }
697 : }
698 :
699 : uno_Any aUnoExc;
700 2905 : uno_Any * pUnoExc = &aUnoExc;
701 :
702 : (*pUnoI->pDispatcher)(
703 2905 : pUnoI, getTypeDescr(), pUnoReturn, ppUnoArgs, &pUnoExc );
704 2905 : (*pUnoI->release)( pUnoI );
705 :
706 2905 : Any aRet;
707 2905 : if (pUnoExc)
708 : {
709 : // cleanup
710 19 : while (nParams--)
711 : {
712 9 : if (pParams[nParams].bIn)
713 9 : uno_destructData( ppUnoArgs[nParams], ppParamTypes[nParams], 0 );
714 9 : TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
715 : }
716 5 : TYPELIB_DANGER_RELEASE( pReturnType );
717 :
718 5 : InvocationTargetException aExc;
719 5 : aExc.Context = *(const Reference< XInterface > *)rObj.getValue();
720 5 : aExc.Message = "exception occurred during invocation!";
721 : uno_any_destruct(
722 : &aExc.TargetException,
723 5 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
724 : uno_type_copyAndConvertData(
725 5 : &aExc.TargetException, pUnoExc, ::getCppuType( (const Any *)0 ).getTypeLibType(),
726 10 : getReflection()->getUno2Cpp().get() );
727 5 : uno_any_destruct( pUnoExc, 0 );
728 5 : throw aExc;
729 : }
730 : else
731 : {
732 : // reconvert arguments and cleanup
733 10781 : while (nParams--)
734 : {
735 4981 : if (pParams[nParams].bOut) // write back
736 : {
737 : uno_any_destruct(
738 8 : &pCppArgs[nParams],
739 16 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
740 : uno_any_constructAndConvert(
741 24 : &pCppArgs[nParams], ppUnoArgs[nParams], ppParamTypes[nParams],
742 32 : getReflection()->getUno2Cpp().get() );
743 : }
744 4981 : uno_destructData( ppUnoArgs[nParams], ppParamTypes[nParams], 0 );
745 4981 : TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
746 : }
747 : uno_any_destruct(
748 2900 : &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
749 : uno_any_constructAndConvert(
750 : &aRet, pUnoReturn, pReturnType,
751 2900 : getReflection()->getUno2Cpp().get() );
752 2900 : uno_destructData( pUnoReturn, pReturnType, 0 );
753 2900 : TYPELIB_DANGER_RELEASE( pReturnType );
754 : }
755 2905 : return aRet;
756 : }
757 : throw IllegalArgumentException(
758 : OUString("illegal destination object given!"),
759 0 : (XWeak *)(OWeakObject *)this, 0 );
760 : }
761 :
762 :
763 :
764 :
765 :
766 :
767 :
768 :
769 17820 : InterfaceIdlClassImpl::~InterfaceIdlClassImpl()
770 : {
771 38870 : for ( sal_Int32 nPos = _nMethods + _nAttributes; nPos--; )
772 26990 : typelib_typedescription_release( _pSortedMemberInit[nPos].second );
773 :
774 5940 : delete [] _pSortedMemberInit;
775 11880 : }
776 :
777 :
778 24764 : Sequence< Reference< XIdlClass > > InterfaceIdlClassImpl::getSuperclasses()
779 : throw(::com::sun::star::uno::RuntimeException, std::exception)
780 : {
781 24764 : MutexGuard aGuard(getMutexAccess());
782 24764 : if (_xSuperClasses.getLength() == 0) {
783 16498 : typelib_InterfaceTypeDescription * pType = getTypeDescr();
784 16498 : _xSuperClasses.realloc(pType->nBaseTypes);
785 22722 : for (sal_Int32 i = 0; i < pType->nBaseTypes; ++i) {
786 12448 : _xSuperClasses[i] = getReflection()->forType(
787 12448 : &pType->ppBaseTypes[i]->aBase);
788 : OSL_ASSERT(_xSuperClasses[i].is());
789 : }
790 : }
791 24764 : return Sequence< Reference< XIdlClass > >(_xSuperClasses);
792 : }
793 :
794 5442 : void InterfaceIdlClassImpl::initMembers()
795 : {
796 5442 : sal_Int32 nAll = getTypeDescr()->nAllMembers;
797 5442 : MemberInit * pSortedMemberInit = new MemberInit[nAll];
798 5442 : typelib_TypeDescriptionReference ** ppAllMembers = getTypeDescr()->ppAllMembers;
799 :
800 42873 : for ( sal_Int32 nPos = 0; nPos < nAll; ++nPos )
801 : {
802 : sal_Int32 nIndex;
803 37431 : if (ppAllMembers[nPos]->eTypeClass == typelib_TypeClass_INTERFACE_METHOD)
804 : {
805 : // methods to front
806 35986 : nIndex = _nMethods;
807 35986 : ++_nMethods;
808 : }
809 : else
810 : {
811 1445 : ++_nAttributes;
812 1445 : nIndex = (nAll - _nAttributes);
813 : // attributes at the back
814 : }
815 :
816 37431 : typelib_TypeDescription * pTD = 0;
817 37431 : typelib_typedescriptionreference_getDescription( &pTD, ppAllMembers[nPos] );
818 : OSL_ENSURE( pTD, "### cannot get type description!" );
819 37431 : pSortedMemberInit[nIndex].first = ((typelib_InterfaceMemberTypeDescription *)pTD)->pMemberName;
820 37431 : pSortedMemberInit[nIndex].second = pTD;
821 : }
822 :
823 5442 : _pSortedMemberInit = pSortedMemberInit;
824 5442 : }
825 :
826 42 : sal_Bool InterfaceIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
827 : throw(::com::sun::star::uno::RuntimeException, std::exception)
828 : {
829 42 : if (xType.is() && xType->getTypeClass() == TypeClass_INTERFACE)
830 : {
831 42 : if (equals( xType ))
832 22 : return sal_True;
833 : else
834 : {
835 20 : const Sequence< Reference< XIdlClass > > & rSeq = xType->getSuperclasses();
836 20 : for (sal_Int32 i = 0; i < rSeq.getLength(); ++i) {
837 12 : if (isAssignableFrom(rSeq[i])) {
838 12 : return true;
839 : }
840 8 : }
841 : }
842 : }
843 8 : return sal_False;
844 : }
845 :
846 0 : Uik InterfaceIdlClassImpl::getUik()
847 : throw(::com::sun::star::uno::RuntimeException, std::exception)
848 : {
849 0 : return Uik(0, 0, 0, 0, 0);
850 : // Uiks are deprecated and this function must not be called
851 : }
852 :
853 11115 : Sequence< Reference< XIdlMethod > > InterfaceIdlClassImpl::getMethods()
854 : throw(::com::sun::star::uno::RuntimeException, std::exception)
855 : {
856 11115 : MutexGuard aGuard( getMutexAccess() );
857 11115 : if (! _pSortedMemberInit)
858 0 : initMembers();
859 :
860 : // create methods sequence
861 11115 : Sequence< Reference< XIdlMethod > > aRet( _nMethods );
862 11115 : Reference< XIdlMethod > * pRet = aRet.getArray();
863 92950 : for ( sal_Int32 nPos = _nMethods; nPos--; )
864 : {
865 :
866 212160 : /*_aName2Method[_pSortedMemberInit[nPos].first] = */pRet[nPos] = new IdlInterfaceMethodImpl(
867 141440 : getReflection(), _pSortedMemberInit[nPos].first,
868 282880 : _pSortedMemberInit[nPos].second, IdlClassImpl::getTypeDescr() );
869 : }
870 11115 : return aRet;
871 : }
872 :
873 11115 : Sequence< Reference< XIdlField > > InterfaceIdlClassImpl::getFields()
874 : throw(::com::sun::star::uno::RuntimeException, std::exception)
875 : {
876 11115 : MutexGuard aGuard( getMutexAccess() );
877 11115 : if (! _pSortedMemberInit)
878 5425 : initMembers();
879 :
880 : // create fields sequence
881 11115 : Sequence< Reference< XIdlField > > aRet( _nAttributes );
882 11115 : Reference< XIdlField > * pRet = aRet.getArray();
883 24386 : for ( sal_Int32 nPos = _nAttributes; nPos--; )
884 : {
885 6468 : /*_aName2Field[_pSortedMemberInit[_nMethods+nPos].first] = */pRet[_nAttributes-nPos-1] =
886 : new IdlAttributeFieldImpl(
887 4312 : getReflection(), _pSortedMemberInit[_nMethods+nPos].first,
888 8624 : _pSortedMemberInit[_nMethods+nPos].second, IdlClassImpl::getTypeDescr() );
889 : }
890 11115 : return aRet;
891 : }
892 :
893 19 : Reference< XIdlMethod > InterfaceIdlClassImpl::getMethod( const OUString & rName )
894 : throw(::com::sun::star::uno::RuntimeException, std::exception)
895 : {
896 19 : MutexGuard aGuard( getMutexAccess() );
897 19 : if (! _pSortedMemberInit)
898 0 : initMembers();
899 :
900 19 : Reference< XIdlMethod > xRet;
901 :
902 : // try weak map
903 19 : const OUString2Method::const_iterator iFind( _aName2Method.find( rName ) );
904 19 : if (iFind != _aName2Method.end())
905 15 : xRet = (*iFind).second; // harden ref
906 :
907 19 : if (! xRet.is())
908 : {
909 56 : for ( sal_Int32 nPos = _nMethods; nPos--; )
910 : {
911 37 : if (_pSortedMemberInit[nPos].first == rName)
912 : {
913 57 : _aName2Method[rName] = xRet = new IdlInterfaceMethodImpl(
914 19 : getReflection(), rName,
915 57 : _pSortedMemberInit[nPos].second, IdlClassImpl::getTypeDescr() );
916 19 : break;
917 : }
918 : }
919 : }
920 19 : return xRet;
921 : }
922 :
923 1344 : Reference< XIdlField > InterfaceIdlClassImpl::getField( const OUString & rName )
924 : throw(::com::sun::star::uno::RuntimeException, std::exception)
925 : {
926 1344 : MutexGuard aGuard( getMutexAccess() );
927 1344 : if (! _pSortedMemberInit)
928 17 : initMembers();
929 :
930 1344 : Reference< XIdlField > xRet;
931 :
932 : // try weak map
933 1344 : const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
934 1344 : if (iFind != _aName2Field.end())
935 1310 : xRet = (*iFind).second; // harden ref
936 :
937 1344 : if (! xRet.is())
938 : {
939 2240 : for ( sal_Int32 nPos = _nAttributes; nPos--; )
940 : {
941 1344 : if (_pSortedMemberInit[_nMethods+nPos].first == rName)
942 : {
943 2688 : _aName2Field[rName] = xRet = new IdlAttributeFieldImpl(
944 896 : getReflection(), rName,
945 2688 : _pSortedMemberInit[_nMethods+nPos].second, IdlClassImpl::getTypeDescr() );
946 896 : break;
947 : }
948 : }
949 : }
950 1344 : return xRet;
951 : }
952 :
953 0 : void InterfaceIdlClassImpl::createObject( Any & rObj )
954 : throw(::com::sun::star::uno::RuntimeException, std::exception)
955 : {
956 : // interfaces cannot be constructed
957 0 : rObj.clear();
958 0 : }
959 :
960 : }
961 :
962 :
963 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|