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
10cdf0e10cSrcweir *
1161dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
2061dff127SAndrew Rist *************************************************************/
2161dff127SAndrew Rist
2261dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir
27baf6650dSPedro Giffuni #include <typeinfo>
28baf6650dSPedro Giffuni #include <exception>
29baf6650dSPedro Giffuni #include <cstddef>
30baf6650dSPedro Giffuni #include <cxxabi.h>
31cdf0e10cSrcweir #include <stdlib.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
34cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
35cdf0e10cSrcweir #include <uno/data.h>
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
38cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
39cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
40cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtables.hxx"
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include "share.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace ::rtl;
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46baf6650dSPedro Giffuni #ifdef __GLIBCXX__
47*fe740d6fSTijl Coosemans using CPPU_CURRENT_NAMESPACE::__cxa_exception;
48baf6650dSPedro Giffuni using CPPU_CURRENT_NAMESPACE::__cxa_get_globals;
49baf6650dSPedro Giffuni #else
50*fe740d6fSTijl Coosemans using __cxxabiv1::__cxa_exception;
51*fe740d6fSTijl Coosemans using __cxxabiv1::__cxa_current_primary_exception;
52*fe740d6fSTijl Coosemans using __cxxabiv1::__cxa_decrement_exception_refcount;
53baf6650dSPedro Giffuni #endif
54cdf0e10cSrcweir
55cdf0e10cSrcweir namespace
56cdf0e10cSrcweir {
57cdf0e10cSrcweir
58cdf0e10cSrcweir //==================================================================================================
59cdf0e10cSrcweir // The call instruction within the asm section of callVirtualMethod may throw
60cdf0e10cSrcweir // exceptions. So that the compiler handles this correctly, it is important
61cdf0e10cSrcweir // that (a) callVirtualMethod might call dummy_can_throw_anything (although this
62cdf0e10cSrcweir // never happens at runtime), which in turn can throw exceptions, and (b)
63cdf0e10cSrcweir // callVirtualMethod is not inlined at its call site (so that any exceptions are
64cdf0e10cSrcweir // caught which are thrown from the instruction calling callVirtualMethod):
65cdf0e10cSrcweir void callVirtualMethod(
66cdf0e10cSrcweir void * pAdjustedThisPtr,
67cdf0e10cSrcweir sal_Int32 nVtableIndex,
68cdf0e10cSrcweir void * pRegisterReturn,
69cdf0e10cSrcweir typelib_TypeClass eReturnType,
70cdf0e10cSrcweir sal_Int32 * pStackLongs,
71cdf0e10cSrcweir sal_Int32 nStackLongs ) __attribute__((noinline));
72cdf0e10cSrcweir
callVirtualMethod(void * pAdjustedThisPtr,sal_Int32 nVtableIndex,void * pRegisterReturn,typelib_TypeClass eReturnType,sal_Int32 * pStackLongs,sal_Int32 nStackLongs)73cdf0e10cSrcweir void callVirtualMethod(
74cdf0e10cSrcweir void * pAdjustedThisPtr,
75cdf0e10cSrcweir sal_Int32 nVtableIndex,
76cdf0e10cSrcweir void * pRegisterReturn,
77cdf0e10cSrcweir typelib_TypeClass eReturnType,
78cdf0e10cSrcweir sal_Int32 * pStackLongs,
79cdf0e10cSrcweir sal_Int32 nStackLongs )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir // parameter list is mixed list of * and values
82cdf0e10cSrcweir // reference parameters are pointers
83cdf0e10cSrcweir
84cdf0e10cSrcweir OSL_ENSURE( pStackLongs && pAdjustedThisPtr, "### null ptr!" );
85cdf0e10cSrcweir OSL_ENSURE( (sizeof(void *) == 4) && (sizeof(sal_Int32) == 4), "### unexpected size of int!" );
86cdf0e10cSrcweir OSL_ENSURE( nStackLongs && pStackLongs, "### no stack in callVirtualMethod !" );
87cdf0e10cSrcweir
88cdf0e10cSrcweir // never called
89cdf0e10cSrcweir if (! pAdjustedThisPtr) CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
90cdf0e10cSrcweir
91cdf0e10cSrcweir volatile long edx = 0, eax = 0; // for register returns
92cdf0e10cSrcweir void * stackptr;
93cdf0e10cSrcweir asm volatile (
94cdf0e10cSrcweir "mov %%esp, %6\n\t"
95047744ddSPedro Giffuni // preserve potential 128bit stack alignment
96047744ddSPedro Giffuni "and $0xfffffff0, %%esp\n\t"
97047744ddSPedro Giffuni "mov %0, %%eax\n\t"
98047744ddSPedro Giffuni "lea -4(,%%eax,4), %%eax\n\t"
99047744ddSPedro Giffuni "and $0xf, %%eax\n\t"
100047744ddSPedro Giffuni "sub $0xc, %%eax\n\t"
101047744ddSPedro Giffuni "add %%eax, %%esp\n\t"
102cdf0e10cSrcweir // copy values
103cdf0e10cSrcweir "mov %0, %%eax\n\t"
104cdf0e10cSrcweir "mov %%eax, %%edx\n\t"
105cdf0e10cSrcweir "dec %%edx\n\t"
106cdf0e10cSrcweir "shl $2, %%edx\n\t"
107cdf0e10cSrcweir "add %1, %%edx\n"
108cdf0e10cSrcweir "Lcopy:\n\t"
109cdf0e10cSrcweir "pushl 0(%%edx)\n\t"
110cdf0e10cSrcweir "sub $4, %%edx\n\t"
111cdf0e10cSrcweir "dec %%eax\n\t"
112cdf0e10cSrcweir "jne Lcopy\n\t"
113cdf0e10cSrcweir // do the actual call
114cdf0e10cSrcweir "mov %2, %%edx\n\t"
115cdf0e10cSrcweir "mov 0(%%edx), %%edx\n\t"
116cdf0e10cSrcweir "mov %3, %%eax\n\t"
117cdf0e10cSrcweir "shl $2, %%eax\n\t"
118cdf0e10cSrcweir "add %%eax, %%edx\n\t"
119cdf0e10cSrcweir "mov 0(%%edx), %%edx\n\t"
120cdf0e10cSrcweir "call *%%edx\n\t"
121cdf0e10cSrcweir // save return registers
122cdf0e10cSrcweir "mov %%eax, %4\n\t"
123cdf0e10cSrcweir "mov %%edx, %5\n\t"
124cdf0e10cSrcweir // cleanup stack
125cdf0e10cSrcweir "mov %6, %%esp\n\t"
126cdf0e10cSrcweir :
127cdf0e10cSrcweir : "m"(nStackLongs), "m"(pStackLongs), "m"(pAdjustedThisPtr),
128cdf0e10cSrcweir "m"(nVtableIndex), "m"(eax), "m"(edx), "m"(stackptr)
129cdf0e10cSrcweir : "eax", "edx" );
130cdf0e10cSrcweir switch( eReturnType )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir case typelib_TypeClass_HYPER:
133cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
134cdf0e10cSrcweir ((long*)pRegisterReturn)[1] = edx;
135cdf0e10cSrcweir case typelib_TypeClass_LONG:
136cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
137cdf0e10cSrcweir case typelib_TypeClass_CHAR:
138cdf0e10cSrcweir case typelib_TypeClass_ENUM:
139cdf0e10cSrcweir ((long*)pRegisterReturn)[0] = eax;
140cdf0e10cSrcweir break;
141cdf0e10cSrcweir case typelib_TypeClass_SHORT:
142cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
143cdf0e10cSrcweir *(unsigned short*)pRegisterReturn = eax;
144cdf0e10cSrcweir break;
145cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
146cdf0e10cSrcweir case typelib_TypeClass_BYTE:
147cdf0e10cSrcweir *(unsigned char*)pRegisterReturn = eax;
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
150cdf0e10cSrcweir asm ( "fstps %0" : : "m"(*(char *)pRegisterReturn) );
151cdf0e10cSrcweir break;
152cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
153cdf0e10cSrcweir asm ( "fstpl %0\n\t" : : "m"(*(char *)pRegisterReturn) );
154cdf0e10cSrcweir break;
155cdf0e10cSrcweir default:
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir //==================================================================================================
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)161cdf0e10cSrcweir static void cpp_call(
162cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
163cdf0e10cSrcweir bridges::cpp_uno::shared::VtableSlot aVtableSlot,
164cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef,
165cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
166cdf0e10cSrcweir void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir // max space for: [complex ret ptr], values|ptr ...
169cdf0e10cSrcweir char * pCppStack =
170cdf0e10cSrcweir (char *)alloca( sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) );
171cdf0e10cSrcweir char * pCppStackStart = pCppStack;
172cdf0e10cSrcweir
173cdf0e10cSrcweir // return
174cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
175cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
176cdf0e10cSrcweir OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
177cdf0e10cSrcweir
178cdf0e10cSrcweir void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
179cdf0e10cSrcweir
180cdf0e10cSrcweir if (pReturnTypeDescr)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
183cdf0e10cSrcweir {
184cdf0e10cSrcweir pCppReturn = pUnoReturn; // direct way for simple types
185cdf0e10cSrcweir }
186cdf0e10cSrcweir else
187cdf0e10cSrcweir {
188cdf0e10cSrcweir // complex return via ptr
189cdf0e10cSrcweir pCppReturn = *(void **)pCppStack
190cdf0e10cSrcweir = (bridges::cpp_uno::shared::relatesToInterfaceType(
191cdf0e10cSrcweir pReturnTypeDescr )
192cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
193cdf0e10cSrcweir : pUnoReturn); // direct way
194cdf0e10cSrcweir pCppStack += sizeof(void *);
195cdf0e10cSrcweir }
196cdf0e10cSrcweir }
197cdf0e10cSrcweir // push this
198cdf0e10cSrcweir void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
199cdf0e10cSrcweir + aVtableSlot.offset;
200cdf0e10cSrcweir *(void**)pCppStack = pAdjustedThisPtr;
201cdf0e10cSrcweir pCppStack += sizeof( void* );
202cdf0e10cSrcweir
203cdf0e10cSrcweir // stack space
204cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
205cdf0e10cSrcweir // args
206cdf0e10cSrcweir void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
207cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion cpp<=>uno)
208cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
209cdf0e10cSrcweir // type descriptions for reconversions
210cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
211cdf0e10cSrcweir
212cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
213cdf0e10cSrcweir
214cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
217cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
218cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
219cdf0e10cSrcweir
220cdf0e10cSrcweir if (!rParam.bOut
221cdf0e10cSrcweir && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
222cdf0e10cSrcweir {
223cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nPos] = pCppStack, pUnoArgs[nPos], pParamTypeDescr,
224cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
225cdf0e10cSrcweir
226cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
227cdf0e10cSrcweir {
228cdf0e10cSrcweir case typelib_TypeClass_HYPER:
229cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
230cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
231cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // extra long
232cdf0e10cSrcweir break;
233cdf0e10cSrcweir default:
234cdf0e10cSrcweir break;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir // no longer needed
237cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir else // ptr to complex value | ref
240cdf0e10cSrcweir {
241cdf0e10cSrcweir if (! rParam.bIn) // is pure out
242cdf0e10cSrcweir {
243cdf0e10cSrcweir // cpp out is constructed mem, uno out is not!
244cdf0e10cSrcweir uno_constructData(
245cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
246cdf0e10cSrcweir pParamTypeDescr );
247cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
248cdf0e10cSrcweir // will be released at reconversion
249cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir // is in/inout
252cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType(
253cdf0e10cSrcweir pParamTypeDescr ))
254cdf0e10cSrcweir {
255cdf0e10cSrcweir uno_copyAndConvertData(
256cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
257cdf0e10cSrcweir pUnoArgs[nPos], pParamTypeDescr,
258cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
259cdf0e10cSrcweir
260cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
261cdf0e10cSrcweir // will be released at reconversion
262cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir else // direct way
265cdf0e10cSrcweir {
266cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = pUnoArgs[nPos];
267cdf0e10cSrcweir // no longer needed
268cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
269cdf0e10cSrcweir }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // standard parameter length
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274cdf0e10cSrcweir try
275cdf0e10cSrcweir {
276cdf0e10cSrcweir OSL_ENSURE( !( (pCppStack - pCppStackStart ) & 3), "UNALIGNED STACK !!! (Please DO panic)" );
277cdf0e10cSrcweir callVirtualMethod(
278cdf0e10cSrcweir pAdjustedThisPtr, aVtableSlot.index,
279cdf0e10cSrcweir pCppReturn, pReturnTypeDescr->eTypeClass,
280cdf0e10cSrcweir (sal_Int32 *)pCppStackStart, (pCppStack - pCppStackStart) / sizeof(sal_Int32) );
28107a3d7f1SPedro Giffuni // NO exception occurred...
282cdf0e10cSrcweir *ppUnoExc = 0;
283cdf0e10cSrcweir
284cdf0e10cSrcweir // reconvert temporary params
285cdf0e10cSrcweir for ( ; nTempIndizes--; )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
288cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
289cdf0e10cSrcweir
290cdf0e10cSrcweir if (pParams[nIndex].bIn)
291cdf0e10cSrcweir {
292cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout
293cdf0e10cSrcweir {
294cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
295cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
296cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir }
299cdf0e10cSrcweir else // pure out
300cdf0e10cSrcweir {
301cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
302cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
305cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
306cdf0e10cSrcweir
307cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
308cdf0e10cSrcweir }
309cdf0e10cSrcweir // return value
310cdf0e10cSrcweir if (pCppReturn && pUnoReturn != pCppReturn)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
313cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
314cdf0e10cSrcweir uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
315cdf0e10cSrcweir }
316cdf0e10cSrcweir }
317cdf0e10cSrcweir catch (...)
318cdf0e10cSrcweir {
319*fe740d6fSTijl Coosemans __cxa_exception *header;
320*fe740d6fSTijl Coosemans #ifdef __GLIBCXX__
321*fe740d6fSTijl Coosemans header = __cxa_get_globals()->caughtExceptions;
322*fe740d6fSTijl Coosemans #else
323*fe740d6fSTijl Coosemans header = reinterpret_cast<__cxa_exception *>( __cxa_current_primary_exception() );
324*fe740d6fSTijl Coosemans if (header) {
325*fe740d6fSTijl Coosemans __cxa_decrement_exception_refcount( header );
326*fe740d6fSTijl Coosemans header--;
327*fe740d6fSTijl Coosemans uint64_t exc_class = header->unwindHeader.exception_class
328*fe740d6fSTijl Coosemans & 0xffffffffffffff00;
329*fe740d6fSTijl Coosemans if (exc_class != /* "GNUCC++" */ 0x474e5543432b2b00) {
330*fe740d6fSTijl Coosemans // _Unwind_Exception was made __aligned__ which
331*fe740d6fSTijl Coosemans // increased its size by 12 bytes.
332*fe740d6fSTijl Coosemans header = reinterpret_cast<__cxa_exception *>(
333*fe740d6fSTijl Coosemans reinterpret_cast<char *>( header ) - 12 );
334*fe740d6fSTijl Coosemans exc_class = header->unwindHeader.exception_class
335*fe740d6fSTijl Coosemans & 0xffffffffffffff00;
336*fe740d6fSTijl Coosemans if (exc_class != /* "GNUCC++" */ 0x474e5543432b2b00) {
337*fe740d6fSTijl Coosemans header = nullptr;
338*fe740d6fSTijl Coosemans }
339*fe740d6fSTijl Coosemans }
340*fe740d6fSTijl Coosemans }
341*fe740d6fSTijl Coosemans #endif
342cdf0e10cSrcweir // fill uno exception
343*fe740d6fSTijl Coosemans CPPU_CURRENT_NAMESPACE::fillUnoException( header, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
344cdf0e10cSrcweir
345cdf0e10cSrcweir // temporary params
346cdf0e10cSrcweir for ( ; nTempIndizes--; )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
349cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
350cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
351cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
352cdf0e10cSrcweir }
353cdf0e10cSrcweir // return type
354cdf0e10cSrcweir if (pReturnTypeDescr)
355cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
356cdf0e10cSrcweir }
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir }
360cdf0e10cSrcweir
361cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
362cdf0e10cSrcweir
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)363cdf0e10cSrcweir void unoInterfaceProxyDispatch(
364cdf0e10cSrcweir uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
365cdf0e10cSrcweir void * pReturn, void * pArgs[], uno_Any ** ppException )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir // is my surrogate
368cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
369cdf0e10cSrcweir = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
370cdf0e10cSrcweir
371cdf0e10cSrcweir switch (pMemberDescr->eTypeClass)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
374cdf0e10cSrcweir {
375cdf0e10cSrcweir VtableSlot aVtableSlot(
376cdf0e10cSrcweir getVtableSlot(
377cdf0e10cSrcweir reinterpret_cast<
378cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription const * >(
379cdf0e10cSrcweir pMemberDescr)));
380cdf0e10cSrcweir if (pReturn)
381cdf0e10cSrcweir {
382cdf0e10cSrcweir // dependent dispatch
383cdf0e10cSrcweir cpp_call(
384cdf0e10cSrcweir pThis, aVtableSlot,
385cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
386cdf0e10cSrcweir 0, 0, // no params
387cdf0e10cSrcweir pReturn, pArgs, ppException );
388cdf0e10cSrcweir }
389cdf0e10cSrcweir else
390cdf0e10cSrcweir {
391cdf0e10cSrcweir // is SET
392cdf0e10cSrcweir typelib_MethodParameter aParam;
393cdf0e10cSrcweir aParam.pTypeRef =
394cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
395cdf0e10cSrcweir aParam.bIn = sal_True;
396cdf0e10cSrcweir aParam.bOut = sal_False;
397cdf0e10cSrcweir
398cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef = 0;
399cdf0e10cSrcweir OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
400cdf0e10cSrcweir typelib_typedescriptionreference_new(
401cdf0e10cSrcweir &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
402cdf0e10cSrcweir
403cdf0e10cSrcweir // dependent dispatch
404cdf0e10cSrcweir aVtableSlot.index += 1; // get, then set method
405cdf0e10cSrcweir cpp_call(
406cdf0e10cSrcweir pThis, aVtableSlot,
407cdf0e10cSrcweir pReturnTypeRef,
408cdf0e10cSrcweir 1, &aParam,
409cdf0e10cSrcweir pReturn, pArgs, ppException );
410cdf0e10cSrcweir
411cdf0e10cSrcweir typelib_typedescriptionreference_release( pReturnTypeRef );
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir break;
415cdf0e10cSrcweir }
416cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
417cdf0e10cSrcweir {
418cdf0e10cSrcweir VtableSlot aVtableSlot(
419cdf0e10cSrcweir getVtableSlot(
420cdf0e10cSrcweir reinterpret_cast<
421cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription const * >(
422cdf0e10cSrcweir pMemberDescr)));
423cdf0e10cSrcweir switch (aVtableSlot.index)
424cdf0e10cSrcweir {
425cdf0e10cSrcweir // standard calls
426cdf0e10cSrcweir case 1: // acquire uno interface
427cdf0e10cSrcweir (*pUnoI->acquire)( pUnoI );
428cdf0e10cSrcweir *ppException = 0;
429cdf0e10cSrcweir break;
430cdf0e10cSrcweir case 2: // release uno interface
431cdf0e10cSrcweir (*pUnoI->release)( pUnoI );
432cdf0e10cSrcweir *ppException = 0;
433cdf0e10cSrcweir break;
434cdf0e10cSrcweir case 0: // queryInterface() opt
435cdf0e10cSrcweir {
436cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
437cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
438cdf0e10cSrcweir if (pTD)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir uno_Interface * pInterface = 0;
441cdf0e10cSrcweir (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
442cdf0e10cSrcweir pThis->pBridge->getUnoEnv(),
443cdf0e10cSrcweir (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
444cdf0e10cSrcweir
445cdf0e10cSrcweir if (pInterface)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir ::uno_any_construct(
448cdf0e10cSrcweir reinterpret_cast< uno_Any * >( pReturn ),
449cdf0e10cSrcweir &pInterface, pTD, 0 );
450cdf0e10cSrcweir (*pInterface->release)( pInterface );
451cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
452cdf0e10cSrcweir *ppException = 0;
453cdf0e10cSrcweir break;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
456cdf0e10cSrcweir }
457cdf0e10cSrcweir } // else perform queryInterface()
458cdf0e10cSrcweir default:
459cdf0e10cSrcweir // dependent dispatch
460cdf0e10cSrcweir cpp_call(
461cdf0e10cSrcweir pThis, aVtableSlot,
462cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
463cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
464cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
465cdf0e10cSrcweir pReturn, pArgs, ppException );
466cdf0e10cSrcweir }
467cdf0e10cSrcweir break;
468cdf0e10cSrcweir }
469cdf0e10cSrcweir default:
470cdf0e10cSrcweir {
471cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException aExc(
472cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
473cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
474cdf0e10cSrcweir
475cdf0e10cSrcweir Type const & rExcType = ::getCppuType( &aExc );
476cdf0e10cSrcweir // binary identical null reference
477cdf0e10cSrcweir ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
478cdf0e10cSrcweir }
479cdf0e10cSrcweir }
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
482cdf0e10cSrcweir } } }
483