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