tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / bridges / source / cpp_uno / gcc3_linux_powerpc64 / uno2cpp.cxx
blob37d75659fdb6b01d1da55ec03bc48f06b84d4580
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <exception>
23 #include <malloc.h>
24 #include <typeinfo>
26 #include <com/sun/star/uno/Exception.hpp>
27 #include <com/sun/star/uno/RuntimeException.hpp>
28 #include <com/sun/star/uno/genfunc.hxx>
29 #include <o3tl/runtimetooustring.hxx>
30 #include <uno/data.h>
32 #include "bridge.hxx"
33 #include "types.hxx"
34 #include "unointerfaceproxy.hxx"
35 #include "vtables.hxx"
37 #include "share.hxx"
39 #include <stdio.h>
40 #include <string.h>
43 using namespace ::com::sun::star::uno;
45 namespace ppc64
47 #if defined(_CALL_ELF) && _CALL_ELF == 2
48 bool is_complex_struct(const typelib_TypeDescription * type)
50 const typelib_CompoundTypeDescription * p
51 = reinterpret_cast< const typelib_CompoundTypeDescription * >(type);
52 for (sal_Int32 i = 0; i < p->nMembers; ++i)
54 if (p->ppTypeRefs[i]->eTypeClass == typelib_TypeClass_STRUCT ||
55 p->ppTypeRefs[i]->eTypeClass == typelib_TypeClass_EXCEPTION)
57 typelib_TypeDescription * t = 0;
58 TYPELIB_DANGER_GET(&t, p->ppTypeRefs[i]);
59 bool b = is_complex_struct(t);
60 TYPELIB_DANGER_RELEASE(t);
61 if (b) {
62 return true;
65 else if (!bridges::cpp_uno::shared::isSimpleType(p->ppTypeRefs[i]->eTypeClass))
66 return true;
68 if (p->pBaseTypeDescription != 0)
69 return is_complex_struct(&p->pBaseTypeDescription->aBase);
70 return false;
72 #endif
74 bool return_in_hidden_param( typelib_TypeDescriptionReference *pTypeRef )
76 if (bridges::cpp_uno::shared::isSimpleType(pTypeRef))
77 return false;
78 #if defined(_CALL_ELF) && _CALL_ELF == 2
79 else if (pTypeRef->eTypeClass == typelib_TypeClass_STRUCT || pTypeRef->eTypeClass == typelib_TypeClass_EXCEPTION)
81 typelib_TypeDescription * pTypeDescr = 0;
82 TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
84 //A Composite Type not larger than 16 bytes is returned in up to two GPRs
85 bool bRet = pTypeDescr->nSize > 16 || is_complex_struct(pTypeDescr);
87 TYPELIB_DANGER_RELEASE( pTypeDescr );
88 return bRet;
90 #endif
91 return true;
95 void MapReturn(long r3, long r4, double dret, typelib_TypeDescriptionReference* pReturnType, void *pRegisterReturn)
97 switch (pReturnType->eTypeClass)
99 case typelib_TypeClass_HYPER:
100 case typelib_TypeClass_UNSIGNED_HYPER:
101 *reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = r3;
102 break;
103 case typelib_TypeClass_LONG:
104 case typelib_TypeClass_UNSIGNED_LONG:
105 case typelib_TypeClass_ENUM:
106 *reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = r3;
107 break;
108 case typelib_TypeClass_CHAR:
109 case typelib_TypeClass_SHORT:
110 case typelib_TypeClass_UNSIGNED_SHORT:
111 *reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = (unsigned short)r3;
112 break;
113 case typelib_TypeClass_BOOLEAN:
114 case typelib_TypeClass_BYTE:
115 *reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = (unsigned char)r3;
116 break;
117 case typelib_TypeClass_FLOAT:
118 *reinterpret_cast<float *>( pRegisterReturn ) = dret;
119 break;
120 case typelib_TypeClass_DOUBLE:
121 *reinterpret_cast<double *>( pRegisterReturn ) = dret;
122 break;
123 #if defined(_CALL_ELF) && _CALL_ELF == 2
124 case typelib_TypeClass_STRUCT:
125 case typelib_TypeClass_EXCEPTION:
126 if (!ppc64::return_in_hidden_param(pReturnType))
128 sal_uInt64 *pRegisters = reinterpret_cast<sal_uInt64*>(pRegisterReturn);
129 pRegisters[0] = r3;
130 if (pReturnType->pType->nSize > 8)
131 pRegisters[1] = r4;
133 #else
134 (void)r4;
135 #endif
136 default:
137 break;
141 namespace
144 static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
145 void * pRegisterReturn, typelib_TypeDescription * pReturnTypeDescr,
146 sal_uInt64 *pStack, sal_uInt32 nStack,
147 sal_uInt64 *pGPR, sal_uInt32 nGPR,
148 double *pFPR, sal_uInt32 nFPR)
150 // Stack, if used, must be 16-bytes aligned
151 if ( nStack )
152 nStack = ( nStack + 1 ) & ~1;
154 // Should not happen, but...
155 if ( nFPR > ppc64::MAX_SSE_REGS )
156 nFPR = ppc64::MAX_SSE_REGS;
157 if ( nGPR > ppc64::MAX_GPR_REGS )
158 nGPR = ppc64::MAX_GPR_REGS;
160 #if OSL_DEBUG_LEVEL > 2
161 // Let's figure out what is really going on here
163 fprintf( stderr, "= callVirtualMethod() =\nGPR's (%d): ", nGPR );
164 for ( sal_uInt32 i = 0; i < nGPR; ++i )
165 fprintf( stderr, "0x%lx, ", pGPR[i] );
166 fprintf( stderr, "\nFPR's (%d): ", nFPR );
167 for ( sal_uInt32 i = 0; i < nFPR; ++i )
168 fprintf( stderr, "0x%lx (%lf), ", (sal_Int64)pFPR[i], pFPR[i] );
169 fprintf( stderr, "\nStack (%d): ", nStack );
170 for ( sal_uInt32 i = 0; i < nStack; ++i )
171 fprintf( stderr, "0x%lx, ", pStack[i] );
172 fprintf( stderr, "\n" );
174 #endif
176 // Load parameters to stack, if necessary
177 sal_uInt64 *stack = (sal_uInt64 *) __builtin_alloca( nStack * 8 );
178 memcpy( stack, pStack, nStack * 8 );
180 // Get pointer to method
181 sal_uInt64 pMethod = *((sal_uInt64 *)pThis);
182 pMethod += 8 * nVtableIndex;
183 pMethod = *((sal_uInt64 *)pMethod);
185 #if defined(_CALL_ELF) && _CALL_ELF == 2
186 typedef void (* FunctionCall )(...);
187 #else
188 typedef void (* FunctionCall )( sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64 );
189 #endif
190 FunctionCall pFunc = (FunctionCall)pMethod;
192 volatile double dret;
194 // fill registers
195 __asm__ __volatile__ (
196 "lfd 1, 0(%0)\n\t"
197 "lfd 2, 8(%0)\n\t"
198 "lfd 3, 16(%0)\n\t"
199 "lfd 4, 24(%0)\n\t"
200 "lfd 5, 32(%0)\n\t"
201 "lfd 6, 40(%0)\n\t"
202 "lfd 7, 48(%0)\n\t"
203 "lfd 8, 56(%0)\n\t"
204 "lfd 9, 64(%0)\n\t"
205 "lfd 10, 72(%0)\n\t"
206 "lfd 11, 80(%0)\n\t"
207 "lfd 12, 88(%0)\n\t"
208 "lfd 13, 96(%0)\n\t"
209 : : "r" (pFPR)
210 : "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9",
211 "fr10", "fr11", "fr12", "fr13"
214 // tell gcc that r3 to r11 are not available to it for doing the TOC and exception munge on the func call
215 register sal_uInt64 r3 asm("r3");
216 register sal_uInt64 r4 asm("r4");
218 (*pFunc)(pGPR[0], pGPR[1], pGPR[2], pGPR[3], pGPR[4], pGPR[5], pGPR[6], pGPR[7]);
220 // get return value
221 __asm__ __volatile__ (
222 "mr %1, 3\n\t"
223 "mr %2, 4\n\t"
224 "fmr %0, 1\n\t"
225 : "=f" (dret), "=r" (r3), "=r" (r4) : );
227 MapReturn(r3, r4, dret, reinterpret_cast<typelib_TypeDescriptionReference *>(pReturnTypeDescr), pRegisterReturn);
230 // Macros for easier insertion of values to registers or stack
231 // pSV - pointer to the source
232 // nr - order of the value [will be increased if stored to register]
233 // pFPR, pGPR - pointer to the registers
234 // pDS - pointer to the stack [will be increased if stored here]
236 // The value in %xmm register is already prepared to be retrieved as a float,
237 // thus we treat float and double the same
238 #define INSERT_FLOAT( pSV, nr, pFPR, nGPR, pDS, bOverflow ) \
239 if ( nGPR < ppc64::MAX_GPR_REGS ) \
240 ++nGPR; \
241 if ( nr < ppc64::MAX_SSE_REGS ) \
242 pFPR[nr++] = *reinterpret_cast<float *>( pSV ); \
243 else \
244 bOverflow = true; \
245 if (bOverflow) \
246 *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
248 #define INSERT_DOUBLE( pSV, nr, pFPR, nGPR, pDS, bOverflow ) \
249 if ( nGPR < ppc64::MAX_GPR_REGS ) \
250 ++nGPR; \
251 if ( nr < ppc64::MAX_SSE_REGS ) \
252 pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
253 else \
254 bOverflow = true; \
255 if (bOverflow) \
256 *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
258 #define INSERT_INT64( pSV, nr, pGPR, pDS, bOverflow ) \
259 if ( nr < ppc64::MAX_GPR_REGS ) \
260 pGPR[nr++] = *reinterpret_cast<sal_Int64 *>( pSV ); \
261 else \
262 bOverflow = true; \
263 if (bOverflow) \
264 *pDS++ = *reinterpret_cast<sal_Int64 *>( pSV );
266 #define INSERT_UINT64( pSV, nr, pGPR, pDS, bOverflow ) \
267 if ( nr < ppc64::MAX_GPR_REGS ) \
268 pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \
269 else \
270 bOverflow = true; \
271 if (bOverflow) \
272 *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
274 #define INSERT_INT32( pSV, nr, pGPR, pDS, bOverflow ) \
275 if ( nr < ppc64::MAX_GPR_REGS ) \
276 pGPR[nr++] = *reinterpret_cast<sal_Int32 *>( pSV ); \
277 else \
278 bOverflow = true; \
279 if (bOverflow) \
280 *pDS++ = *reinterpret_cast<sal_Int32 *>( pSV );
282 #define INSERT_UINT32( pSV, nr, pGPR, pDS, bOverflow ) \
283 if ( nr < ppc64::MAX_GPR_REGS ) \
284 pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \
285 else \
286 bOverflow = true; \
287 if (bOverflow) \
288 *pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
290 #define INSERT_INT16( pSV, nr, pGPR, pDS, bOverflow ) \
291 if ( nr < ppc64::MAX_GPR_REGS ) \
292 pGPR[nr++] = *reinterpret_cast<sal_Int16 *>( pSV ); \
293 else \
294 bOverflow = true; \
295 if (bOverflow) \
296 *pDS++ = *reinterpret_cast<sal_Int16 *>( pSV );
298 #define INSERT_UINT16( pSV, nr, pGPR, pDS, bOverflow ) \
299 if ( nr < ppc64::MAX_GPR_REGS ) \
300 pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
301 else \
302 bOverflow = true; \
303 if (bOverflow) \
304 *pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
306 #define INSERT_INT8( pSV, nr, pGPR, pDS, bOverflow ) \
307 if ( nr < ppc64::MAX_GPR_REGS ) \
308 pGPR[nr++] = *reinterpret_cast<sal_Int8 *>( pSV ); \
309 else \
310 bOverflow = true; \
311 if (bOverflow) \
312 *pDS++ = *reinterpret_cast<sal_Int8 *>( pSV );
314 #define INSERT_UINT8( pSV, nr, pGPR, pDS, bOverflow ) \
315 if ( nr < ppc64::MAX_GPR_REGS ) \
316 pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \
317 else \
318 bOverflow = true; \
319 if (bOverflow) \
320 *pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
322 static void cpp_call(
323 bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
324 bridges::cpp_uno::shared::VtableSlot aVtableSlot,
325 typelib_TypeDescriptionReference * pReturnTypeRef,
326 sal_Int32 nParams, typelib_MethodParameter * pParams,
327 void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
329 #if OSL_DEBUG_LEVEL > 2
330 fprintf( stderr, "= cpp_call() =\n" );
331 #endif
333 // max space for: [complex ret ptr], values|ptr ...
334 sal_uInt64 * pStack = (sal_uInt64 *)alloca( (nParams+3) * sizeof(sal_Int64) );
335 sal_uInt64 * pStackStart = pStack;
337 sal_uInt64 pGPR[ppc64::MAX_GPR_REGS];
338 sal_uInt32 nGPR = 0;
340 double pFPR[ppc64::MAX_SSE_REGS];
341 sal_uInt32 nFPR = 0;
343 // return
344 typelib_TypeDescription * pReturnTypeDescr = 0;
345 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
346 assert(pReturnTypeDescr);
348 void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
350 bool bOverflow = false;
352 if (pReturnTypeDescr)
354 #if OSL_DEBUG_LEVEL > 2
355 fprintf(stderr, "return type is %d\n", pReturnTypeDescr->eTypeClass);
356 #endif
357 bool bSimpleReturn =!ppc64::return_in_hidden_param(pReturnTypeRef);
359 if (bSimpleReturn)
361 pCppReturn = pUnoReturn; // direct way for simple types
362 #if OSL_DEBUG_LEVEL > 2
363 fprintf(stderr, "simple return\n");
364 #endif
366 else
368 // complex return via ptr
369 pCppReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
370 ? alloca( pReturnTypeDescr->nSize ) : pUnoReturn);
371 #if OSL_DEBUG_LEVEL > 2
372 fprintf(stderr, "pCppReturn/pUnoReturn is %p/%p\n", pCppReturn, pUnoReturn);
373 #endif
374 INSERT_UINT64( &pCppReturn, nGPR, pGPR, pStack, bOverflow );
377 // push "this" pointer
378 void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
379 #if OSL_DEBUG_LEVEL > 2
380 fprintf(stderr, "this pointer is %p\n", pAdjustedThisPtr);
381 #endif
382 INSERT_UINT64( &pAdjustedThisPtr, nGPR, pGPR, pStack, bOverflow );
384 // Args
385 void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
386 // indices of values this have to be converted (interface conversion cpp<=>uno)
387 sal_Int32 * pTempIndices = (sal_Int32 *)(pCppArgs + nParams);
388 // type descriptions for reconversions
389 typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
391 sal_Int32 nTempIndices = 0;
393 #if OSL_DEBUG_LEVEL > 2
394 fprintf(stderr, "n params is %d\n", nParams);
395 #endif
397 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
399 const typelib_MethodParameter & rParam = pParams[nPos];
400 typelib_TypeDescription * pParamTypeDescr = 0;
401 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
403 #if OSL_DEBUG_LEVEL > 2
404 fprintf(stderr, "param %d is %d %d %d\n", nPos, rParam.bOut, bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ),
405 pParamTypeDescr->eTypeClass);
406 #endif
408 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
410 uno_copyAndConvertData( pCppArgs[nPos] = pStack, pUnoArgs[nPos], pParamTypeDescr,
411 pThis->getBridge()->getUno2Cpp() );
412 switch (pParamTypeDescr->eTypeClass)
414 case typelib_TypeClass_HYPER:
415 #if OSL_DEBUG_LEVEL > 2
416 fprintf(stderr, "hyper is 0x%lx\n", *(sal_Int64 *)pCppArgs[nPos]);
417 #endif
418 INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
419 break;
420 case typelib_TypeClass_UNSIGNED_HYPER:
421 #if OSL_DEBUG_LEVEL > 2
422 fprintf(stderr, "uhyper is 0x%lx\n", *(sal_Int64 *)pCppArgs[nPos]);
423 #endif
424 INSERT_UINT64( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
425 break;
426 case typelib_TypeClass_LONG:
427 case typelib_TypeClass_ENUM:
428 #if OSL_DEBUG_LEVEL > 2
429 fprintf(stderr, "long is 0x%x\n", *(sal_Int32 *)pCppArgs[nPos]);
430 #endif
431 INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
432 break;
433 case typelib_TypeClass_UNSIGNED_LONG:
434 #if OSL_DEBUG_LEVEL > 2
435 fprintf(stderr, "ulong is 0x%x\n", *(sal_Int32 *)pCppArgs[nPos]);
436 #endif
437 INSERT_UINT32( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
438 break;
439 case typelib_TypeClass_SHORT:
440 INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
441 break;
442 case typelib_TypeClass_CHAR:
443 case typelib_TypeClass_UNSIGNED_SHORT:
444 INSERT_UINT16( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
445 break;
446 case typelib_TypeClass_BOOLEAN:
447 INSERT_UINT8( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
448 break;
449 case typelib_TypeClass_BYTE:
450 INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow );
451 break;
452 case typelib_TypeClass_FLOAT:
453 INSERT_FLOAT( pCppArgs[nPos], nFPR, pFPR, nGPR, pStack, bOverflow );
454 break;
455 case typelib_TypeClass_DOUBLE:
456 INSERT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, nGPR, pStack, bOverflow );
457 break;
458 default:
459 break;
462 // no longer needed
463 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
466 else // ptr to complex value | ref
468 #if OSL_DEBUG_LEVEL > 2
469 fprintf(stderr, "complex type again %d\n", rParam.bIn);
470 #endif
471 if (! rParam.bIn) // is pure out
473 #if OSL_DEBUG_LEVEL > 2
474 fprintf(stderr, "complex size is %d\n", pParamTypeDescr->nSize );
475 #endif
476 // cpp out is constructed mem, uno out is not!
477 uno_constructData(
478 pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
479 pParamTypeDescr );
480 pTempIndices[nTempIndices] = nPos; // default constructed for cpp call
481 // will be released at reconversion
482 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
484 // is in/inout
485 else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
487 #if OSL_DEBUG_LEVEL > 2
488 fprintf(stderr, "this one\n");
489 #endif
490 uno_copyAndConvertData(
491 pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
492 pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
494 pTempIndices[nTempIndices] = nPos; // has to be reconverted
495 // will be released at reconversion
496 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
498 else // direct way
500 #if OSL_DEBUG_LEVEL > 2
501 fprintf(stderr, "that one, passing %p through\n", pUnoArgs[nPos]);
502 #endif
503 pCppArgs[nPos] = pUnoArgs[nPos];
504 // no longer needed
505 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
507 INSERT_UINT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack, bOverflow );
513 try {
514 callVirtualMethod(
515 pAdjustedThisPtr, aVtableSlot.index,
516 pCppReturn, pReturnTypeDescr,
517 pStackStart, ( pStack - pStackStart ),
518 pGPR, nGPR,
519 pFPR, nFPR );
520 } catch (css::uno::Exception &) {
521 throw;
522 } catch (std::exception & e) {
523 throw css::uno::RuntimeException(
524 "C++ code threw " + o3tl::runtimeToOUString(typeid(e).name()) + ": "
525 + o3tl::runtimeToOUString(e.what()));
526 } catch (...) {
527 throw css::uno::RuntimeException("C++ code threw unknown exception");
529 // NO exception occurred...
530 *ppUnoExc = 0;
532 // reconvert temporary params
533 for ( ; nTempIndices--; )
535 sal_Int32 nIndex = pTempIndices[nTempIndices];
536 typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
538 if (pParams[nIndex].bIn)
540 if (pParams[nIndex].bOut) // inout
542 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
543 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
544 pThis->getBridge()->getCpp2Uno() );
547 else // pure out
549 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
550 pThis->getBridge()->getCpp2Uno() );
552 // destroy temp cpp param => cpp: every param was constructed
553 uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
555 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
557 // return value
558 if (pCppReturn && pUnoReturn != pCppReturn)
560 uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
561 pThis->getBridge()->getCpp2Uno() );
562 uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
565 catch (...)
567 // fill uno exception
568 CPPU_CURRENT_NAMESPACE::fillUnoException(*ppUnoExc, pThis->getBridge()->getCpp2Uno());
570 // temporary params
571 for ( ; nTempIndices--; )
573 sal_Int32 nIndex = pTempIndices[nTempIndices];
574 // destroy temp cpp param => cpp: every param was constructed
575 uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndices], cpp_release );
576 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
578 // return type
579 if (pReturnTypeDescr)
580 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
586 namespace bridges::cpp_uno::shared {
588 void unoInterfaceProxyDispatch(
589 uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
590 void * pReturn, void * pArgs[], uno_Any ** ppException )
592 // is my surrogate
593 bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
594 = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy *> (pUnoI);
596 switch (pMemberDescr->eTypeClass)
598 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
601 VtableSlot aVtableSlot(
602 getVtableSlot(
603 reinterpret_cast<
604 typelib_InterfaceAttributeTypeDescription const * >(
605 pMemberDescr)));
607 if (pReturn)
609 // dependent dispatch
610 cpp_call(
611 pThis, aVtableSlot,
612 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
613 0, 0, // no params
614 pReturn, pArgs, ppException );
616 else
618 // is SET
619 typelib_MethodParameter aParam;
620 aParam.pTypeRef =
621 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
622 aParam.bIn = sal_True;
623 aParam.bOut = sal_False;
625 typelib_TypeDescriptionReference * pReturnTypeRef = 0;
626 OUString aVoidName("void");
627 typelib_typedescriptionreference_new(
628 &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
630 // dependent dispatch
631 aVtableSlot.index += 1; //get then set method
632 cpp_call(
633 pThis, aVtableSlot,
634 pReturnTypeRef,
635 1, &aParam,
636 pReturn, pArgs, ppException );
638 typelib_typedescriptionreference_release( pReturnTypeRef );
641 break;
643 case typelib_TypeClass_INTERFACE_METHOD:
646 VtableSlot aVtableSlot(
647 getVtableSlot(
648 reinterpret_cast<
649 typelib_InterfaceMethodTypeDescription const * >(
650 pMemberDescr)));
651 switch (aVtableSlot.index)
653 // standard calls
654 case 1: // acquire uno interface
655 (*pUnoI->acquire)( pUnoI );
656 *ppException = 0;
657 break;
658 case 2: // release uno interface
659 (*pUnoI->release)( pUnoI );
660 *ppException = 0;
661 break;
662 case 0: // queryInterface() opt
664 typelib_TypeDescription * pTD = 0;
665 TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
666 if (pTD)
668 uno_Interface * pInterface = 0;
669 (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
670 pThis->pBridge->getUnoEnv(),
671 (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
673 if (pInterface)
675 ::uno_any_construct(
676 reinterpret_cast< uno_Any * >( pReturn ),
677 &pInterface, pTD, 0 );
678 (*pInterface->release)( pInterface );
679 TYPELIB_DANGER_RELEASE( pTD );
680 *ppException = 0;
681 break;
683 TYPELIB_DANGER_RELEASE( pTD );
685 } // else perform queryInterface()
686 default:
687 // dependent dispatch
688 cpp_call(
689 pThis, aVtableSlot,
690 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
691 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
692 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
693 pReturn, pArgs, ppException );
695 break;
697 default:
699 ::com::sun::star::uno::RuntimeException aExc(
700 "illegal member type description!",
701 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
703 Type const & rExcType = cppu::UnoType<decltype(aExc)>::get();
704 // binary identical null reference
705 ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
712 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */