1af84ad07SPedro Giffuni /**************************************************************
2af84ad07SPedro Giffuni *
3af84ad07SPedro Giffuni * Licensed to the Apache Software Foundation (ASF) under one
4af84ad07SPedro Giffuni * or more contributor license agreements. See the NOTICE file
5af84ad07SPedro Giffuni * distributed with this work for additional information
6af84ad07SPedro Giffuni * regarding copyright ownership. The ASF licenses this file
7af84ad07SPedro Giffuni * to you under the Apache License, Version 2.0 (the
8af84ad07SPedro Giffuni * "License"); you may not use this file except in compliance
9af84ad07SPedro Giffuni * with the License. You may obtain a copy of the License at
10af84ad07SPedro Giffuni *
11af84ad07SPedro Giffuni * http://www.apache.org/licenses/LICENSE-2.0
12af84ad07SPedro Giffuni *
13af84ad07SPedro Giffuni * Unless required by applicable law or agreed to in writing,
14af84ad07SPedro Giffuni * software distributed under the License is distributed on an
15af84ad07SPedro Giffuni * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16af84ad07SPedro Giffuni * KIND, either express or implied. See the License for the
17af84ad07SPedro Giffuni * specific language governing permissions and limitations
18af84ad07SPedro Giffuni * under the License.
19af84ad07SPedro Giffuni *
20af84ad07SPedro Giffuni *************************************************************/
21af84ad07SPedro Giffuni
22af84ad07SPedro Giffuni
23af84ad07SPedro Giffuni
24af84ad07SPedro Giffuni // MARKER(update_precomp.py): autogen include statement, do not remove
25af84ad07SPedro Giffuni #include "precompiled_bridges.hxx"
26af84ad07SPedro Giffuni
27*941ddfd7Spfg #include <stdlib.h>
28af84ad07SPedro Giffuni
29af84ad07SPedro Giffuni #include <com/sun/star/uno/genfunc.hxx>
30af84ad07SPedro Giffuni #include <uno/data.h>
31af84ad07SPedro Giffuni
32af84ad07SPedro Giffuni #include "bridges/cpp_uno/shared/bridge.hxx"
33af84ad07SPedro Giffuni #include "bridges/cpp_uno/shared/types.hxx"
34af84ad07SPedro Giffuni #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
35af84ad07SPedro Giffuni #include "bridges/cpp_uno/shared/vtables.hxx"
36af84ad07SPedro Giffuni
37af84ad07SPedro Giffuni #include "share.hxx"
38af84ad07SPedro Giffuni
39af84ad07SPedro Giffuni #include <stdio.h>
40af84ad07SPedro Giffuni #include <string.h>
41af84ad07SPedro Giffuni
42af84ad07SPedro Giffuni
43af84ad07SPedro Giffuni using namespace ::rtl;
44af84ad07SPedro Giffuni using namespace ::com::sun::star::uno;
45af84ad07SPedro Giffuni
MapReturn(long r3,double dret,typelib_TypeClass eTypeClass,void * pRegisterReturn)46af84ad07SPedro Giffuni void MapReturn(long r3, double dret, typelib_TypeClass eTypeClass, void *pRegisterReturn)
47af84ad07SPedro Giffuni {
48af84ad07SPedro Giffuni switch (eTypeClass)
49af84ad07SPedro Giffuni {
50af84ad07SPedro Giffuni case typelib_TypeClass_HYPER:
51af84ad07SPedro Giffuni case typelib_TypeClass_UNSIGNED_HYPER:
52af84ad07SPedro Giffuni *reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = r3;
53af84ad07SPedro Giffuni break;
54af84ad07SPedro Giffuni case typelib_TypeClass_LONG:
55af84ad07SPedro Giffuni case typelib_TypeClass_UNSIGNED_LONG:
56af84ad07SPedro Giffuni case typelib_TypeClass_ENUM:
57af84ad07SPedro Giffuni *reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = r3;
58af84ad07SPedro Giffuni break;
59af84ad07SPedro Giffuni case typelib_TypeClass_CHAR:
60af84ad07SPedro Giffuni case typelib_TypeClass_SHORT:
61af84ad07SPedro Giffuni case typelib_TypeClass_UNSIGNED_SHORT:
62af84ad07SPedro Giffuni *reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = (unsigned short)r3;
63af84ad07SPedro Giffuni break;
64af84ad07SPedro Giffuni case typelib_TypeClass_BOOLEAN:
65af84ad07SPedro Giffuni case typelib_TypeClass_BYTE:
66af84ad07SPedro Giffuni *reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = (unsigned char)r3;
67af84ad07SPedro Giffuni break;
68af84ad07SPedro Giffuni case typelib_TypeClass_FLOAT:
69af84ad07SPedro Giffuni *reinterpret_cast<float *>( pRegisterReturn ) = dret;
70af84ad07SPedro Giffuni break;
71af84ad07SPedro Giffuni case typelib_TypeClass_DOUBLE:
72af84ad07SPedro Giffuni *reinterpret_cast<double *>( pRegisterReturn ) = dret;
73af84ad07SPedro Giffuni break;
74af84ad07SPedro Giffuni default:
75af84ad07SPedro Giffuni break;
76af84ad07SPedro Giffuni }
77af84ad07SPedro Giffuni }
78af84ad07SPedro Giffuni
79af84ad07SPedro Giffuni namespace
80af84ad07SPedro Giffuni {
81af84ad07SPedro Giffuni //==================================================================================================
callVirtualMethod(void * pThis,sal_uInt32 nVtableIndex,void * pRegisterReturn,typelib_TypeDescription * pReturnTypeDescr,sal_uInt64 * pStack,sal_uInt32 nStack,sal_uInt64 * pGPR,sal_uInt32 nGPR,double * pFPR,sal_uInt32 nFPR)82af84ad07SPedro Giffuni static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
83af84ad07SPedro Giffuni void * pRegisterReturn, typelib_TypeDescription * pReturnTypeDescr,
84af84ad07SPedro Giffuni sal_uInt64 *pStack, sal_uInt32 nStack,
85af84ad07SPedro Giffuni sal_uInt64 *pGPR, sal_uInt32 nGPR,
86af84ad07SPedro Giffuni double *pFPR, sal_uInt32 nFPR)
87af84ad07SPedro Giffuni {
88af84ad07SPedro Giffuni // Stack, if used, must be 16-bytes aligned
89af84ad07SPedro Giffuni if ( nStack )
90af84ad07SPedro Giffuni nStack = ( nStack + 1 ) & ~1;
91af84ad07SPedro Giffuni
92af84ad07SPedro Giffuni // Should not happen, but...
93af84ad07SPedro Giffuni if ( nFPR > ppc64::MAX_SSE_REGS )
94af84ad07SPedro Giffuni nFPR = ppc64::MAX_SSE_REGS;
95af84ad07SPedro Giffuni if ( nGPR > ppc64::MAX_GPR_REGS )
96af84ad07SPedro Giffuni nGPR = ppc64::MAX_GPR_REGS;
97af84ad07SPedro Giffuni
98af84ad07SPedro Giffuni #ifdef CMC_DEBUG
99af84ad07SPedro Giffuni // Let's figure out what is really going on here
100af84ad07SPedro Giffuni {
101af84ad07SPedro Giffuni fprintf( stderr, "= callVirtualMethod() =\nGPR's (%d): ", nGPR );
102af84ad07SPedro Giffuni for ( int i = 0; i < nGPR; ++i )
103af84ad07SPedro Giffuni fprintf( stderr, "0x%lx, ", pGPR[i] );
104af84ad07SPedro Giffuni fprintf( stderr, "\nFPR's (%d): ", nFPR );
105af84ad07SPedro Giffuni for ( int i = 0; i < nFPR; ++i )
106af84ad07SPedro Giffuni fprintf( stderr, "0x%lx (%f), ", pFPR[i], pFPR[i] );
107af84ad07SPedro Giffuni fprintf( stderr, "\nStack (%d): ", nStack );
108af84ad07SPedro Giffuni for ( int i = 0; i < nStack; ++i )
109af84ad07SPedro Giffuni fprintf( stderr, "0x%lx, ", pStack[i] );
110af84ad07SPedro Giffuni fprintf( stderr, "\n" );
111af84ad07SPedro Giffuni }
112af84ad07SPedro Giffuni #endif
113af84ad07SPedro Giffuni
114af84ad07SPedro Giffuni // Load parameters to stack, if necessary
115af84ad07SPedro Giffuni sal_uInt64 *stack = (sal_uInt64 *) __builtin_alloca( nStack * 8 );
116af84ad07SPedro Giffuni memcpy( stack, pStack, nStack * 8 );
117af84ad07SPedro Giffuni
118af84ad07SPedro Giffuni // Get pointer to method
119af84ad07SPedro Giffuni sal_uInt64 pMethod = *((sal_uInt64 *)pThis);
120af84ad07SPedro Giffuni pMethod += 8 * nVtableIndex;
121af84ad07SPedro Giffuni pMethod = *((sal_uInt64 *)pMethod);
122af84ad07SPedro Giffuni
123af84ad07SPedro Giffuni typedef void (* FunctionCall )( sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64 );
124af84ad07SPedro Giffuni FunctionCall pFunc = (FunctionCall)pMethod;
125af84ad07SPedro Giffuni
126af84ad07SPedro Giffuni volatile double dret;
127af84ad07SPedro Giffuni
128af84ad07SPedro Giffuni // fill registers
129af84ad07SPedro Giffuni __asm__ __volatile__ (
130af84ad07SPedro Giffuni "ld 3, 0(%0)\n\t"
131af84ad07SPedro Giffuni "ld 4, 8(%0)\n\t"
132af84ad07SPedro Giffuni "ld 5, 16(%0)\n\t"
133af84ad07SPedro Giffuni "ld 6, 24(%0)\n\t"
134af84ad07SPedro Giffuni "ld 7, 32(%0)\n\t"
135af84ad07SPedro Giffuni "ld 8, 40(%0)\n\t"
136af84ad07SPedro Giffuni "ld 9, 48(%0)\n\t"
137af84ad07SPedro Giffuni "ld 10, 56(%0)\n\t"
138af84ad07SPedro Giffuni "lfd 1, 0(%1)\n\t"
139af84ad07SPedro Giffuni "lfd 2, 8(%1)\n\t"
140af84ad07SPedro Giffuni "lfd 3, 16(%1)\n\t"
141af84ad07SPedro Giffuni "lfd 4, 24(%1)\n\t"
142af84ad07SPedro Giffuni "lfd 5, 32(%1)\n\t"
143af84ad07SPedro Giffuni "lfd 6, 40(%1)\n\t"
144af84ad07SPedro Giffuni "lfd 7, 48(%1)\n\t"
145af84ad07SPedro Giffuni "lfd 8, 56(%1)\n\t"
146af84ad07SPedro Giffuni "lfd 9, 64(%1)\n\t"
147af84ad07SPedro Giffuni "lfd 10, 72(%1)\n\t"
148af84ad07SPedro Giffuni "lfd 11, 80(%1)\n\t"
149af84ad07SPedro Giffuni "lfd 12, 88(%1)\n\t"
150af84ad07SPedro Giffuni "lfd 13, 96(%1)\n\t"
151af84ad07SPedro Giffuni : : "r" (pGPR), "r" (pFPR)
152af84ad07SPedro Giffuni : "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
153af84ad07SPedro Giffuni "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9",
154af84ad07SPedro Giffuni "fr10", "fr11", "fr12", "fr13"
155af84ad07SPedro Giffuni );
156af84ad07SPedro Giffuni
157af84ad07SPedro Giffuni // tell gcc that r3 to r11 are not available to it for doing the TOC and exception munge on the func call
158af84ad07SPedro Giffuni register sal_uInt64 r3 asm("r3");
159af84ad07SPedro Giffuni register sal_uInt64 r4 asm("r4");
160af84ad07SPedro Giffuni register sal_uInt64 r5 asm("r5");
161af84ad07SPedro Giffuni register sal_uInt64 r6 asm("r6");
162af84ad07SPedro Giffuni register sal_uInt64 r7 asm("r7");
163af84ad07SPedro Giffuni register sal_uInt64 r8 asm("r8");
164af84ad07SPedro Giffuni register sal_uInt64 r9 asm("r9");
165af84ad07SPedro Giffuni register sal_uInt64 r10 asm("r10");
166af84ad07SPedro Giffuni register sal_uInt64 r11 asm("r11");
167af84ad07SPedro Giffuni
168af84ad07SPedro Giffuni (*pFunc)(r3, r4, r5, r6, r7, r8, r9, r10);
169af84ad07SPedro Giffuni
170af84ad07SPedro Giffuni // get return value
171af84ad07SPedro Giffuni __asm__ __volatile__ (
172af84ad07SPedro Giffuni "mr %1, 3\n\t"
173af84ad07SPedro Giffuni "mr %2, 4\n\t"
174af84ad07SPedro Giffuni "fmr %0, 1\n\t"
175af84ad07SPedro Giffuni : "=f" (dret), "=r" (r3), "=r" (r4) : );
176af84ad07SPedro Giffuni
177af84ad07SPedro Giffuni MapReturn(r3, dret, pReturnTypeDescr->eTypeClass, pRegisterReturn);
178af84ad07SPedro Giffuni }
179af84ad07SPedro Giffuni
180af84ad07SPedro Giffuni // Macros for easier insertion of values to registers or stack
181af84ad07SPedro Giffuni // pSV - pointer to the source
182af84ad07SPedro Giffuni // nr - order of the value [will be increased if stored to register]
183af84ad07SPedro Giffuni // pFPR, pGPR - pointer to the registers
184af84ad07SPedro Giffuni // pDS - pointer to the stack [will be increased if stored here]
185af84ad07SPedro Giffuni
186af84ad07SPedro Giffuni // The value in %xmm register is already prepared to be retrieved as a float,
187af84ad07SPedro Giffuni // thus we treat float and double the same
188af84ad07SPedro Giffuni #define INSERT_FLOAT( pSV, nr, pFPR, pDS, bOverflow ) \
189af84ad07SPedro Giffuni if ( nr < ppc64::MAX_SSE_REGS ) \
190af84ad07SPedro Giffuni pFPR[nr++] = *reinterpret_cast<float *>( pSV ); \
191af84ad07SPedro Giffuni else \
192af84ad07SPedro Giffuni bOverFlow = true; \
193af84ad07SPedro Giffuni if (bOverFlow) \
194af84ad07SPedro Giffuni *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
195af84ad07SPedro Giffuni
196af84ad07SPedro Giffuni #define INSERT_DOUBLE( pSV, nr, pFPR, pDS, bOverflow ) \
197af84ad07SPedro Giffuni if ( nr < ppc64::MAX_SSE_REGS ) \
198af84ad07SPedro Giffuni pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
199af84ad07SPedro Giffuni else \
200af84ad07SPedro Giffuni bOverFlow = true; \
201af84ad07SPedro Giffuni if (bOverFlow) \
202af84ad07SPedro Giffuni *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
203af84ad07SPedro Giffuni
204af84ad07SPedro Giffuni #define INSERT_INT64( pSV, nr, pGPR, pDS, bOverflow ) \
205af84ad07SPedro Giffuni if ( nr < ppc64::MAX_GPR_REGS ) \
206af84ad07SPedro Giffuni pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \
207af84ad07SPedro Giffuni else \
208af84ad07SPedro Giffuni bOverFlow = true; \
209af84ad07SPedro Giffuni if (bOverFlow) \
210af84ad07SPedro Giffuni *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
211af84ad07SPedro Giffuni
212af84ad07SPedro Giffuni #define INSERT_INT32( pSV, nr, pGPR, pDS, bOverflow ) \
213af84ad07SPedro Giffuni if ( nr < ppc64::MAX_GPR_REGS ) \
214af84ad07SPedro Giffuni pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \
215af84ad07SPedro Giffuni else \
216af84ad07SPedro Giffuni bOverFlow = true; \
217af84ad07SPedro Giffuni if (bOverFlow) \
218af84ad07SPedro Giffuni *pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
219af84ad07SPedro Giffuni
220af84ad07SPedro Giffuni #define INSERT_INT16( pSV, nr, pGPR, pDS, bOverflow ) \
221af84ad07SPedro Giffuni if ( nr < ppc64::MAX_GPR_REGS ) \
222af84ad07SPedro Giffuni pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
223af84ad07SPedro Giffuni else \
224af84ad07SPedro Giffuni bOverFlow = true; \
225af84ad07SPedro Giffuni if (bOverFlow) \
226af84ad07SPedro Giffuni *pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
227af84ad07SPedro Giffuni
228af84ad07SPedro Giffuni #define INSERT_INT8( pSV, nr, pGPR, pDS, bOverflow ) \
229af84ad07SPedro Giffuni if ( nr < ppc64::MAX_GPR_REGS ) \
230af84ad07SPedro Giffuni pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \
231af84ad07SPedro Giffuni else \
232af84ad07SPedro Giffuni bOverFlow = true; \
233af84ad07SPedro Giffuni if (bOverFlow) \
234af84ad07SPedro Giffuni *pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
235af84ad07SPedro Giffuni
236af84ad07SPedro Giffuni //==================================================================================================
cpp_call(bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,bridges::cpp_uno::shared::VtableSlot aVtableSlot,typelib_TypeDescriptionReference * pReturnTypeRef,sal_Int32 nParams,typelib_MethodParameter * pParams,void * pUnoReturn,void * pUnoArgs[],uno_Any ** ppUnoExc)237af84ad07SPedro Giffuni static void cpp_call(
238af84ad07SPedro Giffuni bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
239af84ad07SPedro Giffuni bridges::cpp_uno::shared::VtableSlot aVtableSlot,
240af84ad07SPedro Giffuni typelib_TypeDescriptionReference * pReturnTypeRef,
241af84ad07SPedro Giffuni sal_Int32 nParams, typelib_MethodParameter * pParams,
242af84ad07SPedro Giffuni void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
243af84ad07SPedro Giffuni {
244af84ad07SPedro Giffuni // max space for: [complex ret ptr], values|ptr ...
245af84ad07SPedro Giffuni sal_uInt64 * pStack = (sal_uInt64 *)alloca( (nParams+3) * sizeof(sal_Int64) );
246af84ad07SPedro Giffuni sal_uInt64 * pStackStart = pStack;
247af84ad07SPedro Giffuni
248af84ad07SPedro Giffuni sal_uInt64 pGPR[ppc64::MAX_GPR_REGS];
249af84ad07SPedro Giffuni sal_uInt32 nGPR = 0;
250af84ad07SPedro Giffuni
251af84ad07SPedro Giffuni double pFPR[ppc64::MAX_SSE_REGS];
252af84ad07SPedro Giffuni sal_uInt32 nFPR = 0;
253af84ad07SPedro Giffuni
254af84ad07SPedro Giffuni // return
255af84ad07SPedro Giffuni typelib_TypeDescription * pReturnTypeDescr = 0;
256af84ad07SPedro Giffuni TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
257af84ad07SPedro Giffuni OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
258af84ad07SPedro Giffuni
259af84ad07SPedro Giffuni void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
260af84ad07SPedro Giffuni
261af84ad07SPedro Giffuni bool bOverFlow = false;
262af84ad07SPedro Giffuni
263af84ad07SPedro Giffuni if (pReturnTypeDescr)
264af84ad07SPedro Giffuni {
265af84ad07SPedro Giffuni #ifdef CMC_DEBUG
266af84ad07SPedro Giffuni fprintf(stderr, "return type is %d\n", pReturnTypeDescr->eTypeClass);
267af84ad07SPedro Giffuni #endif
268af84ad07SPedro Giffuni if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
269af84ad07SPedro Giffuni {
270af84ad07SPedro Giffuni pCppReturn = pUnoReturn; // direct way for simple types
271af84ad07SPedro Giffuni #ifdef CMC_DEBUG
272af84ad07SPedro Giffuni fprintf(stderr, "simple return\n");
273af84ad07SPedro Giffuni #endif
274af84ad07SPedro Giffuni }
275af84ad07SPedro Giffuni else
276af84ad07SPedro Giffuni {
277af84ad07SPedro Giffuni // complex return via ptr
278af84ad07SPedro Giffuni pCppReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
279af84ad07SPedro Giffuni ? alloca( pReturnTypeDescr->nSize ) : pUnoReturn);
280af84ad07SPedro Giffuni #ifdef CMC_DEBUG
281af84ad07SPedro Giffuni fprintf(stderr, "pCppReturn/pUnoReturn is %lx/%lx", pCppReturn, pUnoReturn);
282af84ad07SPedro Giffuni #endif
283af84ad07SPedro Giffuni INSERT_INT64( &pCppReturn, nGPR, pGPR, pStack, bOverFlow );
284af84ad07SPedro Giffuni }
285af84ad07SPedro Giffuni }
286af84ad07SPedro Giffuni // push "this" pointer
287af84ad07SPedro Giffuni void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
288af84ad07SPedro Giffuni #ifdef CMC_DEBUG
289af84ad07SPedro Giffuni fprintf(stderr, "this pointer is %p\n", pAdjustedThisPtr);
290af84ad07SPedro Giffuni #endif
291af84ad07SPedro Giffuni INSERT_INT64( &pAdjustedThisPtr, nGPR, pGPR, pStack, bOverFlow );
292af84ad07SPedro Giffuni
293af84ad07SPedro Giffuni // Args
294af84ad07SPedro Giffuni void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
295af84ad07SPedro Giffuni // indizes of values this have to be converted (interface conversion cpp<=>uno)
296af84ad07SPedro Giffuni sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
297af84ad07SPedro Giffuni // type descriptions for reconversions
298af84ad07SPedro Giffuni typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
299af84ad07SPedro Giffuni
300af84ad07SPedro Giffuni sal_Int32 nTempIndizes = 0;
301af84ad07SPedro Giffuni
302af84ad07SPedro Giffuni #ifdef CMC_DEBUG
303af84ad07SPedro Giffuni fprintf(stderr, "n params is %d\n", nParams);
304af84ad07SPedro Giffuni #endif
305af84ad07SPedro Giffuni
306af84ad07SPedro Giffuni for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
307af84ad07SPedro Giffuni {
308af84ad07SPedro Giffuni const typelib_MethodParameter & rParam = pParams[nPos];
309af84ad07SPedro Giffuni typelib_TypeDescription * pParamTypeDescr = 0;
310af84ad07SPedro Giffuni TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
311af84ad07SPedro Giffuni
312af84ad07SPedro Giffuni #ifdef CMC_DEBUG
313af84ad07SPedro Giffuni fprintf(stderr, "param %d is %d %d %d\n", nPos, rParam.bOut, bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ),
314af84ad07SPedro Giffuni pParamTypeDescr->eTypeClass);
315af84ad07SPedro Giffuni #endif
316af84ad07SPedro Giffuni
317af84ad07SPedro Giffuni if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
318af84ad07SPedro Giffuni {
319af84ad07SPedro Giffuni // uno_copyAndConvertData( pCppArgs[nPos] = alloca( 8 ), pUnoArgs[nPos], pParamTypeDescr,
320af84ad07SPedro Giffuni uno_copyAndConvertData( pCppArgs[nPos] = pStack, pUnoArgs[nPos], pParamTypeDescr,
321af84ad07SPedro Giffuni pThis->getBridge()->getUno2Cpp() );
322af84ad07SPedro Giffuni switch (pParamTypeDescr->eTypeClass)
323af84ad07SPedro Giffuni {
324af84ad07SPedro Giffuni case typelib_TypeClass_HYPER:
325af84ad07SPedro Giffuni case typelib_TypeClass_UNSIGNED_HYPER:
326af84ad07SPedro Giffuni #ifdef CMC_DEBUG
327af84ad07SPedro Giffuni fprintf(stderr, "hyper is %lx\n", pCppArgs[nPos]);
328af84ad07SPedro Giffuni #endif
329af84ad07SPedro Giffuni INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack, bOverFlow );
330af84ad07SPedro Giffuni break;
331af84ad07SPedro Giffuni case typelib_TypeClass_LONG:
332af84ad07SPedro Giffuni case typelib_TypeClass_UNSIGNED_LONG:
333af84ad07SPedro Giffuni case typelib_TypeClass_ENUM:
334af84ad07SPedro Giffuni #ifdef CMC_DEBUG
335af84ad07SPedro Giffuni fprintf(stderr, "long is %x\n", pCppArgs[nPos]);
336af84ad07SPedro Giffuni #endif
337af84ad07SPedro Giffuni INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack, bOverFlow );
338af84ad07SPedro Giffuni break;
339af84ad07SPedro Giffuni case typelib_TypeClass_SHORT:
340af84ad07SPedro Giffuni case typelib_TypeClass_CHAR:
341af84ad07SPedro Giffuni case typelib_TypeClass_UNSIGNED_SHORT:
342af84ad07SPedro Giffuni INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack, bOverFlow );
343af84ad07SPedro Giffuni break;
344af84ad07SPedro Giffuni case typelib_TypeClass_BOOLEAN:
345af84ad07SPedro Giffuni case typelib_TypeClass_BYTE:
346af84ad07SPedro Giffuni INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack, bOverFlow );
347af84ad07SPedro Giffuni break;
348af84ad07SPedro Giffuni case typelib_TypeClass_FLOAT:
349af84ad07SPedro Giffuni INSERT_FLOAT( pCppArgs[nPos], nFPR, pFPR, pStack, bOverFlow );
350af84ad07SPedro Giffuni break;
351af84ad07SPedro Giffuni case typelib_TypeClass_DOUBLE:
352af84ad07SPedro Giffuni INSERT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, pStack, bOverFlow );
353af84ad07SPedro Giffuni break;
354af84ad07SPedro Giffuni }
355af84ad07SPedro Giffuni
356af84ad07SPedro Giffuni // no longer needed
357af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( pParamTypeDescr );
358af84ad07SPedro Giffuni
359af84ad07SPedro Giffuni }
360af84ad07SPedro Giffuni else // ptr to complex value | ref
361af84ad07SPedro Giffuni {
362af84ad07SPedro Giffuni #ifdef CMC_DEBUG
363af84ad07SPedro Giffuni fprintf(stderr, "complex type again %d\n", rParam.bIn);
364af84ad07SPedro Giffuni #endif
365af84ad07SPedro Giffuni if (! rParam.bIn) // is pure out
366af84ad07SPedro Giffuni {
367af84ad07SPedro Giffuni #ifdef CMC_DEBUG
368af84ad07SPedro Giffuni fprintf(stderr, "complex size is %d\n", pParamTypeDescr->nSize );
369af84ad07SPedro Giffuni #endif
370af84ad07SPedro Giffuni // cpp out is constructed mem, uno out is not!
371af84ad07SPedro Giffuni uno_constructData(
372af84ad07SPedro Giffuni pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
373af84ad07SPedro Giffuni pParamTypeDescr );
374af84ad07SPedro Giffuni pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
375af84ad07SPedro Giffuni // will be released at reconversion
376af84ad07SPedro Giffuni ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
377af84ad07SPedro Giffuni }
378af84ad07SPedro Giffuni // is in/inout
379af84ad07SPedro Giffuni else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
380af84ad07SPedro Giffuni {
381af84ad07SPedro Giffuni #ifdef CMC_DEBUG
382af84ad07SPedro Giffuni fprintf(stderr, "this one\n");
383af84ad07SPedro Giffuni #endif
384af84ad07SPedro Giffuni uno_copyAndConvertData(
385af84ad07SPedro Giffuni pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
386af84ad07SPedro Giffuni pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
387af84ad07SPedro Giffuni
388af84ad07SPedro Giffuni pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
389af84ad07SPedro Giffuni // will be released at reconversion
390af84ad07SPedro Giffuni ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
391af84ad07SPedro Giffuni }
392af84ad07SPedro Giffuni else // direct way
393af84ad07SPedro Giffuni {
394af84ad07SPedro Giffuni #ifdef CMC_DEBUG
395af84ad07SPedro Giffuni fprintf(stderr, "that one, passing %lx through\n", pUnoArgs[nPos]);
396af84ad07SPedro Giffuni #endif
397af84ad07SPedro Giffuni pCppArgs[nPos] = pUnoArgs[nPos];
398af84ad07SPedro Giffuni // no longer needed
399af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( pParamTypeDescr );
400af84ad07SPedro Giffuni }
401af84ad07SPedro Giffuni INSERT_INT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack, bOverFlow );
402af84ad07SPedro Giffuni }
403af84ad07SPedro Giffuni }
404af84ad07SPedro Giffuni
405af84ad07SPedro Giffuni try
406af84ad07SPedro Giffuni {
407af84ad07SPedro Giffuni callVirtualMethod(
408af84ad07SPedro Giffuni pAdjustedThisPtr, aVtableSlot.index,
409af84ad07SPedro Giffuni pCppReturn, pReturnTypeDescr,
410af84ad07SPedro Giffuni pStackStart, ( pStack - pStackStart ),
411af84ad07SPedro Giffuni pGPR, nGPR,
412af84ad07SPedro Giffuni pFPR, nFPR );
413af84ad07SPedro Giffuni // NO exception occurred...
414af84ad07SPedro Giffuni *ppUnoExc = 0;
415af84ad07SPedro Giffuni
416af84ad07SPedro Giffuni // reconvert temporary params
417af84ad07SPedro Giffuni for ( ; nTempIndizes--; )
418af84ad07SPedro Giffuni {
419af84ad07SPedro Giffuni sal_Int32 nIndex = pTempIndizes[nTempIndizes];
420af84ad07SPedro Giffuni typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
421af84ad07SPedro Giffuni
422af84ad07SPedro Giffuni if (pParams[nIndex].bIn)
423af84ad07SPedro Giffuni {
424af84ad07SPedro Giffuni if (pParams[nIndex].bOut) // inout
425af84ad07SPedro Giffuni {
426af84ad07SPedro Giffuni uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
427af84ad07SPedro Giffuni uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
428af84ad07SPedro Giffuni pThis->getBridge()->getCpp2Uno() );
429af84ad07SPedro Giffuni }
430af84ad07SPedro Giffuni }
431af84ad07SPedro Giffuni else // pure out
432af84ad07SPedro Giffuni {
433af84ad07SPedro Giffuni uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
434af84ad07SPedro Giffuni pThis->getBridge()->getCpp2Uno() );
435af84ad07SPedro Giffuni }
436af84ad07SPedro Giffuni // destroy temp cpp param => cpp: every param was constructed
437af84ad07SPedro Giffuni uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
438af84ad07SPedro Giffuni
439af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( pParamTypeDescr );
440af84ad07SPedro Giffuni }
441af84ad07SPedro Giffuni // return value
442af84ad07SPedro Giffuni if (pCppReturn && pUnoReturn != pCppReturn)
443af84ad07SPedro Giffuni {
444af84ad07SPedro Giffuni uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
445af84ad07SPedro Giffuni pThis->getBridge()->getCpp2Uno() );
446af84ad07SPedro Giffuni uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
447af84ad07SPedro Giffuni }
448af84ad07SPedro Giffuni }
449af84ad07SPedro Giffuni catch (...)
450af84ad07SPedro Giffuni {
451af84ad07SPedro Giffuni // fill uno exception
452af84ad07SPedro Giffuni fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions,
453af84ad07SPedro Giffuni *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
454af84ad07SPedro Giffuni
455af84ad07SPedro Giffuni // temporary params
456af84ad07SPedro Giffuni for ( ; nTempIndizes--; )
457af84ad07SPedro Giffuni {
458af84ad07SPedro Giffuni sal_Int32 nIndex = pTempIndizes[nTempIndizes];
459af84ad07SPedro Giffuni // destroy temp cpp param => cpp: every param was constructed
460af84ad07SPedro Giffuni uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
461af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
462af84ad07SPedro Giffuni }
463af84ad07SPedro Giffuni // return type
464af84ad07SPedro Giffuni if (pReturnTypeDescr)
465af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
466af84ad07SPedro Giffuni }
467af84ad07SPedro Giffuni }
468af84ad07SPedro Giffuni
469af84ad07SPedro Giffuni }
470af84ad07SPedro Giffuni
471af84ad07SPedro Giffuni namespace bridges { namespace cpp_uno { namespace shared {
472af84ad07SPedro Giffuni
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)473af84ad07SPedro Giffuni void unoInterfaceProxyDispatch(
474af84ad07SPedro Giffuni uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
475af84ad07SPedro Giffuni void * pReturn, void * pArgs[], uno_Any ** ppException )
476af84ad07SPedro Giffuni {
477af84ad07SPedro Giffuni // is my surrogate
478af84ad07SPedro Giffuni bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
479af84ad07SPedro Giffuni = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy *> (pUnoI);
480af84ad07SPedro Giffuni typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
481af84ad07SPedro Giffuni
482af84ad07SPedro Giffuni switch (pMemberDescr->eTypeClass)
483af84ad07SPedro Giffuni {
484af84ad07SPedro Giffuni case typelib_TypeClass_INTERFACE_ATTRIBUTE:
485af84ad07SPedro Giffuni {
486af84ad07SPedro Giffuni
487af84ad07SPedro Giffuni VtableSlot aVtableSlot(
488af84ad07SPedro Giffuni getVtableSlot(
489af84ad07SPedro Giffuni reinterpret_cast<
490af84ad07SPedro Giffuni typelib_InterfaceAttributeTypeDescription const * >(
491af84ad07SPedro Giffuni pMemberDescr)));
492af84ad07SPedro Giffuni
493af84ad07SPedro Giffuni if (pReturn)
494af84ad07SPedro Giffuni {
495af84ad07SPedro Giffuni // dependent dispatch
496af84ad07SPedro Giffuni cpp_call(
497af84ad07SPedro Giffuni pThis, aVtableSlot,
498af84ad07SPedro Giffuni ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
499af84ad07SPedro Giffuni 0, 0, // no params
500af84ad07SPedro Giffuni pReturn, pArgs, ppException );
501af84ad07SPedro Giffuni }
502af84ad07SPedro Giffuni else
503af84ad07SPedro Giffuni {
504af84ad07SPedro Giffuni // is SET
505af84ad07SPedro Giffuni typelib_MethodParameter aParam;
506af84ad07SPedro Giffuni aParam.pTypeRef =
507af84ad07SPedro Giffuni ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
508af84ad07SPedro Giffuni aParam.bIn = sal_True;
509af84ad07SPedro Giffuni aParam.bOut = sal_False;
510af84ad07SPedro Giffuni
511af84ad07SPedro Giffuni typelib_TypeDescriptionReference * pReturnTypeRef = 0;
512af84ad07SPedro Giffuni OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
513af84ad07SPedro Giffuni typelib_typedescriptionreference_new(
514af84ad07SPedro Giffuni &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
515af84ad07SPedro Giffuni
516af84ad07SPedro Giffuni // dependent dispatch
517af84ad07SPedro Giffuni aVtableSlot.index += 1; //get then set method
518af84ad07SPedro Giffuni cpp_call(
519af84ad07SPedro Giffuni pThis, aVtableSlot,
520af84ad07SPedro Giffuni pReturnTypeRef,
521af84ad07SPedro Giffuni 1, &aParam,
522af84ad07SPedro Giffuni pReturn, pArgs, ppException );
523af84ad07SPedro Giffuni
524af84ad07SPedro Giffuni typelib_typedescriptionreference_release( pReturnTypeRef );
525af84ad07SPedro Giffuni }
526af84ad07SPedro Giffuni
527af84ad07SPedro Giffuni break;
528af84ad07SPedro Giffuni }
529af84ad07SPedro Giffuni case typelib_TypeClass_INTERFACE_METHOD:
530af84ad07SPedro Giffuni {
531af84ad07SPedro Giffuni
532af84ad07SPedro Giffuni VtableSlot aVtableSlot(
533af84ad07SPedro Giffuni getVtableSlot(
534af84ad07SPedro Giffuni reinterpret_cast<
535af84ad07SPedro Giffuni typelib_InterfaceMethodTypeDescription const * >(
536af84ad07SPedro Giffuni pMemberDescr)));
537af84ad07SPedro Giffuni switch (aVtableSlot.index)
538af84ad07SPedro Giffuni {
539af84ad07SPedro Giffuni // standard calls
540af84ad07SPedro Giffuni case 1: // acquire uno interface
541af84ad07SPedro Giffuni (*pUnoI->acquire)( pUnoI );
542af84ad07SPedro Giffuni *ppException = 0;
543af84ad07SPedro Giffuni break;
544af84ad07SPedro Giffuni case 2: // release uno interface
545af84ad07SPedro Giffuni (*pUnoI->release)( pUnoI );
546af84ad07SPedro Giffuni *ppException = 0;
547af84ad07SPedro Giffuni break;
548af84ad07SPedro Giffuni case 0: // queryInterface() opt
549af84ad07SPedro Giffuni {
550af84ad07SPedro Giffuni typelib_TypeDescription * pTD = 0;
551af84ad07SPedro Giffuni TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
552af84ad07SPedro Giffuni if (pTD)
553af84ad07SPedro Giffuni {
554af84ad07SPedro Giffuni uno_Interface * pInterface = 0;
555af84ad07SPedro Giffuni (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
556af84ad07SPedro Giffuni pThis->pBridge->getUnoEnv(),
557af84ad07SPedro Giffuni (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
558af84ad07SPedro Giffuni
559af84ad07SPedro Giffuni if (pInterface)
560af84ad07SPedro Giffuni {
561af84ad07SPedro Giffuni ::uno_any_construct(
562af84ad07SPedro Giffuni reinterpret_cast< uno_Any * >( pReturn ),
563af84ad07SPedro Giffuni &pInterface, pTD, 0 );
564af84ad07SPedro Giffuni (*pInterface->release)( pInterface );
565af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( pTD );
566af84ad07SPedro Giffuni *ppException = 0;
567af84ad07SPedro Giffuni break;
568af84ad07SPedro Giffuni }
569af84ad07SPedro Giffuni TYPELIB_DANGER_RELEASE( pTD );
570af84ad07SPedro Giffuni }
571af84ad07SPedro Giffuni } // else perform queryInterface()
572af84ad07SPedro Giffuni default:
573af84ad07SPedro Giffuni // dependent dispatch
574af84ad07SPedro Giffuni cpp_call(
575af84ad07SPedro Giffuni pThis, aVtableSlot,
576af84ad07SPedro Giffuni ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
577af84ad07SPedro Giffuni ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
578af84ad07SPedro Giffuni ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
579af84ad07SPedro Giffuni pReturn, pArgs, ppException );
580af84ad07SPedro Giffuni }
581af84ad07SPedro Giffuni break;
582af84ad07SPedro Giffuni }
583af84ad07SPedro Giffuni default:
584af84ad07SPedro Giffuni {
585af84ad07SPedro Giffuni ::com::sun::star::uno::RuntimeException aExc(
586af84ad07SPedro Giffuni OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
587af84ad07SPedro Giffuni ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
588af84ad07SPedro Giffuni
589af84ad07SPedro Giffuni Type const & rExcType = ::getCppuType( &aExc );
590af84ad07SPedro Giffuni // binary identical null reference
591af84ad07SPedro Giffuni ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
592af84ad07SPedro Giffuni }
593af84ad07SPedro Giffuni }
594af84ad07SPedro Giffuni }
595af84ad07SPedro Giffuni
596af84ad07SPedro Giffuni } } }
597