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