Update ooo320-m1
[ooovba.git] / bridges / source / remote / static / helper.cxx
blobcb2f50ba79af9ed592e572f4d1a984635230bc33
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: helper.cxx,v $
10 * $Revision: 1.8 $
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 <rtl/alloc.h>
34 #include <osl/diagnose.h>
36 #include <bridges/remote/helper.hxx>
38 #include <bridges/remote/stub.hxx>
39 #include <bridges/remote/proxy.hxx>
40 #include <bridges/remote/remote.hxx>
42 #include <com/sun/star/uno/Sequence.hxx>
44 using namespace ::rtl;
45 using namespace ::com::sun::star::uno;
47 namespace bridges_remote
50 void SAL_CALL remote_createStub (
51 remote_Interface **ppRemoteI,
52 rtl_uString *pOid ,
53 typelib_TypeDescriptionReference *pTypeRef,
54 uno_Environment *pEnvRemote,
55 ReleaseRemoteCallbackFunc releaseRemoteCallback )
57 typelib_TypeDescription *pType = 0;
58 typelib_typedescriptionreference_getDescription( &pType, pTypeRef );
60 (void) pEnvRemote->pExtEnv->getRegisteredInterface(
61 pEnvRemote->pExtEnv,
62 (void **)ppRemoteI,
63 pOid,
64 (typelib_InterfaceTypeDescription* )pType );
66 if( *ppRemoteI )
68 if( (*ppRemoteI)->acquire == acquireRemote2RemoteStub ) {
70 if( releaseRemoteCallback )
72 // use the callback handler, the bridge wants to send the call immeadiatly
73 releaseRemoteCallback( *ppRemoteI , pOid, pTypeRef , pEnvRemote );
75 else
77 ((::bridges_remote::Remote2RemoteStub *)*ppRemoteI)->releaseRemote();
80 else
82 // Uno2RemoteStub
83 // no release necessary
86 else
88 remote_BridgeImpl *pImpl = ((remote_Context *)pEnvRemote->pContext)->m_pBridgeImpl;
89 *ppRemoteI =
90 new ::bridges_remote::Remote2RemoteStub(
91 pOid,
92 (typelib_InterfaceTypeDescription * ) pType,
93 pEnvRemote,
94 pImpl->m_sendRequest);
96 // ppRemoteI may change during registration
97 pEnvRemote->pExtEnv->registerProxyInterface(
98 pEnvRemote->pExtEnv,
99 (void **) ppRemoteI,
100 freeRemote2RemoteStub,
101 pOid,
102 (typelib_InterfaceTypeDescription * ) pType );
105 typelib_typedescription_release( pType );
108 void SAL_CALL remote_sendQueryInterface(
109 uno_Environment *pEnvRemote,
110 remote_Interface **ppRemoteI,
111 rtl_uString *pOid ,
112 typelib_TypeDescriptionReference *pTypeRef,
113 uno_Any **ppException
116 OSL_ASSERT( ppRemoteI );
118 typelib_InterfaceTypeDescription *pType = 0;
119 typelib_typedescriptionreference_getDescription( (typelib_TypeDescription ** )&pType, pTypeRef );
121 if( *ppRemoteI )
123 (*ppRemoteI)->release( *ppRemoteI );
124 (*ppRemoteI) = 0;
127 remote_BridgeImpl *pImpl = ((remote_Context *)pEnvRemote->pContext)->m_pBridgeImpl;
129 Type type = ::getCppuType( (Reference < XInterface > *)0 );
131 // get type for queryInterface
132 OUString sCompleteMethodName = type.getTypeName();
133 sCompleteMethodName += OUString::createFromAscii("::queryInterface");
135 typelib_InterfaceMemberTypeDescription *pMemberType = 0;
136 typelib_typedescription_getByName(
137 (typelib_TypeDescription **) &pMemberType,
138 sCompleteMethodName.pData );
140 OSL_ASSERT( pMemberType );
142 uno_Any anyInterface;
143 anyInterface.pType = 0;
144 anyInterface.pData = 0;
146 void *pReturn = &anyInterface;
147 void *ppArgs[1];
149 ppArgs[0] = 0;
150 typelib_TypeDescriptionReference *pRef = 0;
151 typelib_typedescriptionreference_new( &pRef ,
152 pType->aBase.eTypeClass,
153 pType->aBase.pTypeName);
155 ppArgs[0] = &pRef;
157 // uno_Any anyException;
158 // uno_Any *pAnyException = &anyException;
160 // do the queryInterface
161 pImpl->m_sendRequest(
162 pEnvRemote,
163 (typelib_TypeDescription * ) pMemberType,
164 pOid,
165 pType,
166 pReturn,
167 ppArgs,
168 ppException );
171 // now release everything
172 typelib_typedescriptionreference_release( pRef );
173 typelib_typedescription_release( (typelib_TypeDescription * ) pMemberType );
175 if( *ppException )
177 *ppRemoteI = 0;
179 else
181 // set out parameter
182 if( typelib_TypeClass_INTERFACE == anyInterface.pType->eTypeClass )
184 *ppRemoteI = ( remote_Interface * ) anyInterface.pReserved;
186 typelib_typedescriptionreference_release( anyInterface.pType );
189 typelib_typedescription_release( (typelib_TypeDescription * ) pType );
193 void SAL_CALL remote_retrieveOidFromProxy(
194 remote_Interface *pRemoteI,
195 rtl_uString **ppOid )
197 if( pRemoteI->acquire == acquireRemote2RemoteStub )
199 // Remote2RemoteStub
200 ::bridges_remote::Remote2RemoteStub *pStub = (::bridges_remote::Remote2RemoteStub * ) pRemoteI;
201 rtl_uString_newFromString( ppOid , pStub->m_sOid.pData );
203 else
205 // Uno2RemoteStub
206 ::bridges_remote::Uno2RemoteStub *pStub = (::bridges_remote::Uno2RemoteStub * ) pRemoteI;
207 rtl_uString_newFromString( ppOid , pStub->m_sOid.pData );
208 pRemoteI->acquire( pRemoteI );