1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mapping.cxx,v $
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"
33 #include <osl/diagnose.h>
35 #include <bridges/remote/proxy.hxx>
36 #include <bridges/remote/stub.hxx>
37 #include <bridges/remote/counter.hxx>
38 #include <bridges/remote/mapping.hxx>
40 using namespace bridges_remote
;
44 static void SAL_CALL
thisAcquire( uno_Mapping
*pMap
)
46 RemoteMapping
*p
= SAL_REINTERPRET_CAST( RemoteMapping
* , pMap
);
47 if( 1 == osl_incrementInterlockedCount( &(p
->m_nRef
) ) )
49 if( remoteToUno
== pMap
->mapInterface
)
51 uno_registerMapping( &pMap
,
55 p
->m_sPurpose
.pData
);
59 uno_registerMapping( &pMap
,
63 p
->m_sPurpose
.pData
);
69 static void SAL_CALL
thisRelease( uno_Mapping
*pMap
)
71 RemoteMapping
*p
= SAL_REINTERPRET_CAST( RemoteMapping
* , pMap
);
72 if (! osl_decrementInterlockedCount( &(p
->m_nRef
) ))
74 uno_revokeMapping( pMap
);
80 namespace bridges_remote
{
82 void remoteToUno( uno_Mapping
*pMapping
, void **ppUnoI
, void *pRemoteI
,
83 typelib_InterfaceTypeDescription
*pTypeDescr
)
85 remote_Mapping
*pRemoteMapping
= ( remote_Mapping
* ) pMapping
;
87 OSL_ASSERT( ppUnoI
&& pTypeDescr
);
90 ((uno_Interface
*)*ppUnoI
)->release( (uno_Interface
*)*ppUnoI
);
94 if (pRemoteI
&& pTypeDescr
)
96 // get object id of interface to be wrapped
97 rtl_uString
* pOid
= 0;
98 pRemoteMapping
->pEnvRemote
->pExtEnv
->getObjectIdentifier(
99 pRemoteMapping
->pEnvRemote
->pExtEnv
,
109 // try to get any known interface from target environment
110 pRemoteMapping
->pEnvUno
->pExtEnv
->getRegisteredInterface(
111 pRemoteMapping
->pEnvUno
->pExtEnv
,
116 if ( ! *ppUnoI
) // already existing interface
118 // try to publish a new proxy; proxy may be exchanged during registration
119 *ppUnoI
= new Remote2UnoProxy(
120 ( remote_Interface
* ) pRemoteI
,
123 pRemoteMapping
->pEnvUno
,
124 pRemoteMapping
->pEnvRemote
);
126 pRemoteMapping
->pEnvUno
->pExtEnv
->registerProxyInterface(
127 pRemoteMapping
->pEnvUno
->pExtEnv
,
133 OSL_ASSERT( *ppUnoI
);
135 rtl_uString_release( pOid
);
139 void unoToRemote( uno_Mapping
*pMapping
, void **ppRemoteI
, void *pUnoI
,
140 typelib_InterfaceTypeDescription
*pTypeDescr
)
142 remote_Mapping
*pRemoteMapping
= ( remote_Mapping
* ) pMapping
;
143 OSL_ASSERT( ppRemoteI
&& pTypeDescr
);
146 ((remote_Interface
*)*ppRemoteI
)->release( (remote_Interface
*)*ppRemoteI
);
149 if (pUnoI
&& pTypeDescr
)
151 // get object id of interface to be wrapped
152 rtl_uString
* pOid
= 0;
153 pRemoteMapping
->pEnvUno
->pExtEnv
->getObjectIdentifier(
154 pRemoteMapping
->pEnvUno
->pExtEnv
,
164 pRemoteMapping
->pEnvRemote
->pExtEnv
->getRegisteredInterface(
165 pRemoteMapping
->pEnvRemote
->pExtEnv
,
172 // try to publish a new proxy;
173 *ppRemoteI
= new Uno2RemoteStub(
174 ( uno_Interface
* ) pUnoI
,
177 pRemoteMapping
->pEnvUno
,
178 pRemoteMapping
->pEnvRemote
);
180 // note : ppRemoteI may change during registration
181 pRemoteMapping
->pEnvRemote
->pExtEnv
->registerProxyInterface(
182 pRemoteMapping
->pEnvRemote
->pExtEnv
,
189 rtl_uString_release( pOid
);
193 void freeRemoteMapping(uno_Mapping
* mapping
) {
194 delete reinterpret_cast< RemoteMapping
* >(mapping
);
197 RemoteMapping::RemoteMapping( uno_Environment
*pEnvUno_
,
198 uno_Environment
*pEnvRemote_
,
199 uno_MapInterfaceFunc func
,
200 const ::rtl::OUString sPurpose
) :
202 m_sPurpose( sPurpose
)
205 pEnvRemote
= pEnvRemote_
;
207 pEnvUno
->acquire( pEnvUno
);
208 pEnvRemote
->acquire( pEnvRemote
);
210 aBase
.mapInterface
= func
;
211 aBase
.acquire
= thisAcquire
;
212 aBase
.release
= thisRelease
;
215 RemoteMapping::~RemoteMapping( )
217 pEnvUno
->release( pEnvUno
);
218 pEnvRemote
->release( pEnvRemote
);