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()) {
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;
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
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
);
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()->
94 static_cast< UnoInterfaceProxy
* >( pUnoI
)->pBridge
->getUnoEnv(),
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_
)
114 , pBridge( pBridge_
)
116 , pTypeDescr( pTypeDescr_
)
120 ::typelib_typedescription_acquire( (typelib_TypeDescription
*)pTypeDescr
);
121 if (! ((typelib_TypeDescription
*)pTypeDescr
)->bComplete
)
122 ::typelib_typedescription_complete(
123 (typelib_TypeDescription
**)&pTypeDescr
);
125 ((typelib_TypeDescription
*)pTypeDescr
)->bComplete
,
126 "### type is incomplete!" );
128 (*pBridge
->getCppEnv()->registerInterface
)(
129 pBridge
->getCppEnv(), reinterpret_cast< void ** >( &pCppI
), oid
.pData
,
133 acquire
= acquireProxy
;
134 release
= releaseProxy
;
135 pDispatcher
= unoInterfaceProxyDispatch
;
138 UnoInterfaceProxy::~UnoInterfaceProxy()
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */