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