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
10*61dff127SAndrew Rist  *
11*61dff127SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*61dff127SAndrew Rist  *
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.
19*61dff127SAndrew Rist  *
20*61dff127SAndrew Rist  *************************************************************/
21*61dff127SAndrew Rist 
22*61dff127SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_bridges.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir #include <cstddef>
29cdf0e10cSrcweir #include <cstring>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
32cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
34cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtables.hxx"
35cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
36cdf0e10cSrcweir #include "com/sun/star/uno/genfunc.hxx"
37cdf0e10cSrcweir #include "osl/diagnose.h"
38cdf0e10cSrcweir #include "rtl/ustring.h"
39cdf0e10cSrcweir #include "rtl/ustring.hxx"
40cdf0e10cSrcweir #include "sal/alloca.h"
41cdf0e10cSrcweir #include "sal/types.h"
42cdf0e10cSrcweir #include "typelib/typeclass.h"
43cdf0e10cSrcweir #include "typelib/typedescription.h"
44cdf0e10cSrcweir #include "uno/any2.h"
45cdf0e10cSrcweir #include "uno/data.h"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include "callvirtualmethod.hxx"
48cdf0e10cSrcweir #include "exceptions.hxx"
49cdf0e10cSrcweir #include "fp.hxx"
50cdf0e10cSrcweir #include "isdirectreturntype.hxx"
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir namespace css = com::sun::star;
55cdf0e10cSrcweir 
storeFpRegsToStruct(typelib_TypeDescription * type,void * data)56cdf0e10cSrcweir void storeFpRegsToStruct(typelib_TypeDescription * type, void * data) {
57cdf0e10cSrcweir     for (typelib_CompoundTypeDescription * t =
58cdf0e10cSrcweir              reinterpret_cast< typelib_CompoundTypeDescription * >(type);
59cdf0e10cSrcweir          t != NULL; t = t->pBaseTypeDescription)
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         for (sal_Int32 i = 0; i < t->nMembers; ++i) {
62cdf0e10cSrcweir             switch (t->ppTypeRefs[i]->eTypeClass) {
63cdf0e10cSrcweir             case typelib_TypeClass_FLOAT:
64cdf0e10cSrcweir                 switch (t->pMemberOffsets[i]) {
65cdf0e10cSrcweir                 case 0:
66cdf0e10cSrcweir                     fp_storef0(reinterpret_cast< float * >(data));
67cdf0e10cSrcweir                     break;
68cdf0e10cSrcweir                 case 4:
69cdf0e10cSrcweir                     fp_storef1(reinterpret_cast< float * >(data) + 1);
70cdf0e10cSrcweir                     break;
71cdf0e10cSrcweir                 case 8:
72cdf0e10cSrcweir                     fp_storef2(reinterpret_cast< float * >(data) + 2);
73cdf0e10cSrcweir                     break;
74cdf0e10cSrcweir                 case 12:
75cdf0e10cSrcweir                     fp_storef3(reinterpret_cast< float * >(data) + 3);
76cdf0e10cSrcweir                     break;
77cdf0e10cSrcweir                 case 16:
78cdf0e10cSrcweir                     fp_storef4(reinterpret_cast< float * >(data) + 4);
79cdf0e10cSrcweir                     break;
80cdf0e10cSrcweir                 case 20:
81cdf0e10cSrcweir                     fp_storef5(reinterpret_cast< float * >(data) + 5);
82cdf0e10cSrcweir                     break;
83cdf0e10cSrcweir                 case 24:
84cdf0e10cSrcweir                     fp_storef6(reinterpret_cast< float * >(data) + 6);
85cdf0e10cSrcweir                     break;
86cdf0e10cSrcweir                 case 28:
87cdf0e10cSrcweir                     fp_storef7(reinterpret_cast< float * >(data) + 7);
88cdf0e10cSrcweir                     break;
89cdf0e10cSrcweir                 default:
90cdf0e10cSrcweir                     OSL_ASSERT(false);
91cdf0e10cSrcweir                     break;
92cdf0e10cSrcweir                 }
93cdf0e10cSrcweir                 break;
94cdf0e10cSrcweir             case typelib_TypeClass_DOUBLE:
95cdf0e10cSrcweir                 switch (t->pMemberOffsets[i]) {
96cdf0e10cSrcweir                 case 0:
97cdf0e10cSrcweir                     fp_stored0(reinterpret_cast< double * >(data));
98cdf0e10cSrcweir                     break;
99cdf0e10cSrcweir                 case 8:
100cdf0e10cSrcweir                     fp_stored2(reinterpret_cast< double * >(data) + 1);
101cdf0e10cSrcweir                     break;
102cdf0e10cSrcweir                 case 16:
103cdf0e10cSrcweir                     fp_stored4(reinterpret_cast< double * >(data) + 2);
104cdf0e10cSrcweir                     break;
105cdf0e10cSrcweir                 case 24:
106cdf0e10cSrcweir                     fp_stored6(reinterpret_cast< double * >(data) + 3);
107cdf0e10cSrcweir                     break;
108cdf0e10cSrcweir                 default:
109cdf0e10cSrcweir                     OSL_ASSERT(false);
110cdf0e10cSrcweir                     break;
111cdf0e10cSrcweir                 }
112cdf0e10cSrcweir                 break;
113cdf0e10cSrcweir             case typelib_TypeClass_STRUCT:
114cdf0e10cSrcweir                 {
115cdf0e10cSrcweir                     typelib_TypeDescription * td = NULL;
116cdf0e10cSrcweir                     TYPELIB_DANGER_GET(&td, t->ppTypeRefs[i]);
117cdf0e10cSrcweir                     storeFpRegsToStruct(td, data);
118cdf0e10cSrcweir                     TYPELIB_DANGER_RELEASE(td);
119cdf0e10cSrcweir                     break;
120cdf0e10cSrcweir                 }
121cdf0e10cSrcweir             }
122cdf0e10cSrcweir         }
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
call(bridges::cpp_uno::shared::UnoInterfaceProxy * proxy,bridges::cpp_uno::shared::VtableSlot slot,typelib_TypeDescriptionReference * returnType,sal_Int32 count,typelib_MethodParameter * parameters,void * returnValue,void ** arguments,uno_Any ** exception)126cdf0e10cSrcweir void call(
127cdf0e10cSrcweir     bridges::cpp_uno::shared::UnoInterfaceProxy * proxy,
128cdf0e10cSrcweir     bridges::cpp_uno::shared::VtableSlot slot,
129cdf0e10cSrcweir     typelib_TypeDescriptionReference * returnType, sal_Int32 count,
130cdf0e10cSrcweir     typelib_MethodParameter * parameters, void * returnValue, void ** arguments,
131cdf0e10cSrcweir     uno_Any ** exception)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     bool directRet = bridges::cpp_uno::cc5_solaris_sparc64::isDirectReturnType(
134cdf0e10cSrcweir         returnType);
135cdf0e10cSrcweir     long * stack = static_cast< long * >(
136cdf0e10cSrcweir         alloca(
137cdf0e10cSrcweir             std::max< sal_Int32 >(count + (directRet ? 1 : 2), 4) *
138cdf0e10cSrcweir             sizeof (long)));
139cdf0e10cSrcweir     sal_Int32 sp = 0;
140cdf0e10cSrcweir     typelib_TypeDescription * rtd = NULL;
141cdf0e10cSrcweir     TYPELIB_DANGER_GET(&rtd, returnType);
142cdf0e10cSrcweir     bool retconv = bridges::cpp_uno::shared::relatesToInterfaceType(rtd);
143cdf0e10cSrcweir     OSL_ASSERT(!(directRet && retconv));
144cdf0e10cSrcweir     void * ret;
145cdf0e10cSrcweir     if (!directRet) {
146cdf0e10cSrcweir         ret = retconv ? alloca(rtd->nSize) : returnValue;
147cdf0e10cSrcweir         stack[sp++] = reinterpret_cast< long >(ret);
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     unsigned long ** thisPtr = reinterpret_cast< unsigned long ** >(
150cdf0e10cSrcweir         proxy->getCppI()) + slot.offset;
151cdf0e10cSrcweir     stack[sp++] = reinterpret_cast< long >(thisPtr);
152cdf0e10cSrcweir     void ** cppArgs = static_cast< void ** >(alloca(count * sizeof (void *)));
153cdf0e10cSrcweir     typelib_TypeDescription ** ptds =
154cdf0e10cSrcweir         static_cast< typelib_TypeDescription ** >(
155cdf0e10cSrcweir             alloca(count * sizeof (typelib_TypeDescription *)));
156cdf0e10cSrcweir     for (sal_Int32 i = 0; i < count; ++i) {
157cdf0e10cSrcweir         if (!parameters[i].bOut &&
158cdf0e10cSrcweir             bridges::cpp_uno::shared::isSimpleType(parameters[i].pTypeRef))
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             cppArgs[i] = NULL;
161cdf0e10cSrcweir             switch (parameters[i].pTypeRef->eTypeClass) {
162cdf0e10cSrcweir             case typelib_TypeClass_BOOLEAN:
163cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_Bool * >(arguments[i]);
164cdf0e10cSrcweir                 break;
165cdf0e10cSrcweir             case typelib_TypeClass_BYTE:
166cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_Int8 * >(arguments[i]);
167cdf0e10cSrcweir                 break;
168cdf0e10cSrcweir             case typelib_TypeClass_SHORT:
169cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_Int16 * >(arguments[i]);
170cdf0e10cSrcweir                 break;
171cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_SHORT:
172cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_uInt16 * >(arguments[i]);
173cdf0e10cSrcweir                 break;
174cdf0e10cSrcweir             case typelib_TypeClass_LONG:
175cdf0e10cSrcweir             case typelib_TypeClass_ENUM:
176cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_Int32 * >(arguments[i]);
177cdf0e10cSrcweir                 break;
178cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_LONG:
179cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_uInt32 * >(arguments[i]);
180cdf0e10cSrcweir                 break;
181cdf0e10cSrcweir             case typelib_TypeClass_HYPER:
182cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_Int64 * >(arguments[i]);
183cdf0e10cSrcweir                 break;
184cdf0e10cSrcweir             case typelib_TypeClass_UNSIGNED_HYPER:
185cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_uInt64 * >(arguments[i]);
186cdf0e10cSrcweir                 break;
187cdf0e10cSrcweir             case typelib_TypeClass_FLOAT:
188cdf0e10cSrcweir                 {
189cdf0e10cSrcweir                     float * f = static_cast< float * >(arguments[i]);
190cdf0e10cSrcweir                     switch (sp) {
191cdf0e10cSrcweir                     case 1:
192cdf0e10cSrcweir                         fp_loadf3(f);
193cdf0e10cSrcweir                         break;
194cdf0e10cSrcweir                     case 2:
195cdf0e10cSrcweir                         fp_loadf5(f);
196cdf0e10cSrcweir                         break;
197cdf0e10cSrcweir                     case 3:
198cdf0e10cSrcweir                         fp_loadf7(f);
199cdf0e10cSrcweir                         break;
200cdf0e10cSrcweir                     case 4:
201cdf0e10cSrcweir                         fp_loadf9(f);
202cdf0e10cSrcweir                         break;
203cdf0e10cSrcweir                     case 5:
204cdf0e10cSrcweir                         fp_loadf11(f);
205cdf0e10cSrcweir                         break;
206cdf0e10cSrcweir                     case 6:
207cdf0e10cSrcweir                         fp_loadf13(f);
208cdf0e10cSrcweir                         break;
209cdf0e10cSrcweir                     case 7:
210cdf0e10cSrcweir                         fp_loadf15(f);
211cdf0e10cSrcweir                         break;
212cdf0e10cSrcweir                     case 8:
213cdf0e10cSrcweir                         fp_loadf17(f);
214cdf0e10cSrcweir                         break;
215cdf0e10cSrcweir                     case 9:
216cdf0e10cSrcweir                         fp_loadf19(f);
217cdf0e10cSrcweir                         break;
218cdf0e10cSrcweir                     case 10:
219cdf0e10cSrcweir                         fp_loadf21(f);
220cdf0e10cSrcweir                         break;
221cdf0e10cSrcweir                     case 11:
222cdf0e10cSrcweir                         fp_loadf23(f);
223cdf0e10cSrcweir                         break;
224cdf0e10cSrcweir                     case 12:
225cdf0e10cSrcweir                         fp_loadf25(f);
226cdf0e10cSrcweir                         break;
227cdf0e10cSrcweir                     case 13:
228cdf0e10cSrcweir                         fp_loadf27(f);
229cdf0e10cSrcweir                         break;
230cdf0e10cSrcweir                     case 14:
231cdf0e10cSrcweir                         fp_loadf29(f);
232cdf0e10cSrcweir                         break;
233cdf0e10cSrcweir                     case 15:
234cdf0e10cSrcweir                         fp_loadf31(f);
235cdf0e10cSrcweir                         break;
236cdf0e10cSrcweir                     default:
237cdf0e10cSrcweir                         reinterpret_cast< float * >(stack + sp)[1] = *f;
238cdf0e10cSrcweir                         break;
239cdf0e10cSrcweir                     }
240cdf0e10cSrcweir                     break;
241cdf0e10cSrcweir                 }
242cdf0e10cSrcweir             case typelib_TypeClass_DOUBLE:
243cdf0e10cSrcweir                 {
244cdf0e10cSrcweir                     double * d = static_cast< double * >(arguments[i]);
245cdf0e10cSrcweir                     switch (sp) {
246cdf0e10cSrcweir                     case 1:
247cdf0e10cSrcweir                         fp_loadd2(d);
248cdf0e10cSrcweir                         break;
249cdf0e10cSrcweir                     case 2:
250cdf0e10cSrcweir                         fp_loadd4(d);
251cdf0e10cSrcweir                         break;
252cdf0e10cSrcweir                     case 3:
253cdf0e10cSrcweir                         fp_loadd6(d);
254cdf0e10cSrcweir                         break;
255cdf0e10cSrcweir                     case 4:
256cdf0e10cSrcweir                         fp_loadd8(d);
257cdf0e10cSrcweir                         break;
258cdf0e10cSrcweir                     case 5:
259cdf0e10cSrcweir                         fp_loadd10(d);
260cdf0e10cSrcweir                         break;
261cdf0e10cSrcweir                     case 6:
262cdf0e10cSrcweir                         fp_loadd12(d);
263cdf0e10cSrcweir                         break;
264cdf0e10cSrcweir                     case 7:
265cdf0e10cSrcweir                         fp_loadd14(d);
266cdf0e10cSrcweir                         break;
267cdf0e10cSrcweir                     case 8:
268cdf0e10cSrcweir                         fp_loadd16(d);
269cdf0e10cSrcweir                         break;
270cdf0e10cSrcweir                     case 9:
271cdf0e10cSrcweir                         fp_loadd18(d);
272cdf0e10cSrcweir                         break;
273cdf0e10cSrcweir                     case 10:
274cdf0e10cSrcweir                         fp_loadd20(d);
275cdf0e10cSrcweir                         break;
276cdf0e10cSrcweir                     case 11:
277cdf0e10cSrcweir                         fp_loadd22(d);
278cdf0e10cSrcweir                         break;
279cdf0e10cSrcweir                     case 12:
280cdf0e10cSrcweir                         fp_loadd24(d);
281cdf0e10cSrcweir                         break;
282cdf0e10cSrcweir                     case 13:
283cdf0e10cSrcweir                         fp_loadd26(d);
284cdf0e10cSrcweir                         break;
285cdf0e10cSrcweir                     case 14:
286cdf0e10cSrcweir                         fp_loadd28(d);
287cdf0e10cSrcweir                         break;
288cdf0e10cSrcweir                     case 15:
289cdf0e10cSrcweir                         fp_loadd30(d);
290cdf0e10cSrcweir                         break;
291cdf0e10cSrcweir                     default:
292cdf0e10cSrcweir                         *reinterpret_cast< double * >(stack + sp) = *d;
293cdf0e10cSrcweir                         break;
294cdf0e10cSrcweir                     }
295cdf0e10cSrcweir                     break;
296cdf0e10cSrcweir                 }
297cdf0e10cSrcweir             case typelib_TypeClass_CHAR:
298cdf0e10cSrcweir                 stack[sp] = *static_cast< sal_Unicode * >(arguments[i]);
299cdf0e10cSrcweir                 break;
300cdf0e10cSrcweir             default:
301cdf0e10cSrcweir                 OSL_ASSERT(false);
302cdf0e10cSrcweir                 break;
303cdf0e10cSrcweir             }
304cdf0e10cSrcweir         } else {
305cdf0e10cSrcweir             typelib_TypeDescription * ptd = NULL;
306cdf0e10cSrcweir             TYPELIB_DANGER_GET(&ptd, parameters[i].pTypeRef);
307cdf0e10cSrcweir             if (!parameters[i].bIn) {
308cdf0e10cSrcweir                 cppArgs[i] = alloca(ptd->nSize);
309cdf0e10cSrcweir                 uno_constructData(cppArgs[i], ptd);
310cdf0e10cSrcweir                 ptds[i] = ptd;
311cdf0e10cSrcweir                 *reinterpret_cast< void ** >(stack + sp) = cppArgs[i];
312cdf0e10cSrcweir             } else if (bridges::cpp_uno::shared::relatesToInterfaceType(ptd)) {
313cdf0e10cSrcweir                 cppArgs[i] = alloca(ptd->nSize);
314cdf0e10cSrcweir                 uno_copyAndConvertData(
315cdf0e10cSrcweir                     cppArgs[i], arguments[i], ptd,
316cdf0e10cSrcweir                     proxy->getBridge()->getUno2Cpp());
317cdf0e10cSrcweir                 ptds[i] = ptd;
318cdf0e10cSrcweir                 *reinterpret_cast< void ** >(stack + sp) = cppArgs[i];
319cdf0e10cSrcweir             } else {
320cdf0e10cSrcweir                 cppArgs[i] = NULL;
321cdf0e10cSrcweir                 *reinterpret_cast< void ** >(stack + sp) = arguments[i];
322cdf0e10cSrcweir                 TYPELIB_DANGER_RELEASE(ptd);
323cdf0e10cSrcweir             }
324cdf0e10cSrcweir         }
325cdf0e10cSrcweir         ++sp;
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir     try {
328cdf0e10cSrcweir         callVirtualMethod(
329cdf0e10cSrcweir             (*thisPtr)[slot.index + 2], stack,
330cdf0e10cSrcweir             std::max< sal_Int32 >(sp - 6, 0) * sizeof (long));
331cdf0e10cSrcweir     } catch (css::uno::Exception &) {
332cdf0e10cSrcweir         void * exc = __Crun::ex_get();
333cdf0e10cSrcweir         char const * name = __Cimpl::ex_name();
334cdf0e10cSrcweir         bridges::cpp_uno::cc5_solaris_sparc64::fillUnoException(
335cdf0e10cSrcweir             exc, name, *exception, proxy->getBridge()->getCpp2Uno());
336cdf0e10cSrcweir         for (sal_Int32 i = 0; i < count; ++i) {
337cdf0e10cSrcweir             if (cppArgs[i] != NULL) {
338cdf0e10cSrcweir                 uno_destructData(
339cdf0e10cSrcweir                     cppArgs[i], ptds[i],
340cdf0e10cSrcweir                     reinterpret_cast< uno_ReleaseFunc >(css::uno::cpp_release));
341cdf0e10cSrcweir                 TYPELIB_DANGER_RELEASE(ptds[i]);
342cdf0e10cSrcweir             }
343cdf0e10cSrcweir         }
344cdf0e10cSrcweir         TYPELIB_DANGER_RELEASE(rtd);
345cdf0e10cSrcweir         return;
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir     *exception = NULL;
348cdf0e10cSrcweir     for (sal_Int32 i = 0; i < count; ++i) {
349cdf0e10cSrcweir         if (cppArgs[i] != NULL) {
350cdf0e10cSrcweir             if (parameters[i].bOut) {
351cdf0e10cSrcweir                 if (parameters[i].bIn) {
352cdf0e10cSrcweir                     uno_destructData(arguments[i], ptds[i], NULL);
353cdf0e10cSrcweir                 }
354cdf0e10cSrcweir                 uno_copyAndConvertData(
355cdf0e10cSrcweir                     arguments[i], cppArgs[i], ptds[i],
356cdf0e10cSrcweir                     proxy->getBridge()->getCpp2Uno());
357cdf0e10cSrcweir             }
358cdf0e10cSrcweir             uno_destructData(
359cdf0e10cSrcweir                 cppArgs[i], ptds[i],
360cdf0e10cSrcweir                 reinterpret_cast< uno_ReleaseFunc >(css::uno::cpp_release));
361cdf0e10cSrcweir             TYPELIB_DANGER_RELEASE(ptds[i]);
362cdf0e10cSrcweir         }
363cdf0e10cSrcweir     }
364cdf0e10cSrcweir     if (directRet) {
365cdf0e10cSrcweir         switch (rtd->eTypeClass) {
366cdf0e10cSrcweir         case typelib_TypeClass_FLOAT:
367cdf0e10cSrcweir             fp_storef0(reinterpret_cast< float * >(returnValue));
368cdf0e10cSrcweir             break;
369cdf0e10cSrcweir         case typelib_TypeClass_DOUBLE:
370cdf0e10cSrcweir             fp_stored0(reinterpret_cast< double * >(returnValue));
371cdf0e10cSrcweir             break;
372cdf0e10cSrcweir         case typelib_TypeClass_STRUCT:
373cdf0e10cSrcweir             storeFpRegsToStruct(rtd, stack);
374cdf0e10cSrcweir             // fall through
375cdf0e10cSrcweir         case typelib_TypeClass_ANY:
376cdf0e10cSrcweir             std::memcpy(returnValue, stack, rtd->nSize);
377cdf0e10cSrcweir             break;
378cdf0e10cSrcweir         default:
379cdf0e10cSrcweir             OSL_ASSERT(rtd->nSize <= 8);
380cdf0e10cSrcweir             std::memcpy(
381cdf0e10cSrcweir                 returnValue,
382cdf0e10cSrcweir                 reinterpret_cast< char * >(stack) + (8 - rtd->nSize),
383cdf0e10cSrcweir                 rtd->nSize);
384cdf0e10cSrcweir             break;
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir     } else if (retconv) {
387cdf0e10cSrcweir         uno_copyAndConvertData(
388cdf0e10cSrcweir             returnValue, ret, rtd, proxy->getBridge()->getCpp2Uno());
389cdf0e10cSrcweir         uno_destructData(
390cdf0e10cSrcweir             ret, rtd,
391cdf0e10cSrcweir             reinterpret_cast< uno_ReleaseFunc >(css::uno::cpp_release));
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir     TYPELIB_DANGER_RELEASE(rtd);
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
399cdf0e10cSrcweir 
unoInterfaceProxyDispatch(uno_Interface * pUnoI,typelib_TypeDescription const * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)400cdf0e10cSrcweir void unoInterfaceProxyDispatch(
401cdf0e10cSrcweir     uno_Interface * pUnoI, typelib_TypeDescription const * pMemberDescr,
402cdf0e10cSrcweir     void * pReturn, void * pArgs[], uno_Any ** ppException)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir     bridges::cpp_uno::shared::UnoInterfaceProxy * proxy =
405cdf0e10cSrcweir         static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
406cdf0e10cSrcweir     switch (pMemberDescr->eTypeClass) {
407cdf0e10cSrcweir     case typelib_TypeClass_INTERFACE_ATTRIBUTE:
408cdf0e10cSrcweir         {
409cdf0e10cSrcweir             VtableSlot slot(
410cdf0e10cSrcweir                 getVtableSlot(
411cdf0e10cSrcweir                     reinterpret_cast<
412cdf0e10cSrcweir                     typelib_InterfaceAttributeTypeDescription const * >(
413cdf0e10cSrcweir                         pMemberDescr)));
414cdf0e10cSrcweir             if (pReturn != NULL) {
415cdf0e10cSrcweir                 // Getter:
416cdf0e10cSrcweir                 call(
417cdf0e10cSrcweir                     proxy, slot,
418cdf0e10cSrcweir                     (reinterpret_cast<
419cdf0e10cSrcweir                      typelib_InterfaceAttributeTypeDescription const * >(
420cdf0e10cSrcweir                          pMemberDescr)->pAttributeTypeRef),
421cdf0e10cSrcweir                     0, NULL, pReturn, pArgs, ppException);
422cdf0e10cSrcweir             } else {
423cdf0e10cSrcweir                 // Setter:
424cdf0e10cSrcweir                 typelib_MethodParameter param = {
425cdf0e10cSrcweir                     NULL,
426cdf0e10cSrcweir                     (reinterpret_cast<
427cdf0e10cSrcweir                      typelib_InterfaceAttributeTypeDescription const * >(
428cdf0e10cSrcweir                          pMemberDescr)->pAttributeTypeRef),
429cdf0e10cSrcweir                     true, false };
430cdf0e10cSrcweir                 typelib_TypeDescriptionReference * rtd = NULL;
431cdf0e10cSrcweir                 typelib_typedescriptionreference_new(
432cdf0e10cSrcweir                     &rtd, typelib_TypeClass_VOID,
433cdf0e10cSrcweir                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("void")).pData);
434cdf0e10cSrcweir                 slot.index += 1;
435cdf0e10cSrcweir                 call(proxy, slot, rtd, 1, &param, pReturn, pArgs, ppException);
436cdf0e10cSrcweir                 typelib_typedescriptionreference_release(rtd);
437cdf0e10cSrcweir             }
438cdf0e10cSrcweir             break;
439cdf0e10cSrcweir         }
440cdf0e10cSrcweir     case typelib_TypeClass_INTERFACE_METHOD:
441cdf0e10cSrcweir         {
442cdf0e10cSrcweir             VtableSlot slot(
443cdf0e10cSrcweir                 getVtableSlot(
444cdf0e10cSrcweir                     reinterpret_cast<
445cdf0e10cSrcweir                     typelib_InterfaceMethodTypeDescription const * >(
446cdf0e10cSrcweir                         pMemberDescr)));
447cdf0e10cSrcweir             switch (slot.index) {
448cdf0e10cSrcweir             case 1:
449cdf0e10cSrcweir                 pUnoI->acquire(pUnoI);
450cdf0e10cSrcweir                 *ppException = NULL;
451cdf0e10cSrcweir                 break;
452cdf0e10cSrcweir             case 2:
453cdf0e10cSrcweir                 pUnoI->release(pUnoI);
454cdf0e10cSrcweir                 *ppException = NULL;
455cdf0e10cSrcweir                 break;
456cdf0e10cSrcweir             case 0:
457cdf0e10cSrcweir                 {
458cdf0e10cSrcweir                     typelib_TypeDescription * td = NULL;
459cdf0e10cSrcweir                     TYPELIB_DANGER_GET(
460cdf0e10cSrcweir                         &td,
461cdf0e10cSrcweir                         reinterpret_cast< css::uno::Type * >(
462cdf0e10cSrcweir                             pArgs[0])->getTypeLibType());
463cdf0e10cSrcweir                     if (td != NULL) {
464cdf0e10cSrcweir                         uno_Interface * ifc = NULL;
465cdf0e10cSrcweir                         proxy->pBridge->getUnoEnv()->getRegisteredInterface(
466cdf0e10cSrcweir                             proxy->pBridge->getUnoEnv(),
467cdf0e10cSrcweir                             reinterpret_cast< void ** >(&ifc),
468cdf0e10cSrcweir                             proxy->oid.pData,
469cdf0e10cSrcweir                             (reinterpret_cast<
470cdf0e10cSrcweir                              typelib_InterfaceTypeDescription * >(td)));
471cdf0e10cSrcweir                         if (ifc != NULL) {
472cdf0e10cSrcweir                             uno_any_construct(
473cdf0e10cSrcweir                                 reinterpret_cast< uno_Any * >(pReturn),
474cdf0e10cSrcweir                                 &ifc, td, NULL);
475cdf0e10cSrcweir                             ifc->release(ifc);
476cdf0e10cSrcweir                             TYPELIB_DANGER_RELEASE(td);
477cdf0e10cSrcweir                             *ppException = NULL;
478cdf0e10cSrcweir                             break;
479cdf0e10cSrcweir                         }
480cdf0e10cSrcweir                         TYPELIB_DANGER_RELEASE(td);
481cdf0e10cSrcweir                     }
482cdf0e10cSrcweir                 } // fall through
483cdf0e10cSrcweir             default:
484cdf0e10cSrcweir                 call(
485cdf0e10cSrcweir                     proxy, slot,
486cdf0e10cSrcweir                     (reinterpret_cast<
487cdf0e10cSrcweir                      typelib_InterfaceMethodTypeDescription const * >(
488cdf0e10cSrcweir                          pMemberDescr)->pReturnTypeRef),
489cdf0e10cSrcweir                     (reinterpret_cast<
490cdf0e10cSrcweir                      typelib_InterfaceMethodTypeDescription const * >(
491cdf0e10cSrcweir                          pMemberDescr)->nParams),
492cdf0e10cSrcweir                     (reinterpret_cast<
493cdf0e10cSrcweir                      typelib_InterfaceMethodTypeDescription const * >(
494cdf0e10cSrcweir                          pMemberDescr)->pParams),
495cdf0e10cSrcweir                     pReturn, pArgs, ppException);
496cdf0e10cSrcweir             }
497cdf0e10cSrcweir             break;
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir     default:
500cdf0e10cSrcweir         OSL_ASSERT(false);
501cdf0e10cSrcweir         break;
502cdf0e10cSrcweir     }
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir } } }
506