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 <typelib/typedescription.h>
26 #include <uno/dispatcher.h>
27 
28 namespace bridges::cpp_uno::shared {
29 
30 void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
31 {
32  UnoInterfaceProxy * pThis =
33  static_cast< UnoInterfaceProxy * >(
34  static_cast< uno_Interface * >( pProxy ) );
35  if (pEnv != pThis->pBridge->getUnoEnv()) {
36  assert(false);
37  }
38 
39  (*pThis->pBridge->getCppEnv()->revokeInterface)(
40  pThis->pBridge->getCppEnv(), pThis->pCppI );
41  pThis->pCppI->release();
42  ::typelib_typedescription_release(&pThis->pTypeDescr->aBase);
43  pThis->pBridge->release();
44 
45 #if OSL_DEBUG_LEVEL > 1
46  *(int *)pProxy = 0xdeadbabe;
47 #endif
48  delete pThis;
49 }
50 
51 void acquireProxy(uno_Interface * pUnoI)
52 {
53  if (++static_cast< UnoInterfaceProxy * >( pUnoI )->nRef != 1)
54  return;
55 
56  // rebirth of proxy zombie
57  // register at uno env
58 #if OSL_DEBUG_LEVEL > 1
59  void * pThis = pUnoI;
60 #endif
61  (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
62  registerProxyInterface)(
63  static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
64  reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy,
65  static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData,
66  static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
67 #if OSL_DEBUG_LEVEL > 1
68  assert(pThis == pUnoI);
69 #endif
70 }
71 
72 void releaseProxy(uno_Interface * pUnoI)
73 {
74  if (! --static_cast< UnoInterfaceProxy * >( pUnoI )->nRef )
75  {
76  // revoke from uno env on last release
77  (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
78  revokeInterface)(
79  static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
80  pUnoI );
81  }
82 }
83 
86  com::sun::star::uno::XInterface * pCppI,
87  typelib_InterfaceTypeDescription * pTypeDescr,
88  OUString const & rOId)
89 {
90  return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
91 }
92 
95  com::sun::star::uno::XInterface * pCppI_,
96  typelib_InterfaceTypeDescription * pTypeDescr_, OUString const & rOId_)
97  : nRef( 1 )
98  , pBridge( pBridge_ )
99  , pCppI( pCppI_ )
100  , pTypeDescr( pTypeDescr_ )
101  , oid( rOId_ )
102 {
103  pBridge->acquire();
104  ::typelib_typedescription_acquire(&pTypeDescr->aBase);
105  if (!pTypeDescr->aBase.bComplete)
106  ::typelib_typedescription_complete(
107  reinterpret_cast<typelib_TypeDescription **>(&pTypeDescr));
108  assert(pTypeDescr->aBase.bComplete);
109  pCppI->acquire();
110  (*pBridge->getCppEnv()->registerInterface)(
111  pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
112  pTypeDescr );
113 
114  // uno_Interface
115  acquire = acquireProxy;
116  release = releaseProxy;
117  pDispatcher = unoInterfaceProxyDispatch;
118 }
119 
121 {}
122 
123 }
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::XInterface * pCppI
friend void unoInterfaceProxyDispatch(uno_Interface *pUnoI, typelib_TypeDescription const *pMemberDescr, void *pReturn, void *pArgs[], uno_Any **ppException)
A uno proxy wrapping a cpp interface.
void freeUnoInterfaceProxy(uno_ExtEnvironment *pEnv, void *pProxy)
static UnoInterfaceProxy * create(Bridge *pBridge, com::sun::star::uno::XInterface *pCppI, typelib_InterfaceTypeDescription *pTypeDescr, OUString const &rOId)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void releaseProxy(uno_Interface *pUnoI)
uno_ExtEnvironment * getUnoEnv()
Definition: bridge.hxx:70
uno_ExtEnvironment * getCppEnv()
Definition: bridge.hxx:69
sal_Int32 nRef
typelib_InterfaceTypeDescription * pTypeDescr
friend void releaseProxy(uno_Interface *pUnoI)
void acquireProxy(uno_Interface *pUnoI)
UnoInterfaceProxy(UnoInterfaceProxy const &)=delete
friend void acquireProxy(uno_Interface *pUnoI)
Holding environments and mappings.
Definition: bridge.hxx:54