LibreOffice Module bridges (master) 1
unointerfaceproxy.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <unointerfaceproxy.hxx>
21
22#include <bridge.hxx>
23
24#include <com/sun/star/uno/XInterface.hpp>
25#include <utility>
26#include <typelib/typedescription.h>
27#include <uno/dispatcher.h>
28
30
31void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
32{
33 UnoInterfaceProxy * pThis =
34 static_cast< UnoInterfaceProxy * >(
35 static_cast< uno_Interface * >( pProxy ) );
36 if (pEnv != pThis->pBridge->getUnoEnv()) {
37 assert(false);
38 }
39
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();
45
46#if OSL_DEBUG_LEVEL > 1
47 *(int *)pProxy = 0xdeadbabe;
48#endif
49 delete pThis;
50}
51
52void acquireProxy(uno_Interface * pUnoI)
53{
54 if (++static_cast< UnoInterfaceProxy * >( pUnoI )->nRef != 1)
55 return;
56
57 // rebirth of proxy zombie
58 // register at uno env
59#if OSL_DEBUG_LEVEL > 1
60 void * pThis = pUnoI;
61#endif
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);
70#endif
71}
72
73void releaseProxy(uno_Interface * pUnoI)
74{
75 if (! --static_cast< UnoInterfaceProxy * >( pUnoI )->nRef )
76 {
77 // revoke from uno env on last release
78 (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
79 revokeInterface)(
80 static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
81 pUnoI );
82 }
83}
84
87 com::sun::star::uno::XInterface * pCppI,
88 typelib_InterfaceTypeDescription * pTypeDescr,
89 OUString const & rOId)
90{
91 return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
92}
93
96 com::sun::star::uno::XInterface * pCppI_,
97 typelib_InterfaceTypeDescription * pTypeDescr_, OUString aOId_)
98 : nRef( 1 )
99 , pBridge( pBridge_ )
100 , pCppI( pCppI_ )
101 , pTypeDescr( pTypeDescr_ )
102 , oid(std::move( aOId_ ))
103{
104 pBridge->acquire();
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);
110 pCppI->acquire();
111 (*pBridge->getCppEnv()->registerInterface)(
112 pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
113 pTypeDescr );
114
115 // uno_Interface
116 acquire = acquireProxy;
117 release = releaseProxy;
118 pDispatcher = unoInterfaceProxyDispatch;
119}
120
122{}
123
124}
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Holding environments and mappings.
Definition: bridge.hxx:54
uno_ExtEnvironment * getCppEnv()
Definition: bridge.hxx:69
uno_ExtEnvironment * getUnoEnv()
Definition: bridge.hxx:70
A uno proxy wrapping a cpp interface.
com::sun::star::uno::XInterface * pCppI
friend void releaseProxy(uno_Interface *pUnoI)
static UnoInterfaceProxy * create(Bridge *pBridge, com::sun::star::uno::XInterface *pCppI, typelib_InterfaceTypeDescription *pTypeDescr, OUString const &rOId)
friend void acquireProxy(uno_Interface *pUnoI)
friend void unoInterfaceProxyDispatch(uno_Interface *pUnoI, typelib_TypeDescription const *pMemberDescr, void *pReturn, void *pArgs[], uno_Any **ppException)
UnoInterfaceProxy(UnoInterfaceProxy const &)=delete
typelib_InterfaceTypeDescription * pTypeDescr
sal_Int32 nRef
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:53
void freeUnoInterfaceProxy(uno_ExtEnvironment *pEnv, void *pProxy)
void releaseProxy(uno_Interface *pUnoI)
void acquireProxy(uno_Interface *pUnoI)