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