26#include <osl/diagnose.h>
27#include <rtl/ustring.hxx>
29#include <uno/lbnames.h>
30#include <uno/mapping.hxx>
34#include <typelib/typedescription.h>
36#include <com/sun/star/lang/XComponent.hpp>
37#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38#include <com/sun/star/reflection/XTypeDescription.hpp>
39#include <com/sun/star/reflection/XEnumTypeDescription.hpp>
40#include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
41#include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
42#include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
43#include <com/sun/star/reflection/XMethodParameter.hpp>
44#include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
45#include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
46#include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
47#include <com/sun/star/reflection/XStructTypeDescription.hpp>
59 Reference< container::XHierarchicalNameAccess >
const & access,
60 const Reference< XTypeDescription > & xType );
64 const Reference< XCompoundTypeDescription > & xType )
70 Reference< XCompoundTypeDescription >::query( xType->getBaseType() ) );
75 const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
76 const Sequence< OUString > & rMemberNames = xType->getMemberNames();
78 const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
79 const OUString * pMemberNames = rMemberNames.getConstArray();
81 sal_Int32 nMembers = rMemberTypes.getLength();
82 OSL_ENSURE( nMembers == rMemberNames.getLength(),
"### lens differ!" );
84 OUString aTypeName( xType->getName() );
86 typelib_CompoundMember_Init * pMemberInits =
static_cast<typelib_CompoundMember_Init *
>(alloca(
87 sizeof(typelib_CompoundMember_Init) * nMembers ));
92 typelib_CompoundMember_Init & rInit = pMemberInits[
nPos];
93 rInit.eTypeClass =
static_cast<typelib_TypeClass
>(pMemberTypes[
nPos]->getTypeClass());
95 OUString aMemberTypeName( pMemberTypes[
nPos]->getName() );
96 rInit.pTypeName = aMemberTypeName.pData;
97 rtl_uString_acquire( rInit.pTypeName );
100 rInit.pMemberName = pMemberNames[
nPos].pData;
105 static_cast<typelib_TypeClass
>(xType->getTypeClass()),
107 (pBaseType ? pBaseType->pWeakRef :
nullptr),
108 nMembers, pMemberInits );
113 rtl_uString_release( pMemberInits[
nPos].pTypeName );
122 Reference< container::XHierarchicalNameAccess >
const & access,
123 const Reference< XStructTypeDescription > & xType )
126 if (xType.is() && !xType->getTypeParameters().hasElements())
129 access, xType->getBaseType() );
134 const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
135 const Sequence< OUString > & rMemberNames = xType->getMemberNames();
137 const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
138 const OUString * pMemberNames = rMemberNames.getConstArray();
140 sal_Int32 nMembers = rMemberTypes.getLength();
141 OSL_ENSURE( nMembers == rMemberNames.getLength(),
"### lens differ!" );
143 OUString aTypeName( xType->getName() );
145 typelib_StructMember_Init * pMemberInits =
static_cast<typelib_StructMember_Init *
>(alloca(
146 sizeof(typelib_StructMember_Init) * nMembers ));
148 Sequence< Reference< XTypeDescription > > templateMemberTypes;
149 sal_Int32
i = aTypeName.indexOf(
'<');
151 Reference< XStructTypeDescription > templateDesc(
152 access->getByHierarchicalName(aTypeName.copy(0,
i)),
155 templateDesc->getTypeParameters().getLength()
156 == xType->getTypeArguments().getLength());
157 templateMemberTypes = templateDesc->getMemberTypes();
158 OSL_ASSERT(templateMemberTypes.getLength() == nMembers);
164 typelib_StructMember_Init & rInit = pMemberInits[
nPos];
165 rInit.aBase.eTypeClass
166 =
static_cast<typelib_TypeClass
>(pMemberTypes[
nPos]->getTypeClass());
168 OUString aMemberTypeName( pMemberTypes[
nPos]->getName() );
169 rInit.aBase.pTypeName = aMemberTypeName.pData;
170 rtl_uString_acquire( rInit.aBase.pTypeName );
173 rInit.aBase.pMemberName = pMemberNames[
nPos].pData;
175 rInit.bParameterizedType = templateMemberTypes.hasElements()
176 && (templateMemberTypes[
nPos]->getTypeClass()
177 == TypeClass_UNKNOWN);
183 (pBaseType ? pBaseType->pWeakRef :
nullptr),
184 nMembers, pMemberInits );
189 rtl_uString_release( pMemberInits[
nPos].aBase.pTypeName );
198 const Reference< XInterfaceAttributeTypeDescription2 > & xAttribute )
203 OUString aMemberName( xAttribute->getName() );
204 Reference< XTypeDescription > xType( xAttribute->getType() );
205 OUString aMemberTypeName( xType->getName() );
206 std::vector< rtl_uString * > getExc;
207 const Sequence< Reference< XCompoundTypeDescription > > getExcs(
208 xAttribute->getGetExceptions() );
209 for (
const auto & ctd : getExcs)
211 OSL_ASSERT( ctd.is() );
212 getExc.push_back( ctd->getName().pData );
214 std::vector< rtl_uString * > setExc;
215 const Sequence< Reference< XCompoundTypeDescription > > setExcs(
216 xAttribute->getSetExceptions() );
217 for (
const auto & ctd : setExcs)
219 OSL_ASSERT( ctd.is() );
220 setExc.push_back( ctd->getName().pData );
223 reinterpret_cast<typelib_InterfaceAttributeTypeDescription **
>(&pRet),
224 xAttribute->getPosition(),
226 static_cast<typelib_TypeClass
>(xType->getTypeClass()),
227 aMemberTypeName.pData,
228 xAttribute->isReadOnly(),
229 getExc.size(), getExc.data(),
230 setExc.size(), setExc.data() );
236 const Reference< XInterfaceMethodTypeDescription > & xMethod )
241 Reference< XTypeDescription > xReturnType(
xMethod->getReturnType() );
244 const Sequence<Reference< XMethodParameter > > & rParams =
xMethod->getParameters();
245 const Reference< XMethodParameter > * pParams = rParams.getConstArray();
246 sal_Int32 nParams = rParams.getLength();
248 typelib_Parameter_Init * pParamInit =
static_cast<typelib_Parameter_Init *
>(alloca(
249 sizeof(typelib_Parameter_Init) * nParams ));
254 const Reference< XMethodParameter > & xParam = pParams[
nPos];
255 const Reference< XTypeDescription > & xType = xParam->getType();
256 typelib_Parameter_Init & rInit = pParamInit[xParam->getPosition()];
258 rInit.eTypeClass =
static_cast<typelib_TypeClass
>(xType->getTypeClass());
259 OUString aParamTypeName( xType->getName() );
260 rInit.pTypeName = aParamTypeName.pData;
261 rtl_uString_acquire( rInit.pTypeName );
262 OUString aParamName( xParam->getName() );
263 rInit.pParamName = aParamName.pData;
264 rtl_uString_acquire( rInit.pParamName );
265 rInit.bIn = xParam->isIn();
266 rInit.bOut = xParam->isOut();
270 const Sequence<Reference< XTypeDescription > > & rExceptions =
xMethod->getExceptions();
271 const Reference< XTypeDescription > * pExceptions = rExceptions.getConstArray();
272 sal_Int32 nExceptions = rExceptions.getLength();
273 rtl_uString ** ppExceptionNames =
static_cast<rtl_uString **
>(alloca(
274 sizeof(rtl_uString *) * nExceptions ));
278 OUString aExceptionTypeName( pExceptions[
nPos]->getName() );
279 ppExceptionNames[
nPos] = aExceptionTypeName.pData;
280 rtl_uString_acquire( ppExceptionNames[
nPos] );
283 OUString aTypeName(
xMethod->getName() );
284 OUString aReturnTypeName( xReturnType->getName() );
287 reinterpret_cast<typelib_InterfaceMethodTypeDescription **
>(&pRet),
291 static_cast<typelib_TypeClass
>(xReturnType->getTypeClass()),
292 aReturnTypeName.pData,
294 nExceptions, ppExceptionNames );
298 rtl_uString_release( pParamInit[
nPos].pTypeName );
299 rtl_uString_release( pParamInit[
nPos].pParamName );
303 rtl_uString_release( ppExceptionNames[
nPos] );
310 Reference< container::XHierarchicalNameAccess >
const & access,
311 const Reference< XInterfaceTypeDescription2 > & xType )
316 Sequence< Reference< XTypeDescription > > aBases(xType->getBaseTypes());
317 sal_Int32 nBases = aBases.getLength();
320 std::unique_ptr< typelib_TypeDescription * []> aBaseTypes(
322 for (sal_Int32
i = 0;
i < nBases; ++
i) {
325 !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(
p->eTypeClass));
329 typelib_TypeDescriptionReference ** pBaseTypeRefs
330 =
reinterpret_cast< typelib_TypeDescriptionReference **
>(
334 const Sequence<Reference< XInterfaceMemberTypeDescription > > & rMembers = xType->getMembers();
335 sal_Int32 nMembers = rMembers.getLength();
337 typelib_TypeDescriptionReference ** ppMemberRefs =
static_cast<typelib_TypeDescriptionReference **
>(alloca(
338 sizeof(typelib_TypeDescriptionReference *) * nMembers ));
340 const Reference< XInterfaceMemberTypeDescription > * pMembers = rMembers.getConstArray();
342 OUString aTypeName( xType->getName() );
347 OUString aMemberTypeName( pMembers[
nPos]->getName() );
348 ppMemberRefs[
nPos] =
nullptr;
352 aMemberTypeName.pData );
356 reinterpret_cast<typelib_InterfaceTypeDescription **
>(&pRet),
359 nBases, pBaseTypeRefs,
360 nMembers, ppMemberRefs );
363 for (
int i = 0;
i < nBases; ++
i) {
380 OUString aTypeName( xType->getName() );
381 Sequence< OUString > aNames( xType->getEnumNames() );
382 OSL_ASSERT(
sizeof(OUString) ==
sizeof(rtl_uString *) );
383 Sequence< sal_Int32 > aValues( xType->getEnumValues() );
386 &pRet, aTypeName.pData, xType->getDefaultEnumValue(),
388 const_cast<rtl_uString **
>(
reinterpret_cast<rtl_uString *
const *
>(aNames.getConstArray())),
389 const_cast< sal_Int32 *
>( aValues.getConstArray() ) );
395 Reference< container::XHierarchicalNameAccess >
const & access,
396 const Reference< XIndirectTypeDescription > & xType )
402 access, xType->getReferencedType() );
405 OUString aTypeName( xType->getName() );
409 static_cast<typelib_TypeClass
>(xType->getTypeClass()),
422 Reference< container::XHierarchicalNameAccess >
const & access,
423 const Reference< XTypeDescription > & xType )
429 switch (xType->getTypeClass())
434 OUString aTypeName(
"void");
440 OUString aTypeName(
"char");
444 case TypeClass_BOOLEAN:
446 OUString aTypeName(
"boolean");
452 OUString aTypeName(
"byte");
456 case TypeClass_SHORT:
458 OUString aTypeName(
"short");
462 case TypeClass_UNSIGNED_SHORT:
464 OUString aTypeName(
"unsigned short");
470 OUString aTypeName(
"long");
474 case TypeClass_UNSIGNED_LONG:
476 OUString aTypeName(
"unsigned long");
480 case TypeClass_HYPER:
482 OUString aTypeName(
"hyper");
486 case TypeClass_UNSIGNED_HYPER:
488 OUString aTypeName(
"unsigned hyper");
492 case TypeClass_FLOAT:
494 OUString aTypeName(
"float");
498 case TypeClass_DOUBLE:
500 OUString aTypeName(
"double");
504 case TypeClass_STRING:
506 OUString aTypeName(
"string");
512 OUString aTypeName(
"type");
518 OUString aTypeName(
"any");
523 case TypeClass_EXCEPTION:
524 pRet =
createCTD( Reference< XCompoundTypeDescription >::query( xType ) );
526 case TypeClass_STRUCT:
528 access, Reference< XStructTypeDescription >::query( xType ) );
531 pRet =
createCTD( Reference< XEnumTypeDescription >::query( xType ) );
533 case TypeClass_TYPEDEF:
535 Reference< XIndirectTypeDescription > xTypedef( xType, UNO_QUERY );
537 pRet =
createCTD( access, xTypedef->getReferencedType() );
540 case TypeClass_SEQUENCE:
542 access, Reference< XIndirectTypeDescription >::query( xType ) );
544 case TypeClass_INTERFACE:
547 Reference< XInterfaceTypeDescription2 >::query( xType ) );
549 case TypeClass_INTERFACE_METHOD:
550 pRet =
createCTD( Reference< XInterfaceMethodTypeDescription >::query( xType ) );
552 case TypeClass_INTERFACE_ATTRIBUTE:
553 pRet =
createCTD( Reference< XInterfaceAttributeTypeDescription2 >::query( xType ) );
569 OSL_ENSURE( pContext && ppRet && pTypeName,
"### null ptr!" );
575 ::typelib_typedescription_release( *ppRet );
578 if (!(pContext && pTypeName))
581 Reference< container::XHierarchicalNameAccess > access(
582 static_cast< container::XHierarchicalNameAccess *
>(
586 OUString
const & rTypeName = OUString::unacquired( &pTypeName );
587 Reference< XTypeDescription > xTD;
588 if (access->getByHierarchicalName(rTypeName ) >>= xTD)
593 catch (
const container::NoSuchElementException & exc)
595 SAL_INFO(
"cppuhelper",
"typelibrary type not available: " << exc );
606class EventListenerImpl
607 :
public WeakImplHelper< lang::XEventListener >
609 Reference< container::XHierarchicalNameAccess >
m_xTDMgr;
612 explicit EventListenerImpl(
613 Reference< container::XHierarchicalNameAccess >
const & xTDMgr )
618 virtual void SAL_CALL disposing( lang::EventObject
const & rEvt )
override;
623void EventListenerImpl::disposing( lang::EventObject
const & rEvt )
634 Reference< container::XHierarchicalNameAccess >
const & xTDMgr_c )
636 uno::Environment curr_env(Environment::getCurrent());
637 uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
639 uno::Mapping curr2target(curr_env, target_env);
642 Reference<container::XHierarchicalNameAccess> xTDMgr(
643 static_cast<container::XHierarchicalNameAccess *
>(
644 curr2target.mapInterface(xTDMgr_c.get(),
cppu::UnoType<
decltype(xTDMgr_c)>::get())),
647 Reference< lang::XComponent > xComp( xTDMgr, UNO_QUERY );
650 xComp->addEventListener(
new EventListenerImpl( xTDMgr ) );
652 ::typelib_typedescription_registerCallback( xTDMgr.get(),
typelib_callback );
#define SAL_INFO(area, stream)
struct _typelib_TypeDescription typelib_TypeDescription
static typelib_TypeDescription * createCTD(Reference< container::XHierarchicalNameAccess > const &access, const Reference< XTypeDescription > &xType)
sal_Bool SAL_CALL installTypeDescriptionManager(Reference< container::XHierarchicalNameAccess > const &xTDMgr_c)
static void typelib_callback(void *pContext, typelib_TypeDescription **ppRet, rtl_uString *pTypeName)
PyRef getTypeClass(const Runtime &)
Reference< container::XHierarchicalNameAccess > m_xTDMgr
void SAL_CALL typelib_typedescriptionreference_new(typelib_TypeDescriptionReference **ppTDR, typelib_TypeClass eTypeClass, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_register(typelib_TypeDescription **ppNewDescription) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_newEnum(typelib_TypeDescription **ppRet, rtl_uString *pTypeName, sal_Int32 nDefaultValue, sal_Int32 nEnumValues, rtl_uString **ppEnumNames, sal_Int32 *pEnumValues) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_newMIInterface(typelib_InterfaceTypeDescription **ppRet, rtl_uString *pTypeName, SAL_UNUSED_PARAMETER sal_uInt32, SAL_UNUSED_PARAMETER sal_uInt16, SAL_UNUSED_PARAMETER sal_uInt16, SAL_UNUSED_PARAMETER sal_uInt32, SAL_UNUSED_PARAMETER sal_uInt32, sal_Int32 nBaseInterfaces, typelib_TypeDescriptionReference **ppBaseInterfaces, sal_Int32 nMembers, typelib_TypeDescriptionReference **ppMembers) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_newExtendedInterfaceAttribute(typelib_InterfaceAttributeTypeDescription **ppRet, sal_Int32 nAbsolutePosition, rtl_uString *pTypeName, typelib_TypeClass eAttributeTypeClass, rtl_uString *pAttributeTypeName, sal_Bool bReadOnly, sal_Int32 nGetExceptions, rtl_uString **ppGetExceptionNames, sal_Int32 nSetExceptions, rtl_uString **ppSetExceptionNames) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_release(typelib_TypeDescription *pTD) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_release(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_new(typelib_TypeDescription **ppRet, typelib_TypeClass eTypeClass, rtl_uString *pTypeName, typelib_TypeDescriptionReference *pType, sal_Int32 nMembers, typelib_CompoundMember_Init *pMembers) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_newStruct(typelib_TypeDescription **ppRet, rtl_uString *pTypeName, typelib_TypeDescriptionReference *pType, sal_Int32 nMembers, typelib_StructMember_Init *pMembers) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_newInterfaceMethod(typelib_InterfaceMethodTypeDescription **ppRet, sal_Int32 nAbsolutePosition, sal_Bool bOneWay, rtl_uString *pTypeName, typelib_TypeClass eReturnTypeClass, rtl_uString *pReturnTypeName, sal_Int32 nParams, typelib_Parameter_Init *pParams, sal_Int32 nExceptions, rtl_uString **ppExceptionNames) SAL_THROW_EXTERN_C()