Line data Source code
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 "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
21 :
22 : #include "bridges/cpp_uno/shared/bridge.hxx"
23 :
24 : #include "com/sun/star/uno/XInterface.hpp"
25 : #include "osl/diagnose.h"
26 : #include "osl/interlck.h"
27 : #include "typelib/typedescription.h"
28 : #include "uno/dispatcher.h"
29 :
30 : namespace bridges { namespace cpp_uno { namespace shared {
31 :
32 163547 : void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
33 : {
34 : UnoInterfaceProxy * pThis =
35 : static_cast< UnoInterfaceProxy * >(
36 163547 : reinterpret_cast< uno_Interface * >( pProxy ) );
37 163547 : if (pEnv != pThis->pBridge->getUnoEnv()) {
38 : OSL_ASSERT(false);
39 : }
40 :
41 163547 : (*pThis->pBridge->getCppEnv()->revokeInterface)(
42 163547 : pThis->pBridge->getCppEnv(), pThis->pCppI );
43 163547 : pThis->pCppI->release();
44 : ::typelib_typedescription_release(
45 163547 : (typelib_TypeDescription *)pThis->pTypeDescr );
46 163547 : pThis->pBridge->release();
47 :
48 : #if OSL_DEBUG_LEVEL > 1
49 : *(int *)pProxy = 0xdeadbabe;
50 : #endif
51 163547 : delete pThis;
52 163547 : }
53 :
54 2406047 : void acquireProxy(uno_Interface * pUnoI)
55 : {
56 2406047 : if (1 == osl_atomic_increment(
57 : & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
58 : {
59 : // rebirth of proxy zombie
60 : // register at uno env
61 : #if OSL_DEBUG_LEVEL > 1
62 : void * pThis = pUnoI;
63 : #endif
64 4868 : (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
65 : registerProxyInterface)(
66 : static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
67 : reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy,
68 : static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData,
69 4868 : static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
70 : #if OSL_DEBUG_LEVEL > 1
71 : OSL_ASSERT( pThis == pUnoI );
72 : #endif
73 : }
74 2406047 : }
75 :
76 2569617 : void releaseProxy(uno_Interface * pUnoI)
77 : {
78 2569617 : if (! osl_atomic_decrement(
79 : & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
80 : {
81 : // revoke from uno env on last release
82 169151 : (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
83 : revokeInterface)(
84 : static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
85 169151 : pUnoI );
86 : }
87 2569617 : }
88 :
89 165183 : UnoInterfaceProxy * UnoInterfaceProxy::create(
90 : bridges::cpp_uno::shared::Bridge * pBridge,
91 : com::sun::star::uno::XInterface * pCppI,
92 : typelib_InterfaceTypeDescription * pTypeDescr,
93 : OUString const & rOId)
94 : {
95 165183 : return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
96 : }
97 :
98 165183 : UnoInterfaceProxy::UnoInterfaceProxy(
99 : bridges::cpp_uno::shared::Bridge * pBridge_,
100 : com::sun::star::uno::XInterface * pCppI_,
101 : typelib_InterfaceTypeDescription * pTypeDescr_, OUString const & rOId_)
102 : : nRef( 1 )
103 : , pBridge( pBridge_ )
104 : , pCppI( pCppI_ )
105 : , pTypeDescr( pTypeDescr_ )
106 165183 : , oid( rOId_ )
107 : {
108 165183 : pBridge->acquire();
109 165183 : ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr );
110 165183 : if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete)
111 : ::typelib_typedescription_complete(
112 2658 : (typelib_TypeDescription **)&pTypeDescr );
113 : OSL_ENSURE(
114 : ((typelib_TypeDescription *)pTypeDescr)->bComplete,
115 : "### type is incomplete!" );
116 165183 : pCppI->acquire();
117 165183 : (*pBridge->getCppEnv()->registerInterface)(
118 : pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
119 165183 : pTypeDescr );
120 :
121 : // uno_Interface
122 165183 : acquire = acquireProxy;
123 165183 : release = releaseProxy;
124 165183 : pDispatcher = unoInterfaceProxyDispatch;
125 165183 : }
126 :
127 163547 : UnoInterfaceProxy::~UnoInterfaceProxy()
128 163547 : {}
129 :
130 : } } }
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|