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 #include <malloc.h>
25cdf0e10cSrcweir #include <rtl/alloc.h>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
28cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
29cdf0e10cSrcweir #include <uno/data.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <bridges/cpp_uno/shared/bridge.hxx>
32cdf0e10cSrcweir #include <bridges/cpp_uno/shared/types.hxx>
33cdf0e10cSrcweir #include <bridges/cpp_uno/shared/unointerfaceproxy.hxx>
34cdf0e10cSrcweir #include <bridges/cpp_uno/shared/vtables.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "share.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <stdio.h>
39cdf0e10cSrcweir #include <string.h>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace ::rtl;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir 
MapReturn(long d0,long d1,typelib_TypeClass eReturnType,long * pRegisterReturn)44cdf0e10cSrcweir void MapReturn(long d0, long d1, typelib_TypeClass eReturnType, long *pRegisterReturn)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     register float fret asm("fp0");
47cdf0e10cSrcweir     register double dret asm("fp0");
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     switch( eReturnType )
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         case typelib_TypeClass_HYPER:
52cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_HYPER:
53cdf0e10cSrcweir             pRegisterReturn[1] = d1;
54cdf0e10cSrcweir         case typelib_TypeClass_LONG:
55cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_LONG:
56cdf0e10cSrcweir         case typelib_TypeClass_ENUM:
57cdf0e10cSrcweir         case typelib_TypeClass_CHAR:
58cdf0e10cSrcweir         case typelib_TypeClass_SHORT:
59cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_SHORT:
60cdf0e10cSrcweir         case typelib_TypeClass_BOOLEAN:
61cdf0e10cSrcweir         case typelib_TypeClass_BYTE:
62cdf0e10cSrcweir             pRegisterReturn[0] = d0;
63cdf0e10cSrcweir             break;
64cdf0e10cSrcweir         case typelib_TypeClass_FLOAT:
65cdf0e10cSrcweir             *(float*)pRegisterReturn = fret;
66cdf0e10cSrcweir 	    break;
67cdf0e10cSrcweir         case typelib_TypeClass_DOUBLE:
68cdf0e10cSrcweir             *(double*)pRegisterReturn = dret;
69cdf0e10cSrcweir             break;
70cdf0e10cSrcweir         default:
71cdf0e10cSrcweir             break;
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir namespace
76cdf0e10cSrcweir {
77cdf0e10cSrcweir //================================================================
78cdf0e10cSrcweir 
79cdf0e10cSrcweir void callVirtualMethod(
80cdf0e10cSrcweir     void * pThis,
81cdf0e10cSrcweir     sal_Int32 nVtableIndex,
82cdf0e10cSrcweir     void * pRegisterReturn,
83cdf0e10cSrcweir     typelib_TypeClass eReturnType,
84cdf0e10cSrcweir     sal_uInt32 *pStack,
85cdf0e10cSrcweir     sal_uInt32 nStack) __attribute__((noinline));
86cdf0e10cSrcweir 
callVirtualMethod(void * pThis,sal_Int32 nVtableIndex,void * pRegisterReturn,typelib_TypeClass eReturnType,sal_uInt32 * pStack,sal_uInt32 nStack)87cdf0e10cSrcweir void callVirtualMethod(
88cdf0e10cSrcweir     void * pThis,
89cdf0e10cSrcweir     sal_Int32 nVtableIndex,
90cdf0e10cSrcweir     void * pRegisterReturn,
91cdf0e10cSrcweir     typelib_TypeClass eReturnType,
92cdf0e10cSrcweir     sal_uInt32 *pStack,
93cdf0e10cSrcweir     sal_uInt32 nStack)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     // never called
96cdf0e10cSrcweir     if (! pThis)
97cdf0e10cSrcweir         CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     if ( nStack )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir 	// m68k stack is either 2 or 4 bytes aligned, doesn't really matter as
102cdf0e10cSrcweir 	// we deal in 4 byte units anyway
103cdf0e10cSrcweir         sal_uInt32 nStackBytes = nStack * sizeof(sal_uInt32);
104cdf0e10cSrcweir         sal_uInt32 *stack = (sal_uInt32 *) __builtin_alloca( nStackBytes );
105cdf0e10cSrcweir         memcpy( stack, pStack, nStackBytes );
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir #ifdef CMC_DEBUG
109cdf0e10cSrcweir         // Let's figure out what is really going on here
110cdf0e10cSrcweir         {
111cdf0e10cSrcweir                 fprintf( stderr, "\nStack (%d): ", nStack );
112cdf0e10cSrcweir                 for ( unsigned int i = 0; i < nStack; ++i )
113cdf0e10cSrcweir                         fprintf( stderr, "0x%lx, ", pStack[i] );
114cdf0e10cSrcweir                 fprintf( stderr, "\n" );
115cdf0e10cSrcweir                 fprintf( stderr, "pRegisterReturn is %p\n", pRegisterReturn);
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir #endif
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     sal_uInt32 pMethod = *((sal_uInt32*)pThis);
120cdf0e10cSrcweir     pMethod += 4 * nVtableIndex;
121cdf0e10cSrcweir     pMethod = *((sal_uInt32 *)pMethod);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     typedef long (*FunctionCall )();
124cdf0e10cSrcweir     FunctionCall pFunc = (FunctionCall)pMethod;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     //stick the return area into r8 for big struct returning
127cdf0e10cSrcweir     asm volatile("movel %0,%%a1" : : "m"(pRegisterReturn) : );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     long d0 = (*pFunc)();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     register long d1 asm("d1");
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     MapReturn(d0, d1, eReturnType, (long*)pRegisterReturn);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir #define INSERT_INT32( pSV, pDS )\
138cdf0e10cSrcweir         *pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir #define INSERT_INT64( pSV, pDS )\
141cdf0e10cSrcweir         INSERT_INT32( pSV, pDS ) \
142cdf0e10cSrcweir         INSERT_INT32( ((sal_uInt32*)pSV)+1, pDS )
143cdf0e10cSrcweir 
144cdf0e10cSrcweir #define INSERT_FLOAT( pSV, pDS ) \
145cdf0e10cSrcweir 	INSERT_INT32( pSV, pDS )
146cdf0e10cSrcweir 
147cdf0e10cSrcweir #define INSERT_DOUBLE( pSV, pDS ) \
148cdf0e10cSrcweir 	INSERT_INT64( pSV, pDS )
149cdf0e10cSrcweir 
150cdf0e10cSrcweir #define INSERT_INT16( pSV, pDS ) \
151cdf0e10cSrcweir         *pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir #define INSERT_INT8( pSV, pDS ) \
154cdf0e10cSrcweir         *pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir namespace {
157cdf0e10cSrcweir //=======================================================================
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)158cdf0e10cSrcweir static void cpp_call(
159cdf0e10cSrcweir     bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
160cdf0e10cSrcweir     bridges::cpp_uno::shared::VtableSlot aVtableSlot,
161cdf0e10cSrcweir     typelib_TypeDescriptionReference * pReturnTypeRef,
162cdf0e10cSrcweir     sal_Int32 nParams, typelib_MethodParameter * pParams,
163cdf0e10cSrcweir     void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     // max space for: [complex ret ptr], values|ptr ...
167cdf0e10cSrcweir     sal_uInt32 * pStack = (sal_uInt32 *)__builtin_alloca(
168cdf0e10cSrcweir         sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) );
169cdf0e10cSrcweir     sal_uInt32 * pStackStart = pStack;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     // return
172cdf0e10cSrcweir     typelib_TypeDescription * pReturnTypeDescr = 0;
173cdf0e10cSrcweir     TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
174cdf0e10cSrcweir     OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     if (pReturnTypeDescr)
179cdf0e10cSrcweir     {
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
182cdf0e10cSrcweir         {
183cdf0e10cSrcweir             pCppReturn = pUnoReturn; // direct way for simple types
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir         else
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir             // complex return via ptr
188cdf0e10cSrcweir             pCppReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
189cdf0e10cSrcweir                     ? __builtin_alloca( pReturnTypeDescr->nSize )
190cdf0e10cSrcweir                     : pUnoReturn); // direct way
191cdf0e10cSrcweir 
192cdf0e10cSrcweir //            INSERT_INT32( &pCppReturn, pStack );
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     // push this
196cdf0e10cSrcweir     void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
197cdf0e10cSrcweir         + aVtableSlot.offset;
198cdf0e10cSrcweir     INSERT_INT32( &pAdjustedThisPtr, pStack );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     // stack space
201cdf0e10cSrcweir     OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
202cdf0e10cSrcweir     // args
203cdf0e10cSrcweir     void ** pCppArgs  = (void **)alloca( 3 * sizeof(void *) * nParams );
204cdf0e10cSrcweir     // indizes of values this have to be converted (interface conversion cpp<=>uno)
205cdf0e10cSrcweir     sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
206cdf0e10cSrcweir     // type descriptions for reconversions
207cdf0e10cSrcweir     typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     sal_Int32 nTempIndizes   = 0;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         const typelib_MethodParameter & rParam = pParams[nPos];
214cdf0e10cSrcweir         typelib_TypeDescription * pParamTypeDescr = 0;
215cdf0e10cSrcweir         TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir         if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
218cdf0e10cSrcweir         {
219cdf0e10cSrcweir //            uno_copyAndConvertData( pCppArgs[nPos] = pStack, pUnoArgs[nPos],
220cdf0e10cSrcweir             uno_copyAndConvertData( pCppArgs[nPos] = alloca(8), pUnoArgs[nPos],
221cdf0e10cSrcweir                 pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir             switch (pParamTypeDescr->eTypeClass)
224cdf0e10cSrcweir             {
225cdf0e10cSrcweir             case typelib_TypeClass_HYPER:
226cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_HYPER:
227cdf0e10cSrcweir #ifdef CMC_DEBUG
228cdf0e10cSrcweir 			    fprintf(stderr, "hyper is %lx\n", pCppArgs[nPos]);
229cdf0e10cSrcweir #endif
230cdf0e10cSrcweir                 INSERT_INT64( pCppArgs[nPos], pStack );
231cdf0e10cSrcweir                 break;
232cdf0e10cSrcweir             case typelib_TypeClass_LONG:
233cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_LONG:
234cdf0e10cSrcweir             case typelib_TypeClass_ENUM:
235cdf0e10cSrcweir #ifdef CMC_DEBUG
236cdf0e10cSrcweir 			    fprintf(stderr, "long is %x\n", pCppArgs[nPos]);
237cdf0e10cSrcweir #endif
238cdf0e10cSrcweir                 INSERT_INT32( pCppArgs[nPos], pStack );
239cdf0e10cSrcweir                 break;
240cdf0e10cSrcweir             case typelib_TypeClass_SHORT:
241cdf0e10cSrcweir             case typelib_TypeClass_CHAR:
242cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_SHORT:
243cdf0e10cSrcweir                 INSERT_INT16( pCppArgs[nPos], pStack );
244cdf0e10cSrcweir                 break;
245cdf0e10cSrcweir             case typelib_TypeClass_BOOLEAN:
246cdf0e10cSrcweir             case typelib_TypeClass_BYTE:
247cdf0e10cSrcweir                 INSERT_INT8( pCppArgs[nPos], pStack );
248cdf0e10cSrcweir                 break;
249cdf0e10cSrcweir             case typelib_TypeClass_FLOAT:
250cdf0e10cSrcweir                 INSERT_FLOAT( pCppArgs[nPos], pStack );
251cdf0e10cSrcweir 			    break;
252cdf0e10cSrcweir             case typelib_TypeClass_DOUBLE:
253cdf0e10cSrcweir                 INSERT_DOUBLE( pCppArgs[nPos], pStack );
254cdf0e10cSrcweir                 break;
255cdf0e10cSrcweir             }
256cdf0e10cSrcweir             // no longer needed
257cdf0e10cSrcweir             TYPELIB_DANGER_RELEASE( pParamTypeDescr );
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         else // ptr to complex value | ref
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             if (! rParam.bIn) // is pure out
262cdf0e10cSrcweir             {
263cdf0e10cSrcweir                 // cpp out is constructed mem, uno out is not!
264cdf0e10cSrcweir                 uno_constructData(
265cdf0e10cSrcweir                     pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
266cdf0e10cSrcweir                     pParamTypeDescr );
267cdf0e10cSrcweir                 pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
268cdf0e10cSrcweir                 // will be released at reconversion
269cdf0e10cSrcweir                 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
270cdf0e10cSrcweir             }
271cdf0e10cSrcweir             // is in/inout
272cdf0e10cSrcweir             else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
273cdf0e10cSrcweir             {
274cdf0e10cSrcweir                 uno_copyAndConvertData(
275cdf0e10cSrcweir                     pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
276cdf0e10cSrcweir                     pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir                 pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
279cdf0e10cSrcweir                 // will be released at reconversion
280cdf0e10cSrcweir                 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
281cdf0e10cSrcweir             }
282cdf0e10cSrcweir             else // direct way
283cdf0e10cSrcweir             {
284cdf0e10cSrcweir                 pCppArgs[nPos] = pUnoArgs[nPos];
285cdf0e10cSrcweir                 // no longer needed
286cdf0e10cSrcweir                 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir             INSERT_INT32( &(pCppArgs[nPos]), pStack );
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     try
293cdf0e10cSrcweir     {
294cdf0e10cSrcweir         callVirtualMethod(
295cdf0e10cSrcweir             pAdjustedThisPtr, aVtableSlot.index,
296cdf0e10cSrcweir             pCppReturn, pReturnTypeDescr->eTypeClass,
297cdf0e10cSrcweir             pStackStart,
298cdf0e10cSrcweir             (pStack - pStackStart));
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         // NO exception occured...
301cdf0e10cSrcweir         *ppUnoExc = 0;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir         // reconvert temporary params
304cdf0e10cSrcweir         for ( ; nTempIndizes--; )
305cdf0e10cSrcweir         {
306cdf0e10cSrcweir             sal_Int32 nIndex = pTempIndizes[nTempIndizes];
307cdf0e10cSrcweir             typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
308cdf0e10cSrcweir 
309cdf0e10cSrcweir             if (pParams[nIndex].bIn)
310cdf0e10cSrcweir             {
311cdf0e10cSrcweir                 if (pParams[nIndex].bOut) // inout
312cdf0e10cSrcweir                 {
313cdf0e10cSrcweir                     uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
314cdf0e10cSrcweir                     uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
315cdf0e10cSrcweir                                             pThis->getBridge()->getCpp2Uno() );
316cdf0e10cSrcweir                 }
317cdf0e10cSrcweir             }
318cdf0e10cSrcweir             else // pure out
319cdf0e10cSrcweir             {
320cdf0e10cSrcweir                 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
321cdf0e10cSrcweir                                         pThis->getBridge()->getCpp2Uno() );
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir             // destroy temp cpp param => cpp: every param was constructed
324cdf0e10cSrcweir             uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
325cdf0e10cSrcweir 
326cdf0e10cSrcweir             TYPELIB_DANGER_RELEASE( pParamTypeDescr );
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir         // return value
329cdf0e10cSrcweir         if (pCppReturn && pUnoReturn != pCppReturn)
330cdf0e10cSrcweir         {
331cdf0e10cSrcweir             uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
332cdf0e10cSrcweir                                     pThis->getBridge()->getCpp2Uno() );
333cdf0e10cSrcweir             uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir     catch (...)
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         // fill uno exception
339cdf0e10cSrcweir         fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         // temporary params
342cdf0e10cSrcweir         for ( ; nTempIndizes--; )
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             sal_Int32 nIndex = pTempIndizes[nTempIndizes];
345cdf0e10cSrcweir             // destroy temp cpp param => cpp: every param was constructed
346cdf0e10cSrcweir             uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
347cdf0e10cSrcweir             TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir         // return type
351cdf0e10cSrcweir         if (pReturnTypeDescr)
352cdf0e10cSrcweir             TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir }
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
358cdf0e10cSrcweir 
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)359cdf0e10cSrcweir void unoInterfaceProxyDispatch(
360cdf0e10cSrcweir     uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
361cdf0e10cSrcweir     void * pReturn, void * pArgs[], uno_Any ** ppException )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     // is my surrogate
364cdf0e10cSrcweir     bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
365cdf0e10cSrcweir           = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
366cdf0e10cSrcweir     typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     switch (pMemberDescr->eTypeClass)
369cdf0e10cSrcweir     {
370cdf0e10cSrcweir     case typelib_TypeClass_INTERFACE_ATTRIBUTE:
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         // determine vtable call index
373cdf0e10cSrcweir         sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
374cdf0e10cSrcweir         OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         VtableSlot aVtableSlot(
377cdf0e10cSrcweir             getVtableSlot(
378cdf0e10cSrcweir             reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>
379cdf0e10cSrcweir               (pMemberDescr)));
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         if (pReturn)
382cdf0e10cSrcweir         {
383cdf0e10cSrcweir             // dependent dispatch
384cdf0e10cSrcweir             cpp_call(
385cdf0e10cSrcweir                 pThis, aVtableSlot,
386cdf0e10cSrcweir                 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
387cdf0e10cSrcweir                 0, 0, // no params
388cdf0e10cSrcweir                 pReturn, pArgs, ppException );
389cdf0e10cSrcweir         }
390cdf0e10cSrcweir         else
391cdf0e10cSrcweir         {
392cdf0e10cSrcweir             // is SET
393cdf0e10cSrcweir             typelib_MethodParameter aParam;
394cdf0e10cSrcweir             aParam.pTypeRef =
395cdf0e10cSrcweir                 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
396cdf0e10cSrcweir             aParam.bIn      = sal_True;
397cdf0e10cSrcweir             aParam.bOut     = sal_False;
398cdf0e10cSrcweir 
399cdf0e10cSrcweir             typelib_TypeDescriptionReference * pReturnTypeRef = 0;
400cdf0e10cSrcweir             OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
401cdf0e10cSrcweir             typelib_typedescriptionreference_new(
402cdf0e10cSrcweir                 &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
403cdf0e10cSrcweir 
404cdf0e10cSrcweir             // dependent dispatch
405cdf0e10cSrcweir             aVtableSlot.index += 1;
406cdf0e10cSrcweir             cpp_call(
407cdf0e10cSrcweir                 pThis, aVtableSlot, // get, then set method
408cdf0e10cSrcweir                 pReturnTypeRef,
409cdf0e10cSrcweir                 1, &aParam,
410cdf0e10cSrcweir                 pReturn, pArgs, ppException );
411cdf0e10cSrcweir 
412cdf0e10cSrcweir             typelib_typedescriptionreference_release( pReturnTypeRef );
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir         break;
416cdf0e10cSrcweir     }
417cdf0e10cSrcweir     case typelib_TypeClass_INTERFACE_METHOD:
418cdf0e10cSrcweir     {
419cdf0e10cSrcweir         // determine vtable call index
420cdf0e10cSrcweir         sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
421cdf0e10cSrcweir         OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         VtableSlot aVtableSlot(
424cdf0e10cSrcweir             getVtableSlot(
425cdf0e10cSrcweir             reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>
426cdf0e10cSrcweir               (pMemberDescr)));
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         switch (aVtableSlot.index)
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             // standard calls
431cdf0e10cSrcweir         case 1: // acquire uno interface
432cdf0e10cSrcweir             (*pUnoI->acquire)( pUnoI );
433cdf0e10cSrcweir             *ppException = 0;
434cdf0e10cSrcweir             break;
435cdf0e10cSrcweir         case 2: // release uno interface
436cdf0e10cSrcweir             (*pUnoI->release)( pUnoI );
437cdf0e10cSrcweir             *ppException = 0;
438cdf0e10cSrcweir             break;
439cdf0e10cSrcweir         case 0: // queryInterface() opt
440cdf0e10cSrcweir         {
441cdf0e10cSrcweir             typelib_TypeDescription * pTD = 0;
442cdf0e10cSrcweir             TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
443cdf0e10cSrcweir             if (pTD)
444cdf0e10cSrcweir             {
445cdf0e10cSrcweir                 uno_Interface * pInterface = 0;
446cdf0e10cSrcweir                 (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
447cdf0e10cSrcweir                     pThis->getBridge()->getUnoEnv(),
448cdf0e10cSrcweir                     (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir                 if (pInterface)
451cdf0e10cSrcweir                 {
452cdf0e10cSrcweir                     ::uno_any_construct(
453cdf0e10cSrcweir                         reinterpret_cast< uno_Any * >( pReturn ),
454cdf0e10cSrcweir                         &pInterface, pTD, 0 );
455cdf0e10cSrcweir                     (*pInterface->release)( pInterface );
456cdf0e10cSrcweir                     TYPELIB_DANGER_RELEASE( pTD );
457cdf0e10cSrcweir                     *ppException = 0;
458cdf0e10cSrcweir                     break;
459cdf0e10cSrcweir                 }
460cdf0e10cSrcweir                 TYPELIB_DANGER_RELEASE( pTD );
461cdf0e10cSrcweir             }
462cdf0e10cSrcweir         } // else perform queryInterface()
463cdf0e10cSrcweir         default:
464cdf0e10cSrcweir             // dependent dispatch
465cdf0e10cSrcweir             cpp_call(
466cdf0e10cSrcweir                 pThis, aVtableSlot,
467cdf0e10cSrcweir                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
468cdf0e10cSrcweir                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
469cdf0e10cSrcweir                 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
470cdf0e10cSrcweir                 pReturn, pArgs, ppException );
471cdf0e10cSrcweir         }
472cdf0e10cSrcweir         break;
473cdf0e10cSrcweir     }
474cdf0e10cSrcweir     default:
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         ::com::sun::star::uno::RuntimeException aExc(
477cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
478cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
479cdf0e10cSrcweir 
480cdf0e10cSrcweir         Type const & rExcType = ::getCppuType( &aExc );
481cdf0e10cSrcweir         // binary identical null reference
482cdf0e10cSrcweir         ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
483cdf0e10cSrcweir     }
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir } } }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
490