1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_bridges.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
36*cdf0e10cSrcweir #include "osl/diagnose.h"
37*cdf0e10cSrcweir #include "osl/interlck.h"
38*cdf0e10cSrcweir #include "typelib/typedescription.h"
39*cdf0e10cSrcweir #include "uno/dispatcher.h"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir     UnoInterfaceProxy * pThis =
46*cdf0e10cSrcweir         static_cast< UnoInterfaceProxy * >(
47*cdf0e10cSrcweir             reinterpret_cast< uno_Interface * >( pProxy ) );
48*cdf0e10cSrcweir     if (pEnv != pThis->pBridge->getUnoEnv()) {
49*cdf0e10cSrcweir         OSL_ASSERT(false);
50*cdf0e10cSrcweir     }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir     (*pThis->pBridge->getCppEnv()->revokeInterface)(
53*cdf0e10cSrcweir         pThis->pBridge->getCppEnv(), pThis->pCppI );
54*cdf0e10cSrcweir     pThis->pCppI->release();
55*cdf0e10cSrcweir     ::typelib_typedescription_release(
56*cdf0e10cSrcweir         (typelib_TypeDescription *)pThis->pTypeDescr );
57*cdf0e10cSrcweir     pThis->pBridge->release();
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
60*cdf0e10cSrcweir     *(int *)pProxy = 0xdeadbabe;
61*cdf0e10cSrcweir #endif
62*cdf0e10cSrcweir     delete pThis;
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir void acquireProxy(uno_Interface * pUnoI)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     if (1 == osl_incrementInterlockedCount(
68*cdf0e10cSrcweir             & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
69*cdf0e10cSrcweir     {
70*cdf0e10cSrcweir         // rebirth of proxy zombie
71*cdf0e10cSrcweir         // register at uno env
72*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
73*cdf0e10cSrcweir         void * pThis = pUnoI;
74*cdf0e10cSrcweir #endif
75*cdf0e10cSrcweir         (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
76*cdf0e10cSrcweir          registerProxyInterface)(
77*cdf0e10cSrcweir              static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
78*cdf0e10cSrcweir              reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy,
79*cdf0e10cSrcweir              static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData,
80*cdf0e10cSrcweir              static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
81*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
82*cdf0e10cSrcweir         OSL_ASSERT( pThis == pUnoI );
83*cdf0e10cSrcweir #endif
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir void releaseProxy(uno_Interface * pUnoI)
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     if (! osl_decrementInterlockedCount(
90*cdf0e10cSrcweir             & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         // revoke from uno env on last release
93*cdf0e10cSrcweir         (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
94*cdf0e10cSrcweir          revokeInterface)(
95*cdf0e10cSrcweir              static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
96*cdf0e10cSrcweir              pUnoI );
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir UnoInterfaceProxy * UnoInterfaceProxy::create(
101*cdf0e10cSrcweir     bridges::cpp_uno::shared::Bridge * pBridge,
102*cdf0e10cSrcweir     com::sun::star::uno::XInterface * pCppI,
103*cdf0e10cSrcweir     typelib_InterfaceTypeDescription * pTypeDescr,
104*cdf0e10cSrcweir     rtl::OUString const & rOId) SAL_THROW(())
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir     return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir UnoInterfaceProxy::UnoInterfaceProxy(
110*cdf0e10cSrcweir     bridges::cpp_uno::shared::Bridge * pBridge_,
111*cdf0e10cSrcweir     com::sun::star::uno::XInterface * pCppI_,
112*cdf0e10cSrcweir     typelib_InterfaceTypeDescription * pTypeDescr_, rtl::OUString const & rOId_)
113*cdf0e10cSrcweir     SAL_THROW(())
114*cdf0e10cSrcweir     : nRef( 1 )
115*cdf0e10cSrcweir     , pBridge( pBridge_ )
116*cdf0e10cSrcweir     , pCppI( pCppI_ )
117*cdf0e10cSrcweir     , pTypeDescr( pTypeDescr_ )
118*cdf0e10cSrcweir     , oid( rOId_ )
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     pBridge->acquire();
121*cdf0e10cSrcweir     ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr );
122*cdf0e10cSrcweir     if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete)
123*cdf0e10cSrcweir         ::typelib_typedescription_complete(
124*cdf0e10cSrcweir             (typelib_TypeDescription **)&pTypeDescr );
125*cdf0e10cSrcweir     OSL_ENSURE(
126*cdf0e10cSrcweir         ((typelib_TypeDescription *)pTypeDescr)->bComplete,
127*cdf0e10cSrcweir         "### type is incomplete!" );
128*cdf0e10cSrcweir     pCppI->acquire();
129*cdf0e10cSrcweir     (*pBridge->getCppEnv()->registerInterface)(
130*cdf0e10cSrcweir         pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
131*cdf0e10cSrcweir         pTypeDescr );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     // uno_Interface
134*cdf0e10cSrcweir     acquire = acquireProxy;
135*cdf0e10cSrcweir     release = releaseProxy;
136*cdf0e10cSrcweir     pDispatcher = unoInterfaceProxyDispatch;
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir UnoInterfaceProxy::~UnoInterfaceProxy()
140*cdf0e10cSrcweir {}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir } } }
143