1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sal/alloca.h>
32 #include <com/sun/star/uno/genfunc.hxx>
33 #include "com/sun/star/uno/RuntimeException.hpp"
36 #include "bridges/cpp_uno/shared/bridge.hxx"
37 #include "bridges/cpp_uno/shared/types.hxx"
38 #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
39 #include "bridges/cpp_uno/shared/vtables.hxx"
41 #include "cc50_solaris_sparc.hxx"
43 using namespace com::sun::star::uno
;
45 using ::rtl::OUString
;
50 extern "C" void callVirtualMethod(
51 void * pAdjustedThisPtr
,
52 sal_Int32 nVtableIndex
,
53 void * pRegisterReturn
,
54 typelib_TypeClass eReturnType
,
55 sal_Int32
* pStackLongs
,
59 //==================================================================================================
61 bridges::cpp_uno::shared::UnoInterfaceProxy
* pThis
,
62 bridges::cpp_uno::shared::VtableSlot aVtableSlot
,
63 typelib_TypeDescriptionReference
* pReturnTypeRef
,
64 sal_Int32 nParams
, typelib_MethodParameter
* pParams
,
65 void * pUnoReturn
, void * pUnoArgs
[], uno_Any
** ppUnoExc
)
67 // pCppI is cc50_solaris_sparc this pointer
68 OSL_ENSURE( pThis
, "### no interface given!" );
70 // max space for: [complex ret ptr], values|ptr ...
71 char * pCppStack
= (char *)alloca( ((nParams
+3) * sizeof(sal_Int64
)) );
72 char * pCppStackStart
= pCppStack
;
75 typelib_TypeDescription
* pReturnTypeDescr
= 0;
76 TYPELIB_DANGER_GET( &pReturnTypeDescr
, pReturnTypeRef
);
77 OSL_ENSURE( pReturnTypeDescr
, "### expected return type description!" );
79 void * pCppReturn
= 0; // if != 0 && != pUnoReturn, needs reconversion
83 if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr
))
85 pCppReturn
= pUnoReturn
; // direct way for simple types
89 // complex return via ptr
90 pCppReturn
= *(void **)pCppStack
91 = (bridges::cpp_uno::shared::relatesToInterfaceType(
93 ? alloca( pReturnTypeDescr
->nSize
)
94 : pUnoReturn
); // direct way
95 pCppStack
+= sizeof(void *);
99 void * pAdjustedThisPtr
= reinterpret_cast< void ** >(pThis
->getCppI())
100 + aVtableSlot
.offset
;
101 *(void**)pCppStack
= pAdjustedThisPtr
;
102 pCppStack
+= sizeof( void* );
105 void ** pCppArgs
= (void **)alloca( 3 * sizeof(void *) * nParams
);
106 // indizes of values this have to be converted (interface conversion cpp<=>uno)
107 sal_Int32
* pTempIndizes
= (sal_Int32
*)(pCppArgs
+ nParams
);
108 // type descriptions for reconversions
109 typelib_TypeDescription
** ppTempParamTypeDescr
= (typelib_TypeDescription
**)(pCppArgs
+ (2 * nParams
));
111 sal_Int32 nTempIndizes
= 0;
113 for ( sal_Int32 nPos
= 0; nPos
< nParams
; ++nPos
)
115 const typelib_MethodParameter
& rParam
= pParams
[nPos
];
116 typelib_TypeDescription
* pParamTypeDescr
= 0;
117 TYPELIB_DANGER_GET( &pParamTypeDescr
, rParam
.pTypeRef
);
120 && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr
))
122 pCppArgs
[ nPos
] = CPPU_CURRENT_NAMESPACE::adjustPointer(
123 pCppStack
, pParamTypeDescr
);
124 uno_copyAndConvertData( pCppArgs
[nPos
], pUnoArgs
[nPos
], pParamTypeDescr
,
125 pThis
->getBridge()->getUno2Cpp() );
127 switch (pParamTypeDescr
->eTypeClass
)
129 case typelib_TypeClass_HYPER
:
130 case typelib_TypeClass_UNSIGNED_HYPER
:
131 case typelib_TypeClass_DOUBLE
:
132 pCppStack
+= sizeof(sal_Int32
); // extra long
135 TYPELIB_DANGER_RELEASE( pParamTypeDescr
);
137 else // ptr to complex value | ref
139 if (! rParam
.bIn
) // is pure out
141 // cpp out is constructed mem, uno out is not!
143 *(void **)pCppStack
= pCppArgs
[nPos
] = alloca( pParamTypeDescr
->nSize
),
145 pTempIndizes
[nTempIndizes
] = nPos
; // default constructed for cpp call
146 // will be released at reconversion
147 ppTempParamTypeDescr
[nTempIndizes
++] = pParamTypeDescr
;
150 else if (bridges::cpp_uno::shared::relatesToInterfaceType(
153 uno_copyAndConvertData(
154 *(void **)pCppStack
= pCppArgs
[nPos
] = alloca( pParamTypeDescr
->nSize
),
155 pUnoArgs
[nPos
], pParamTypeDescr
,
156 pThis
->getBridge()->getUno2Cpp() );
158 pTempIndizes
[nTempIndizes
] = nPos
; // has to be reconverted
159 // will be released at reconversion
160 ppTempParamTypeDescr
[nTempIndizes
++] = pParamTypeDescr
;
164 *(void **)pCppStack
= pCppArgs
[nPos
] = pUnoArgs
[nPos
];
166 TYPELIB_DANGER_RELEASE( pParamTypeDescr
);
169 pCppStack
+= sizeof(sal_Int32
); // standard parameter length
172 // seems that EH registration for callVirtualMethod is not really
175 // static unsigned long* pFrameInfo = NULL;
177 // if( ! pFrameInfo )
179 // pFrameInfo = new unsigned long[ 7 ];
180 // pFrameInfo[ 0 ] = 0x40000000 | (((unsigned long)__Crun::ex_rethrow_q) >> 2);
181 // pFrameInfo[ 1 ] = 0x01000000;
182 // pFrameInfo[ 2 ] = (unsigned long)callVirtualMethodExceptionHandler;
183 // pFrameInfo[ 3 ] = 0;
184 // pFrameInfo[ 4 ] = (unsigned long)pFrameInfo - (unsigned long)callVirtualMethodExceptionHandler;
185 // pFrameInfo[ 5 ] = 0;
186 // pFrameInfo[ 6 ] = 0;
187 // _ex_register( pFrameInfo+2, 1 );
192 int nStackLongs
= (pCppStack
- pCppStackStart
)/sizeof(sal_Int32
);
193 if( nStackLongs
& 1 )
194 // stack has to be 8 byte aligned
201 pReturnTypeDescr
->eTypeClass
,
202 (sal_Int32
*)pCppStackStart
,
206 // NO exception occurred...
209 // reconvert temporary params
210 for ( ; nTempIndizes
--; )
212 sal_Int32 nIndex
= pTempIndizes
[nTempIndizes
];
213 typelib_TypeDescription
* pParamTypeDescr
= ppTempParamTypeDescr
[nTempIndizes
];
215 if (pParams
[nIndex
].bIn
)
217 if (pParams
[nIndex
].bOut
) // inout
219 uno_destructData( pUnoArgs
[nIndex
], pParamTypeDescr
, 0 ); // destroy uno value
220 uno_copyAndConvertData( pUnoArgs
[nIndex
], pCppArgs
[nIndex
], pParamTypeDescr
,
221 pThis
->getBridge()->getCpp2Uno() );
226 uno_copyAndConvertData( pUnoArgs
[nIndex
], pCppArgs
[nIndex
], pParamTypeDescr
,
227 pThis
->getBridge()->getCpp2Uno() );
229 // destroy temp cpp param => cpp: every param was constructed
231 pCppArgs
[nIndex
], pParamTypeDescr
,
232 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
234 TYPELIB_DANGER_RELEASE( pParamTypeDescr
);
237 if (pCppReturn
&& pUnoReturn
!= pCppReturn
)
239 uno_copyAndConvertData( pUnoReturn
, pCppReturn
, pReturnTypeDescr
,
240 pThis
->getBridge()->getCpp2Uno() );
242 pCppReturn
, pReturnTypeDescr
,
243 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
248 void* pExc
= __Crun::ex_get();
249 const char* pName
= __Cimpl::ex_name();
252 CPPU_CURRENT_NAMESPACE::cc50_solaris_sparc_fillUnoException(
253 pExc
, pName
, *ppUnoExc
, pThis
->getBridge()->getCpp2Uno());
256 for ( ; nTempIndizes
--; )
258 sal_Int32 nIndex
= pTempIndizes
[nTempIndizes
];
259 // destroy temp cpp param => cpp: every param was constructed
262 ppTempParamTypeDescr
[nTempIndizes
],
263 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
264 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr
[nTempIndizes
] );
267 if (pReturnTypeDescr
)
268 TYPELIB_DANGER_RELEASE( pReturnTypeDescr
);
274 namespace bridges
{ namespace cpp_uno
{ namespace shared
{
276 void unoInterfaceProxyDispatch(
277 uno_Interface
* pUnoI
, const typelib_TypeDescription
* pMemberDescr
,
278 void * pReturn
, void * pArgs
[], uno_Any
** ppException
)
281 bridges::cpp_uno::shared::UnoInterfaceProxy
* pThis
282 = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy
* >(pUnoI
);
283 typelib_InterfaceTypeDescription
* pTypeDescr
= pThis
->pTypeDescr
;
285 switch (pMemberDescr
->eTypeClass
)
287 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
289 VtableSlot
aVtableSlot(
292 typelib_InterfaceAttributeTypeDescription
const * >(
296 // dependent dispatch
299 ((typelib_InterfaceAttributeTypeDescription
*)pMemberDescr
)->pAttributeTypeRef
,
301 pReturn
, pArgs
, ppException
);
306 typelib_MethodParameter aParam
;
308 ((typelib_InterfaceAttributeTypeDescription
*)pMemberDescr
)->pAttributeTypeRef
;
309 aParam
.bIn
= sal_True
;
310 aParam
.bOut
= sal_False
;
312 typelib_TypeDescriptionReference
* pReturnTypeRef
= 0;
313 OUString
aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
314 typelib_typedescriptionreference_new(
315 &pReturnTypeRef
, typelib_TypeClass_VOID
, aVoidName
.pData
);
317 // dependent dispatch
318 aVtableSlot
.index
+= 1; // get, then set method
323 pReturn
, pArgs
, ppException
);
325 typelib_typedescriptionreference_release( pReturnTypeRef
);
330 case typelib_TypeClass_INTERFACE_METHOD
:
332 VtableSlot
aVtableSlot(
335 typelib_InterfaceMethodTypeDescription
const * >(
337 switch (aVtableSlot
.index
)
340 case 1: // acquire uno interface
341 (*pUnoI
->acquire
)( pUnoI
);
344 case 2: // release uno interface
345 (*pUnoI
->release
)( pUnoI
);
348 case 0: // queryInterface() opt
350 typelib_TypeDescription
* pTD
= 0;
351 TYPELIB_DANGER_GET( &pTD
, reinterpret_cast< Type
* >( pArgs
[0] )->getTypeLibType() );
354 uno_Interface
* pInterface
= 0;
355 (*pThis
->pBridge
->getUnoEnv()->getRegisteredInterface
)(
356 pThis
->pBridge
->getUnoEnv(),
357 (void **)&pInterface
, pThis
->oid
.pData
, (typelib_InterfaceTypeDescription
*)pTD
);
362 reinterpret_cast< uno_Any
* >( pReturn
),
363 &pInterface
, pTD
, 0 );
364 (*pInterface
->release
)( pInterface
);
365 TYPELIB_DANGER_RELEASE( pTD
);
369 TYPELIB_DANGER_RELEASE( pTD
);
371 } // else perform queryInterface()
373 // dependent dispatch
376 ((typelib_InterfaceMethodTypeDescription
*)pMemberDescr
)->pReturnTypeRef
,
377 ((typelib_InterfaceMethodTypeDescription
*)pMemberDescr
)->nParams
,
378 ((typelib_InterfaceMethodTypeDescription
*)pMemberDescr
)->pParams
,
379 pReturn
, pArgs
, ppException
);
385 ::com::sun::star::uno::RuntimeException
aExc(
386 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
387 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>() );
389 Type
const & rExcType
= ::getCppuType( &aExc
);
390 // binary identical null reference
391 ::uno_type_any_construct( *ppException
, &aExc
, rExcType
.getTypeLibType(), 0 );
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */