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 <unointerfaceproxy.hxx>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <typelib/typedescription.h>
27 #include <uno/dispatcher.h>
29 namespace bridges::cpp_uno::shared
{
31 void freeUnoInterfaceProxy(uno_ExtEnvironment
* pEnv
, void * pProxy
)
33 UnoInterfaceProxy
* pThis
=
34 static_cast< UnoInterfaceProxy
* >(
35 static_cast< uno_Interface
* >( pProxy
) );
36 if (pEnv
!= pThis
->pBridge
->getUnoEnv()) {
40 (*pThis
->pBridge
->getCppEnv()->revokeInterface
)(
41 pThis
->pBridge
->getCppEnv(), pThis
->pCppI
);
42 pThis
->pCppI
->release();
43 ::typelib_typedescription_release(&pThis
->pTypeDescr
->aBase
);
44 pThis
->pBridge
->release();
46 #if OSL_DEBUG_LEVEL > 1
47 *(int *)pProxy
= 0xdeadbabe;
52 void acquireProxy(uno_Interface
* pUnoI
)
54 if (++static_cast< UnoInterfaceProxy
* >( pUnoI
)->nRef
!= 1)
57 // rebirth of proxy zombie
58 // register at uno env
59 #if OSL_DEBUG_LEVEL > 1
62 (*static_cast< UnoInterfaceProxy
* >( pUnoI
)->pBridge
->getUnoEnv()->
63 registerProxyInterface
)(
64 static_cast< UnoInterfaceProxy
* >( pUnoI
)->pBridge
->getUnoEnv(),
65 reinterpret_cast< void ** >( &pUnoI
), freeUnoInterfaceProxy
,
66 static_cast< UnoInterfaceProxy
* >( pUnoI
)->oid
.pData
,
67 static_cast< UnoInterfaceProxy
* >( pUnoI
)->pTypeDescr
);
68 #if OSL_DEBUG_LEVEL > 1
69 assert(pThis
== pUnoI
);
73 void releaseProxy(uno_Interface
* pUnoI
)
75 if (! --static_cast< UnoInterfaceProxy
* >( pUnoI
)->nRef
)
77 // revoke from uno env on last release
78 (*static_cast< UnoInterfaceProxy
* >( pUnoI
)->pBridge
->getUnoEnv()->
80 static_cast< UnoInterfaceProxy
* >( pUnoI
)->pBridge
->getUnoEnv(),
85 UnoInterfaceProxy
* UnoInterfaceProxy::create(
86 bridges::cpp_uno::shared::Bridge
* pBridge
,
87 css::uno::XInterface
* pCppI
,
88 typelib_InterfaceTypeDescription
* pTypeDescr
,
89 OUString
const & rOId
)
91 return new UnoInterfaceProxy(pBridge
, pCppI
, pTypeDescr
, rOId
);
94 UnoInterfaceProxy::UnoInterfaceProxy(
95 bridges::cpp_uno::shared::Bridge
* pBridge_
,
96 css::uno::XInterface
* pCppI_
,
97 typelib_InterfaceTypeDescription
* pTypeDescr_
, OUString aOId_
)
101 , pTypeDescr( pTypeDescr_
)
102 , oid(std::move( aOId_
))
105 ::typelib_typedescription_acquire(&pTypeDescr
->aBase
);
106 if (!pTypeDescr
->aBase
.bComplete
)
107 ::typelib_typedescription_complete(
108 reinterpret_cast<typelib_TypeDescription
**>(&pTypeDescr
));
109 assert(pTypeDescr
->aBase
.bComplete
);
111 (*pBridge
->getCppEnv()->registerInterface
)(
112 pBridge
->getCppEnv(), reinterpret_cast< void ** >( &pCppI
), oid
.pData
,
116 acquire
= acquireProxy
;
117 release
= releaseProxy
;
118 pDispatcher
= unoInterfaceProxyDispatch
;
121 UnoInterfaceProxy::~UnoInterfaceProxy()
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */