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