LibreOffice Module stoc (master) 1
criface.cxx
Go to the documentation of this file.
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
22#include <cassert>
23#include <cstddef>
24#include <limits>
25
26#ifdef SAL_UNX
27#include <sal/alloca.h>
28#endif
29#include <o3tl/any.hxx>
30#include <typelib/typedescription.hxx>
31#include <uno/data.h>
32
33#include "base.hxx"
34
35#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
36#include <com/sun/star/reflection/XIdlField2.hpp>
37#include <com/sun/star/uno/RuntimeException.hpp>
41
42using namespace css::lang;
43using namespace css::reflection;
44using namespace css::uno;
45
46namespace {
47
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);
51}
52
53}
54
55namespace stoc_corefl
56{
57
58namespace {
59
60typedef cppu::ImplInheritanceHelper<IdlMemberImpl, XIdlField, XIdlField2> IdlAttributeFieldImpl_Base;
61class IdlAttributeFieldImpl : public IdlAttributeFieldImpl_Base
62{
63public:
64 typelib_InterfaceAttributeTypeDescription * getAttributeTypeDescr() const
65 { return reinterpret_cast<typelib_InterfaceAttributeTypeDescription *>(getTypeDescr()); }
66
67 IdlAttributeFieldImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
68 typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr )
69 : IdlAttributeFieldImpl_Base( pReflection, rName, pTypeDescr, pDeclTypeDescr )
70 {}
71
72 // XIdlMember
73 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() override;
74 virtual OUString SAL_CALL getName() override;
75 // XIdlField
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;
80 // XIdlField2: getType, getAccessMode and get are equal to XIdlField
81 virtual void SAL_CALL set( Any & rObj, const Any & rValue ) override;
82
83private:
84 void checkException(
85 uno_Any * exception, Reference< XInterface > const & context) const;
86};
87
88}
89
90// XIdlMember
91
92Reference< XIdlClass > IdlAttributeFieldImpl::getDeclaringClass()
93{
94 if (! _xDeclClass.is())
95 {
96 ::osl::MutexGuard aGuard( getMutexAccess() );
97 if (! _xDeclClass.is())
98 {
99 OUString aName(getAttributeTypeDescr()->aBase.aBase.pTypeName);
100 sal_Int32 i = aName.indexOf(':');
101 OSL_ASSERT(i >= 0);
102 _xDeclClass = getReflection()->forName(aName.copy(0, i));
103 }
104 }
105 return _xDeclClass;
106}
107
108OUString IdlAttributeFieldImpl::getName()
109{
110 return IdlMemberImpl::getName();
111}
112
113// XIdlField
114
115Reference< XIdlClass > IdlAttributeFieldImpl::getType()
116{
117 return getReflection()->forType(
118 getAttributeTypeDescr()->pAttributeTypeRef );
119}
120
121FieldAccessMode IdlAttributeFieldImpl::getAccessMode()
122{
123 return (getAttributeTypeDescr()->bReadOnly
124 ? FieldAccessMode_READONLY : FieldAccessMode_READWRITE);
125}
126
127Any IdlAttributeFieldImpl::get( const Any & rObj )
128{
129 uno_Interface * pUnoI = getReflection()->mapToUno(
130 rObj, reinterpret_cast<typelib_InterfaceTypeDescription *>(getDeclTypeDescr()) );
131 OSL_ENSURE( pUnoI, "### illegal destination object given!" );
132 if (pUnoI)
133 {
134 TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
135 typelib_TypeDescription * pTD = aTD.get();
136
137 uno_Any aExc;
138 uno_Any * pExc = &aExc;
139 void * pReturn = alloca( pTD->nSize );
140
141 (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), pReturn, nullptr, &pExc );
142 (*pUnoI->release)( pUnoI );
143
144 checkException(pExc, *o3tl::doAccess<Reference<XInterface>>(rObj));
145 Any aRet;
147 &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
148 uno_any_constructAndConvert( &aRet, pReturn, pTD, getReflection()->getUno2Cpp().get() );
149 uno_destructData( pReturn, pTD, nullptr );
150 return aRet;
151 }
152 throw IllegalArgumentException(
153 "illegal object given!",
154 getXWeak(), 0 );
155}
156
157void IdlAttributeFieldImpl::set( Any & rObj, const Any & rValue )
158{
159 if (getAttributeTypeDescr()->bReadOnly)
160 {
161 throw IllegalAccessException(
162 "cannot set readonly attribute!",
163 getXWeak() );
164 }
165
166 uno_Interface * pUnoI = getReflection()->mapToUno(
167 rObj, reinterpret_cast<typelib_InterfaceTypeDescription *>(getDeclTypeDescr()) );
168 OSL_ENSURE( pUnoI, "### illegal destination object given!" );
169 if (pUnoI)
170 {
171 TypeDescription aTD( getAttributeTypeDescr()->pAttributeTypeRef );
172 typelib_TypeDescription * pTD = aTD.get();
173
174 // construct uno value to be set
175 void * pArgs[1];
176 void * pArg = pArgs[0] = alloca( pTD->nSize );
177
178 bool bAssign;
179 if (pTD->eTypeClass == typelib_TypeClass_ANY)
180 {
181 uno_copyAndConvertData( pArg, const_cast< Any * >(&rValue),
182 pTD, getReflection()->getCpp2Uno().get() );
183 bAssign = true;
184 }
185 else if (typelib_typedescriptionreference_equals( rValue.getValueTypeRef(), pTD->pWeakRef ))
186 {
187 uno_copyAndConvertData( pArg, const_cast< void * >(rValue.getValue()),
188 pTD, getReflection()->getCpp2Uno().get() );
189 bAssign = true;
190 }
191 else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
192 {
193 Reference< XInterface > xObj;
194 bAssign = extract(
195 rValue, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD), xObj,
196 getReflection() );
197 if (bAssign)
198 {
199 *static_cast<void **>(pArg) = getReflection()->getCpp2Uno().mapInterface(
200 xObj.get(), reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
201 }
202 }
203 else
204 {
205 typelib_TypeDescription * pValueTD = nullptr;
206 TYPELIB_DANGER_GET( &pValueTD, rValue.getValueTypeRef() );
207 // construct temp uno val to do proper assignment: todo opt
208 void * pTemp = alloca( pValueTD->nSize );
210 pTemp, const_cast<void *>(rValue.getValue()), pValueTD, getReflection()->getCpp2Uno().get() );
212 pArg, pTD );
213 // assignment does simple conversion
214 bAssign = uno_assignData(
215 pArg, pTD, pTemp, pValueTD, nullptr, nullptr, nullptr );
217 pTemp, pValueTD, nullptr );
218 TYPELIB_DANGER_RELEASE( pValueTD );
219 }
220
221 if (bAssign)
222 {
223 uno_Any aExc;
224 uno_Any * pExc = &aExc;
225 (*pUnoI->pDispatcher)( pUnoI, getTypeDescr(), nullptr, pArgs, &pExc );
226 (*pUnoI->release)( pUnoI );
227
228 uno_destructData( pArg, pTD, nullptr );
229 checkException(pExc, *o3tl::doAccess<Reference<XInterface>>(rObj));
230 return;
231 }
232 (*pUnoI->release)( pUnoI );
233
234 throw IllegalArgumentException(
235 "illegal value given!",
236 *o3tl::doAccess<Reference<XInterface>>(rObj), 1 );
237 }
238 throw IllegalArgumentException(
239 "illegal destination object given!",
240 getXWeak(), 0 );
241}
242
243void IdlAttributeFieldImpl::set( const Any & rObj, const Any & rValue )
244{
245 IdlAttributeFieldImpl::set( const_cast< Any & >( rObj ), rValue );
246}
247
248void IdlAttributeFieldImpl::checkException(
249 uno_Any * exception, Reference< XInterface > const & context) const
250{
251 if (exception == nullptr)
252 return;
253
254 Any e;
255 uno_any_destruct(&e, reinterpret_cast< uno_ReleaseFunc >(cpp_release));
257 &e, exception->pData, exception->pType,
258 getReflection()->getUno2Cpp().get());
259 uno_any_destruct(exception, nullptr);
260 if (!e.isExtractableTo(
262 {
263 throw WrappedTargetRuntimeException(
264 "non-RuntimeException occurred when accessing an"
265 " interface type attribute",
266 context, e);
267 }
269}
270
271namespace {
272
273typedef cppu::ImplInheritanceHelper<IdlMemberImpl, XIdlMethod> IdlInterfaceMethodImpl_Base;
274class IdlInterfaceMethodImpl : public IdlInterfaceMethodImpl_Base
275{
276 std::optional<Sequence< Reference< XIdlClass > >> m_xExceptionTypes;
277 std::optional<Sequence< Reference< XIdlClass > >> m_xParamTypes;
278 std::optional<Sequence< ParamInfo >> m_xParamInfos;
279
280public:
281 typelib_InterfaceMethodTypeDescription * getMethodTypeDescr() const
282 { return reinterpret_cast<typelib_InterfaceMethodTypeDescription *>(getTypeDescr()); }
283
284 IdlInterfaceMethodImpl( IdlReflectionServiceImpl * pReflection, const OUString & rName,
285 typelib_TypeDescription * pTypeDescr, typelib_TypeDescription * pDeclTypeDescr )
286 : IdlInterfaceMethodImpl_Base( pReflection, rName, pTypeDescr, pDeclTypeDescr )
287 {}
288
289 // XTypeProvider
290 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
291
292 // XIdlMember
293 virtual Reference< XIdlClass > SAL_CALL getDeclaringClass() override;
294 virtual OUString SAL_CALL getName() override;
295 // XIdlMethod
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;
302};
303
304}
305
306// XTypeProvider
307
308Sequence< sal_Int8 > IdlInterfaceMethodImpl::getImplementationId()
309{
310 return css::uno::Sequence<sal_Int8>();
311}
312
313// XIdlMember
314
315Reference< XIdlClass > IdlInterfaceMethodImpl::getDeclaringClass()
316{
317 if (! _xDeclClass.is())
318 {
319 ::osl::MutexGuard aGuard( getMutexAccess() );
320 if (! _xDeclClass.is())
321 {
322 OUString aName(getMethodTypeDescr()->aBase.aBase.pTypeName);
323 sal_Int32 i = aName.indexOf(':');
324 OSL_ASSERT(i >= 0);
325 _xDeclClass = getReflection()->forName(aName.copy(0, i));
326 }
327 }
328 return _xDeclClass;
329}
330
331OUString IdlInterfaceMethodImpl::getName()
332{
333 return IdlMemberImpl::getName();
334}
335
336// XIdlMethod
337
338Reference< XIdlClass > SAL_CALL IdlInterfaceMethodImpl::getReturnType()
339{
340 return getReflection()->forType( getMethodTypeDescr()->pReturnTypeRef );
341}
342
343Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes()
344{
345 if (! m_xExceptionTypes)
346 {
347 ::osl::MutexGuard aGuard( getMutexAccess() );
348 if (! m_xExceptionTypes)
349 {
350 sal_Int32 nExc = getMethodTypeDescr()->nExceptions;
351 Sequence< Reference< XIdlClass > > aTempExceptionTypes( nExc );
352 Reference< XIdlClass > * pExceptionTypes = aTempExceptionTypes.getArray();
353
354 typelib_TypeDescriptionReference ** ppExc =
355 getMethodTypeDescr()->ppExceptions;
356 IdlReflectionServiceImpl * pRefl = getReflection();
357
358 while (nExc--)
359 pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] );
360
361 m_xExceptionTypes = std::move(aTempExceptionTypes);
362 }
363 }
364 return *m_xExceptionTypes;
365}
366
367Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes()
368{
369 if (! m_xParamTypes)
370 {
371 ::osl::MutexGuard aGuard( getMutexAccess() );
372 if (! m_xParamTypes)
373 {
374 sal_Int32 nParams = getMethodTypeDescr()->nParams;
375 Sequence< Reference< XIdlClass > > aTempParamTypes( nParams );
376 Reference< XIdlClass > * pParamTypes = aTempParamTypes.getArray();
377
378 typelib_MethodParameter * pTypelibParams =
379 getMethodTypeDescr()->pParams;
380 IdlReflectionServiceImpl * pRefl = getReflection();
381
382 while (nParams--)
383 pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef );
384
385 m_xParamTypes = std::move(aTempParamTypes);
386 }
387 }
388 return *m_xParamTypes;
389}
390
391Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos()
392{
393 if (! m_xParamInfos)
394 {
395 ::osl::MutexGuard aGuard( getMutexAccess() );
396 if (! m_xParamInfos)
397 {
398 sal_Int32 nParams = getMethodTypeDescr()->nParams;
399 Sequence< ParamInfo > aTempParamInfos( nParams );
400 ParamInfo * pParamInfos = aTempParamInfos.getArray();
401
402 typelib_MethodParameter * pTypelibParams =
403 getMethodTypeDescr()->pParams;
404
405 if (m_xParamTypes) // use param types
406 {
407 const Reference< XIdlClass > * pParamTypes = m_xParamTypes->getConstArray();
408
409 while (nParams--)
410 {
411 const typelib_MethodParameter & rParam = pTypelibParams[nParams];
412 ParamInfo & rInfo = pParamInfos[nParams];
413 rInfo.aName = rParam.pName;
414 if (rParam.bIn)
415 rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
416 else
417 rInfo.aMode = ParamMode_OUT;
418 rInfo.aType = pParamTypes[nParams];
419 }
420 }
421 else // make also param types sequence if not already initialized
422 {
423 Sequence< Reference< XIdlClass > > aTempParamTypes( nParams );
424 Reference< XIdlClass > * pParamTypes = aTempParamTypes.getArray();
425
426 IdlReflectionServiceImpl * pRefl = getReflection();
427
428 while (nParams--)
429 {
430 const typelib_MethodParameter & rParam = pTypelibParams[nParams];
431 ParamInfo & rInfo = pParamInfos[nParams];
432 rInfo.aName = rParam.pName;
433 if (rParam.bIn)
434 rInfo.aMode = (rParam.bOut ? ParamMode_INOUT : ParamMode_IN);
435 else
436 rInfo.aMode = ParamMode_OUT;
437 rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef );
438 }
439
440 m_xParamTypes = std::move(aTempParamTypes);
441 }
442
443 m_xParamInfos = std::move(aTempParamInfos);
444 }
445 }
446 return *m_xParamInfos;
447}
448
449MethodMode SAL_CALL IdlInterfaceMethodImpl::getMode()
450{
451 return
452 getMethodTypeDescr()->bOneWay ? MethodMode_ONEWAY : MethodMode_TWOWAY;
453}
454
455Any SAL_CALL IdlInterfaceMethodImpl::invoke( const Any & rObj, Sequence< Any > & rArgs )
456{
457 if (auto ifc = o3tl::tryAccess<css::uno::Reference<css::uno::XInterface>>(
458 rObj))
459 {
460 // acquire()/ release()
461 if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
462 "com.sun.star.uno.XInterface::acquire" ) == 0)
463 {
464 (*ifc)->acquire();
465 return Any();
466 }
467 else if (rtl_ustr_ascii_compare( getTypeDescr()->pTypeName->buffer,
468 "com.sun.star.uno.XInterface::release" ) == 0)
469 {
470 (*ifc)->release();
471 return Any();
472 }
473 }
474
475 uno_Interface * pUnoI = getReflection()->mapToUno(
476 rObj, reinterpret_cast<typelib_InterfaceTypeDescription *>(getDeclTypeDescr()) );
477 OSL_ENSURE( pUnoI, "### illegal destination object given!" );
478 if (pUnoI)
479 {
480 sal_Int32 nParams = getMethodTypeDescr()->nParams;
481 if (rArgs.getLength() != nParams)
482 {
483 (*pUnoI->release)( pUnoI );
484 throw IllegalArgumentException(
485 "expected " + OUString::number(nParams) +
486 " arguments, got " + OUString::number(rArgs.getLength()),
487 *o3tl::doAccess<Reference<XInterface>>(rObj), 1 );
488 }
489
490 Any * pCppArgs = rArgs.getArray();
491 typelib_MethodParameter * pParams = getMethodTypeDescr()->pParams;
492 typelib_TypeDescription * pReturnType = nullptr;
493 TYPELIB_DANGER_GET(
494 &pReturnType, getMethodTypeDescr()->pReturnTypeRef );
495
496 // C/C++ ABIs typically assume that structs are padded at the end, and
497 // that those padding bytes may be written to (e.g., to write into the
498 // end of a "short" struct by writing the full contents of a "long"
499 // register); so create enough space here (assuming that no ABI requires
500 // padding larger than 16 byte boundaries):
501 void * pUnoReturn = (pReturnType->nSize == 0) ? nullptr : alloca( multipleOf16(pReturnType->nSize) );
502 void ** ppUnoArgs = static_cast<void **>(alloca( sizeof(void *) * nParams *2 ));
503 typelib_TypeDescription ** ppParamTypes = reinterpret_cast<typelib_TypeDescription **>(ppUnoArgs + nParams);
504
505 // convert arguments
506 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
507 {
508 ppParamTypes[nPos] = nullptr;
509 TYPELIB_DANGER_GET( ppParamTypes + nPos, pParams[nPos].pTypeRef );
510 typelib_TypeDescription * pTD = ppParamTypes[nPos];
511
512 ppUnoArgs[nPos] = alloca( pTD->nSize );
513 if (pParams[nPos].bIn)
514 {
515 bool bAssign;
517 pCppArgs[nPos].getValueTypeRef(), pTD->pWeakRef ))
518 {
520 ppUnoArgs[nPos], const_cast<void *>(pCppArgs[nPos].getValue()),
521 pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
522 bAssign = true;
523 }
524 else if (pTD->eTypeClass == typelib_TypeClass_ANY)
525 {
527 static_cast<uno_Any *>(ppUnoArgs[nPos]), const_cast<void *>(pCppArgs[nPos].getValue()),
528 pCppArgs[nPos].getValueTypeRef(), getReflection()->getCpp2Uno().get() );
529 bAssign = true;
530 }
531 else if (pTD->eTypeClass == typelib_TypeClass_INTERFACE)
532 {
533 Reference< XInterface > xDest;
534 bAssign = extract(
535 pCppArgs[nPos], reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD),
536 xDest, getReflection() );
537 if (bAssign)
538 {
539 *static_cast<void **>(ppUnoArgs[nPos]) = getReflection()->getCpp2Uno().mapInterface(
540 xDest.get(), reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
541 }
542 }
543 else
544 {
545 typelib_TypeDescription * pValueTD = nullptr;
546 TYPELIB_DANGER_GET( &pValueTD, pCppArgs[nPos].getValueTypeRef() );
547 // construct temp uno val to do proper assignment: todo opt
548 void * pTemp = alloca( pValueTD->nSize );
550 pTemp, const_cast<void *>(pCppArgs[nPos].getValue()), pValueTD,
551 getReflection()->getCpp2Uno().get() );
553 ppUnoArgs[nPos], pTD );
554 // assignment does simple conversion
555 bAssign = uno_assignData(
556 ppUnoArgs[nPos], pTD, pTemp, pValueTD, nullptr, nullptr, nullptr );
558 pTemp, pValueTD, nullptr );
559 TYPELIB_DANGER_RELEASE( pValueTD );
560 }
561
562 if (! bAssign)
563 {
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)
569 + "\"",
570 *o3tl::doAccess<Reference<XInterface>>(rObj), static_cast<sal_Int16>(nPos) );
571
572 // cleanup
573 while (nPos--)
574 {
575 if (pParams[nPos].bIn)
576 uno_destructData( ppUnoArgs[nPos], ppParamTypes[nPos], nullptr );
577 TYPELIB_DANGER_RELEASE( ppParamTypes[nPos] );
578 }
579 TYPELIB_DANGER_RELEASE( pReturnType );
580 (*pUnoI->release)( pUnoI );
581
582 throw aExc;
583 }
584 }
585 }
586
587 uno_Any aUnoExc;
588 uno_Any * pUnoExc = &aUnoExc;
589
590 (*pUnoI->pDispatcher)(
591 pUnoI, getTypeDescr(), pUnoReturn, ppUnoArgs, &pUnoExc );
592 (*pUnoI->release)( pUnoI );
593
594 Any aRet;
595 if (pUnoExc)
596 {
597 // cleanup
598 while (nParams--)
599 {
600 if (pParams[nParams].bIn)
601 uno_destructData( ppUnoArgs[nParams], ppParamTypes[nParams], nullptr );
602 TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
603 }
604 TYPELIB_DANGER_RELEASE( pReturnType );
605
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) );
613 &aExc.TargetException, pUnoExc, cppu::UnoType<Any>::get().getTypeLibType(),
614 getReflection()->getUno2Cpp().get() );
615 uno_any_destruct( pUnoExc, nullptr );
616 throw aExc;
617 }
618 else
619 {
620 // reconvert arguments and cleanup
621 while (nParams--)
622 {
623 if (pParams[nParams].bOut) // write back
624 {
626 &pCppArgs[nParams],
627 reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
629 &pCppArgs[nParams], ppUnoArgs[nParams], ppParamTypes[nParams],
630 getReflection()->getUno2Cpp().get() );
631 }
632 uno_destructData( ppUnoArgs[nParams], ppParamTypes[nParams], nullptr );
633 TYPELIB_DANGER_RELEASE( ppParamTypes[nParams] );
634 }
636 &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
638 &aRet, pUnoReturn, pReturnType,
639 getReflection()->getUno2Cpp().get() );
640 uno_destructData( pUnoReturn, pReturnType, nullptr );
641 TYPELIB_DANGER_RELEASE( pReturnType );
642 }
643 return aRet;
644 }
645 throw IllegalArgumentException(
646 "illegal destination object given!",
647 getXWeak(), 0 );
648}
649
650
652{
653 for ( sal_Int32 nPos = _nMethods + _nAttributes; nPos--; )
655}
656
657
658Sequence< Reference< XIdlClass > > InterfaceIdlClassImpl::getSuperclasses()
659{
660 ::osl::MutexGuard aGuard(getMutexAccess());
661 if (!_xSuperClasses.hasElements()) {
662 typelib_InterfaceTypeDescription * pType = getTypeDescr();
663 _xSuperClasses.realloc(pType->nBaseTypes);
664 auto pSuperClasses = _xSuperClasses.getArray();
665 for (sal_Int32 i = 0; i < pType->nBaseTypes; ++i) {
666 pSuperClasses[i] = getReflection()->forType(
667 &pType->ppBaseTypes[i]->aBase);
668 OSL_ASSERT(_xSuperClasses[i].is());
669 }
670 }
671 return _xSuperClasses;
672}
673
675{
676 sal_Int32 nAll = getTypeDescr()->nAllMembers;
677 std::unique_ptr<MemberInit[]> pSortedMemberInit(new MemberInit[nAll]);
678 typelib_TypeDescriptionReference ** ppAllMembers = getTypeDescr()->ppAllMembers;
679
680 for ( sal_Int32 nPos = 0; nPos < nAll; ++nPos )
681 {
682 sal_Int32 nIndex;
683 if (ppAllMembers[nPos]->eTypeClass == typelib_TypeClass_INTERFACE_METHOD)
684 {
685 // methods to front
687 ++_nMethods;
688 }
689 else
690 {
691 ++_nAttributes;
692 nIndex = (nAll - _nAttributes);
693 // attributes at the back
694 }
695
696 typelib_TypeDescription * pTD = nullptr;
698 assert(pTD && "### cannot get type description!");
699 pSortedMemberInit[nIndex].first = reinterpret_cast<typelib_InterfaceMemberTypeDescription *>(pTD)->pMemberName;
700 pSortedMemberInit[nIndex].second = pTD;
701 }
702
703 _pSortedMemberInit = std::move(pSortedMemberInit);
704}
705
706sal_Bool InterfaceIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
707{
708 if (xType.is() && xType->getTypeClass() == TypeClass_INTERFACE)
709 {
710 if (equals( xType ))
711 return true;
712 else
713 {
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); }))
717 return true;
718 }
719 }
720 return false;
721}
722
724{
725 return Uik(0, 0, 0, 0, 0);
726 // Uiks are deprecated and this function must not be called
727}
728
729Sequence< Reference< XIdlMethod > > InterfaceIdlClassImpl::getMethods()
730{
731 ::osl::MutexGuard aGuard( getMutexAccess() );
732 if (! _pSortedMemberInit)
733 initMembers();
734
735 // create methods sequence
736 Sequence< Reference< XIdlMethod > > aRet( _nMethods );
737 Reference< XIdlMethod > * pRet = aRet.getArray();
738 for ( sal_Int32 nPos = _nMethods; nPos--; )
739 {
740
741 /*_aName2Method[_pSortedMemberInit[nPos].first] = */pRet[nPos] = new IdlInterfaceMethodImpl(
744 }
745 return aRet;
746}
747
748Sequence< Reference< XIdlField > > InterfaceIdlClassImpl::getFields()
749{
750 ::osl::MutexGuard aGuard( getMutexAccess() );
751 if (! _pSortedMemberInit)
752 initMembers();
753
754 // create fields sequence
755 Sequence< Reference< XIdlField > > aRet( _nAttributes );
756 Reference< XIdlField > * pRet = aRet.getArray();
757 for ( sal_Int32 nPos = _nAttributes; nPos--; )
758 {
759 /*_aName2Field[_pSortedMemberInit[_nMethods+nPos].first] = */pRet[_nAttributes-nPos-1] =
760 new IdlAttributeFieldImpl(
763 }
764 return aRet;
765}
766
767Reference< XIdlMethod > InterfaceIdlClassImpl::getMethod( const OUString & rName )
768{
769 ::osl::MutexGuard aGuard( getMutexAccess() );
770 if (! _pSortedMemberInit)
771 initMembers();
772
773 Reference< XIdlMethod > xRet;
774
775 // try weak map
776 const OUString2Method::const_iterator iFind( _aName2Method.find( rName ) );
777 if (iFind != _aName2Method.end())
778 xRet = (*iFind).second; // harden ref
779
780 if (! xRet.is())
781 {
782 for ( sal_Int32 nPos = _nMethods; nPos--; )
783 {
784 if (_pSortedMemberInit[nPos].first == rName)
785 {
786 _aName2Method[rName] = xRet = new IdlInterfaceMethodImpl(
787 getReflection(), rName,
789 break;
790 }
791 }
792 }
793 return xRet;
794}
795
796Reference< XIdlField > InterfaceIdlClassImpl::getField( const OUString & rName )
797{
798 ::osl::MutexGuard aGuard( getMutexAccess() );
799 if (! _pSortedMemberInit)
800 initMembers();
801
802 Reference< XIdlField > xRet;
803
804 // try weak map
805 const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) );
806 if (iFind != _aName2Field.end())
807 xRet = (*iFind).second; // harden ref
808
809 if (! xRet.is())
810 {
811 for ( sal_Int32 nPos = _nAttributes; nPos--; )
812 {
814 {
815 _aName2Field[rName] = xRet = new IdlAttributeFieldImpl(
816 getReflection(), rName,
818 break;
819 }
820 }
821 }
822 return xRet;
823}
824
826{
827 // interfaces cannot be constructed
828 rObj.clear();
829}
830
831}
832
833
834/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
Definition: base.hxx:142
typelib_TypeDescription * getTypeDescr() const
Definition: base.hxx:140
virtual sal_Bool SAL_CALL equals(const css::uno::Reference< css::reflection::XIdlClass > &xType) override
Definition: crbase.cxx:92
virtual OUString SAL_CALL getName() override
Definition: crbase.cxx:242
css::uno::Reference< css::reflection::XIdlClass > forType(typelib_TypeDescription *pTypeDescr)
Definition: crefl.cxx:235
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlMethod > > SAL_CALL getMethods() override
Definition: criface.cxx:729
std::unique_ptr< MemberInit[]> _pSortedMemberInit
Definition: base.hxx:186
typelib_InterfaceTypeDescription * getTypeDescr() const
Definition: base.hxx:195
OUString2Method _aName2Method
Definition: base.hxx:188
css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > _xSuperClasses
Definition: base.hxx:184
virtual css::uno::Reference< css::reflection::XIdlMethod > SAL_CALL getMethod(const OUString &rName) override
Definition: criface.cxx:767
std::pair< OUString, typelib_TypeDescription * > MemberInit
Definition: base.hxx:182
virtual sal_Bool SAL_CALL isAssignableFrom(const css::uno::Reference< css::reflection::XIdlClass > &xType) override
Definition: criface.cxx:706
virtual void SAL_CALL createObject(css::uno::Any &rObj) override
Definition: criface.cxx:825
virtual css::uno::Reference< css::reflection::XIdlField > SAL_CALL getField(const OUString &rName) override
Definition: criface.cxx:796
virtual ~InterfaceIdlClassImpl() override
Definition: criface.cxx:651
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > SAL_CALL getFields() override
Definition: criface.cxx:748
virtual css::uno::Uik SAL_CALL getUik() override
Definition: criface.cxx:723
virtual css::uno::Sequence< css::uno::Reference< css::reflection::XIdlClass > > SAL_CALL getSuperclasses() override
Definition: criface.cxx:658
std::optional< Sequence< Reference< XIdlClass > > > m_xParamTypes
Definition: criface.cxx:277
std::optional< Sequence< ParamInfo > > m_xParamInfos
Definition: criface.cxx:278
std::optional< Sequence< Reference< XIdlClass > > > m_xExceptionTypes
Definition: criface.cxx:276
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()
sal_Int32 nIndex
Definition: invocation.cxx:697
OUString aName
Definition: invocation.cxx:689
sal_uInt16 nPos
struct _typelib_TypeDescription typelib_TypeDescription
struct _uno_Any uno_Any
void set(css::uno::UnoInterfaceReference const &value)
void SAL_CALL throwException(Any const &exc)
int i
constexpr OUStringLiteral first
JFW_MODE getMode()
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()
Definition: crbase.cxx:37
bool extract(const css::uno::Any &rObj, typelib_InterfaceTypeDescription *pTo, css::uno::Reference< css::uno::XInterface > &rDest, IdlReflectionServiceImpl *pRefl)
Definition: base.hxx:335
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()
unsigned char sal_Bool