1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: uno2cpp.cxx,v $
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"
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"
48 using namespace com::sun::star::uno
;
53 extern "C" void callVirtualMethod(
54 void * pAdjustedThisPtr
,
55 sal_Int32 nVtableIndex
,
56 void * pRegisterReturn
,
57 typelib_TypeClass eReturnType
,
58 sal_Int32
* pStackLongs
,
62 //==================================================================================================
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
;
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
86 if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr
))
88 pCppReturn
= pUnoReturn
; // direct way for simple types
92 // complex return via ptr
93 pCppReturn
= *(void **)pCppStack
94 = (bridges::cpp_uno::shared::relatesToInterfaceType(
96 ? alloca( pReturnTypeDescr
->nSize
)
97 : pUnoReturn
); // direct way
98 pCppStack
+= sizeof(void *);
102 void * pAdjustedThisPtr
= reinterpret_cast< void ** >(pThis
->getCppI())
103 + aVtableSlot
.offset
;
104 *(void**)pCppStack
= pAdjustedThisPtr
;
105 pCppStack
+= sizeof( void* );
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
);
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
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!
146 *(void **)pCppStack
= pCppArgs
[nPos
] = alloca( pParamTypeDescr
->nSize
),
148 pTempIndizes
[nTempIndizes
] = nPos
; // default constructed for cpp call
149 // will be released at reconversion
150 ppTempParamTypeDescr
[nTempIndizes
++] = pParamTypeDescr
;
153 else if (bridges::cpp_uno::shared::relatesToInterfaceType(
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
;
167 *(void **)pCppStack
= pCppArgs
[nPos
] = pUnoArgs
[nPos
];
169 TYPELIB_DANGER_RELEASE( pParamTypeDescr
);
172 pCppStack
+= sizeof(sal_Int32
); // standard parameter length
175 // seems that EH registration for callVirtualMethod is not really
178 // static unsigned long* pFrameInfo = NULL;
180 // if( ! pFrameInfo )
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 );
195 int nStackLongs
= (pCppStack
- pCppStackStart
)/sizeof(sal_Int32
);
196 if( nStackLongs
& 1 )
197 // stack has to be 8 byte aligned
204 pReturnTypeDescr
->eTypeClass
,
205 (sal_Int32
*)pCppStackStart
,
209 // NO exception occured...
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() );
229 uno_copyAndConvertData( pUnoArgs
[nIndex
], pCppArgs
[nIndex
], pParamTypeDescr
,
230 pThis
->getBridge()->getCpp2Uno() );
232 // destroy temp cpp param => cpp: every param was constructed
234 pCppArgs
[nIndex
], pParamTypeDescr
,
235 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
237 TYPELIB_DANGER_RELEASE( pParamTypeDescr
);
240 if (pCppReturn
&& pUnoReturn
!= pCppReturn
)
242 uno_copyAndConvertData( pUnoReturn
, pCppReturn
, pReturnTypeDescr
,
243 pThis
->getBridge()->getCpp2Uno() );
245 pCppReturn
, pReturnTypeDescr
,
246 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
251 void* pExc
= __Crun::ex_get();
252 const char* pName
= __Cimpl::ex_name();
255 CPPU_CURRENT_NAMESPACE::cc50_solaris_sparc_fillUnoException(
256 pExc
, pName
, *ppUnoExc
, pThis
->getBridge()->getCpp2Uno());
259 for ( ; nTempIndizes
--; )
261 sal_Int32 nIndex
= pTempIndizes
[nTempIndizes
];
262 // destroy temp cpp param => cpp: every param was constructed
265 ppTempParamTypeDescr
[nTempIndizes
],
266 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
267 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr
[nTempIndizes
] );
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
)
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(
295 typelib_InterfaceAttributeTypeDescription
const * >(
299 // dependent dispatch
302 ((typelib_InterfaceAttributeTypeDescription
*)pMemberDescr
)->pAttributeTypeRef
,
304 pReturn
, pArgs
, ppException
);
309 typelib_MethodParameter aParam
;
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
326 pReturn
, pArgs
, ppException
);
328 typelib_typedescriptionreference_release( pReturnTypeRef
);
333 case typelib_TypeClass_INTERFACE_METHOD
:
335 VtableSlot
aVtableSlot(
338 typelib_InterfaceMethodTypeDescription
const * >(
340 switch (aVtableSlot
.index
)
343 case 1: // acquire uno interface
344 (*pUnoI
->acquire
)( pUnoI
);
347 case 2: // release uno interface
348 (*pUnoI
->release
)( pUnoI
);
351 case 0: // queryInterface() opt
353 typelib_TypeDescription
* pTD
= 0;
354 TYPELIB_DANGER_GET( &pTD
, reinterpret_cast< Type
* >( pArgs
[0] )->getTypeLibType() );
357 uno_Interface
* pInterface
= 0;
358 (*pThis
->pBridge
->getUnoEnv()->getRegisteredInterface
)(
359 pThis
->pBridge
->getUnoEnv(),
360 (void **)&pInterface
, pThis
->oid
.pData
, (typelib_InterfaceTypeDescription
*)pTD
);
365 reinterpret_cast< uno_Any
* >( pReturn
),
366 &pInterface
, pTD
, 0 );
367 (*pInterface
->release
)( pInterface
);
368 TYPELIB_DANGER_RELEASE( pTD
);
372 TYPELIB_DANGER_RELEASE( pTD
);
374 } // else perform queryInterface()
376 // dependent dispatch
379 ((typelib_InterfaceMethodTypeDescription
*)pMemberDescr
)->pReturnTypeRef
,
380 ((typelib_InterfaceMethodTypeDescription
*)pMemberDescr
)->nParams
,
381 ((typelib_InterfaceMethodTypeDescription
*)pMemberDescr
)->pParams
,
382 pReturn
, pArgs
, ppException
);
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 );