30#include <typelib/typedescription.hxx>
35#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
36#include <com/sun/star/reflection/XIdlField2.hpp>
37#include <com/sun/star/uno/RuntimeException.hpp>
42using namespace css::lang;
43using namespace css::reflection;
44using namespace css::uno;
48std::size_t multipleOf16(std::size_t n) {
49 assert(n <= std::numeric_limits<std::size_t>::max() - 15);
50 return (n + 15) &
~std::size_t(15);
60typedef cppu::ImplInheritanceHelper<IdlMemberImpl, XIdlField, XIdlField2> IdlAttributeFieldImpl_Base;
61class IdlAttributeFieldImpl :
public IdlAttributeFieldImpl_Base
64 typelib_InterfaceAttributeTypeDescription * getAttributeTypeDescr()
const
65 {
return reinterpret_cast<typelib_InterfaceAttributeTypeDescription *
>(getTypeDescr()); }
67 IdlAttributeFieldImpl( IdlReflectionServiceImpl * pReflection,
const OUString & rName,
69 : IdlAttributeFieldImpl_Base( pReflection, rName, pTypeDescr, pDeclTypeDescr )
73 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass()
override;
74 virtual OUString SAL_CALL getName()
override;
76 virtual Reference< XIdlClass > SAL_CALL
getType()
override;
77 virtual FieldAccessMode SAL_CALL getAccessMode()
override;
78 virtual Any SAL_CALL
get(
const Any & rObj )
override;
79 virtual void SAL_CALL
set(
const Any & rObj,
const Any & rValue )
override;
81 virtual void SAL_CALL
set( Any & rObj,
const Any & rValue )
override;
85 uno_Any * exception, Reference< XInterface >
const & context)
const;
92Reference< XIdlClass > IdlAttributeFieldImpl::getDeclaringClass()
94 if (! _xDeclClass.is())
97 if (! _xDeclClass.is())
99 OUString
aName(getAttributeTypeDescr()->aBase.aBase.pTypeName);
100 sal_Int32
i =
aName.indexOf(
':');
102 _xDeclClass = getReflection()->forName(
aName.copy(0, i));
108OUString IdlAttributeFieldImpl::getName()
115Reference< XIdlClass > IdlAttributeFieldImpl::getType()
117 return getReflection()->forType(
118 getAttributeTypeDescr()->pAttributeTypeRef );
121FieldAccessMode IdlAttributeFieldImpl::getAccessMode()
123 return (getAttributeTypeDescr()->bReadOnly
124 ? FieldAccessMode_READONLY : FieldAccessMode_READWRITE);
127Any IdlAttributeFieldImpl::get(
const Any & rObj )
129 uno_Interface * pUnoI = getReflection()->mapToUno(
130 rObj,
reinterpret_cast<typelib_InterfaceTypeDescription *
>(getDeclTypeDescr()) );
131 OSL_ENSURE( pUnoI,
"### illegal destination object given!" );
134 TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
139 void * pReturn = alloca( pTD->nSize );
141 (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), pReturn,
nullptr, &pExc );
142 (*pUnoI->release)( pUnoI );
144 checkException(pExc, *
o3tl::doAccess<Reference<XInterface>>(rObj));
147 &aRet,
reinterpret_cast< uno_ReleaseFunc
>(cpp_release) );
152 throw IllegalArgumentException(
153 "illegal object given!",
157void IdlAttributeFieldImpl::set( Any & rObj,
const Any & rValue )
159 if (getAttributeTypeDescr()->bReadOnly)
161 throw IllegalAccessException(
162 "cannot set readonly attribute!",
166 uno_Interface * pUnoI = getReflection()->mapToUno(
167 rObj,
reinterpret_cast<typelib_InterfaceTypeDescription *
>(getDeclTypeDescr()) );
168 OSL_ENSURE( pUnoI,
"### illegal destination object given!" );
171 TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
176 void * pArg = pArgs[0] = alloca( pTD->nSize );
179 if (pTD->eTypeClass == typelib_TypeClass_ANY)
182 pTD, getReflection()->getCpp2Uno().
get() );
188 pTD, getReflection()->getCpp2Uno().
get() );
191 else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
193 Reference< XInterface > xObj;
195 rValue,
reinterpret_cast<typelib_InterfaceTypeDescription *
>(pTD), xObj,
199 *
static_cast<void **
>(pArg) = getReflection()->getCpp2Uno().mapInterface(
200 xObj.get(),
reinterpret_cast<typelib_InterfaceTypeDescription *
>(pTD) );
206 TYPELIB_DANGER_GET( &pValueTD, rValue.getValueTypeRef() );
208 void * pTemp = alloca( pValueTD->nSize );
210 pTemp,
const_cast<void *
>(rValue.getValue()), pValueTD, getReflection()->getCpp2Uno().
get() );
215 pArg, pTD, pTemp, pValueTD,
nullptr,
nullptr,
nullptr );
217 pTemp, pValueTD,
nullptr );
218 TYPELIB_DANGER_RELEASE( pValueTD );
225 (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(),
nullptr, pArgs, &pExc );
226 (*pUnoI->release)( pUnoI );
229 checkException(pExc, *
o3tl::doAccess<Reference<XInterface>>(rObj));
232 (*pUnoI->release)( pUnoI );
234 throw IllegalArgumentException(
235 "illegal value given!",
238 throw IllegalArgumentException(
239 "illegal destination object given!",
243void IdlAttributeFieldImpl::set(
const Any & rObj,
const Any & rValue )
245 IdlAttributeFieldImpl::set(
const_cast< Any &
>( rObj ), rValue );
248void IdlAttributeFieldImpl::checkException(
249 uno_Any * exception, Reference< XInterface >
const & context)
const
251 if (exception ==
nullptr)
257 &e, exception->pData, exception->pType,
258 getReflection()->getUno2Cpp().
get());
260 if (!e.isExtractableTo(
263 throw WrappedTargetRuntimeException(
264 "non-RuntimeException occurred when accessing an"
265 " interface type attribute",
273typedef cppu::ImplInheritanceHelper<IdlMemberImpl, XIdlMethod> IdlInterfaceMethodImpl_Base;
274class IdlInterfaceMethodImpl :
public IdlInterfaceMethodImpl_Base
281 typelib_InterfaceMethodTypeDescription * getMethodTypeDescr()
const
282 {
return reinterpret_cast<typelib_InterfaceMethodTypeDescription *
>(getTypeDescr()); }
284 IdlInterfaceMethodImpl( IdlReflectionServiceImpl * pReflection,
const OUString & rName,
286 : IdlInterfaceMethodImpl_Base( pReflection, rName, pTypeDescr, pDeclTypeDescr )
293 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass()
override;
294 virtual OUString SAL_CALL getName()
override;
296 virtual Reference< XIdlClass > SAL_CALL getReturnType()
override;
297 virtual Sequence< Reference< XIdlClass > > SAL_CALL getParameterTypes()
override;
298 virtual Sequence< ParamInfo > SAL_CALL getParameterInfos()
override;
299 virtual Sequence< Reference< XIdlClass > > SAL_CALL getExceptionTypes()
override;
300 virtual MethodMode SAL_CALL
getMode()
override;
301 virtual Any SAL_CALL
invoke(
const Any & rObj, Sequence< Any > & rArgs )
override;
310 return css::uno::Sequence<sal_Int8>();
315Reference< XIdlClass > IdlInterfaceMethodImpl::getDeclaringClass()
317 if (! _xDeclClass.is())
320 if (! _xDeclClass.is())
322 OUString
aName(getMethodTypeDescr()->aBase.aBase.pTypeName);
323 sal_Int32
i =
aName.indexOf(
':');
325 _xDeclClass = getReflection()->forName(
aName.copy(0, i));
331OUString IdlInterfaceMethodImpl::getName()
338Reference< XIdlClass > SAL_CALL IdlInterfaceMethodImpl::getReturnType()
340 return getReflection()->forType( getMethodTypeDescr()->pReturnTypeRef );
343Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes()
350 sal_Int32 nExc = getMethodTypeDescr()->nExceptions;
351 Sequence< Reference< XIdlClass > > aTempExceptionTypes( nExc );
352 Reference< XIdlClass > * pExceptionTypes = aTempExceptionTypes.getArray();
354 typelib_TypeDescriptionReference ** ppExc =
355 getMethodTypeDescr()->ppExceptions;
356 IdlReflectionServiceImpl * pRefl = getReflection();
359 pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] );
367Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes()
374 sal_Int32 nParams = getMethodTypeDescr()->nParams;
375 Sequence< Reference< XIdlClass > > aTempParamTypes( nParams );
376 Reference< XIdlClass > * pParamTypes = aTempParamTypes.getArray();
378 typelib_MethodParameter * pTypelibParams =
379 getMethodTypeDescr()->pParams;
380 IdlReflectionServiceImpl * pRefl = getReflection();
383 pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef );
391Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
398 sal_Int32 nParams = getMethodTypeDescr()->nParams;
399 Sequence< ParamInfo > aTempParamInfos( nParams );
400 ParamInfo * pParamInfos = aTempParamInfos.getArray();
402 typelib_MethodParameter * pTypelibParams =
403 getMethodTypeDescr()->pParams;
407 const Reference< XIdlClass > * pParamTypes =
m_xParamTypes->getConstArray();
411 const typelib_MethodParameter & rParam = pTypelibParams[nParams];
412 ParamInfo & rInfo = pParamInfos[nParams];
413 rInfo.aName = rParam.pName;
415 rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
417 rInfo.aMode = ParamMode_OUT;
418 rInfo.aType = pParamTypes[nParams];
423 Sequence< Reference< XIdlClass > > aTempParamTypes( nParams );
424 Reference< XIdlClass > * pParamTypes = aTempParamTypes.getArray();
426 IdlReflectionServiceImpl * pRefl = getReflection();
430 const typelib_MethodParameter & rParam = pTypelibParams[nParams];
431 ParamInfo & rInfo = pParamInfos[nParams];
432 rInfo.aName = rParam.pName;
434 rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
436 rInfo.aMode = ParamMode_OUT;
437 rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef );
449MethodMode SAL_CALL IdlInterfaceMethodImpl::getMode()
452 getMethodTypeDescr()->bOneWay ? MethodMode_ONEWAY : MethodMode_TWOWAY;
455Any SAL_CALL IdlInterfaceMethodImpl::invoke(
const Any & rObj, Sequence< Any > & rArgs )
457 if (
auto ifc =
o3tl::tryAccess<css::uno::Reference<css::uno::XInterface>>(
461 if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
462 "com.sun.star.uno.XInterface::acquire" ) == 0)
467 else if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
468 "com.sun.star.uno.XInterface::release" ) == 0)
475 uno_Interface * pUnoI = getReflection()->mapToUno(
476 rObj,
reinterpret_cast<typelib_InterfaceTypeDescription *
>(getDeclTypeDescr()) );
477 OSL_ENSURE( pUnoI,
"### illegal destination object given!" );
480 sal_Int32 nParams = getMethodTypeDescr()->nParams;
481 if (rArgs.getLength() != nParams)
483 (*pUnoI->release)( pUnoI );
484 throw IllegalArgumentException(
485 "expected " + OUString::number(nParams) +
486 " arguments, got " + OUString::number(rArgs.getLength()),
490 Any * pCppArgs = rArgs.getArray();
491 typelib_MethodParameter * pParams = getMethodTypeDescr()->pParams;
494 &pReturnType, getMethodTypeDescr()->pReturnTypeRef );
501 void * pUnoReturn = (pReturnType->nSize == 0) ?
nullptr : alloca( multipleOf16(pReturnType->nSize) );
502 void ** ppUnoArgs =
static_cast<void **
>(alloca(
sizeof(
void *) * nParams *2 ));
506 for ( sal_Int32 nPos = 0;
nPos < nParams; ++
nPos )
508 ppParamTypes[
nPos] =
nullptr;
509 TYPELIB_DANGER_GET( ppParamTypes + nPos, pParams[nPos].pTypeRef );
512 ppUnoArgs[
nPos] = alloca( pTD->nSize );
513 if (pParams[nPos].bIn)
517 pCppArgs[nPos].getValueTypeRef(), pTD->pWeakRef ))
520 ppUnoArgs[nPos],
const_cast<void *
>(pCppArgs[nPos].
getValue()),
521 pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().
get() );
524 else if (pTD->eTypeClass == typelib_TypeClass_ANY)
527 static_cast<uno_Any *
>(ppUnoArgs[nPos]),
const_cast<void *
>(pCppArgs[nPos].
getValue()),
528 pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().
get() );
531 else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
533 Reference< XInterface > xDest;
535 pCppArgs[nPos],
reinterpret_cast<typelib_InterfaceTypeDescription *
>(pTD),
536 xDest, getReflection() );
539 *
static_cast<void **
>(ppUnoArgs[
nPos]) = getReflection()->getCpp2Uno().mapInterface(
540 xDest.get(),
reinterpret_cast<typelib_InterfaceTypeDescription *
>(pTD) );
546 TYPELIB_DANGER_GET( &pValueTD, pCppArgs[nPos].getValueTypeRef() );
548 void * pTemp = alloca( pValueTD->nSize );
550 pTemp,
const_cast<void *
>(pCppArgs[nPos].
getValue()), pValueTD,
551 getReflection()->getCpp2Uno().
get() );
553 ppUnoArgs[nPos], pTD );
556 ppUnoArgs[nPos], pTD, pTemp, pValueTD,
nullptr,
nullptr,
nullptr );
558 pTemp, pValueTD,
nullptr );
559 TYPELIB_DANGER_RELEASE( pValueTD );
564 IllegalArgumentException aExc(
565 "cannot coerce argument type during corereflection call:"
566 "\narg no.: " + OUString::number(nPos)
567 +
" expected: \"" + OUString::unacquired(&pTD->pTypeName)
568 +
"\" actual: \"" + OUString::unacquired(&pCppArgs[nPos].getValueTypeRef()->pTypeName)
570 *
o3tl::doAccess<Reference<XInterface>>(rObj),
static_cast<sal_Int16
>(nPos) );
575 if (pParams[nPos].bIn)
577 TYPELIB_DANGER_RELEASE( ppParamTypes[nPos] );
579 TYPELIB_DANGER_RELEASE( pReturnType );
580 (*pUnoI->release)( pUnoI );
590 (*pUnoI->pDispatcher)(
591 pUnoI, getTypeDescr(), pUnoReturn, ppUnoArgs, &pUnoExc );
592 (*pUnoI->release)( pUnoI );
600 if (pParams[nParams].bIn)
602 TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
604 TYPELIB_DANGER_RELEASE( pReturnType );
606 InvocationTargetException aExc;
607 aExc.Context = *o3tl::doAccess<Reference<XInterface>>(rObj);
608 aExc.Message =
"exception occurred during invocation!";
610 &aExc.TargetException,
611 reinterpret_cast< uno_ReleaseFunc
>(cpp_release) );
614 getReflection()->getUno2Cpp().
get() );
623 if (pParams[nParams].bOut)
627 reinterpret_cast< uno_ReleaseFunc
>(cpp_release) );
629 &pCppArgs[nParams], ppUnoArgs[nParams], ppParamTypes[nParams],
630 getReflection()->getUno2Cpp().
get() );
633 TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
636 &aRet,
reinterpret_cast< uno_ReleaseFunc
>(cpp_release) );
638 &aRet, pUnoReturn, pReturnType,
639 getReflection()->getUno2Cpp().
get() );
641 TYPELIB_DANGER_RELEASE( pReturnType );
645 throw IllegalArgumentException(
646 "illegal destination object given!",
662 typelib_InterfaceTypeDescription * pType =
getTypeDescr();
665 for (sal_Int32
i = 0;
i < pType->nBaseTypes; ++
i) {
667 &pType->ppBaseTypes[
i]->aBase);
677 std::unique_ptr<MemberInit[]> pSortedMemberInit(
new MemberInit[nAll]);
678 typelib_TypeDescriptionReference ** ppAllMembers =
getTypeDescr()->ppAllMembers;
683 if (ppAllMembers[
nPos]->eTypeClass == typelib_TypeClass_INTERFACE_METHOD)
698 assert(pTD &&
"### cannot get type description!");
699 pSortedMemberInit[
nIndex].first =
reinterpret_cast<typelib_InterfaceMemberTypeDescription *
>(pTD)->pMemberName;
700 pSortedMemberInit[
nIndex].second = pTD;
708 if (xType.is() && xType->getTypeClass() == TypeClass_INTERFACE)
714 const Sequence< Reference< XIdlClass > > & rSeq = xType->getSuperclasses();
715 if (std::any_of(rSeq.begin(), rSeq.end(),
716 [
this](
const Reference<XIdlClass>& rType){ return isAssignableFrom(rType); }))
725 return Uik(0, 0, 0, 0, 0);
736 Sequence< Reference< XIdlMethod > > aRet(
_nMethods );
737 Reference< XIdlMethod > * pRet = aRet.getArray();
741 pRet[
nPos] =
new IdlInterfaceMethodImpl(
755 Sequence< Reference< XIdlField > > aRet(
_nAttributes );
756 Reference< XIdlField > * pRet = aRet.getArray();
760 new IdlAttributeFieldImpl(
773 Reference< XIdlMethod > xRet;
776 const OUString2Method::const_iterator iFind(
_aName2Method.find( rName ) );
778 xRet = (*iFind).second;
802 Reference< XIdlField > xRet;
805 const OUString2Field::const_iterator iFind(
_aName2Field.find( rName ) );
807 xRet = (*iFind).second;
void SAL_CALL uno_type_any_constructAndConvert(uno_Any *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_constructAndConvert(uno_Any *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
IdlReflectionServiceImpl * getReflection() const
typelib_TypeDescription * getTypeDescr() const
virtual sal_Bool SAL_CALL equals(const css::uno::Reference< css::reflection::XIdlClass > &xType) override
virtual OUString SAL_CALL getName() override
css::uno::Reference< css::reflection::XIdlClass > forType(typelib_TypeDescription *pTypeDescr)
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlMethod > > SAL_CALL getMethods() override
std::unique_ptr< MemberInit[]> _pSortedMemberInit
typelib_InterfaceTypeDescription * getTypeDescr() const
OUString2Method _aName2Method
css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > _xSuperClasses
virtual css::uno::Reference< css::reflection::XIdlMethod > SAL_CALL getMethod(const OUString &rName) override
std::pair< OUString, typelib_TypeDescription * > MemberInit
virtual sal_Bool SAL_CALL isAssignableFrom(const css::uno::Reference< css::reflection::XIdlClass > &xType) override
virtual void SAL_CALL createObject(css::uno::Any &rObj) override
virtual css::uno::Reference< css::reflection::XIdlField > SAL_CALL getField(const OUString &rName) override
virtual ~InterfaceIdlClassImpl() override
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > SAL_CALL getFields() override
virtual css::uno::Uik SAL_CALL getUik() override
OUString2Field _aName2Field
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > SAL_CALL getSuperclasses() override
std::optional< Sequence< Reference< XIdlClass > > > m_xParamTypes
std::optional< Sequence< ParamInfo > > m_xParamInfos
std::optional< Sequence< Reference< XIdlClass > > > m_xExceptionTypes
sal_Bool SAL_CALL uno_assignData(void *pDest, typelib_TypeDescription *pDestTD, void *pSource, typelib_TypeDescription *pSourceTD, uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_type_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void SAL_CALL uno_constructData(void *pMem, typelib_TypeDescription *pTypeDescr) SAL_THROW_EXTERN_C()
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
struct _typelib_TypeDescription typelib_TypeDescription
void set(css::uno::UnoInterfaceReference const &value)
void SAL_CALL throwException(Any const &exc)
constexpr OUStringLiteral first
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
detail::Optional< T >::type doAccess(css::uno::Any const &any)
std::enable_if<!(detail::IsDerivedReference< T >::value||detail::IsUnoSequenceType< T >::value||std::is_base_of< css::uno::XInterface, T >::value), typenamedetail::Optional< T >::type >::type tryAccess(css::uno::Any const &any)
::osl::Mutex & getMutexAccess()
bool extract(const css::uno::Any &rObj, typelib_InterfaceTypeDescription *pTo, css::uno::Reference< css::uno::XInterface > &rDest, IdlReflectionServiceImpl *pRefl)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
def invoke(object, methodname, argTuple)
bool getType(BSTR name, Type &type)
void SAL_CALL typelib_typedescription_release(typelib_TypeDescription *pTD) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
sal_Bool SAL_CALL typelib_typedescriptionreference_equals(const typelib_TypeDescriptionReference *p1, const typelib_TypeDescriptionReference *p2) SAL_THROW_EXTERN_C()