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