1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
26 #include "cppuhelper/exc_hlp.hxx"
27 #include "rtl/ref.hxx"
28 #include "rtl/ustring.hxx"
29 #include "sal/types.h"
30 #include "typelib/typedescription.h"
31 #include "typelib/typedescription.hxx"
33 #include "uno/dispatcher.h"
34 #include "uno/dispatcher.hxx"
36 #include "binaryany.hxx"
44 extern "C" void SAL_CALL
proxy_acquireInterface(uno_Interface
* pInterface
) {
45 assert(pInterface
!= 0);
46 static_cast< Proxy
* >(pInterface
)->do_acquire();
49 extern "C" void SAL_CALL
proxy_releaseInterface(uno_Interface
* pInterface
) {
50 assert(pInterface
!= 0);
51 static_cast< Proxy
* >(pInterface
)->do_release();
54 extern "C" void SAL_CALL
proxy_dispatchInterface(
55 uno_Interface
* pUnoI
, typelib_TypeDescription
const * pMemberType
,
56 void * pReturn
, void ** pArgs
, uno_Any
** ppException
)
59 static_cast< Proxy
* >(pUnoI
)->do_dispatch(
60 pMemberType
, pReturn
, pArgs
, ppException
);
66 rtl::Reference
< Bridge
> const & bridge
, OUString
const & oid
,
67 css::uno::TypeDescription
const & type
):
68 bridge_(bridge
), oid_(oid
), type_(type
), references_(1)
71 acquire
= &proxy_acquireInterface
;
72 release
= &proxy_releaseInterface
;
73 pDispatcher
= &proxy_dispatchInterface
;
76 OUString
Proxy::getOid() const {
80 css::uno::TypeDescription
Proxy::getType() const {
84 void Proxy::do_acquire() {
85 if (osl_atomic_increment(&references_
) == 1) {
86 bridge_
->resurrectProxy(*this);
90 void Proxy::do_release() {
91 if (osl_atomic_decrement(&references_
) == 0) {
92 bridge_
->revokeProxy(*this);
96 void Proxy::do_free() {
97 bridge_
->freeProxy(*this);
101 void Proxy::do_dispatch(
102 typelib_TypeDescription
const * member
, void * returnValue
,
103 void ** arguments
, uno_Any
** exception
) const
107 do_dispatch_throw(member
, returnValue
, arguments
, exception
);
108 } catch (const std::exception
& e
) {
109 throw css::uno::RuntimeException(
110 ("caught C++ exception: " +
112 OString(e
.what()), RTL_TEXTENCODING_ASCII_US
)),
113 css::uno::Reference
< css::uno::XInterface
>());
114 // best-effort string conversion
116 } catch (const css::uno::RuntimeException
&) {
117 css::uno::Any
exc(cppu::getCaughtException());
118 uno_copyAndConvertData(
120 (css::uno::TypeDescription(cppu::UnoType
< css::uno::Any
>::get()).
122 bridge_
->getCppToBinaryMapping().get());
127 rtl::Reference
< Bridge
> const & bridge
,
128 css::uno::UnoInterfaceReference
const & object
, OUString
* oid
)
131 return object
.m_pUnoI
->acquire
== &proxy_acquireInterface
&&
132 static_cast< Proxy
* >(object
.m_pUnoI
)->isProxy(bridge
, oid
);
137 void Proxy::do_dispatch_throw(
138 typelib_TypeDescription
const * member
, void * returnValue
,
139 void ** arguments
, uno_Any
** exception
) const
141 //TODO: Optimize queryInterface:
144 std::vector
< BinaryAny
> inArgs
;
145 switch (member
->eTypeClass
) {
146 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
147 setter
= returnValue
== 0;
151 css::uno::TypeDescription(
153 typelib_InterfaceAttributeTypeDescription
const * >(
159 case typelib_TypeClass_INTERFACE_METHOD
:
161 typelib_InterfaceMethodTypeDescription
const * mtd
=
163 typelib_InterfaceMethodTypeDescription
const * >(member
);
164 for (sal_Int32 i
= 0; i
!= mtd
->nParams
; ++i
) {
165 if (mtd
->pParams
[i
].bIn
) {
168 css::uno::TypeDescription(mtd
->pParams
[i
].pTypeRef
),
175 assert(false); // this cannot happen
179 std::vector
< BinaryAny
> outArgs
;
180 if (bridge_
->makeCall(
182 css::uno::TypeDescription(
183 const_cast< typelib_TypeDescription
* >(member
)),
184 setter
, inArgs
, &ret
, &outArgs
))
186 assert(ret
.getType().get()->eTypeClass
== typelib_TypeClass_EXCEPTION
);
188 *exception
, ret
.getValue(ret
.getType()), ret
.getType().get(), 0);
190 switch (member
->eTypeClass
) {
191 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
193 css::uno::TypeDescription
t(
195 typelib_InterfaceAttributeTypeDescription
const * >(
198 uno_copyData(returnValue
, ret
.getValue(t
), t
.get(), 0);
201 case typelib_TypeClass_INTERFACE_METHOD
:
203 typelib_InterfaceMethodTypeDescription
const * mtd
=
205 typelib_InterfaceMethodTypeDescription
const * >(
207 css::uno::TypeDescription
t(mtd
->pReturnTypeRef
);
208 if (t
.get()->eTypeClass
!= typelib_TypeClass_VOID
) {
209 uno_copyData(returnValue
, ret
.getValue(t
), t
.get(), 0);
211 std::vector
< BinaryAny
>::iterator
i(outArgs
.begin());
212 for (sal_Int32 j
= 0; j
!= mtd
->nParams
; ++j
) {
213 if (mtd
->pParams
[j
].bOut
) {
214 css::uno::TypeDescription
pt(mtd
->pParams
[j
].pTypeRef
);
215 if (mtd
->pParams
[j
].bIn
) {
217 arguments
[j
], pt
.get(), i
++->getValue(pt
),
221 arguments
[j
], i
++->getValue(pt
), pt
.get(), 0);
225 assert(i
== outArgs
.end());
229 assert(false); // this cannot happen
237 rtl::Reference
< Bridge
> const & bridge
, OUString
* oid
) const
240 if (bridge
== bridge_
) {
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */