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 <o3tl/runtimetooustring.hxx>
28 #include <rtl/ref.hxx>
29 #include <rtl/ustring.hxx>
30 #include <sal/types.h>
31 #include <typelib/typedescription.h>
32 #include <typelib/typedescription.hxx>
34 #include <uno/dispatcher.h>
35 #include <uno/dispatcher.hxx>
37 #include "binaryany.hxx"
45 extern "C" void proxy_acquireInterface(uno_Interface
* pInterface
) {
46 assert(pInterface
!= nullptr);
47 static_cast< Proxy
* >(pInterface
)->do_acquire();
50 extern "C" void proxy_releaseInterface(uno_Interface
* pInterface
) {
51 assert(pInterface
!= nullptr);
52 static_cast< Proxy
* >(pInterface
)->do_release();
55 extern "C" void proxy_dispatchInterface(
56 uno_Interface
* pUnoI
, typelib_TypeDescription
const * pMemberType
,
57 void * pReturn
, void ** pArgs
, uno_Any
** ppException
)
59 assert(pUnoI
!= nullptr);
60 static_cast< Proxy
* >(pUnoI
)->do_dispatch(
61 pMemberType
, pReturn
, pArgs
, ppException
);
67 rtl::Reference
< Bridge
> const & bridge
, OUString
const & oid
,
68 css::uno::TypeDescription
const & type
):
69 bridge_(bridge
), oid_(oid
), type_(type
), references_(1)
72 acquire
= &proxy_acquireInterface
;
73 release
= &proxy_releaseInterface
;
74 pDispatcher
= &proxy_dispatchInterface
;
78 void Proxy::do_acquire() {
79 if (++references_
== 1) {
80 bridge_
->resurrectProxy(*this);
84 void Proxy::do_release() {
85 if (--references_
== 0) {
86 bridge_
->revokeProxy(*this);
90 void Proxy::do_free() {
91 bridge_
->freeProxy(*this);
95 void Proxy::do_dispatch(
96 typelib_TypeDescription
const * member
, void * returnValue
,
97 void ** arguments
, uno_Any
** exception
) const
101 do_dispatch_throw(member
, returnValue
, arguments
, exception
);
102 } catch (const std::exception
& e
) {
103 throw css::uno::RuntimeException(
104 "caught C++ exception: " + o3tl::runtimeToOUString(e
.what()));
106 } catch (const css::uno::RuntimeException
&) {
107 css::uno::Any
exc(cppu::getCaughtException());
108 uno_copyAndConvertData(
110 (css::uno::TypeDescription(cppu::UnoType
< css::uno::Any
>::get()).
112 bridge_
->getCppToBinaryMapping().get());
117 rtl::Reference
< Bridge
> const & bridge
,
118 css::uno::UnoInterfaceReference
const & object
, OUString
* oid
)
121 return object
.m_pUnoI
->acquire
== &proxy_acquireInterface
&&
122 static_cast< Proxy
* >(object
.m_pUnoI
)->isProxy(bridge
, oid
);
127 void Proxy::do_dispatch_throw(
128 typelib_TypeDescription
const * member
, void * returnValue
,
129 void ** arguments
, uno_Any
** exception
) const
131 //TODO: Optimize queryInterface:
132 assert(member
!= nullptr);
133 bool bSetter
= false;
134 std::vector
< BinaryAny
> inArgs
;
135 switch (member
->eTypeClass
) {
136 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
137 bSetter
= returnValue
== nullptr;
140 css::uno::TypeDescription(
142 typelib_InterfaceAttributeTypeDescription
const * >(
148 case typelib_TypeClass_INTERFACE_METHOD
:
150 typelib_InterfaceMethodTypeDescription
const * mtd
=
152 typelib_InterfaceMethodTypeDescription
const * >(member
);
153 for (sal_Int32 i
= 0; i
!= mtd
->nParams
; ++i
) {
154 if (mtd
->pParams
[i
].bIn
) {
156 css::uno::TypeDescription(mtd
->pParams
[i
].pTypeRef
),
163 assert(false); // this cannot happen
167 std::vector
< BinaryAny
> outArgs
;
168 if (bridge_
->makeCall(
170 css::uno::TypeDescription(
171 const_cast< typelib_TypeDescription
* >(member
)),
172 bSetter
, inArgs
, &ret
, &outArgs
))
174 assert(ret
.getType().get()->eTypeClass
== typelib_TypeClass_EXCEPTION
);
176 *exception
, ret
.getValue(ret
.getType()), ret
.getType().get(), nullptr);
178 switch (member
->eTypeClass
) {
179 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
181 css::uno::TypeDescription
t(
183 typelib_InterfaceAttributeTypeDescription
const * >(
186 uno_copyData(returnValue
, ret
.getValue(t
), t
.get(), nullptr);
189 case typelib_TypeClass_INTERFACE_METHOD
:
191 typelib_InterfaceMethodTypeDescription
const * mtd
=
193 typelib_InterfaceMethodTypeDescription
const * >(
195 css::uno::TypeDescription
t(mtd
->pReturnTypeRef
);
196 if (t
.get()->eTypeClass
!= typelib_TypeClass_VOID
) {
197 uno_copyData(returnValue
, ret
.getValue(t
), t
.get(), nullptr);
199 std::vector
< BinaryAny
>::iterator
i(outArgs
.begin());
200 for (sal_Int32 j
= 0; j
!= mtd
->nParams
; ++j
) {
201 if (mtd
->pParams
[j
].bOut
) {
202 css::uno::TypeDescription
pt(mtd
->pParams
[j
].pTypeRef
);
203 if (mtd
->pParams
[j
].bIn
) {
204 (void) uno_assignData(
205 arguments
[j
], pt
.get(), i
++->getValue(pt
),
206 pt
.get(), nullptr, nullptr, nullptr);
209 arguments
[j
], i
++->getValue(pt
), pt
.get(), nullptr);
213 assert(i
== outArgs
.end());
217 assert(false); // this cannot happen
220 *exception
= nullptr;
225 rtl::Reference
< Bridge
> const & bridge
, OUString
* oid
) const
227 assert(oid
!= nullptr);
228 if (bridge
== bridge_
) {
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */