1*61dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*61dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*61dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*61dff127SAndrew Rist * distributed with this work for additional information
6*61dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*61dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*61dff127SAndrew Rist * "License"); you may not use this file except in compliance
9*61dff127SAndrew Rist * with the License. You may obtain a copy of the License at
10*61dff127SAndrew Rist *
11*61dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*61dff127SAndrew Rist *
13*61dff127SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*61dff127SAndrew Rist * software distributed under the License is distributed on an
15*61dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61dff127SAndrew Rist * KIND, either express or implied. See the License for the
17*61dff127SAndrew Rist * specific language governing permissions and limitations
18*61dff127SAndrew Rist * under the License.
19*61dff127SAndrew Rist *
20*61dff127SAndrew Rist *************************************************************/
21*61dff127SAndrew Rist
22*61dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
32cdf0e10cSrcweir #include "osl/diagnose.h"
33cdf0e10cSrcweir #include "osl/interlck.h"
34cdf0e10cSrcweir #include "typelib/typedescription.h"
35cdf0e10cSrcweir #include "uno/dispatcher.h"
36cdf0e10cSrcweir
37cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
38cdf0e10cSrcweir
freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv,void * pProxy)39cdf0e10cSrcweir void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
40cdf0e10cSrcweir {
41cdf0e10cSrcweir UnoInterfaceProxy * pThis =
42cdf0e10cSrcweir static_cast< UnoInterfaceProxy * >(
43cdf0e10cSrcweir reinterpret_cast< uno_Interface * >( pProxy ) );
44cdf0e10cSrcweir if (pEnv != pThis->pBridge->getUnoEnv()) {
45cdf0e10cSrcweir OSL_ASSERT(false);
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir (*pThis->pBridge->getCppEnv()->revokeInterface)(
49cdf0e10cSrcweir pThis->pBridge->getCppEnv(), pThis->pCppI );
50cdf0e10cSrcweir pThis->pCppI->release();
51cdf0e10cSrcweir ::typelib_typedescription_release(
52cdf0e10cSrcweir (typelib_TypeDescription *)pThis->pTypeDescr );
53cdf0e10cSrcweir pThis->pBridge->release();
54cdf0e10cSrcweir
55cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
56cdf0e10cSrcweir *(int *)pProxy = 0xdeadbabe;
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir delete pThis;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
acquireProxy(uno_Interface * pUnoI)61cdf0e10cSrcweir void acquireProxy(uno_Interface * pUnoI)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir if (1 == osl_incrementInterlockedCount(
64cdf0e10cSrcweir & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
65cdf0e10cSrcweir {
66cdf0e10cSrcweir // rebirth of proxy zombie
67cdf0e10cSrcweir // register at uno env
68cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
69cdf0e10cSrcweir void * pThis = pUnoI;
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
72cdf0e10cSrcweir registerProxyInterface)(
73cdf0e10cSrcweir static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
74cdf0e10cSrcweir reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy,
75cdf0e10cSrcweir static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData,
76cdf0e10cSrcweir static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
77cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
78cdf0e10cSrcweir OSL_ASSERT( pThis == pUnoI );
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir }
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
releaseProxy(uno_Interface * pUnoI)83cdf0e10cSrcweir void releaseProxy(uno_Interface * pUnoI)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir if (! osl_decrementInterlockedCount(
86cdf0e10cSrcweir & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
87cdf0e10cSrcweir {
88cdf0e10cSrcweir // revoke from uno env on last release
89cdf0e10cSrcweir (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
90cdf0e10cSrcweir revokeInterface)(
91cdf0e10cSrcweir static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
92cdf0e10cSrcweir pUnoI );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
create(bridges::cpp_uno::shared::Bridge * pBridge,com::sun::star::uno::XInterface * pCppI,typelib_InterfaceTypeDescription * pTypeDescr,rtl::OUString const & rOId)96cdf0e10cSrcweir UnoInterfaceProxy * UnoInterfaceProxy::create(
97cdf0e10cSrcweir bridges::cpp_uno::shared::Bridge * pBridge,
98cdf0e10cSrcweir com::sun::star::uno::XInterface * pCppI,
99cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr,
100cdf0e10cSrcweir rtl::OUString const & rOId) SAL_THROW(())
101cdf0e10cSrcweir {
102cdf0e10cSrcweir return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
UnoInterfaceProxy(bridges::cpp_uno::shared::Bridge * pBridge_,com::sun::star::uno::XInterface * pCppI_,typelib_InterfaceTypeDescription * pTypeDescr_,rtl::OUString const & rOId_)105cdf0e10cSrcweir UnoInterfaceProxy::UnoInterfaceProxy(
106cdf0e10cSrcweir bridges::cpp_uno::shared::Bridge * pBridge_,
107cdf0e10cSrcweir com::sun::star::uno::XInterface * pCppI_,
108cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr_, rtl::OUString const & rOId_)
109cdf0e10cSrcweir SAL_THROW(())
110cdf0e10cSrcweir : nRef( 1 )
111cdf0e10cSrcweir , pBridge( pBridge_ )
112cdf0e10cSrcweir , pCppI( pCppI_ )
113cdf0e10cSrcweir , pTypeDescr( pTypeDescr_ )
114cdf0e10cSrcweir , oid( rOId_ )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir pBridge->acquire();
117cdf0e10cSrcweir ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr );
118cdf0e10cSrcweir if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete)
119cdf0e10cSrcweir ::typelib_typedescription_complete(
120cdf0e10cSrcweir (typelib_TypeDescription **)&pTypeDescr );
121cdf0e10cSrcweir OSL_ENSURE(
122cdf0e10cSrcweir ((typelib_TypeDescription *)pTypeDescr)->bComplete,
123cdf0e10cSrcweir "### type is incomplete!" );
124cdf0e10cSrcweir pCppI->acquire();
125cdf0e10cSrcweir (*pBridge->getCppEnv()->registerInterface)(
126cdf0e10cSrcweir pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
127cdf0e10cSrcweir pTypeDescr );
128cdf0e10cSrcweir
129cdf0e10cSrcweir // uno_Interface
130cdf0e10cSrcweir acquire = acquireProxy;
131cdf0e10cSrcweir release = releaseProxy;
132cdf0e10cSrcweir pDispatcher = unoInterfaceProxyDispatch;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
~UnoInterfaceProxy()135cdf0e10cSrcweir UnoInterfaceProxy::~UnoInterfaceProxy()
136cdf0e10cSrcweir {}
137cdf0e10cSrcweir
138cdf0e10cSrcweir } } }
139