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 
46cdf0e10cSrcweir namespace
47cdf0e10cSrcweir {
48cdf0e10cSrcweir static sal_Int32
invoke_count_words(char * pPT)49cdf0e10cSrcweir invoke_count_words(char * pPT)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir      sal_Int32 overflow = 0, gpr = 0, fpr = 0;
52cdf0e10cSrcweir      int c;                        // character of parameter type being decoded
53cdf0e10cSrcweir 
54cdf0e10cSrcweir      while (*pPT != 'X') {
55cdf0e10cSrcweir        c = *pPT;
56cdf0e10cSrcweir        switch (c) {
57cdf0e10cSrcweir        case 'D':                   /* type is double */
58cdf0e10cSrcweir             if (fpr < 2) fpr++; else overflow+=2;
59cdf0e10cSrcweir             break;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir        case 'F':                   /* type is float */
62cdf0e10cSrcweir             if (fpr < 2) fpr++; else overflow++;
63cdf0e10cSrcweir             break;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir        case 'H':                /* type is long long */
66cdf0e10cSrcweir             if (gpr < 4) gpr+=2; else gpr=5, overflow+=2;
67cdf0e10cSrcweir             break;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir        case 'S':
70cdf0e10cSrcweir        case 'T':
71cdf0e10cSrcweir        case 'B':
72cdf0e10cSrcweir        case 'C':
73cdf0e10cSrcweir             if (gpr < 5) gpr++; else overflow++;
74cdf0e10cSrcweir             break;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir        default:
77cdf0e10cSrcweir             if (gpr < 5) gpr++; else overflow++;
78cdf0e10cSrcweir             break;
79cdf0e10cSrcweir        }
80cdf0e10cSrcweir        pPT++;
81cdf0e10cSrcweir      }
82cdf0e10cSrcweir      /* Round up number of overflow words to ensure stack
83cdf0e10cSrcweir        stays aligned to 8 bytes.  */
84cdf0e10cSrcweir      return (overflow + 1) & ~1;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir static void
88cdf0e10cSrcweir //invoke_copy_to_stack(sal_Int32 paramCount, sal_Int32 * pStackLongs, char * pPT, sal_Int32* d_ov, sal_Int32 overflow)
invoke_copy_to_stack(sal_Int32 * pStackLongs,char * pPT,sal_Int32 * d_ov,sal_Int32 overflow)89cdf0e10cSrcweir invoke_copy_to_stack(sal_Int32 * pStackLongs, char * pPT, sal_Int32* d_ov, sal_Int32 overflow)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     sal_Int32 *d_gpr = d_ov + overflow;
92cdf0e10cSrcweir     sal_Int64 *d_fpr = (sal_Int64 *)(d_gpr + 5);
93cdf0e10cSrcweir     sal_Int32 gpr = 0, fpr = 0;
94cdf0e10cSrcweir     char c;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir      while (*pPT != 'X') {
97cdf0e10cSrcweir        c = *pPT;
98cdf0e10cSrcweir        switch (c) {
99cdf0e10cSrcweir        case 'D':                   /* type is double */
100cdf0e10cSrcweir             if (fpr < 2)
101cdf0e10cSrcweir                 *((double*)  d_fpr) = *((double *)pStackLongs), d_fpr++, fpr++;
102cdf0e10cSrcweir             else
103cdf0e10cSrcweir                 *((double*)  d_ov ) = *((double *)pStackLongs), d_ov+=2;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             pStackLongs += 2;
106cdf0e10cSrcweir             break;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir        case 'F':                   /* type is float */
109cdf0e10cSrcweir             if (fpr < 2) {
110cdf0e10cSrcweir                 *((sal_Int64*) d_fpr) = 0;
111cdf0e10cSrcweir                 *((float*)   d_fpr) = *((float *)pStackLongs), d_fpr++, fpr++;
112cdf0e10cSrcweir               }
113cdf0e10cSrcweir             else {
114cdf0e10cSrcweir                 *((sal_Int64*) d_ov) = 0;
115cdf0e10cSrcweir                 *((float*)   d_ov ) = *((float *)pStackLongs), d_ov++;
116cdf0e10cSrcweir               }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             pStackLongs += 1;
119cdf0e10cSrcweir             break;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir        case 'H':                /* type is long long */
122cdf0e10cSrcweir             if (gpr < 4) {
123cdf0e10cSrcweir                 *((sal_Int64*) d_gpr) = *((sal_Int64*) pStackLongs), d_gpr+=2, gpr+=2;
124cdf0e10cSrcweir               }
125cdf0e10cSrcweir             else {
126cdf0e10cSrcweir                 *((sal_Int64*) d_ov ) = *((sal_Int64*) pStackLongs), d_ov+=2, gpr=5;
127cdf0e10cSrcweir               }
128cdf0e10cSrcweir             pStackLongs += 2;
129cdf0e10cSrcweir             break;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir        case 'S':
132cdf0e10cSrcweir             if (gpr < 5)
133cdf0e10cSrcweir                 *((sal_uInt32*)d_gpr) = *((unsigned short*)pStackLongs), d_gpr++, gpr++;
134cdf0e10cSrcweir             else
135cdf0e10cSrcweir                 *((sal_uInt32*)d_ov ) = *((unsigned short*)pStackLongs), d_ov++;
136cdf0e10cSrcweir             pStackLongs += 1;
137cdf0e10cSrcweir             break;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir        case 'T':
140cdf0e10cSrcweir             if (gpr < 5)
141cdf0e10cSrcweir                 *((sal_Int32*)d_gpr) = *((signed short*)pStackLongs), d_gpr++, gpr++;
142cdf0e10cSrcweir             else
143cdf0e10cSrcweir                 *((sal_Int32*)d_ov ) = *((signed short*)pStackLongs), d_ov++;
144cdf0e10cSrcweir             pStackLongs += 1;
145cdf0e10cSrcweir             break;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir        case 'B':
148cdf0e10cSrcweir             if (gpr < 5)
149cdf0e10cSrcweir                 *((sal_uInt32*)d_gpr) = *((unsigned char*)pStackLongs), d_gpr++, gpr++;
150cdf0e10cSrcweir             else
151cdf0e10cSrcweir                 *((sal_uInt32*)d_ov ) = *((unsigned char*)pStackLongs), d_ov++;
152cdf0e10cSrcweir             pStackLongs += 1;
153cdf0e10cSrcweir             break;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir        case 'C':
156cdf0e10cSrcweir             if (gpr < 5)
157cdf0e10cSrcweir                 *((sal_Int32*)d_gpr) = *((signed char*)pStackLongs), d_gpr++, gpr++;
158cdf0e10cSrcweir             else
159cdf0e10cSrcweir                 *((sal_Int32*)d_ov ) = *((signed char*)pStackLongs), d_ov++;
160cdf0e10cSrcweir             pStackLongs += 1;
161cdf0e10cSrcweir             break;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir        default:
164cdf0e10cSrcweir             if (gpr < 5)
165cdf0e10cSrcweir                 *((sal_Int32*)d_gpr) = *pStackLongs, d_gpr++, gpr++;
166cdf0e10cSrcweir             else
167cdf0e10cSrcweir                 *((sal_Int32*)d_ov ) = *pStackLongs, d_ov++;
168cdf0e10cSrcweir             pStackLongs += 1;
169cdf0e10cSrcweir             break;
170cdf0e10cSrcweir        }
171cdf0e10cSrcweir        pPT++;
172cdf0e10cSrcweir      }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir //==================================================================================================
callVirtualMethod(void * pThis,sal_Int32 nVtableIndex,void * pRegisterReturn,typelib_TypeClass eReturnType,char * pPT,sal_Int32 * pStackLongs,sal_Int32 nStackLongs)176cdf0e10cSrcweir static void callVirtualMethod(
177cdf0e10cSrcweir     void * pThis,
178cdf0e10cSrcweir     sal_Int32 nVtableIndex,
179cdf0e10cSrcweir     void * pRegisterReturn,
180cdf0e10cSrcweir     typelib_TypeClass eReturnType,
181cdf0e10cSrcweir     char * pPT,
182cdf0e10cSrcweir     sal_Int32 * pStackLongs,
183cdf0e10cSrcweir     sal_Int32 nStackLongs)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 
186cdf0e10cSrcweir   // parameter list is mixed list of * and values
187cdf0e10cSrcweir   // reference parameters are pointers
188cdf0e10cSrcweir 
189cdf0e10cSrcweir   // the basic idea here is to use gpr[5] as a storage area for
190cdf0e10cSrcweir   // the future values of registers r2 to r6 needed for the call,
191cdf0e10cSrcweir   // and similarly fpr[2] as a storage area for the future values
192cdf0e10cSrcweir   // of floating point registers f0 to f2
193cdf0e10cSrcweir 
194cdf0e10cSrcweir      sal_Int32 *vtable = *(sal_Int32 **)pThis;
195cdf0e10cSrcweir //    sal_Int32 method = vtable[nVtableIndex + 2];
196cdf0e10cSrcweir      sal_Int32 method = vtable[nVtableIndex];
197cdf0e10cSrcweir      sal_Int32 overflow = invoke_count_words (pPT);
198cdf0e10cSrcweir      sal_Int32 result;
199cdf0e10cSrcweir      volatile double dret;                  // temporary function return values
200cdf0e10cSrcweir      volatile float fret;
201cdf0e10cSrcweir      volatile int iret, iret2;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir      void * dummy = alloca(32); // dummy alloca to force r11 usage for exception handling
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     __asm__ __volatile__
206cdf0e10cSrcweir      (
207cdf0e10cSrcweir         "lr    7,15\n\t"
208cdf0e10cSrcweir         "ahi   7,-48\n\t"
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         "lr    3,%2\n\t"
211cdf0e10cSrcweir         "sll   3,2\n\t"
212cdf0e10cSrcweir         "lcr   3,3\n\t"
213cdf0e10cSrcweir         "l     2,0(15)\n\t"
214cdf0e10cSrcweir         "la    15,0(3,7)\n\t"
215cdf0e10cSrcweir         "st    2,0(15)\n\t"
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         "lr    2,%0\n\t"
218cdf0e10cSrcweir         "lr    3,%1\n\t"
219cdf0e10cSrcweir         "la    4,96(15)\n\t"
220cdf0e10cSrcweir         "lr    5,%2\n\t"
221cdf0e10cSrcweir         "basr  14,%3\n\t"
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         "ld    0,116(7)\n\t"
224cdf0e10cSrcweir         "ld    2,124(7)\n\t"
225cdf0e10cSrcweir         "lm    2,6,96(7)\n\t"
226cdf0e10cSrcweir         :
227cdf0e10cSrcweir         : "r" (pStackLongs),
228cdf0e10cSrcweir           "r" (pPT),
229cdf0e10cSrcweir           "r" (overflow),
230cdf0e10cSrcweir           "a" (invoke_copy_to_stack),
231cdf0e10cSrcweir           "a" (method),
232cdf0e10cSrcweir           "X" (dummy)
233cdf0e10cSrcweir         : "2", "3", "4", "5", "6", "7", "memory"
234cdf0e10cSrcweir     );
235cdf0e10cSrcweir //	"basr  14,%8\n\t"
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     (*(void (*)())method)();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     __asm__ __volatile__
240cdf0e10cSrcweir      (
241cdf0e10cSrcweir         "la    15,48(7)\n\t"
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         "lr    %2,2\n\t"
244cdf0e10cSrcweir         "lr    %3,3\n\t"
245cdf0e10cSrcweir         "ler   %0,0\n\t"
246cdf0e10cSrcweir         "ldr   %1,0\n\t"
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         : "=f" (fret), "=f" (dret), "=r" (iret), "=r" (iret2)
249cdf0e10cSrcweir     );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     switch( eReturnType )
252cdf0e10cSrcweir 	{
253cdf0e10cSrcweir 		case typelib_TypeClass_HYPER:
254cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_HYPER:
255cdf0e10cSrcweir //		        ((long*)pRegisterReturn)[0] = iret;
256cdf0e10cSrcweir 			((long*)pRegisterReturn)[1] = iret2;
257cdf0e10cSrcweir 		case typelib_TypeClass_LONG:
258cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_LONG:
259cdf0e10cSrcweir 		case typelib_TypeClass_ENUM:
260cdf0e10cSrcweir 			((long*)pRegisterReturn)[0] = iret;
261cdf0e10cSrcweir 			break;
262cdf0e10cSrcweir 		case typelib_TypeClass_CHAR:
263cdf0e10cSrcweir 		case typelib_TypeClass_SHORT:
264cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_SHORT:
265cdf0e10cSrcweir 		        *(unsigned short*)pRegisterReturn = (unsigned short)iret;
266cdf0e10cSrcweir 			break;
267cdf0e10cSrcweir 		case typelib_TypeClass_BOOLEAN:
268cdf0e10cSrcweir 		case typelib_TypeClass_BYTE:
269cdf0e10cSrcweir 		        *(unsigned char*)pRegisterReturn = (unsigned char)iret;
270cdf0e10cSrcweir 			break;
271cdf0e10cSrcweir 		case typelib_TypeClass_FLOAT:
272cdf0e10cSrcweir 		        *(float*)pRegisterReturn = fret;
273cdf0e10cSrcweir 			break;
274cdf0e10cSrcweir 		case typelib_TypeClass_DOUBLE:
275cdf0e10cSrcweir 			*(double*)pRegisterReturn = dret;
276cdf0e10cSrcweir 			break;
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 
281cdf0e10cSrcweir //============================================================================
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)282cdf0e10cSrcweir static void cpp_call(
283cdf0e10cSrcweir         bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
284cdf0e10cSrcweir         bridges::cpp_uno::shared::VtableSlot  aVtableSlot,
285cdf0e10cSrcweir         typelib_TypeDescriptionReference * pReturnTypeRef,
286cdf0e10cSrcweir 	sal_Int32 nParams, typelib_MethodParameter * pParams,
287cdf0e10cSrcweir 	void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir   	// max space for: [complex ret ptr], values|ptr ...
290cdf0e10cSrcweir   	char * pCppStack		=
291cdf0e10cSrcweir   		(char *)alloca( sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) );
292cdf0e10cSrcweir   	char * pCppStackStart	= pCppStack;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         // need to know parameter types for callVirtualMethod so generate a signature string
295cdf0e10cSrcweir         char * pParamType = (char *) alloca(nParams+2);
296cdf0e10cSrcweir         char * pPT = pParamType;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 	// return
299cdf0e10cSrcweir 	typelib_TypeDescription * pReturnTypeDescr = 0;
300cdf0e10cSrcweir 	TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
301cdf0e10cSrcweir 	OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 	void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	if (pReturnTypeDescr)
306cdf0e10cSrcweir 	{
307cdf0e10cSrcweir 		if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
308cdf0e10cSrcweir 		{
309cdf0e10cSrcweir 			pCppReturn = pUnoReturn; // direct way for simple types
310cdf0e10cSrcweir 		}
311cdf0e10cSrcweir 		else
312cdf0e10cSrcweir 		{
313cdf0e10cSrcweir 			// complex return via ptr
314cdf0e10cSrcweir 			pCppReturn = *(void **)pCppStack = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
315cdf0e10cSrcweir 												? alloca( pReturnTypeDescr->nSize )
316cdf0e10cSrcweir 												: pUnoReturn); // direct way
317cdf0e10cSrcweir                         *pPT++ = 'I'; //signify that a complex return type on stack
318cdf0e10cSrcweir 			pCppStack += sizeof(void *);
319cdf0e10cSrcweir 		}
320cdf0e10cSrcweir 	}
321cdf0e10cSrcweir         // push "this" pointer
322cdf0e10cSrcweir         void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
323cdf0e10cSrcweir 	*(void**)pCppStack = pAdjustedThisPtr;
324cdf0e10cSrcweir 	pCppStack += sizeof( void* );
325cdf0e10cSrcweir         *pPT++ = 'I';
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	// stack space
328cdf0e10cSrcweir 	OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
329cdf0e10cSrcweir 	// args
330cdf0e10cSrcweir 	void ** pCppArgs  = (void **)alloca( 3 * sizeof(void *) * nParams );
331cdf0e10cSrcweir 	// indizes of values this have to be converted (interface conversion cpp<=>uno)
332cdf0e10cSrcweir 	sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
333cdf0e10cSrcweir 	// type descriptions for reconversions
334cdf0e10cSrcweir 	typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	sal_Int32 nTempIndizes   = 0;
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
339cdf0e10cSrcweir 	{
340cdf0e10cSrcweir 		const typelib_MethodParameter & rParam = pParams[nPos];
341cdf0e10cSrcweir 		typelib_TypeDescription * pParamTypeDescr = 0;
342cdf0e10cSrcweir 		TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 		if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
345cdf0e10cSrcweir 		{
346cdf0e10cSrcweir 			uno_copyAndConvertData( pCppArgs[nPos] = pCppStack, pUnoArgs[nPos], pParamTypeDescr,
347cdf0e10cSrcweir 									pThis->getBridge()->getUno2Cpp() );
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 			switch (pParamTypeDescr->eTypeClass)
350cdf0e10cSrcweir 			{
351cdf0e10cSrcweir 
352cdf0e10cSrcweir                           // we need to know type of each param so that we know whether to use
353cdf0e10cSrcweir                           // gpr or fpr to pass in parameters:
354cdf0e10cSrcweir                           // Key: I - int, long, pointer, etc means pass in gpr
355cdf0e10cSrcweir                           //      B - byte value passed in gpr
356cdf0e10cSrcweir                           //      S - short value passed in gpr
357cdf0e10cSrcweir                           //      F - float value pass in fpr
358cdf0e10cSrcweir                           //      D - double value pass in fpr
359cdf0e10cSrcweir                           //      H - long long int pass in proper pairs of gpr (3,4) (5,6), etc
360cdf0e10cSrcweir                           //      X - indicates end of parameter description string
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 		          case typelib_TypeClass_LONG:
363cdf0e10cSrcweir 		          case typelib_TypeClass_UNSIGNED_LONG:
364cdf0e10cSrcweir 		          case typelib_TypeClass_ENUM:
365cdf0e10cSrcweir 			    *pPT++ = 'I';
366cdf0e10cSrcweir 			    break;
367cdf0e10cSrcweir  		          case typelib_TypeClass_SHORT:
368cdf0e10cSrcweir                             *pPT++ = 'T';
369cdf0e10cSrcweir                             break;
370cdf0e10cSrcweir 		          case typelib_TypeClass_CHAR:
371cdf0e10cSrcweir 		          case typelib_TypeClass_UNSIGNED_SHORT:
372cdf0e10cSrcweir                             *pPT++ = 'S';
373cdf0e10cSrcweir                             break;
374cdf0e10cSrcweir 		          case typelib_TypeClass_BOOLEAN:
375cdf0e10cSrcweir                             *pPT++ = 'B';
376cdf0e10cSrcweir                             break;
377cdf0e10cSrcweir 		          case typelib_TypeClass_BYTE:
378cdf0e10cSrcweir                             *pPT++ = 'C';
379cdf0e10cSrcweir                             break;
380cdf0e10cSrcweir 		          case typelib_TypeClass_FLOAT:
381cdf0e10cSrcweir                             *pPT++ = 'F';
382cdf0e10cSrcweir 			    break;
383cdf0e10cSrcweir 		        case typelib_TypeClass_DOUBLE:
384cdf0e10cSrcweir 			    *pPT++ = 'D';
385cdf0e10cSrcweir 			    pCppStack += sizeof(sal_Int32); // extra long
386cdf0e10cSrcweir 			    break;
387cdf0e10cSrcweir 			case typelib_TypeClass_HYPER:
388cdf0e10cSrcweir 			case typelib_TypeClass_UNSIGNED_HYPER:
389cdf0e10cSrcweir 			    *pPT++ = 'H';
390cdf0e10cSrcweir 			    pCppStack += sizeof(sal_Int32); // extra long
391cdf0e10cSrcweir 			}
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 			// no longer needed
394cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
395cdf0e10cSrcweir 		}
396cdf0e10cSrcweir 		else // ptr to complex value | ref
397cdf0e10cSrcweir 		{
398cdf0e10cSrcweir 			if (! rParam.bIn) // is pure out
399cdf0e10cSrcweir 			{
400cdf0e10cSrcweir 				// cpp out is constructed mem, uno out is not!
401cdf0e10cSrcweir 				uno_constructData(
402cdf0e10cSrcweir 					*(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
403cdf0e10cSrcweir 					pParamTypeDescr );
404cdf0e10cSrcweir 				pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
405cdf0e10cSrcweir 				// will be released at reconversion
406cdf0e10cSrcweir 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
407cdf0e10cSrcweir 			}
408cdf0e10cSrcweir 			// is in/inout
409cdf0e10cSrcweir 			else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
410cdf0e10cSrcweir 			{
411cdf0e10cSrcweir 				uno_copyAndConvertData(
412cdf0e10cSrcweir 					*(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
413cdf0e10cSrcweir 					pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 				pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
416cdf0e10cSrcweir 				// will be released at reconversion
417cdf0e10cSrcweir 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
418cdf0e10cSrcweir 			}
419cdf0e10cSrcweir 			else // direct way
420cdf0e10cSrcweir 			{
421cdf0e10cSrcweir 				*(void **)pCppStack = pCppArgs[nPos] = pUnoArgs[nPos];
422cdf0e10cSrcweir 				// no longer needed
423cdf0e10cSrcweir 				TYPELIB_DANGER_RELEASE( pParamTypeDescr );
424cdf0e10cSrcweir 			}
425cdf0e10cSrcweir                         // KBH: FIXME: is this the right way to pass these
426cdf0e10cSrcweir                         *pPT++='I';
427cdf0e10cSrcweir 		}
428cdf0e10cSrcweir 		pCppStack += sizeof(sal_Int32); // standard parameter length
429cdf0e10cSrcweir 	}
430cdf0e10cSrcweir 
431cdf0e10cSrcweir         // terminate the signature string
432cdf0e10cSrcweir         *pPT++='X';
433cdf0e10cSrcweir         *pPT=0;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	try
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		OSL_ENSURE( !( (pCppStack - pCppStackStart ) & 3), "UNALIGNED STACK !!! (Please DO panic)" );
438cdf0e10cSrcweir 		callVirtualMethod(
439cdf0e10cSrcweir 			pAdjustedThisPtr, aVtableSlot.index,
440cdf0e10cSrcweir 			pCppReturn, pReturnTypeDescr->eTypeClass, pParamType,
441cdf0e10cSrcweir 			(sal_Int32 *)pCppStackStart, (pCppStack - pCppStackStart) / sizeof(sal_Int32) );
442*07a3d7f1SPedro Giffuni 		// NO exception occurred...
443cdf0e10cSrcweir 		*ppUnoExc = 0;
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 		// reconvert temporary params
446cdf0e10cSrcweir 		for ( ; nTempIndizes--; )
447cdf0e10cSrcweir 		{
448cdf0e10cSrcweir 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
449cdf0e10cSrcweir 			typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 			if (pParams[nIndex].bIn)
452cdf0e10cSrcweir 			{
453cdf0e10cSrcweir 				if (pParams[nIndex].bOut) // inout
454cdf0e10cSrcweir 				{
455cdf0e10cSrcweir 					uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
456cdf0e10cSrcweir 					uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
457cdf0e10cSrcweir 											pThis->getBridge()->getCpp2Uno() );
458cdf0e10cSrcweir 				}
459cdf0e10cSrcweir 			}
460cdf0e10cSrcweir 			else // pure out
461cdf0e10cSrcweir 			{
462cdf0e10cSrcweir 				uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
463cdf0e10cSrcweir 										pThis->getBridge()->getCpp2Uno() );
464cdf0e10cSrcweir 			}
465cdf0e10cSrcweir 			// destroy temp cpp param => cpp: every param was constructed
466cdf0e10cSrcweir 			uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
469cdf0e10cSrcweir 		}
470cdf0e10cSrcweir 		// return value
471cdf0e10cSrcweir 		if (pCppReturn && pUnoReturn != pCppReturn)
472cdf0e10cSrcweir 		{
473cdf0e10cSrcweir 			uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
474cdf0e10cSrcweir 									pThis->getBridge()->getCpp2Uno() );
475cdf0e10cSrcweir 			uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
476cdf0e10cSrcweir 		}
477cdf0e10cSrcweir 	}
478cdf0e10cSrcweir  	catch (...)
479cdf0e10cSrcweir  	{
480cdf0e10cSrcweir   		// fill uno exception
481cdf0e10cSrcweir 		fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions,
482cdf0e10cSrcweir 			*ppUnoExc, pThis->getBridge()->getCpp2Uno() );
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 		// temporary params
486cdf0e10cSrcweir 		for ( ; nTempIndizes--; )
487cdf0e10cSrcweir 		{
488cdf0e10cSrcweir 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
489cdf0e10cSrcweir 			// destroy temp cpp param => cpp: every param was constructed
490cdf0e10cSrcweir 			uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
491cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
492cdf0e10cSrcweir 		}
493cdf0e10cSrcweir 		// return type
494cdf0e10cSrcweir 		if (pReturnTypeDescr)
495cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
496cdf0e10cSrcweir 	}
497cdf0e10cSrcweir }
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
501cdf0e10cSrcweir 
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)502cdf0e10cSrcweir void unoInterfaceProxyDispatch(
503cdf0e10cSrcweir 	uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
504cdf0e10cSrcweir 	void * pReturn, void * pArgs[], uno_Any ** ppException )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir #ifdef CMC_DEBUG
507cdf0e10cSrcweir 	fprintf(stderr, "unoInterfaceProxyDispatch\n");
508cdf0e10cSrcweir #endif
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 	// is my surrogate
512cdf0e10cSrcweir         bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
513cdf0e10cSrcweir             = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy *> (pUnoI);
514cdf0e10cSrcweir 	typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 	switch (pMemberDescr->eTypeClass)
517cdf0e10cSrcweir 	{
518cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE_ATTRIBUTE:
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 
521cdf0e10cSrcweir         VtableSlot aVtableSlot(
522cdf0e10cSrcweir             getVtableSlot(
523cdf0e10cSrcweir                 reinterpret_cast<
524cdf0e10cSrcweir                     typelib_InterfaceAttributeTypeDescription const * >(
525cdf0e10cSrcweir                         pMemberDescr)));
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 		if (pReturn)
528cdf0e10cSrcweir 		{
529cdf0e10cSrcweir 			// dependent dispatch
530cdf0e10cSrcweir 			cpp_call(
531cdf0e10cSrcweir 				pThis, aVtableSlot,
532cdf0e10cSrcweir 				((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
533cdf0e10cSrcweir 				0, 0, // no params
534cdf0e10cSrcweir 				pReturn, pArgs, ppException );
535cdf0e10cSrcweir 		}
536cdf0e10cSrcweir 		else
537cdf0e10cSrcweir 		{
538cdf0e10cSrcweir 			// is SET
539cdf0e10cSrcweir 			typelib_MethodParameter aParam;
540cdf0e10cSrcweir 			aParam.pTypeRef =
541cdf0e10cSrcweir 				((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
542cdf0e10cSrcweir 			aParam.bIn		= sal_True;
543cdf0e10cSrcweir 			aParam.bOut		= sal_False;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 			typelib_TypeDescriptionReference * pReturnTypeRef = 0;
546cdf0e10cSrcweir 			OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
547cdf0e10cSrcweir 			typelib_typedescriptionreference_new(
548cdf0e10cSrcweir 				&pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 			// dependent dispatch
551cdf0e10cSrcweir                         aVtableSlot.index += 1; //get then set method
552cdf0e10cSrcweir 			cpp_call(
553cdf0e10cSrcweir 				pThis, aVtableSlot,
554cdf0e10cSrcweir 				pReturnTypeRef,
555cdf0e10cSrcweir 				1, &aParam,
556cdf0e10cSrcweir 				pReturn, pArgs, ppException );
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 			typelib_typedescriptionreference_release( pReturnTypeRef );
559cdf0e10cSrcweir 		}
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 		break;
562cdf0e10cSrcweir 	}
563cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE_METHOD:
564cdf0e10cSrcweir 	{
565cdf0e10cSrcweir 
566cdf0e10cSrcweir         VtableSlot aVtableSlot(
567cdf0e10cSrcweir             getVtableSlot(
568cdf0e10cSrcweir                 reinterpret_cast<
569cdf0e10cSrcweir                     typelib_InterfaceMethodTypeDescription const * >(
570cdf0e10cSrcweir                         pMemberDescr)));
571cdf0e10cSrcweir 		switch (aVtableSlot.index)
572cdf0e10cSrcweir 		{
573cdf0e10cSrcweir 			// standard calls
574cdf0e10cSrcweir 		case 1: // acquire uno interface
575cdf0e10cSrcweir 			(*pUnoI->acquire)( pUnoI );
576cdf0e10cSrcweir 			*ppException = 0;
577cdf0e10cSrcweir 			break;
578cdf0e10cSrcweir 		case 2: // release uno interface
579cdf0e10cSrcweir 			(*pUnoI->release)( pUnoI );
580cdf0e10cSrcweir 			*ppException = 0;
581cdf0e10cSrcweir 			break;
582cdf0e10cSrcweir 		case 0: // queryInterface() opt
583cdf0e10cSrcweir 		{
584cdf0e10cSrcweir 			typelib_TypeDescription * pTD = 0;
585cdf0e10cSrcweir 			TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
586cdf0e10cSrcweir 			if (pTD)
587cdf0e10cSrcweir 			{
588cdf0e10cSrcweir                 uno_Interface * pInterface = 0;
589cdf0e10cSrcweir                 (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
590cdf0e10cSrcweir                     pThis->pBridge->getUnoEnv(),
591cdf0e10cSrcweir                     (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
592cdf0e10cSrcweir 
593cdf0e10cSrcweir                 if (pInterface)
594cdf0e10cSrcweir                 {
595cdf0e10cSrcweir                     ::uno_any_construct(
596cdf0e10cSrcweir                         reinterpret_cast< uno_Any * >( pReturn ),
597cdf0e10cSrcweir                         &pInterface, pTD, 0 );
598cdf0e10cSrcweir                     (*pInterface->release)( pInterface );
599cdf0e10cSrcweir                     TYPELIB_DANGER_RELEASE( pTD );
600cdf0e10cSrcweir                     *ppException = 0;
601cdf0e10cSrcweir                     break;
602cdf0e10cSrcweir                 }
603cdf0e10cSrcweir                 TYPELIB_DANGER_RELEASE( pTD );
604cdf0e10cSrcweir             }
605cdf0e10cSrcweir 		} // else perform queryInterface()
606cdf0e10cSrcweir 		default:
607cdf0e10cSrcweir 			// dependent dispatch
608cdf0e10cSrcweir 			cpp_call(
609cdf0e10cSrcweir 				pThis, aVtableSlot,
610cdf0e10cSrcweir 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
611cdf0e10cSrcweir 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
612cdf0e10cSrcweir 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
613cdf0e10cSrcweir 				pReturn, pArgs, ppException );
614cdf0e10cSrcweir 		}
615cdf0e10cSrcweir 		break;
616cdf0e10cSrcweir 	}
617cdf0e10cSrcweir 	default:
618cdf0e10cSrcweir 	{
619cdf0e10cSrcweir 		::com::sun::star::uno::RuntimeException aExc(
620cdf0e10cSrcweir 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
621cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 		Type const & rExcType = ::getCppuType( &aExc );
624cdf0e10cSrcweir 		// binary identical null reference
625cdf0e10cSrcweir 		::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
626cdf0e10cSrcweir 	}
627cdf0e10cSrcweir 	}
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
630cdf0e10cSrcweir } } }
631cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
632