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
10cdf0e10cSrcweir *
11*61dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
20*61dff127SAndrew Rist *************************************************************/
21*61dff127SAndrew Rist
22*61dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <sys/types.h>
28cdf0e10cSrcweir #include <sys/malloc.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
31cdf0e10cSrcweir #include <uno/data.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
34cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
35cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
36cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtables.hxx"
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "share.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::rtl;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir
44cdf0e10cSrcweir namespace
45cdf0e10cSrcweir {
46cdf0e10cSrcweir
47cdf0e10cSrcweir //==================================================================================================
callVirtualMethod(void * pAdjustedThisPtr,sal_Int32 nVtableIndex,void * pRegisterReturn,typelib_TypeClass eReturnType,char * pPT,sal_Int32 * pStackLongs,sal_Int32)48cdf0e10cSrcweir static void callVirtualMethod(
49cdf0e10cSrcweir void * pAdjustedThisPtr,
50cdf0e10cSrcweir sal_Int32 nVtableIndex,
51cdf0e10cSrcweir void * pRegisterReturn,
52cdf0e10cSrcweir typelib_TypeClass eReturnType,
53cdf0e10cSrcweir char * pPT,
54cdf0e10cSrcweir sal_Int32 * pStackLongs,
55cdf0e10cSrcweir sal_Int32 /* nStackLongs */)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir
58cdf0e10cSrcweir // parameter list is mixed list of * and values
59cdf0e10cSrcweir // reference parameters are pointers
60cdf0e10cSrcweir
61cdf0e10cSrcweir // the basic idea here is to use gpr[8] as a storage area for
62cdf0e10cSrcweir // the future values of registers r3 to r10 needed for the call,
63cdf0e10cSrcweir // and similarly fpr[13] as a storage area for the future values
64cdf0e10cSrcweir // of floating point registers f1 to f13
65cdf0e10cSrcweir
66cdf0e10cSrcweir unsigned long * mfunc; // actual function to be invoked
67cdf0e10cSrcweir void (*ptr)();
68cdf0e10cSrcweir int gpr[8]; // storage for gpregisters, map to r3-r10
69cdf0e10cSrcweir int off; // offset used to find function
70cdf0e10cSrcweir double fpr[13]; // storage for fpregisters, map to f1-f13
71cdf0e10cSrcweir int n; // number of gprs mapped so far
72cdf0e10cSrcweir int f; // number of fprs mapped so far
73cdf0e10cSrcweir volatile long *p; // pointer to parameter overflow area
74cdf0e10cSrcweir int c; // character of parameter type being decoded
75cdf0e10cSrcweir volatile double dret; // temporary function return values
76cdf0e10cSrcweir volatile int iret, iret2;
77cdf0e10cSrcweir
78cdf0e10cSrcweir // Because of the Power PC calling conventions we could be passing
79cdf0e10cSrcweir // parameters in both register types and on the stack. To create the
80cdf0e10cSrcweir // stack parameter area we need we now simply allocate local
81cdf0e10cSrcweir // variable storage param[] that is at least the size of the parameter stack
82cdf0e10cSrcweir // (more than enough space) which we can overwrite the parameters into.
83cdf0e10cSrcweir
84cdf0e10cSrcweir // Note: This keeps us from having to decode the signature twice and
85cdf0e10cSrcweir // prevents problems with later local variables.
86cdf0e10cSrcweir
87cdf0e10cSrcweir // FIXME: I do not believe the following is true but we will keep the
88cdf0e10cSrcweir // FIXME: extra space just to be safe until proven otherwise
89cdf0e10cSrcweir
90cdf0e10cSrcweir // Note: could require up to 2*nStackLongs words of parameter stack area
91cdf0e10cSrcweir // if the call has many float parameters (i.e. floats take up only 1
92cdf0e10cSrcweir // word on the stack but take 2 words in parameter area in the
93cdf0e10cSrcweir // stack frame .
94cdf0e10cSrcweir
95cdf0e10cSrcweir
96cdf0e10cSrcweir // unsigned long param[(2*nStackLongs)];
97cdf0e10cSrcweir
98cdf0e10cSrcweir /* now begin to load the C++ function arguments into storage */
99cdf0e10cSrcweir n = 0;
100cdf0e10cSrcweir f = 0;
101cdf0e10cSrcweir
102cdf0e10cSrcweir
103cdf0e10cSrcweir /* set up a pointer to the stack parameter area */
104cdf0e10cSrcweir __asm__ ( "addi %0,r1,24" : "=r" (p) : /* no inputs */ );
105cdf0e10cSrcweir
106cdf0e10cSrcweir // #i94421#, work around compiler error:
107cdf0e10cSrcweir volatile long * pCopy = p;
108cdf0e10cSrcweir (void) pCopy; // avoid warning about unused variable
109cdf0e10cSrcweir
110cdf0e10cSrcweir // never called
111cdf0e10cSrcweir // if (! pAdjustedThisPtr )CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
112cdf0e10cSrcweir
113cdf0e10cSrcweir
114cdf0e10cSrcweir // now we need to parse the entire signature string
115cdf0e10cSrcweir // until we get the END indicator
116cdf0e10cSrcweir
117cdf0e10cSrcweir // treat complex return pointer like any other parameter
118cdf0e10cSrcweir
119cdf0e10cSrcweir // parse the argument list up to the ending )
120cdf0e10cSrcweir
121cdf0e10cSrcweir while (*pPT != 'X') {
122cdf0e10cSrcweir c = *pPT;
123cdf0e10cSrcweir switch (c) {
124cdf0e10cSrcweir
125cdf0e10cSrcweir case 'D': /* type is double */
126cdf0e10cSrcweir if (f < 13) {
127cdf0e10cSrcweir fpr[f++] = *((double *)pStackLongs); /* store in register */
128cdf0e10cSrcweir n+=2;
129cdf0e10cSrcweir p+=2;
130cdf0e10cSrcweir } else {
131cdf0e10cSrcweir *p++ = *pStackLongs; /* or on the parameter stack */
132cdf0e10cSrcweir *p++ = *(pStackLongs + 1);
133cdf0e10cSrcweir }
134cdf0e10cSrcweir pStackLongs += 2;
135cdf0e10cSrcweir break;
136cdf0e10cSrcweir
137cdf0e10cSrcweir case 'F': /* type is float */
138cdf0e10cSrcweir /* floats are stored as 1 32 bit word on param stack */
139cdf0e10cSrcweir if (f < 13) {
140cdf0e10cSrcweir fpr[f++] = *((float *)pStackLongs);
141cdf0e10cSrcweir n+=1;
142cdf0e10cSrcweir p++;
143cdf0e10cSrcweir } else {
144cdf0e10cSrcweir *((float *)p) = *((float *)pStackLongs);
145cdf0e10cSrcweir p += 1;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir pStackLongs += 1;
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir
150cdf0e10cSrcweir case 'H': /* type is long long */
151cdf0e10cSrcweir if (n < 8)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir gpr[n++] = *pStackLongs;
154cdf0e10cSrcweir p++;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir else
157cdf0e10cSrcweir *p++ = *pStackLongs;
158cdf0e10cSrcweir if(n < 8)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir gpr[n++] = *(pStackLongs+1);
161cdf0e10cSrcweir p++;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir else
164cdf0e10cSrcweir *p++ = *(pStackLongs+1);
165cdf0e10cSrcweir pStackLongs += 2;
166cdf0e10cSrcweir break;
167cdf0e10cSrcweir
168cdf0e10cSrcweir case 'S':
169cdf0e10cSrcweir if (n < 8) {
170cdf0e10cSrcweir gpr[n++] = *((unsigned short*)pStackLongs);
171cdf0e10cSrcweir p++;
172cdf0e10cSrcweir } else {
173cdf0e10cSrcweir *p++ = *((unsigned short *)pStackLongs);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir pStackLongs += 1;
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir
178cdf0e10cSrcweir case 'B':
179cdf0e10cSrcweir if (n < 8) {
180cdf0e10cSrcweir gpr[n++] = *((char *)pStackLongs);
181cdf0e10cSrcweir p++;
182cdf0e10cSrcweir } else {
183cdf0e10cSrcweir *p++ = *((char *)pStackLongs);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir pStackLongs += 1;
186cdf0e10cSrcweir break;
187cdf0e10cSrcweir
188cdf0e10cSrcweir default:
189cdf0e10cSrcweir if (n < 8) {
190cdf0e10cSrcweir gpr[n++] = *pStackLongs;
191cdf0e10cSrcweir p++;
192cdf0e10cSrcweir } else {
193cdf0e10cSrcweir *p++ = *pStackLongs;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir pStackLongs += 1;
196cdf0e10cSrcweir break;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir pPT++;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
201cdf0e10cSrcweir
202cdf0e10cSrcweir /* figure out the address of the function we need to invoke */
203cdf0e10cSrcweir off = nVtableIndex;
204cdf0e10cSrcweir off = off * 4; // 4 bytes per slot
205cdf0e10cSrcweir mfunc = *((unsigned long **)pAdjustedThisPtr); // get the address of the vtable
206cdf0e10cSrcweir mfunc = (unsigned long *)((char *)mfunc + off); // get the address from the vtable entry at offset
207cdf0e10cSrcweir mfunc = *((unsigned long **)mfunc); // the function is stored at the address
208cdf0e10cSrcweir ptr = (void (*)())mfunc;
209cdf0e10cSrcweir
210cdf0e10cSrcweir /* Set up the machine registers and invoke the function */
211cdf0e10cSrcweir
212cdf0e10cSrcweir __asm__ __volatile__ (
213cdf0e10cSrcweir "lwz r3, 0(%0)\n\t"
214cdf0e10cSrcweir "lwz r4, 4(%0)\n\t"
215cdf0e10cSrcweir "lwz r5, 8(%0)\n\t"
216cdf0e10cSrcweir "lwz r6, 12(%0)\n\t"
217cdf0e10cSrcweir "lwz r7, 16(%0)\n\t"
218cdf0e10cSrcweir "lwz r8, 20(%0)\n\t"
219cdf0e10cSrcweir "lwz r9, 24(%0)\n\t"
220cdf0e10cSrcweir "lwz r10, 28(%0)\n\t"
221cdf0e10cSrcweir "lfd f1, 0(%1)\n\t"
222cdf0e10cSrcweir "lfd f2, 8(%1)\n\t"
223cdf0e10cSrcweir "lfd f3, 16(%1)\n\t"
224cdf0e10cSrcweir "lfd f4, 24(%1)\n\t"
225cdf0e10cSrcweir "lfd f5, 32(%1)\n\t"
226cdf0e10cSrcweir "lfd f6, 40(%1)\n\t"
227cdf0e10cSrcweir "lfd f7, 48(%1)\n\t"
228cdf0e10cSrcweir "lfd f8, 56(%1)\n\t"
229cdf0e10cSrcweir "lfd f9, 64(%1)\n\t"
230cdf0e10cSrcweir "lfd f10, 72(%1)\n\t"
231cdf0e10cSrcweir "lfd f11, 80(%1)\n\t"
232cdf0e10cSrcweir "lfd f12, 88(%1)\n\t"
233cdf0e10cSrcweir "lfd f13, 96(%1)\n\t"
234cdf0e10cSrcweir : : "r" (gpr), "r" (fpr)
235cdf0e10cSrcweir : "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
236cdf0e10cSrcweir "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9",
237cdf0e10cSrcweir "f10", "f11", "f12", "f13"
238cdf0e10cSrcweir );
239cdf0e10cSrcweir
240cdf0e10cSrcweir (*ptr)();
241cdf0e10cSrcweir
242cdf0e10cSrcweir
243cdf0e10cSrcweir __asm__ __volatile__ (
244cdf0e10cSrcweir "stw r3, %1\n\t"
245cdf0e10cSrcweir "stw r4, %2\n\t"
246cdf0e10cSrcweir "stfd f1, %0\n\t"
247cdf0e10cSrcweir : : "m" (dret), "m" (iret), "m" (iret2)
248cdf0e10cSrcweir );
249cdf0e10cSrcweir
250cdf0e10cSrcweir
251cdf0e10cSrcweir switch( eReturnType )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir case typelib_TypeClass_HYPER:
254cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
255cdf0e10cSrcweir ((long*)pRegisterReturn)[1] = iret2;
256cdf0e10cSrcweir // fall thru on purpose
257cdf0e10cSrcweir case typelib_TypeClass_LONG:
258cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
259cdf0e10cSrcweir case typelib_TypeClass_ENUM:
260cdf0e10cSrcweir ((long*)pRegisterReturn)[0] = iret;
261cdf0e10cSrcweir break;
262cdf0e10cSrcweir
263cdf0e10cSrcweir case typelib_TypeClass_CHAR:
264cdf0e10cSrcweir case typelib_TypeClass_SHORT:
265cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
266cdf0e10cSrcweir *(unsigned short*)pRegisterReturn = (unsigned short)iret;
267cdf0e10cSrcweir break;
268cdf0e10cSrcweir
269cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
270cdf0e10cSrcweir case typelib_TypeClass_BYTE:
271cdf0e10cSrcweir *(unsigned char*)pRegisterReturn = (unsigned char)iret;
272cdf0e10cSrcweir break;
273cdf0e10cSrcweir
274cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
275cdf0e10cSrcweir *(float*)pRegisterReturn = (float)dret;
276cdf0e10cSrcweir break;
277cdf0e10cSrcweir
278cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
279cdf0e10cSrcweir *(double*)pRegisterReturn = dret;
280cdf0e10cSrcweir break;
281cdf0e10cSrcweir default:
282cdf0e10cSrcweir break;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir
287cdf0e10cSrcweir //==================================================================================================
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)288cdf0e10cSrcweir static void cpp_call(
289cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
290cdf0e10cSrcweir bridges::cpp_uno::shared::VtableSlot aVtableSlot,
291cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef,
292cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
293cdf0e10cSrcweir void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir // max space for: [complex ret ptr], values|ptr ...
296cdf0e10cSrcweir char * pCppStack =
297cdf0e10cSrcweir (char *)alloca( sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) );
298cdf0e10cSrcweir char * pCppStackStart = pCppStack;
299cdf0e10cSrcweir
300cdf0e10cSrcweir // need to know parameter types for callVirtualMethod so generate a signature string
301cdf0e10cSrcweir char * pParamType = (char *) alloca(nParams+2);
302cdf0e10cSrcweir char * pPT = pParamType;
303cdf0e10cSrcweir
304cdf0e10cSrcweir // return
305cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
306cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
307cdf0e10cSrcweir OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
308cdf0e10cSrcweir
309cdf0e10cSrcweir void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
310cdf0e10cSrcweir
311cdf0e10cSrcweir if (pReturnTypeDescr)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
314cdf0e10cSrcweir {
315cdf0e10cSrcweir pCppReturn = pUnoReturn; // direct way for simple types
316cdf0e10cSrcweir }
317cdf0e10cSrcweir else
318cdf0e10cSrcweir {
319cdf0e10cSrcweir // complex return via ptr
320cdf0e10cSrcweir pCppReturn = *(void **)pCppStack
321cdf0e10cSrcweir = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
322cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
323cdf0e10cSrcweir : pUnoReturn); // direct way
324cdf0e10cSrcweir *pPT++ = 'C'; //signify that a complex return type on stack
325cdf0e10cSrcweir pCppStack += sizeof(void *);
326cdf0e10cSrcweir }
327cdf0e10cSrcweir }
328cdf0e10cSrcweir // push this
329cdf0e10cSrcweir void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
330cdf0e10cSrcweir + aVtableSlot.offset;
331cdf0e10cSrcweir *(void**)pCppStack = pAdjustedThisPtr;
332cdf0e10cSrcweir pCppStack += sizeof( void* );
333cdf0e10cSrcweir *pPT++ = 'I';
334cdf0e10cSrcweir
335cdf0e10cSrcweir // stack space
336cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
337cdf0e10cSrcweir // args
338cdf0e10cSrcweir void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
339cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion cpp<=>uno)
340cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
341cdf0e10cSrcweir // type descriptions for reconversions
342cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
343cdf0e10cSrcweir
344cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
345cdf0e10cSrcweir
346cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
349cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
350cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
351cdf0e10cSrcweir
352cdf0e10cSrcweir if (!rParam.bOut
353cdf0e10cSrcweir && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
354cdf0e10cSrcweir {
355cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nPos] = pCppStack, pUnoArgs[nPos], pParamTypeDescr,
356cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
357cdf0e10cSrcweir
358cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir
361cdf0e10cSrcweir // we need to know type of each param so that we know whether to use
362cdf0e10cSrcweir // gpr or fpr to pass in parameters:
363cdf0e10cSrcweir // Key: I - int, long, pointer, etc means pass in gpr
364cdf0e10cSrcweir // B - byte value passed in gpr
365cdf0e10cSrcweir // S - short value passed in gpr
366cdf0e10cSrcweir // F - float value pass in fpr
367cdf0e10cSrcweir // D - double value pass in fpr
368cdf0e10cSrcweir // H - long long int pass in proper pairs of gpr (3,4) (5,6), etc
369cdf0e10cSrcweir // X - indicates end of parameter description string
370cdf0e10cSrcweir
371cdf0e10cSrcweir case typelib_TypeClass_LONG:
372cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
373cdf0e10cSrcweir case typelib_TypeClass_ENUM:
374cdf0e10cSrcweir *pPT++ = 'I';
375cdf0e10cSrcweir break;
376cdf0e10cSrcweir case typelib_TypeClass_SHORT:
377cdf0e10cSrcweir case typelib_TypeClass_CHAR:
378cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
379cdf0e10cSrcweir *pPT++ = 'S';
380cdf0e10cSrcweir break;
381cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
382cdf0e10cSrcweir case typelib_TypeClass_BYTE:
383cdf0e10cSrcweir *pPT++ = 'B';
384cdf0e10cSrcweir break;
385cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
386cdf0e10cSrcweir *pPT++ = 'F';
387cdf0e10cSrcweir break;
388cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
389cdf0e10cSrcweir *pPT++ = 'D';
390cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // extra long
391cdf0e10cSrcweir break;
392cdf0e10cSrcweir case typelib_TypeClass_HYPER:
393cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
394cdf0e10cSrcweir *pPT++ = 'H';
395cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // extra long
396cdf0e10cSrcweir default:
397cdf0e10cSrcweir break;
398cdf0e10cSrcweir }
399cdf0e10cSrcweir
400cdf0e10cSrcweir // no longer needed
401cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
402cdf0e10cSrcweir }
403cdf0e10cSrcweir else // ptr to complex value | ref
404cdf0e10cSrcweir {
405cdf0e10cSrcweir if (! rParam.bIn) // is pure out
406cdf0e10cSrcweir {
407cdf0e10cSrcweir // cpp out is constructed mem, uno out is not!
408cdf0e10cSrcweir uno_constructData(
409cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
410cdf0e10cSrcweir pParamTypeDescr );
411cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
412cdf0e10cSrcweir // will be released at reconversion
413cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir // is in/inout
416cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
417cdf0e10cSrcweir {
418cdf0e10cSrcweir uno_copyAndConvertData(
419cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
420cdf0e10cSrcweir pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
421cdf0e10cSrcweir
422cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
423cdf0e10cSrcweir // will be released at reconversion
424cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir else // direct way
427cdf0e10cSrcweir {
428cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = pUnoArgs[nPos];
429cdf0e10cSrcweir // no longer needed
430cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
431cdf0e10cSrcweir }
432cdf0e10cSrcweir *pPT++='I';
433cdf0e10cSrcweir }
434cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // standard parameter length
435cdf0e10cSrcweir }
436cdf0e10cSrcweir
437cdf0e10cSrcweir // terminate the signature string
438cdf0e10cSrcweir *pPT++='X';
439cdf0e10cSrcweir *pPT=0;
440cdf0e10cSrcweir
441cdf0e10cSrcweir try
442cdf0e10cSrcweir {
443cdf0e10cSrcweir OSL_ENSURE( !( (pCppStack - pCppStackStart ) & 3), "UNALIGNED STACK !!! (Please DO panic)" );
444cdf0e10cSrcweir callVirtualMethod(
445cdf0e10cSrcweir pAdjustedThisPtr, aVtableSlot.index,
446cdf0e10cSrcweir pCppReturn, pReturnTypeDescr->eTypeClass, pParamType,
447cdf0e10cSrcweir (sal_Int32 *)pCppStackStart, (pCppStack - pCppStackStart) / sizeof(sal_Int32) );
448cdf0e10cSrcweir // NO exception occured...
449cdf0e10cSrcweir *ppUnoExc = 0;
450cdf0e10cSrcweir
451cdf0e10cSrcweir // reconvert temporary params
452cdf0e10cSrcweir for ( ; nTempIndizes--; )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
455cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
456cdf0e10cSrcweir
457cdf0e10cSrcweir if (pParams[nIndex].bIn)
458cdf0e10cSrcweir {
459cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout
460cdf0e10cSrcweir {
461cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
462cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
463cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
464cdf0e10cSrcweir }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir else // pure out
467cdf0e10cSrcweir {
468cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
469cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
472cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
473cdf0e10cSrcweir
474cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
475cdf0e10cSrcweir }
476cdf0e10cSrcweir // return value
477cdf0e10cSrcweir if (pCppReturn && pUnoReturn != pCppReturn)
478cdf0e10cSrcweir {
479cdf0e10cSrcweir uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
480cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
481cdf0e10cSrcweir uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
482cdf0e10cSrcweir }
483cdf0e10cSrcweir }
484cdf0e10cSrcweir catch (...)
485cdf0e10cSrcweir {
486cdf0e10cSrcweir // fill uno exception
487cdf0e10cSrcweir fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
488cdf0e10cSrcweir
489cdf0e10cSrcweir // temporary params
490cdf0e10cSrcweir for ( ; nTempIndizes--; )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
493cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
494cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
495cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
496cdf0e10cSrcweir }
497cdf0e10cSrcweir // return type
498cdf0e10cSrcweir if (pReturnTypeDescr)
499cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
500cdf0e10cSrcweir }
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir }
504cdf0e10cSrcweir
505cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
506cdf0e10cSrcweir
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)507cdf0e10cSrcweir void unoInterfaceProxyDispatch(
508cdf0e10cSrcweir uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
509cdf0e10cSrcweir void * pReturn, void * pArgs[], uno_Any ** ppException )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir // is my surrogate
512cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
513cdf0e10cSrcweir = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * > (pUnoI);
514cdf0e10cSrcweir // typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
515cdf0e10cSrcweir
516cdf0e10cSrcweir switch (pMemberDescr->eTypeClass)
517cdf0e10cSrcweir {
518cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
519cdf0e10cSrcweir {
520cdf0e10cSrcweir
521cdf0e10cSrcweir VtableSlot aVtableSlot(
522cdf0e10cSrcweir getVtableSlot(
523cdf0e10cSrcweir reinterpret_cast<
524cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription const * >(
525cdf0e10cSrcweir pMemberDescr)));
526cdf0e10cSrcweir
527cdf0e10cSrcweir if (pReturn)
528cdf0e10cSrcweir {
529cdf0e10cSrcweir // dependent dispatch
530cdf0e10cSrcweir cpp_call(
531cdf0e10cSrcweir pThis, aVtableSlot,
532cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
533cdf0e10cSrcweir 0, 0, // no params
534cdf0e10cSrcweir pReturn, pArgs, ppException );
535cdf0e10cSrcweir }
536cdf0e10cSrcweir else
537cdf0e10cSrcweir {
538cdf0e10cSrcweir // is SET
539cdf0e10cSrcweir typelib_MethodParameter aParam;
540cdf0e10cSrcweir aParam.pTypeRef =
541cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
542cdf0e10cSrcweir aParam.bIn = sal_True;
543cdf0e10cSrcweir aParam.bOut = sal_False;
544cdf0e10cSrcweir
545cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef = 0;
546cdf0e10cSrcweir OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
547cdf0e10cSrcweir typelib_typedescriptionreference_new(
548cdf0e10cSrcweir &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
549cdf0e10cSrcweir
550cdf0e10cSrcweir // dependent dispatch
551cdf0e10cSrcweir aVtableSlot.index += 1; //get then set method
552cdf0e10cSrcweir cpp_call(
553cdf0e10cSrcweir pThis, aVtableSlot,
554cdf0e10cSrcweir pReturnTypeRef,
555cdf0e10cSrcweir 1, &aParam,
556cdf0e10cSrcweir pReturn, pArgs, ppException );
557cdf0e10cSrcweir
558cdf0e10cSrcweir typelib_typedescriptionreference_release( pReturnTypeRef );
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
561cdf0e10cSrcweir break;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
564cdf0e10cSrcweir {
565cdf0e10cSrcweir
566cdf0e10cSrcweir VtableSlot aVtableSlot(
567cdf0e10cSrcweir getVtableSlot(
568cdf0e10cSrcweir reinterpret_cast<
569cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription const * >(
570cdf0e10cSrcweir pMemberDescr)));
571cdf0e10cSrcweir switch (aVtableSlot.index)
572cdf0e10cSrcweir {
573cdf0e10cSrcweir // standard calls
574cdf0e10cSrcweir case 1: // acquire uno interface
575cdf0e10cSrcweir (*pUnoI->acquire)( pUnoI );
576cdf0e10cSrcweir *ppException = 0;
577cdf0e10cSrcweir break;
578cdf0e10cSrcweir case 2: // release uno interface
579cdf0e10cSrcweir (*pUnoI->release)( pUnoI );
580cdf0e10cSrcweir *ppException = 0;
581cdf0e10cSrcweir break;
582cdf0e10cSrcweir case 0: // queryInterface() opt
583cdf0e10cSrcweir {
584cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
585cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
586cdf0e10cSrcweir if (pTD)
587cdf0e10cSrcweir {
588cdf0e10cSrcweir uno_Interface * pInterface = 0;
589cdf0e10cSrcweir (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
590cdf0e10cSrcweir pThis->pBridge->getUnoEnv(),
591cdf0e10cSrcweir (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
592cdf0e10cSrcweir
593cdf0e10cSrcweir if (pInterface)
594cdf0e10cSrcweir {
595cdf0e10cSrcweir ::uno_any_construct(
596cdf0e10cSrcweir reinterpret_cast< uno_Any * >( pReturn ),
597cdf0e10cSrcweir &pInterface, pTD, 0 );
598cdf0e10cSrcweir (*pInterface->release)( pInterface );
599cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
600cdf0e10cSrcweir *ppException = 0;
601cdf0e10cSrcweir break;
602cdf0e10cSrcweir }
603cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
604cdf0e10cSrcweir }
605cdf0e10cSrcweir } // else perform queryInterface()
606cdf0e10cSrcweir default:
607cdf0e10cSrcweir // dependent dispatch
608cdf0e10cSrcweir cpp_call(
609cdf0e10cSrcweir pThis, aVtableSlot,
610cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
611cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
612cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
613cdf0e10cSrcweir pReturn, pArgs, ppException );
614cdf0e10cSrcweir }
615cdf0e10cSrcweir break;
616cdf0e10cSrcweir }
617cdf0e10cSrcweir default:
618cdf0e10cSrcweir {
619cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException aExc(
620cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
621cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
622cdf0e10cSrcweir
623cdf0e10cSrcweir Type const & rExcType = ::getCppuType( &aExc );
624cdf0e10cSrcweir // binary identical null reference
625cdf0e10cSrcweir ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
626cdf0e10cSrcweir }
627cdf0e10cSrcweir }
628cdf0e10cSrcweir }
629cdf0e10cSrcweir
630cdf0e10cSrcweir } } }
631