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>
27 #include <cppuhelper/exc_hlp.hxx>
28 #include <o3tl/runtimetooustring.hxx>
29 #include <rtl/ref.hxx>
30 #include <rtl/ustring.hxx>
31 #include <sal/types.h>
32 #include <typelib/typedescription.h>
33 #include <typelib/typedescription.hxx>
35 #include <uno/dispatcher.h>
36 #include <uno/dispatcher.hxx>
38 #include "binaryany.hxx"
46 extern "C" void proxy_acquireInterface(uno_Interface
* pInterface
) {
47 assert(pInterface
!= nullptr);
48 static_cast< Proxy
* >(pInterface
)->do_acquire();
51 extern "C" void proxy_releaseInterface(uno_Interface
* pInterface
) {
52 assert(pInterface
!= nullptr);
53 static_cast< Proxy
* >(pInterface
)->do_release();
56 extern "C" void proxy_dispatchInterface(
57 uno_Interface
* pUnoI
, typelib_TypeDescription
const * pMemberType
,
58 void * pReturn
, void ** pArgs
, uno_Any
** ppException
)
60 assert(pUnoI
!= nullptr);
61 static_cast< Proxy
* >(pUnoI
)->do_dispatch(
62 pMemberType
, pReturn
, pArgs
, ppException
);
68 rtl::Reference
< Bridge
> const & bridge
, OUString oid
,
69 css::uno::TypeDescription type
):
70 bridge_(bridge
), oid_(std::move(oid
)), type_(std::move(type
)), references_(1)
73 acquire
= &proxy_acquireInterface
;
74 release
= &proxy_releaseInterface
;
75 pDispatcher
= &proxy_dispatchInterface
;
79 void Proxy::do_acquire() {
80 if (++references_
== 1) {
81 bridge_
->resurrectProxy(*this);
85 void Proxy::do_release() {
86 if (--references_
== 0) {
87 bridge_
->revokeProxy(*this);
91 void Proxy::do_free() {
92 bridge_
->freeProxy(*this);
96 void Proxy::do_dispatch(
97 typelib_TypeDescription
const * member
, void * returnValue
,
98 void ** arguments
, uno_Any
** exception
) const
102 do_dispatch_throw(member
, returnValue
, arguments
, exception
);
103 } catch (const std::exception
& e
) {
104 throw css::uno::RuntimeException(
105 "caught C++ exception: " + o3tl::runtimeToOUString(e
.what()));
107 } catch (const css::uno::RuntimeException
&) {
108 css::uno::Any
exc(cppu::getCaughtException());
109 uno_copyAndConvertData(
111 (css::uno::TypeDescription(cppu::UnoType
< css::uno::Any
>::get()).
113 bridge_
->getCppToBinaryMapping().get());
118 rtl::Reference
< Bridge
> const & bridge
,
119 css::uno::UnoInterfaceReference
const & object
, OUString
* oid
)
122 return object
.m_pUnoI
->acquire
== &proxy_acquireInterface
&&
123 static_cast< Proxy
* >(object
.m_pUnoI
)->isProxy(bridge
, oid
);
128 void Proxy::do_dispatch_throw(
129 typelib_TypeDescription
const * member
, void * returnValue
,
130 void ** arguments
, uno_Any
** exception
) const
132 //TODO: Optimize queryInterface:
133 assert(member
!= nullptr);
134 bool bSetter
= false;
135 std::vector
< BinaryAny
> inArgs
;
136 switch (member
->eTypeClass
) {
137 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
138 bSetter
= returnValue
== nullptr;
141 css::uno::TypeDescription(
143 typelib_InterfaceAttributeTypeDescription
const * >(
149 case typelib_TypeClass_INTERFACE_METHOD
:
151 typelib_InterfaceMethodTypeDescription
const * mtd
=
153 typelib_InterfaceMethodTypeDescription
const * >(member
);
154 for (sal_Int32 i
= 0; i
!= mtd
->nParams
; ++i
) {
155 if (mtd
->pParams
[i
].bIn
) {
157 css::uno::TypeDescription(mtd
->pParams
[i
].pTypeRef
),
164 assert(false); // this cannot happen
168 std::vector
< BinaryAny
> outArgs
;
169 if (bridge_
->makeCall(
171 css::uno::TypeDescription(
172 const_cast< typelib_TypeDescription
* >(member
)),
173 bSetter
, std::move(inArgs
), &ret
, &outArgs
))
175 assert(ret
.getType().get()->eTypeClass
== typelib_TypeClass_EXCEPTION
);
177 *exception
, ret
.getValue(ret
.getType()), ret
.getType().get(), nullptr);
179 switch (member
->eTypeClass
) {
180 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
182 css::uno::TypeDescription
t(
184 typelib_InterfaceAttributeTypeDescription
const * >(
187 uno_copyData(returnValue
, ret
.getValue(t
), t
.get(), nullptr);
190 case typelib_TypeClass_INTERFACE_METHOD
:
192 typelib_InterfaceMethodTypeDescription
const * mtd
=
194 typelib_InterfaceMethodTypeDescription
const * >(
196 css::uno::TypeDescription
t(mtd
->pReturnTypeRef
);
197 if (t
.get()->eTypeClass
!= typelib_TypeClass_VOID
) {
198 uno_copyData(returnValue
, ret
.getValue(t
), t
.get(), nullptr);
200 std::vector
< BinaryAny
>::iterator
i(outArgs
.begin());
201 for (sal_Int32 j
= 0; j
!= mtd
->nParams
; ++j
) {
202 if (mtd
->pParams
[j
].bOut
) {
203 css::uno::TypeDescription
pt(mtd
->pParams
[j
].pTypeRef
);
204 if (mtd
->pParams
[j
].bIn
) {
205 (void) uno_assignData(
206 arguments
[j
], pt
.get(), i
++->getValue(pt
),
207 pt
.get(), nullptr, nullptr, nullptr);
210 arguments
[j
], i
++->getValue(pt
), pt
.get(), nullptr);
214 assert(i
== outArgs
.end());
218 assert(false); // this cannot happen
221 *exception
= nullptr;
226 rtl::Reference
< Bridge
> const & bridge
, OUString
* oid
) const
228 assert(oid
!= nullptr);
229 if (bridge
== bridge_
) {
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */