Update ooo320-m1
[ooovba.git] / bridges / source / cpp_uno / cc50_solaris_sparc / uno2cpp.cxx
blobca5512feaa8c004fa3a530291bca12ba893427fe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: uno2cpp.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
34 #include <sal/alloca.h>
36 #include <com/sun/star/uno/genfunc.hxx>
37 #include "com/sun/star/uno/RuntimeException.hpp"
38 #include <uno/data.h>
40 #include "bridges/cpp_uno/shared/bridge.hxx"
41 #include "bridges/cpp_uno/shared/types.hxx"
42 #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
43 #include "bridges/cpp_uno/shared/vtables.hxx"
45 #include "cc50_solaris_sparc.hxx"
47 using namespace rtl;
48 using namespace com::sun::star::uno;
50 namespace
53 extern "C" void callVirtualMethod(
54 void * pAdjustedThisPtr,
55 sal_Int32 nVtableIndex,
56 void * pRegisterReturn,
57 typelib_TypeClass eReturnType,
58 sal_Int32 * pStackLongs,
59 sal_Int32 nStackLongs
62 //==================================================================================================
63 static void cpp_call(
64 bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
65 bridges::cpp_uno::shared::VtableSlot aVtableSlot,
66 typelib_TypeDescriptionReference * pReturnTypeRef,
67 sal_Int32 nParams, typelib_MethodParameter * pParams,
68 void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
70 // pCppI is cc50_solaris_sparc this pointer
71 OSL_ENSURE( pThis, "### no interface given!" );
73 // max space for: [complex ret ptr], values|ptr ...
74 char * pCppStack = (char *)alloca( ((nParams+3) * sizeof(sal_Int64)) );
75 char * pCppStackStart = pCppStack;
77 // return
78 typelib_TypeDescription * pReturnTypeDescr = 0;
79 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
80 OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
82 void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
84 if (pReturnTypeDescr)
86 if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
88 pCppReturn = pUnoReturn; // direct way for simple types
90 else
92 // complex return via ptr
93 pCppReturn = *(void **)pCppStack
94 = (bridges::cpp_uno::shared::relatesToInterfaceType(
95 pReturnTypeDescr )
96 ? alloca( pReturnTypeDescr->nSize )
97 : pUnoReturn); // direct way
98 pCppStack += sizeof(void *);
101 // push this
102 void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
103 + aVtableSlot.offset;
104 *(void**)pCppStack = pAdjustedThisPtr;
105 pCppStack += sizeof( void* );
107 // args
108 void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
109 // indizes of values this have to be converted (interface conversion cpp<=>uno)
110 sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
111 // type descriptions for reconversions
112 typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
114 sal_Int32 nTempIndizes = 0;
116 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
118 const typelib_MethodParameter & rParam = pParams[nPos];
119 typelib_TypeDescription * pParamTypeDescr = 0;
120 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
122 if (!rParam.bOut
123 && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
125 pCppArgs[ nPos ] = CPPU_CURRENT_NAMESPACE::adjustPointer(
126 pCppStack, pParamTypeDescr );
127 uno_copyAndConvertData( pCppArgs[nPos], pUnoArgs[nPos], pParamTypeDescr,
128 pThis->getBridge()->getUno2Cpp() );
130 switch (pParamTypeDescr->eTypeClass)
132 case typelib_TypeClass_HYPER:
133 case typelib_TypeClass_UNSIGNED_HYPER:
134 case typelib_TypeClass_DOUBLE:
135 pCppStack += sizeof(sal_Int32); // extra long
137 // no longer needed
138 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
140 else // ptr to complex value | ref
142 if (! rParam.bIn) // is pure out
144 // cpp out is constructed mem, uno out is not!
145 uno_constructData(
146 *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
147 pParamTypeDescr );
148 pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
149 // will be released at reconversion
150 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
152 // is in/inout
153 else if (bridges::cpp_uno::shared::relatesToInterfaceType(
154 pParamTypeDescr ))
156 uno_copyAndConvertData(
157 *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
158 pUnoArgs[nPos], pParamTypeDescr,
159 pThis->getBridge()->getUno2Cpp() );
161 pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
162 // will be released at reconversion
163 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
165 else // direct way
167 *(void **)pCppStack = pCppArgs[nPos] = pUnoArgs[nPos];
168 // no longer needed
169 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
172 pCppStack += sizeof(sal_Int32); // standard parameter length
175 // seems that EH registration for callVirtualMethod is not really
176 // necessary
178 // static unsigned long* pFrameInfo = NULL;
180 // if( ! pFrameInfo )
181 // {
182 // pFrameInfo = new unsigned long[ 7 ];
183 // pFrameInfo[ 0 ] = 0x40000000 | (((unsigned long)__Crun::ex_rethrow_q) >> 2);
184 // pFrameInfo[ 1 ] = 0x01000000;
185 // pFrameInfo[ 2 ] = (unsigned long)callVirtualMethodExceptionHandler;
186 // pFrameInfo[ 3 ] = 0;
187 // pFrameInfo[ 4 ] = (unsigned long)pFrameInfo - (unsigned long)callVirtualMethodExceptionHandler;
188 // pFrameInfo[ 5 ] = 0;
189 // pFrameInfo[ 6 ] = 0;
190 // _ex_register( pFrameInfo+2, 1 );
191 // }
195 int nStackLongs = (pCppStack - pCppStackStart)/sizeof(sal_Int32);
196 if( nStackLongs & 1 )
197 // stack has to be 8 byte aligned
198 nStackLongs++;
200 callVirtualMethod(
201 pAdjustedThisPtr,
202 aVtableSlot.index,
203 pCppReturn,
204 pReturnTypeDescr->eTypeClass,
205 (sal_Int32 *)pCppStackStart,
206 nStackLongs
209 // NO exception occured...
210 *ppUnoExc = 0;
212 // reconvert temporary params
213 for ( ; nTempIndizes--; )
215 sal_Int32 nIndex = pTempIndizes[nTempIndizes];
216 typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
218 if (pParams[nIndex].bIn)
220 if (pParams[nIndex].bOut) // inout
222 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
223 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
224 pThis->getBridge()->getCpp2Uno() );
227 else // pure out
229 uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
230 pThis->getBridge()->getCpp2Uno() );
232 // destroy temp cpp param => cpp: every param was constructed
233 uno_destructData(
234 pCppArgs[nIndex], pParamTypeDescr,
235 reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
237 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
239 // return value
240 if (pCppReturn && pUnoReturn != pCppReturn)
242 uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
243 pThis->getBridge()->getCpp2Uno() );
244 uno_destructData(
245 pCppReturn, pReturnTypeDescr,
246 reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
249 catch( ... )
251 void* pExc = __Crun::ex_get();
252 const char* pName = __Cimpl::ex_name();
254 // get exception
255 CPPU_CURRENT_NAMESPACE::cc50_solaris_sparc_fillUnoException(
256 pExc, pName, *ppUnoExc, pThis->getBridge()->getCpp2Uno());
258 // temporary params
259 for ( ; nTempIndizes--; )
261 sal_Int32 nIndex = pTempIndizes[nTempIndizes];
262 // destroy temp cpp param => cpp: every param was constructed
263 uno_destructData(
264 pCppArgs[nIndex],
265 ppTempParamTypeDescr[nTempIndizes],
266 reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
267 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
269 // return type
270 if (pReturnTypeDescr)
271 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
277 namespace bridges { namespace cpp_uno { namespace shared {
279 void unoInterfaceProxyDispatch(
280 uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
281 void * pReturn, void * pArgs[], uno_Any ** ppException )
283 // is my surrogate
284 bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
285 = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
286 typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
288 switch (pMemberDescr->eTypeClass)
290 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
292 VtableSlot aVtableSlot(
293 getVtableSlot(
294 reinterpret_cast<
295 typelib_InterfaceAttributeTypeDescription const * >(
296 pMemberDescr)));
297 if (pReturn)
299 // dependent dispatch
300 cpp_call(
301 pThis, aVtableSlot,
302 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
303 0, 0, // no params
304 pReturn, pArgs, ppException );
306 else
308 // is SET
309 typelib_MethodParameter aParam;
310 aParam.pTypeRef =
311 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
312 aParam.bIn = sal_True;
313 aParam.bOut = sal_False;
315 typelib_TypeDescriptionReference * pReturnTypeRef = 0;
316 OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
317 typelib_typedescriptionreference_new(
318 &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
320 // dependent dispatch
321 aVtableSlot.index += 1; // get, then set method
322 cpp_call(
323 pThis, aVtableSlot,
324 pReturnTypeRef,
325 1, &aParam,
326 pReturn, pArgs, ppException );
328 typelib_typedescriptionreference_release( pReturnTypeRef );
331 break;
333 case typelib_TypeClass_INTERFACE_METHOD:
335 VtableSlot aVtableSlot(
336 getVtableSlot(
337 reinterpret_cast<
338 typelib_InterfaceMethodTypeDescription const * >(
339 pMemberDescr)));
340 switch (aVtableSlot.index)
342 // standard calls
343 case 1: // acquire uno interface
344 (*pUnoI->acquire)( pUnoI );
345 *ppException = 0;
346 break;
347 case 2: // release uno interface
348 (*pUnoI->release)( pUnoI );
349 *ppException = 0;
350 break;
351 case 0: // queryInterface() opt
353 typelib_TypeDescription * pTD = 0;
354 TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
355 if (pTD)
357 uno_Interface * pInterface = 0;
358 (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
359 pThis->pBridge->getUnoEnv(),
360 (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
362 if (pInterface)
364 ::uno_any_construct(
365 reinterpret_cast< uno_Any * >( pReturn ),
366 &pInterface, pTD, 0 );
367 (*pInterface->release)( pInterface );
368 TYPELIB_DANGER_RELEASE( pTD );
369 *ppException = 0;
370 break;
372 TYPELIB_DANGER_RELEASE( pTD );
374 } // else perform queryInterface()
375 default:
376 // dependent dispatch
377 cpp_call(
378 pThis, aVtableSlot,
379 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
380 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
381 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
382 pReturn, pArgs, ppException );
384 break;
386 default:
388 ::com::sun::star::uno::RuntimeException aExc(
389 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
390 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
392 Type const & rExcType = ::getCppuType( &aExc );
393 // binary identical null reference
394 ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
399 } } }