Added
Link Here
|
1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 |
/* |
3 |
* This file is part of the LibreOffice project. |
4 |
* |
5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 |
* |
9 |
* This file incorporates work covered by the following license notice: |
10 |
* |
11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
12 |
* contributor license agreements. See the NOTICE file distributed |
13 |
* with this work for additional information regarding copyright |
14 |
* ownership. The ASF licenses this file to you under the Apache |
15 |
* License, Version 2.0 (the "License"); you may not use this file |
16 |
* except in compliance with the License. You may obtain a copy of |
17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 |
*/ |
19 |
|
20 |
|
21 |
#include <stdlib.h> |
22 |
|
23 |
#include <com/sun/star/uno/genfunc.hxx> |
24 |
#include <uno/data.h> |
25 |
|
26 |
#include "bridges/cpp_uno/shared/bridge.hxx" |
27 |
#include "bridges/cpp_uno/shared/types.hxx" |
28 |
#include "bridges/cpp_uno/shared/unointerfaceproxy.hxx" |
29 |
#include "bridges/cpp_uno/shared/vtables.hxx" |
30 |
|
31 |
#include "share.hxx" |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <string.h> |
35 |
|
36 |
|
37 |
using namespace ::rtl; |
38 |
using namespace ::com::sun::star::uno; |
39 |
|
40 |
namespace ppc64 |
41 |
{ |
42 |
#if _CALL_ELF == 2 |
43 |
bool is_complex_struct(const typelib_TypeDescription * type) |
44 |
{ |
45 |
const typelib_CompoundTypeDescription * p |
46 |
= reinterpret_cast< const typelib_CompoundTypeDescription * >(type); |
47 |
for (sal_Int32 i = 0; i < p->nMembers; ++i) |
48 |
{ |
49 |
if (p->ppTypeRefs[i]->eTypeClass == typelib_TypeClass_STRUCT || |
50 |
p->ppTypeRefs[i]->eTypeClass == typelib_TypeClass_EXCEPTION) |
51 |
{ |
52 |
typelib_TypeDescription * t = 0; |
53 |
TYPELIB_DANGER_GET(&t, p->ppTypeRefs[i]); |
54 |
bool b = is_complex_struct(t); |
55 |
TYPELIB_DANGER_RELEASE(t); |
56 |
if (b) { |
57 |
return true; |
58 |
} |
59 |
} |
60 |
else if (!bridges::cpp_uno::shared::isSimpleType(p->ppTypeRefs[i]->eTypeClass)) |
61 |
return true; |
62 |
} |
63 |
if (p->pBaseTypeDescription != 0) |
64 |
return is_complex_struct(&p->pBaseTypeDescription->aBase); |
65 |
return false; |
66 |
} |
67 |
#endif |
68 |
|
69 |
bool return_in_hidden_param( typelib_TypeDescriptionReference *pTypeRef ) |
70 |
{ |
71 |
if (bridges::cpp_uno::shared::isSimpleType(pTypeRef)) |
72 |
return false; |
73 |
#if _CALL_ELF == 2 |
74 |
else if (pTypeRef->eTypeClass == typelib_TypeClass_STRUCT || pTypeRef->eTypeClass == typelib_TypeClass_EXCEPTION) |
75 |
{ |
76 |
typelib_TypeDescription * pTypeDescr = 0; |
77 |
TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef ); |
78 |
|
79 |
//A Composite Type not larger than 16 bytes is returned in up to two GPRs |
80 |
bool bRet = pTypeDescr->nSize > 16 || is_complex_struct(pTypeDescr); |
81 |
|
82 |
TYPELIB_DANGER_RELEASE( pTypeDescr ); |
83 |
return bRet; |
84 |
} |
85 |
#endif |
86 |
return true; |
87 |
} |
88 |
} |
89 |
|
90 |
void MapReturn(long r3, long r4, double dret, typelib_TypeDescriptionReference* pReturnType, void *pRegisterReturn) |
91 |
{ |
92 |
switch (pReturnType->eTypeClass) |
93 |
{ |
94 |
case typelib_TypeClass_HYPER: |
95 |
case typelib_TypeClass_UNSIGNED_HYPER: |
96 |
*reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = r3; |
97 |
break; |
98 |
case typelib_TypeClass_LONG: |
99 |
case typelib_TypeClass_UNSIGNED_LONG: |
100 |
case typelib_TypeClass_ENUM: |
101 |
*reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = r3; |
102 |
break; |
103 |
case typelib_TypeClass_CHAR: |
104 |
case typelib_TypeClass_SHORT: |
105 |
case typelib_TypeClass_UNSIGNED_SHORT: |
106 |
*reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = (unsigned short)r3; |
107 |
break; |
108 |
case typelib_TypeClass_BOOLEAN: |
109 |
case typelib_TypeClass_BYTE: |
110 |
*reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = (unsigned char)r3; |
111 |
break; |
112 |
case typelib_TypeClass_FLOAT: |
113 |
*reinterpret_cast<float *>( pRegisterReturn ) = dret; |
114 |
break; |
115 |
case typelib_TypeClass_DOUBLE: |
116 |
*reinterpret_cast<double *>( pRegisterReturn ) = dret; |
117 |
break; |
118 |
#if _CALL_ELF == 2 |
119 |
case typelib_TypeClass_STRUCT: |
120 |
case typelib_TypeClass_EXCEPTION: |
121 |
if (!ppc64::return_in_hidden_param(pReturnType)) |
122 |
{ |
123 |
sal_uInt64 *pRegisters = reinterpret_cast<sal_uInt64*>(pRegisterReturn); |
124 |
pRegisters[0] = r3; |
125 |
if (pReturnType->pType->nSize > 8) |
126 |
pRegisters[1] = r4; |
127 |
} |
128 |
#endif |
129 |
default: |
130 |
break; |
131 |
} |
132 |
} |
133 |
|
134 |
namespace |
135 |
{ |
136 |
|
137 |
static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex, |
138 |
void * pRegisterReturn, typelib_TypeDescription * pReturnTypeDescr, |
139 |
sal_uInt64 *pStack, sal_uInt32 nStack, |
140 |
sal_uInt64 *pGPR, sal_uInt32 nGPR, |
141 |
double *pFPR, sal_uInt32 nFPR) |
142 |
{ |
143 |
// Stack, if used, must be 16-bytes aligned |
144 |
if ( nStack ) |
145 |
nStack = ( nStack + 1 ) & ~1; |
146 |
|
147 |
// Should not happen, but... |
148 |
if ( nFPR > ppc64::MAX_SSE_REGS ) |
149 |
nFPR = ppc64::MAX_SSE_REGS; |
150 |
if ( nGPR > ppc64::MAX_GPR_REGS ) |
151 |
nGPR = ppc64::MAX_GPR_REGS; |
152 |
|
153 |
#if OSL_DEBUG_LEVEL > 2 |
154 |
// Let's figure out what is really going on here |
155 |
{ |
156 |
fprintf( stderr, "= callVirtualMethod() =\nGPR's (%d): ", nGPR ); |
157 |
for ( int i = 0; i < nGPR; ++i ) |
158 |
fprintf( stderr, "0x%lx, ", pGPR[i] ); |
159 |
fprintf( stderr, "\nFPR's (%d): ", nFPR ); |
160 |
for ( int i = 0; i < nFPR; ++i ) |
161 |
fprintf( stderr, "0x%lx (%f), ", pFPR[i], pFPR[i] ); |
162 |
fprintf( stderr, "\nStack (%d): ", nStack ); |
163 |
for ( int i = 0; i < nStack; ++i ) |
164 |
fprintf( stderr, "0x%lx, ", pStack[i] ); |
165 |
fprintf( stderr, "\n" ); |
166 |
} |
167 |
#endif |
168 |
|
169 |
// Load parameters to stack, if necessary |
170 |
sal_uInt64 *stack = (sal_uInt64 *) __builtin_alloca( nStack * 8 ); |
171 |
memcpy( stack, pStack, nStack * 8 ); |
172 |
|
173 |
// Get pointer to method |
174 |
sal_uInt64 pMethod = *((sal_uInt64 *)pThis); |
175 |
pMethod += 8 * nVtableIndex; |
176 |
pMethod = *((sal_uInt64 *)pMethod); |
177 |
|
178 |
#if _CALL_ELF == 2 |
179 |
typedef void (* FunctionCall )(...); |
180 |
#else |
181 |
typedef void (* FunctionCall )( sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64, sal_uInt64 ); |
182 |
#endif |
183 |
FunctionCall pFunc = (FunctionCall)pMethod; |
184 |
|
185 |
volatile double dret; |
186 |
|
187 |
// fill registers |
188 |
__asm__ __volatile__ ( |
189 |
"ld 3, 0(%0)\n\t" |
190 |
"ld 4, 8(%0)\n\t" |
191 |
"ld 5, 16(%0)\n\t" |
192 |
"ld 6, 24(%0)\n\t" |
193 |
"ld 7, 32(%0)\n\t" |
194 |
"ld 8, 40(%0)\n\t" |
195 |
"ld 9, 48(%0)\n\t" |
196 |
"ld 10, 56(%0)\n\t" |
197 |
"lfd 1, 0(%1)\n\t" |
198 |
"lfd 2, 8(%1)\n\t" |
199 |
"lfd 3, 16(%1)\n\t" |
200 |
"lfd 4, 24(%1)\n\t" |
201 |
"lfd 5, 32(%1)\n\t" |
202 |
"lfd 6, 40(%1)\n\t" |
203 |
"lfd 7, 48(%1)\n\t" |
204 |
"lfd 8, 56(%1)\n\t" |
205 |
"lfd 9, 64(%1)\n\t" |
206 |
"lfd 10, 72(%1)\n\t" |
207 |
"lfd 11, 80(%1)\n\t" |
208 |
"lfd 12, 88(%1)\n\t" |
209 |
"lfd 13, 96(%1)\n\t" |
210 |
: : "r" (pGPR), "r" (pFPR) |
211 |
: "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", |
212 |
"fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9", |
213 |
"fr10", "fr11", "fr12", "fr13" |
214 |
); |
215 |
|
216 |
// tell gcc that r3 to r11 are not available to it for doing the TOC and exception munge on the func call |
217 |
register sal_uInt64 r3 asm("r3"); |
218 |
register sal_uInt64 r4 asm("r4"); |
219 |
register sal_uInt64 r5 asm("r5"); |
220 |
register sal_uInt64 r6 asm("r6"); |
221 |
register sal_uInt64 r7 asm("r7"); |
222 |
register sal_uInt64 r8 asm("r8"); |
223 |
register sal_uInt64 r9 asm("r9"); |
224 |
register sal_uInt64 r10 asm("r10"); |
225 |
register sal_uInt64 r11 asm("r11"); |
226 |
|
227 |
(*pFunc)(r3, r4, r5, r6, r7, r8, r9, r10); |
228 |
|
229 |
// get return value |
230 |
__asm__ __volatile__ ( |
231 |
"mr %1, 3\n\t" |
232 |
"mr %2, 4\n\t" |
233 |
"fmr %0, 1\n\t" |
234 |
: "=f" (dret), "=r" (r3), "=r" (r4) : ); |
235 |
|
236 |
MapReturn(r3, r4, dret, reinterpret_cast<typelib_TypeDescriptionReference *>(pReturnTypeDescr), pRegisterReturn); |
237 |
} |
238 |
|
239 |
// Macros for easier insertion of values to registers or stack |
240 |
// pSV - pointer to the source |
241 |
// nr - order of the value [will be increased if stored to register] |
242 |
// pFPR, pGPR - pointer to the registers |
243 |
// pDS - pointer to the stack [will be increased if stored here] |
244 |
|
245 |
// The value in %xmm register is already prepared to be retrieved as a float, |
246 |
// thus we treat float and double the same |
247 |
#define INSERT_FLOAT( pSV, nr, pFPR, pDS, bOverflow ) \ |
248 |
if ( nr < ppc64::MAX_SSE_REGS ) \ |
249 |
pFPR[nr++] = *reinterpret_cast<float *>( pSV ); \ |
250 |
else \ |
251 |
bOverflow = true; \ |
252 |
if (bOverflow) \ |
253 |
*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim! |
254 |
|
255 |
#define INSERT_DOUBLE( pSV, nr, pFPR, pDS, bOverflow ) \ |
256 |
if ( nr < ppc64::MAX_SSE_REGS ) \ |
257 |
pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \ |
258 |
else \ |
259 |
bOverflow = true; \ |
260 |
if (bOverflow) \ |
261 |
*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim! |
262 |
|
263 |
#define INSERT_INT64( pSV, nr, pGPR, pDS, bOverflow ) \ |
264 |
if ( nr < ppc64::MAX_GPR_REGS ) \ |
265 |
pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \ |
266 |
else \ |
267 |
bOverflow = true; \ |
268 |
if (bOverflow) \ |
269 |
*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); |
270 |
|
271 |
#define INSERT_INT32( pSV, nr, pGPR, pDS, bOverflow ) \ |
272 |
if ( nr < ppc64::MAX_GPR_REGS ) \ |
273 |
pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \ |
274 |
else \ |
275 |
bOverflow = true; \ |
276 |
if (bOverflow) \ |
277 |
*pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV ); |
278 |
|
279 |
#define INSERT_INT16( pSV, nr, pGPR, pDS, bOverflow ) \ |
280 |
if ( nr < ppc64::MAX_GPR_REGS ) \ |
281 |
pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \ |
282 |
else \ |
283 |
bOverflow = true; \ |
284 |
if (bOverflow) \ |
285 |
*pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV ); |
286 |
|
287 |
#define INSERT_INT8( pSV, nr, pGPR, pDS, bOverflow ) \ |
288 |
if ( nr < ppc64::MAX_GPR_REGS ) \ |
289 |
pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \ |
290 |
else \ |
291 |
bOverflow = true; \ |
292 |
if (bOverflow) \ |
293 |
*pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV ); |
294 |
|
295 |
static void cpp_call( |
296 |
bridges::cpp_uno::shared::UnoInterfaceProxy * pThis, |
297 |
bridges::cpp_uno::shared::VtableSlot aVtableSlot, |
298 |
typelib_TypeDescriptionReference * pReturnTypeRef, |
299 |
sal_Int32 nParams, typelib_MethodParameter * pParams, |
300 |
void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc ) |
301 |
{ |
302 |
// max space for: [complex ret ptr], values|ptr ... |
303 |
sal_uInt64 * pStack = (sal_uInt64 *)alloca( (nParams+3) * sizeof(sal_Int64) ); |
304 |
sal_uInt64 * pStackStart = pStack; |
305 |
|
306 |
sal_uInt64 pGPR[ppc64::MAX_GPR_REGS]; |
307 |
sal_uInt32 nGPR = 0; |
308 |
|
309 |
double pFPR[ppc64::MAX_SSE_REGS]; |
310 |
sal_uInt32 nFPR = 0; |
311 |
|
312 |
// return |
313 |
typelib_TypeDescription * pReturnTypeDescr = 0; |
314 |
TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef ); |
315 |
OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" ); |
316 |
|
317 |
void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion |
318 |
|
319 |
bool bOverflow = false; |
320 |
bool bSimpleReturn = true; |
321 |
|
322 |
if (pReturnTypeDescr) |
323 |
{ |
324 |
#if OSL_DEBUG_LEVEL > 2 |
325 |
fprintf(stderr, "return type is %d\n", pReturnTypeDescr->eTypeClass); |
326 |
#endif |
327 |
if (ppc64::return_in_hidden_param(pReturnTypeRef)) |
328 |
bSimpleReturn = false; |
329 |
|
330 |
if (bSimpleReturn) |
331 |
{ |
332 |
pCppReturn = pUnoReturn; // direct way for simple types |
333 |
#if OSL_DEBUG_LEVEL > 2 |
334 |
fprintf(stderr, "simple return\n"); |
335 |
#endif |
336 |
} |
337 |
else |
338 |
{ |
339 |
// complex return via ptr |
340 |
pCppReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr ) |
341 |
? alloca( pReturnTypeDescr->nSize ) : pUnoReturn); |
342 |
#if OSL_DEBUG_LEVEL > 2 |
343 |
fprintf(stderr, "pCppReturn/pUnoReturn is %lx/%lx", pCppReturn, pUnoReturn); |
344 |
#endif |
345 |
INSERT_INT64( &pCppReturn, nGPR, pGPR, pStack, bOverflow ); |
346 |
} |
347 |
} |
348 |
// push "this" pointer |
349 |
void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset; |
350 |
#if OSL_DEBUG_LEVEL > 2 |
351 |
fprintf(stderr, "this pointer is %p\n", pAdjustedThisPtr); |
352 |
#endif |
353 |
INSERT_INT64( &pAdjustedThisPtr, nGPR, pGPR, pStack, bOverflow ); |
354 |
|
355 |
// Args |
356 |
void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams ); |
357 |
// indices of values this have to be converted (interface conversion cpp<=>uno) |
358 |
sal_Int32 * pTempIndices = (sal_Int32 *)(pCppArgs + nParams); |
359 |
// type descriptions for reconversions |
360 |
typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams)); |
361 |
|
362 |
sal_Int32 nTempIndices = 0; |
363 |
|
364 |
#if OSL_DEBUG_LEVEL > 2 |
365 |
fprintf(stderr, "n params is %d\n", nParams); |
366 |
#endif |
367 |
|
368 |
for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos ) |
369 |
{ |
370 |
const typelib_MethodParameter & rParam = pParams[nPos]; |
371 |
typelib_TypeDescription * pParamTypeDescr = 0; |
372 |
TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef ); |
373 |
|
374 |
#if OSL_DEBUG_LEVEL > 2 |
375 |
fprintf(stderr, "param %d is %d %d %d\n", nPos, rParam.bOut, bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ), |
376 |
pParamTypeDescr->eTypeClass); |
377 |
#endif |
378 |
|
379 |
if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr )) |
380 |
{ |
381 |
// uno_copyAndConvertData( pCppArgs[nPos] = alloca( 8 ), pUnoArgs[nPos], pParamTypeDescr, |
382 |
uno_copyAndConvertData( pCppArgs[nPos] = pStack, pUnoArgs[nPos], pParamTypeDescr, |
383 |
pThis->getBridge()->getUno2Cpp() ); |
384 |
switch (pParamTypeDescr->eTypeClass) |
385 |
{ |
386 |
case typelib_TypeClass_HYPER: |
387 |
case typelib_TypeClass_UNSIGNED_HYPER: |
388 |
#if OSL_DEBUG_LEVEL > 2 |
389 |
fprintf(stderr, "hyper is %lx\n", pCppArgs[nPos]); |
390 |
#endif |
391 |
INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow ); |
392 |
break; |
393 |
case typelib_TypeClass_LONG: |
394 |
case typelib_TypeClass_UNSIGNED_LONG: |
395 |
case typelib_TypeClass_ENUM: |
396 |
#if OSL_DEBUG_LEVEL > 2 |
397 |
fprintf(stderr, "long is %x\n", pCppArgs[nPos]); |
398 |
#endif |
399 |
INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow ); |
400 |
break; |
401 |
case typelib_TypeClass_SHORT: |
402 |
case typelib_TypeClass_CHAR: |
403 |
case typelib_TypeClass_UNSIGNED_SHORT: |
404 |
INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow ); |
405 |
break; |
406 |
case typelib_TypeClass_BOOLEAN: |
407 |
case typelib_TypeClass_BYTE: |
408 |
INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack, bOverflow ); |
409 |
break; |
410 |
case typelib_TypeClass_FLOAT: |
411 |
INSERT_FLOAT( pCppArgs[nPos], nFPR, pFPR, pStack, bOverflow ); |
412 |
break; |
413 |
case typelib_TypeClass_DOUBLE: |
414 |
INSERT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, pStack, bOverflow ); |
415 |
break; |
416 |
} |
417 |
|
418 |
// no longer needed |
419 |
TYPELIB_DANGER_RELEASE( pParamTypeDescr ); |
420 |
|
421 |
} |
422 |
else // ptr to complex value | ref |
423 |
{ |
424 |
#if OSL_DEBUG_LEVEL > 2 |
425 |
fprintf(stderr, "complex type again %d\n", rParam.bIn); |
426 |
#endif |
427 |
if (! rParam.bIn) // is pure out |
428 |
{ |
429 |
#if OSL_DEBUG_LEVEL > 2 |
430 |
fprintf(stderr, "complex size is %d\n", pParamTypeDescr->nSize ); |
431 |
#endif |
432 |
// cpp out is constructed mem, uno out is not! |
433 |
uno_constructData( |
434 |
pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ), |
435 |
pParamTypeDescr ); |
436 |
pTempIndices[nTempIndices] = nPos; // default constructed for cpp call |
437 |
// will be released at reconversion |
438 |
ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr; |
439 |
} |
440 |
// is in/inout |
441 |
else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr )) |
442 |
{ |
443 |
#if OSL_DEBUG_LEVEL > 2 |
444 |
fprintf(stderr, "this one\n"); |
445 |
#endif |
446 |
uno_copyAndConvertData( |
447 |
pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ), |
448 |
pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() ); |
449 |
|
450 |
pTempIndices[nTempIndices] = nPos; // has to be reconverted |
451 |
// will be released at reconversion |
452 |
ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr; |
453 |
} |
454 |
else // direct way |
455 |
{ |
456 |
#if OSL_DEBUG_LEVEL > 2 |
457 |
fprintf(stderr, "that one, passing %lx through\n", pUnoArgs[nPos]); |
458 |
#endif |
459 |
pCppArgs[nPos] = pUnoArgs[nPos]; |
460 |
// no longer needed |
461 |
TYPELIB_DANGER_RELEASE( pParamTypeDescr ); |
462 |
} |
463 |
INSERT_INT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack, bOverflow ); |
464 |
} |
465 |
} |
466 |
|
467 |
try |
468 |
{ |
469 |
callVirtualMethod( |
470 |
pAdjustedThisPtr, aVtableSlot.index, |
471 |
pCppReturn, pReturnTypeDescr, |
472 |
pStackStart, ( pStack - pStackStart ), |
473 |
pGPR, nGPR, |
474 |
pFPR, nFPR ); |
475 |
// NO exception occurred... |
476 |
*ppUnoExc = 0; |
477 |
|
478 |
// reconvert temporary params |
479 |
for ( ; nTempIndices--; ) |
480 |
{ |
481 |
sal_Int32 nIndex = pTempIndices[nTempIndices]; |
482 |
typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices]; |
483 |
|
484 |
if (pParams[nIndex].bIn) |
485 |
{ |
486 |
if (pParams[nIndex].bOut) // inout |
487 |
{ |
488 |
uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value |
489 |
uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr, |
490 |
pThis->getBridge()->getCpp2Uno() ); |
491 |
} |
492 |
} |
493 |
else // pure out |
494 |
{ |
495 |
uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr, |
496 |
pThis->getBridge()->getCpp2Uno() ); |
497 |
} |
498 |
// destroy temp cpp param => cpp: every param was constructed |
499 |
uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release ); |
500 |
|
501 |
TYPELIB_DANGER_RELEASE( pParamTypeDescr ); |
502 |
} |
503 |
// return value |
504 |
if (pCppReturn && pUnoReturn != pCppReturn) |
505 |
{ |
506 |
uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr, |
507 |
pThis->getBridge()->getCpp2Uno() ); |
508 |
uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release ); |
509 |
} |
510 |
} |
511 |
catch (...) |
512 |
{ |
513 |
// fill uno exception |
514 |
fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, |
515 |
*ppUnoExc, pThis->getBridge()->getCpp2Uno() ); |
516 |
|
517 |
// temporary params |
518 |
for ( ; nTempIndices--; ) |
519 |
{ |
520 |
sal_Int32 nIndex = pTempIndices[nTempIndices]; |
521 |
// destroy temp cpp param => cpp: every param was constructed |
522 |
uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndices], cpp_release ); |
523 |
TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] ); |
524 |
} |
525 |
// return type |
526 |
if (pReturnTypeDescr) |
527 |
TYPELIB_DANGER_RELEASE( pReturnTypeDescr ); |
528 |
} |
529 |
} |
530 |
|
531 |
} |
532 |
|
533 |
namespace bridges { namespace cpp_uno { namespace shared { |
534 |
|
535 |
void unoInterfaceProxyDispatch( |
536 |
uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr, |
537 |
void * pReturn, void * pArgs[], uno_Any ** ppException ) |
538 |
{ |
539 |
// is my surrogate |
540 |
bridges::cpp_uno::shared::UnoInterfaceProxy * pThis |
541 |
= static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy *> (pUnoI); |
542 |
|
543 |
switch (pMemberDescr->eTypeClass) |
544 |
{ |
545 |
case typelib_TypeClass_INTERFACE_ATTRIBUTE: |
546 |
{ |
547 |
|
548 |
VtableSlot aVtableSlot( |
549 |
getVtableSlot( |
550 |
reinterpret_cast< |
551 |
typelib_InterfaceAttributeTypeDescription const * >( |
552 |
pMemberDescr))); |
553 |
|
554 |
if (pReturn) |
555 |
{ |
556 |
// dependent dispatch |
557 |
cpp_call( |
558 |
pThis, aVtableSlot, |
559 |
((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef, |
560 |
0, 0, // no params |
561 |
pReturn, pArgs, ppException ); |
562 |
} |
563 |
else |
564 |
{ |
565 |
// is SET |
566 |
typelib_MethodParameter aParam; |
567 |
aParam.pTypeRef = |
568 |
((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef; |
569 |
aParam.bIn = sal_True; |
570 |
aParam.bOut = sal_False; |
571 |
|
572 |
typelib_TypeDescriptionReference * pReturnTypeRef = 0; |
573 |
OUString aVoidName("void"); |
574 |
typelib_typedescriptionreference_new( |
575 |
&pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData ); |
576 |
|
577 |
// dependent dispatch |
578 |
aVtableSlot.index += 1; //get then set method |
579 |
cpp_call( |
580 |
pThis, aVtableSlot, |
581 |
pReturnTypeRef, |
582 |
1, &aParam, |
583 |
pReturn, pArgs, ppException ); |
584 |
|
585 |
typelib_typedescriptionreference_release( pReturnTypeRef ); |
586 |
} |
587 |
|
588 |
break; |
589 |
} |
590 |
case typelib_TypeClass_INTERFACE_METHOD: |
591 |
{ |
592 |
|
593 |
VtableSlot aVtableSlot( |
594 |
getVtableSlot( |
595 |
reinterpret_cast< |
596 |
typelib_InterfaceMethodTypeDescription const * >( |
597 |
pMemberDescr))); |
598 |
switch (aVtableSlot.index) |
599 |
{ |
600 |
// standard calls |
601 |
case 1: // acquire uno interface |
602 |
(*pUnoI->acquire)( pUnoI ); |
603 |
*ppException = 0; |
604 |
break; |
605 |
case 2: // release uno interface |
606 |
(*pUnoI->release)( pUnoI ); |
607 |
*ppException = 0; |
608 |
break; |
609 |
case 0: // queryInterface() opt |
610 |
{ |
611 |
typelib_TypeDescription * pTD = 0; |
612 |
TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() ); |
613 |
if (pTD) |
614 |
{ |
615 |
uno_Interface * pInterface = 0; |
616 |
(*pThis->pBridge->getUnoEnv()->getRegisteredInterface)( |
617 |
pThis->pBridge->getUnoEnv(), |
618 |
(void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD ); |
619 |
|
620 |
if (pInterface) |
621 |
{ |
622 |
::uno_any_construct( |
623 |
reinterpret_cast< uno_Any * >( pReturn ), |
624 |
&pInterface, pTD, 0 ); |
625 |
(*pInterface->release)( pInterface ); |
626 |
TYPELIB_DANGER_RELEASE( pTD ); |
627 |
*ppException = 0; |
628 |
break; |
629 |
} |
630 |
TYPELIB_DANGER_RELEASE( pTD ); |
631 |
} |
632 |
} // else perform queryInterface() |
633 |
default: |
634 |
// dependent dispatch |
635 |
cpp_call( |
636 |
pThis, aVtableSlot, |
637 |
((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef, |
638 |
((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams, |
639 |
((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams, |
640 |
pReturn, pArgs, ppException ); |
641 |
} |
642 |
break; |
643 |
} |
644 |
default: |
645 |
{ |
646 |
::com::sun::star::uno::RuntimeException aExc( |
647 |
OUString("illegal member type description!"), |
648 |
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() ); |
649 |
|
650 |
Type const & rExcType = ::getCppuType( &aExc ); |
651 |
// binary identical null reference |
652 |
::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 ); |
653 |
} |
654 |
} |
655 |
} |
656 |
|
657 |
} } } |
658 |
|
659 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |