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 0 : class IdlAttributeFieldImpl
43 : : public IdlMemberImpl
44 : , public XIdlField
45 : , public XIdlField2
46 : {
47 : public:
48 0 : typelib_InterfaceAttributeTypeDescription * getAttributeTypeDescr()
49 0 : { return (typelib_InterfaceAttributeTypeDescription *)getTypeDescr(); }
50 :
51 0 : IdlAttributeFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
52 : typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr )
53 0 : : IdlMemberImpl( pReflection, rName, pTypeDescr, pDeclTypeDescr )
54 0 : {}
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 0 : 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 0 : static_cast< XIdlField2 * >( this ) ) );
89 0 : return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
90 : }
91 :
92 0 : void IdlAttributeFieldImpl::acquire() throw()
93 : {
94 0 : IdlMemberImpl::acquire();
95 0 : }
96 :
97 0 : void IdlAttributeFieldImpl::release() throw()
98 : {
99 0 : IdlMemberImpl::release();
100 0 : }
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 0 : OUString IdlAttributeFieldImpl::getName()
149 : throw(::com::sun::star::uno::RuntimeException, std::exception)
150 : {
151 0 : return IdlMemberImpl::getName();
152 : }
153 :
154 : // XIdlField
155 :
156 0 : Reference< XIdlClass > IdlAttributeFieldImpl::getType()
157 : throw(::com::sun::star::uno::RuntimeException, std::exception)
158 : {
159 : return getReflection()->forType(
160 0 : getAttributeTypeDescr()->pAttributeTypeRef );
161 : }
162 :
163 0 : FieldAccessMode IdlAttributeFieldImpl::getAccessMode()
164 : throw(::com::sun::star::uno::RuntimeException, std::exception)
165 : {
166 0 : return (((typelib_InterfaceAttributeTypeDescription *)getAttributeTypeDescr())->bReadOnly
167 0 : ? FieldAccessMode_READONLY : FieldAccessMode_READWRITE);
168 : }
169 :
170 0 : 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 0 : rObj, (typelib_InterfaceTypeDescription *)getDeclTypeDescr() );
175 : OSL_ENSURE( pUnoI, "### illegal destination object given!" );
176 0 : if (pUnoI)
177 : {
178 0 : TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
179 0 : typelib_TypeDescription * pTD = aTD.get();
180 :
181 : uno_Any aExc;
182 0 : uno_Any * pExc = &aExc;
183 0 : void * pReturn = alloca( pTD->nSize );
184 :
185 0 : (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), pReturn, 0, &pExc );
186 0 : (*pUnoI->release)( pUnoI );
187 :
188 : checkException(
189 : pExc,
190 0 : *static_cast< Reference< XInterface > const * >(rObj.getValue()));
191 0 : Any aRet;
192 : uno_any_destruct(
193 0 : &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
194 0 : uno_any_constructAndConvert( &aRet, pReturn, pTD, getReflection()->getUno2Cpp().get() );
195 0 : uno_destructData( pReturn, pTD, 0 );
196 0 : return aRet;
197 : }
198 : throw IllegalArgumentException(
199 : OUString("illegal object given!"),
200 0 : (XWeak *)(OWeakObject *)this, 0 );
201 : }
202 :
203 0 : 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 0 : 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 0 : rObj, (typelib_InterfaceTypeDescription *)getDeclTypeDescr() );
215 : OSL_ENSURE( pUnoI, "### illegal destination object given!" );
216 0 : if (pUnoI)
217 : {
218 0 : TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
219 0 : typelib_TypeDescription * pTD = aTD.get();
220 :
221 : // construct uno value to be set
222 : void * pArgs[1];
223 0 : void * pArg = pArgs[0] = alloca( pTD->nSize );
224 :
225 : sal_Bool bAssign;
226 0 : if (pTD->eTypeClass == typelib_TypeClass_ANY)
227 : {
228 : uno_copyAndConvertData( pArg, (const_cast< Any * >(&rValue)),
229 0 : pTD, getReflection()->getCpp2Uno().get() );
230 0 : bAssign = sal_True;
231 : }
232 0 : else if (typelib_typedescriptionreference_equals( rValue.getValueTypeRef(), pTD->pWeakRef ))
233 : {
234 0 : uno_copyAndConvertData( pArg, (const_cast< void * >(rValue.getValue()) ),
235 0 : pTD, getReflection()->getCpp2Uno().get() );
236 0 : 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 0 : if (bAssign)
269 : {
270 : uno_Any aExc;
271 0 : uno_Any * pExc = &aExc;
272 0 : (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), 0, pArgs, &pExc );
273 0 : (*pUnoI->release)( pUnoI );
274 :
275 0 : uno_destructData( pArg, pTD, 0 );
276 : checkException(
277 : pExc,
278 : *static_cast< Reference< XInterface > const * >(
279 0 : rObj.getValue()));
280 0 : return;
281 : }
282 0 : (*pUnoI->release)( pUnoI );
283 :
284 : throw IllegalArgumentException(
285 : OUString("illegal value given!"),
286 0 : *(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 0 : void IdlAttributeFieldImpl::checkException(
300 : uno_Any * exception, Reference< XInterface > const & context)
301 : {
302 0 : 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 0 : }
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 0 : typelib_InterfaceMethodTypeDescription * getMethodTypeDescr()
339 0 : { return (typelib_InterfaceMethodTypeDescription *)getTypeDescr(); }
340 :
341 0 : 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 0 : , _pParamInfos( 0 )
347 0 : {}
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 0 : IdlInterfaceMethodImpl::~IdlInterfaceMethodImpl()
372 : {
373 0 : delete _pParamInfos;
374 0 : delete _pParamTypes;
375 0 : delete _pExceptionTypes;
376 0 : }
377 :
378 : // XInterface
379 :
380 0 : Any IdlInterfaceMethodImpl::queryInterface( const Type & rType )
381 : throw(::com::sun::star::uno::RuntimeException, std::exception)
382 : {
383 0 : Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlMethod * >( this ) ) );
384 0 : return (aRet.hasValue() ? aRet : IdlMemberImpl::queryInterface( rType ));
385 : }
386 :
387 0 : void IdlInterfaceMethodImpl::acquire() throw()
388 : {
389 0 : IdlMemberImpl::acquire();
390 0 : }
391 :
392 0 : void IdlInterfaceMethodImpl::release() throw()
393 : {
394 0 : IdlMemberImpl::release();
395 0 : }
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 0 : Reference< XIdlClass > IdlInterfaceMethodImpl::getDeclaringClass()
426 : throw(::com::sun::star::uno::RuntimeException, std::exception)
427 : {
428 0 : if (! _xDeclClass.is())
429 : {
430 0 : MutexGuard aGuard( getMutexAccess() );
431 0 : if (! _xDeclClass.is())
432 : {
433 0 : OUString aName(getMethodTypeDescr()->aBase.aBase.pTypeName);
434 0 : sal_Int32 i = aName.indexOf(':');
435 : OSL_ASSERT(i >= 0);
436 0 : _xDeclClass = getReflection()->forName(aName.copy(0, i));
437 0 : }
438 : }
439 0 : return _xDeclClass;
440 : }
441 :
442 0 : OUString IdlInterfaceMethodImpl::getName()
443 : throw(::com::sun::star::uno::RuntimeException, std::exception)
444 : {
445 0 : return IdlMemberImpl::getName();
446 : }
447 :
448 : // XIdlMethod
449 :
450 0 : Reference< XIdlClass > SAL_CALL IdlInterfaceMethodImpl::getReturnType()
451 : throw(::com::sun::star::uno::RuntimeException, std::exception)
452 : {
453 0 : return getReflection()->forType( getMethodTypeDescr()->pReturnTypeRef );
454 : }
455 :
456 0 : Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes()
457 : throw(::com::sun::star::uno::RuntimeException, std::exception)
458 : {
459 0 : if (! _pExceptionTypes)
460 : {
461 0 : MutexGuard aGuard( getMutexAccess() );
462 0 : if (! _pExceptionTypes)
463 : {
464 0 : sal_Int32 nExc = getMethodTypeDescr()->nExceptions;
465 : Sequence< Reference< XIdlClass > > * pTempExceptionTypes =
466 0 : new Sequence< Reference< XIdlClass > >( nExc );
467 0 : Reference< XIdlClass > * pExceptionTypes = pTempExceptionTypes->getArray();
468 :
469 : typelib_TypeDescriptionReference ** ppExc =
470 0 : getMethodTypeDescr()->ppExceptions;
471 0 : IdlReflectionServiceImpl * pRefl = getReflection();
472 :
473 0 : while (nExc--)
474 0 : pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] );
475 :
476 0 : _pExceptionTypes = pTempExceptionTypes;
477 0 : }
478 : }
479 0 : return *_pExceptionTypes;
480 : }
481 :
482 0 : Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes()
483 : throw(::com::sun::star::uno::RuntimeException, std::exception)
484 : {
485 0 : if (! _pParamTypes)
486 : {
487 0 : MutexGuard aGuard( getMutexAccess() );
488 0 : if (! _pParamTypes)
489 : {
490 0 : sal_Int32 nParams = getMethodTypeDescr()->nParams;
491 : Sequence< Reference< XIdlClass > > * pTempParamTypes =
492 0 : new Sequence< Reference< XIdlClass > >( nParams );
493 0 : Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray();
494 :
495 : typelib_MethodParameter * pTypelibParams =
496 0 : getMethodTypeDescr()->pParams;
497 0 : IdlReflectionServiceImpl * pRefl = getReflection();
498 :
499 0 : while (nParams--)
500 0 : pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef );
501 :
502 0 : _pParamTypes = pTempParamTypes;
503 0 : }
504 : }
505 0 : return *_pParamTypes;
506 : }
507 :
508 0 : Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
509 : throw(::com::sun::star::uno::RuntimeException, std::exception)
510 : {
511 0 : if (! _pParamInfos)
512 : {
513 0 : MutexGuard aGuard( getMutexAccess() );
514 0 : if (! _pParamInfos)
515 : {
516 0 : sal_Int32 nParams = getMethodTypeDescr()->nParams;
517 0 : Sequence< ParamInfo > * pTempParamInfos = new Sequence< ParamInfo >( nParams );
518 0 : ParamInfo * pParamInfos = pTempParamInfos->getArray();
519 :
520 : typelib_MethodParameter * pTypelibParams =
521 0 : getMethodTypeDescr()->pParams;
522 :
523 0 : if (_pParamTypes) // use param types
524 : {
525 0 : const Reference< XIdlClass > * pParamTypes = _pParamTypes->getConstArray();
526 :
527 0 : while (nParams--)
528 : {
529 0 : const typelib_MethodParameter & rParam = pTypelibParams[nParams];
530 0 : ParamInfo & rInfo = pParamInfos[nParams];
531 0 : rInfo.aName = rParam.pName;
532 0 : if (rParam.bIn)
533 0 : rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
534 : else
535 0 : rInfo.aMode = ParamMode_OUT;
536 0 : rInfo.aType = pParamTypes[nParams];
537 : }
538 : }
539 : else // make also param types sequence if not already initialized
540 : {
541 : Sequence< Reference< XIdlClass > > * pTempParamTypes =
542 0 : new Sequence< Reference< XIdlClass > >( nParams );
543 0 : Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray();
544 :
545 0 : IdlReflectionServiceImpl * pRefl = getReflection();
546 :
547 0 : while (nParams--)
548 : {
549 0 : const typelib_MethodParameter & rParam = pTypelibParams[nParams];
550 0 : ParamInfo & rInfo = pParamInfos[nParams];
551 0 : rInfo.aName = rParam.pName;
552 0 : if (rParam.bIn)
553 0 : rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
554 : else
555 0 : rInfo.aMode = ParamMode_OUT;
556 0 : rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef );
557 : }
558 :
559 0 : _pParamTypes = pTempParamTypes;
560 : }
561 :
562 0 : _pParamInfos = pTempParamInfos;
563 0 : }
564 : }
565 0 : 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 0 : 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 0 : if (rObj.getValueTypeClass() == TypeClass_INTERFACE)
581 : {
582 : // acquire()/ release()
583 0 : if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
584 0 : "com.sun.star.uno.XInterface::acquire" ) == 0)
585 : {
586 0 : (*(const Reference< XInterface > *)rObj.getValue())->acquire();
587 0 : return Any();
588 : }
589 0 : else if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
590 0 : "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 0 : rObj, (typelib_InterfaceTypeDescription *)getDeclTypeDescr() );
599 : OSL_ENSURE( pUnoI, "### illegal destination object given!" );
600 0 : if (pUnoI)
601 : {
602 0 : sal_Int32 nParams = getMethodTypeDescr()->nParams;
603 0 : 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 0 : Any * pCppArgs = rArgs.getArray();
612 0 : typelib_MethodParameter * pParams = getMethodTypeDescr()->pParams;
613 0 : typelib_TypeDescription * pReturnType = 0;
614 : TYPELIB_DANGER_GET(
615 0 : &pReturnType, getMethodTypeDescr()->pReturnTypeRef );
616 :
617 0 : void * pUnoReturn = alloca( pReturnType->nSize );
618 0 : void ** ppUnoArgs = (void **)alloca( sizeof(void *) * nParams *2 );
619 0 : typelib_TypeDescription ** ppParamTypes = (typelib_TypeDescription **)(ppUnoArgs + nParams);
620 :
621 : // convert arguments
622 0 : for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
623 : {
624 0 : ppParamTypes[nPos] = 0;
625 0 : TYPELIB_DANGER_GET( ppParamTypes + nPos, pParams[nPos].pTypeRef );
626 0 : typelib_TypeDescription * pTD = ppParamTypes[nPos];
627 :
628 0 : ppUnoArgs[nPos] = alloca( pTD->nSize );
629 0 : if (pParams[nPos].bIn)
630 : {
631 : sal_Bool bAssign;
632 0 : if (typelib_typedescriptionreference_equals(
633 0 : pCppArgs[nPos].getValueTypeRef(), pTD->pWeakRef ))
634 : {
635 : uno_type_copyAndConvertData(
636 0 : ppUnoArgs[nPos], (void *)pCppArgs[nPos].getValue(),
637 0 : pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
638 0 : bAssign = sal_True;
639 : }
640 0 : else if (pTD->eTypeClass == typelib_TypeClass_ANY)
641 : {
642 : uno_type_any_constructAndConvert(
643 0 : (uno_Any *)ppUnoArgs[nPos], (void *)pCppArgs[nPos].getValue(),
644 0 : pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
645 0 : bAssign = sal_True;
646 : }
647 0 : else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
648 : {
649 0 : Reference< XInterface > xDest;
650 : bAssign = extract(
651 : pCppArgs[nPos], (typelib_InterfaceTypeDescription *)pTD,
652 0 : xDest, getReflection() );
653 0 : if (bAssign)
654 : {
655 0 : *(void **)ppUnoArgs[nPos] = getReflection()->getCpp2Uno().mapInterface(
656 0 : xDest.get(), (typelib_InterfaceTypeDescription *)pTD );
657 0 : }
658 : }
659 : else
660 : {
661 0 : typelib_TypeDescription * pValueTD = 0;
662 0 : TYPELIB_DANGER_GET( &pValueTD, pCppArgs[nPos].getValueTypeRef() );
663 : // construct temp uno val to do proper assignment: todo opt
664 0 : void * pTemp = alloca( pValueTD->nSize );
665 : uno_copyAndConvertData(
666 0 : pTemp, (void *)pCppArgs[nPos].getValue(), pValueTD,
667 0 : getReflection()->getCpp2Uno().get() );
668 : uno_constructData(
669 0 : ppUnoArgs[nPos], pTD );
670 : // assignment does simple conversion
671 : bAssign = uno_assignData(
672 0 : ppUnoArgs[nPos], pTD, pTemp, pValueTD, 0, 0, 0 );
673 : uno_destructData(
674 0 : pTemp, pValueTD, 0 );
675 0 : TYPELIB_DANGER_RELEASE( pValueTD );
676 : }
677 :
678 0 : 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 0 : uno_Any * pUnoExc = &aUnoExc;
701 :
702 : (*pUnoI->pDispatcher)(
703 0 : pUnoI, getTypeDescr(), pUnoReturn, ppUnoArgs, &pUnoExc );
704 0 : (*pUnoI->release)( pUnoI );
705 :
706 0 : Any aRet;
707 0 : if (pUnoExc)
708 : {
709 : // cleanup
710 0 : while (nParams--)
711 : {
712 0 : if (pParams[nParams].bIn)
713 0 : uno_destructData( ppUnoArgs[nParams], ppParamTypes[nParams], 0 );
714 0 : TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
715 : }
716 0 : TYPELIB_DANGER_RELEASE( pReturnType );
717 :
718 0 : InvocationTargetException aExc;
719 0 : aExc.Context = *(const Reference< XInterface > *)rObj.getValue();
720 0 : aExc.Message = "exception occurred during invocation!";
721 : uno_any_destruct(
722 : &aExc.TargetException,
723 0 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
724 : uno_type_copyAndConvertData(
725 0 : &aExc.TargetException, pUnoExc, ::getCppuType( (const Any *)0 ).getTypeLibType(),
726 0 : getReflection()->getUno2Cpp().get() );
727 0 : uno_any_destruct( pUnoExc, 0 );
728 0 : throw aExc;
729 : }
730 : else
731 : {
732 : // reconvert arguments and cleanup
733 0 : while (nParams--)
734 : {
735 0 : if (pParams[nParams].bOut) // write back
736 : {
737 : uno_any_destruct(
738 0 : &pCppArgs[nParams],
739 0 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
740 : uno_any_constructAndConvert(
741 0 : &pCppArgs[nParams], ppUnoArgs[nParams], ppParamTypes[nParams],
742 0 : getReflection()->getUno2Cpp().get() );
743 : }
744 0 : uno_destructData( ppUnoArgs[nParams], ppParamTypes[nParams], 0 );
745 0 : TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
746 : }
747 : uno_any_destruct(
748 0 : &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
749 : uno_any_constructAndConvert(
750 : &aRet, pUnoReturn, pReturnType,
751 0 : getReflection()->getUno2Cpp().get() );
752 0 : uno_destructData( pUnoReturn, pReturnType, 0 );
753 0 : TYPELIB_DANGER_RELEASE( pReturnType );
754 : }
755 0 : 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 0 : InterfaceIdlClassImpl::~InterfaceIdlClassImpl()
770 : {
771 0 : for ( sal_Int32 nPos = _nMethods + _nAttributes; nPos--; )
772 0 : typelib_typedescription_release( _pSortedMemberInit[nPos].second );
773 :
774 0 : delete [] _pSortedMemberInit;
775 0 : }
776 :
777 :
778 0 : Sequence< Reference< XIdlClass > > InterfaceIdlClassImpl::getSuperclasses()
779 : throw(::com::sun::star::uno::RuntimeException, std::exception)
780 : {
781 0 : MutexGuard aGuard(getMutexAccess());
782 0 : if (_xSuperClasses.getLength() == 0) {
783 0 : typelib_InterfaceTypeDescription * pType = getTypeDescr();
784 0 : _xSuperClasses.realloc(pType->nBaseTypes);
785 0 : for (sal_Int32 i = 0; i < pType->nBaseTypes; ++i) {
786 0 : _xSuperClasses[i] = getReflection()->forType(
787 0 : &pType->ppBaseTypes[i]->aBase);
788 : OSL_ASSERT(_xSuperClasses[i].is());
789 : }
790 : }
791 0 : return Sequence< Reference< XIdlClass > >(_xSuperClasses);
792 : }
793 :
794 0 : void InterfaceIdlClassImpl::initMembers()
795 : {
796 0 : sal_Int32 nAll = getTypeDescr()->nAllMembers;
797 0 : MemberInit * pSortedMemberInit = new MemberInit[nAll];
798 0 : typelib_TypeDescriptionReference ** ppAllMembers = getTypeDescr()->ppAllMembers;
799 :
800 0 : for ( sal_Int32 nPos = 0; nPos < nAll; ++nPos )
801 : {
802 : sal_Int32 nIndex;
803 0 : if (ppAllMembers[nPos]->eTypeClass == typelib_TypeClass_INTERFACE_METHOD)
804 : {
805 : // methods to front
806 0 : nIndex = _nMethods;
807 0 : ++_nMethods;
808 : }
809 : else
810 : {
811 0 : ++_nAttributes;
812 0 : nIndex = (nAll - _nAttributes);
813 : // attributes at the back
814 : }
815 :
816 0 : typelib_TypeDescription * pTD = 0;
817 0 : typelib_typedescriptionreference_getDescription( &pTD, ppAllMembers[nPos] );
818 : OSL_ENSURE( pTD, "### cannot get type description!" );
819 0 : pSortedMemberInit[nIndex].first = ((typelib_InterfaceMemberTypeDescription *)pTD)->pMemberName;
820 0 : pSortedMemberInit[nIndex].second = pTD;
821 : }
822 :
823 0 : _pSortedMemberInit = pSortedMemberInit;
824 0 : }
825 :
826 0 : sal_Bool InterfaceIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
827 : throw(::com::sun::star::uno::RuntimeException, std::exception)
828 : {
829 0 : if (xType.is() && xType->getTypeClass() == TypeClass_INTERFACE)
830 : {
831 0 : if (equals( xType ))
832 0 : return sal_True;
833 : else
834 : {
835 0 : const Sequence< Reference< XIdlClass > > & rSeq = xType->getSuperclasses();
836 0 : for (sal_Int32 i = 0; i < rSeq.getLength(); ++i) {
837 0 : if (isAssignableFrom(rSeq[i])) {
838 0 : return true;
839 : }
840 0 : }
841 : }
842 : }
843 0 : 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 0 : Sequence< Reference< XIdlMethod > > InterfaceIdlClassImpl::getMethods()
854 : throw(::com::sun::star::uno::RuntimeException, std::exception)
855 : {
856 0 : MutexGuard aGuard( getMutexAccess() );
857 0 : if (! _pSortedMemberInit)
858 0 : initMembers();
859 :
860 : // create methods sequence
861 0 : Sequence< Reference< XIdlMethod > > aRet( _nMethods );
862 0 : Reference< XIdlMethod > * pRet = aRet.getArray();
863 0 : for ( sal_Int32 nPos = _nMethods; nPos--; )
864 : {
865 :
866 0 : /*_aName2Method[_pSortedMemberInit[nPos].first] = */pRet[nPos] = new IdlInterfaceMethodImpl(
867 0 : getReflection(), _pSortedMemberInit[nPos].first,
868 0 : _pSortedMemberInit[nPos].second, IdlClassImpl::getTypeDescr() );
869 : }
870 0 : return aRet;
871 : }
872 :
873 0 : Sequence< Reference< XIdlField > > InterfaceIdlClassImpl::getFields()
874 : throw(::com::sun::star::uno::RuntimeException, std::exception)
875 : {
876 0 : MutexGuard aGuard( getMutexAccess() );
877 0 : if (! _pSortedMemberInit)
878 0 : initMembers();
879 :
880 : // create fields sequence
881 0 : Sequence< Reference< XIdlField > > aRet( _nAttributes );
882 0 : Reference< XIdlField > * pRet = aRet.getArray();
883 0 : for ( sal_Int32 nPos = _nAttributes; nPos--; )
884 : {
885 0 : /*_aName2Field[_pSortedMemberInit[_nMethods+nPos].first] = */pRet[_nAttributes-nPos-1] =
886 : new IdlAttributeFieldImpl(
887 0 : getReflection(), _pSortedMemberInit[_nMethods+nPos].first,
888 0 : _pSortedMemberInit[_nMethods+nPos].second, IdlClassImpl::getTypeDescr() );
889 : }
890 0 : return aRet;
891 : }
892 :
893 0 : Reference< XIdlMethod > InterfaceIdlClassImpl::getMethod( const OUString & rName )
894 : throw(::com::sun::star::uno::RuntimeException, std::exception)
895 : {
896 0 : MutexGuard aGuard( getMutexAccess() );
897 0 : if (! _pSortedMemberInit)
898 0 : initMembers();
899 :
900 0 : Reference< XIdlMethod > xRet;
901 :
902 : // try weak map
903 0 : const OUString2Method::const_iterator iFind( _aName2Method.find( rName ) );
904 0 : if (iFind != _aName2Method.end())
905 0 : xRet = (*iFind).second; // harden ref
906 :
907 0 : if (! xRet.is())
908 : {
909 0 : for ( sal_Int32 nPos = _nMethods; nPos--; )
910 : {
911 0 : if (_pSortedMemberInit[nPos].first == rName)
912 : {
913 0 : _aName2Method[rName] = xRet = new IdlInterfaceMethodImpl(
914 0 : getReflection(), rName,
915 0 : _pSortedMemberInit[nPos].second, IdlClassImpl::getTypeDescr() );
916 0 : break;
917 : }
918 : }
919 : }
920 0 : return xRet;
921 : }
922 :
923 0 : Reference< XIdlField > InterfaceIdlClassImpl::getField( const OUString & rName )
924 : throw(::com::sun::star::uno::RuntimeException, std::exception)
925 : {
926 0 : MutexGuard aGuard( getMutexAccess() );
927 0 : if (! _pSortedMemberInit)
928 0 : initMembers();
929 :
930 0 : Reference< XIdlField > xRet;
931 :
932 : // try weak map
933 0 : const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
934 0 : if (iFind != _aName2Field.end())
935 0 : xRet = (*iFind).second; // harden ref
936 :
937 0 : if (! xRet.is())
938 : {
939 0 : for ( sal_Int32 nPos = _nAttributes; nPos--; )
940 : {
941 0 : if (_pSortedMemberInit[_nMethods+nPos].first == rName)
942 : {
943 0 : _aName2Field[rName] = xRet = new IdlAttributeFieldImpl(
944 0 : getReflection(), rName,
945 0 : _pSortedMemberInit[_nMethods+nPos].second, IdlClassImpl::getTypeDescr() );
946 0 : break;
947 : }
948 : }
949 : }
950 0 : 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: */
|