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