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: helper.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 <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
,
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(
64 (typelib_InterfaceTypeDescription
* )pType
);
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
);
77 ((::bridges_remote::Remote2RemoteStub
*)*ppRemoteI
)->releaseRemote();
83 // no release necessary
88 remote_BridgeImpl
*pImpl
= ((remote_Context
*)pEnvRemote
->pContext
)->m_pBridgeImpl
;
90 new ::bridges_remote::Remote2RemoteStub(
92 (typelib_InterfaceTypeDescription
* ) pType
,
94 pImpl
->m_sendRequest
);
96 // ppRemoteI may change during registration
97 pEnvRemote
->pExtEnv
->registerProxyInterface(
100 freeRemote2RemoteStub
,
102 (typelib_InterfaceTypeDescription
* ) pType
);
105 typelib_typedescription_release( pType
);
108 void SAL_CALL
remote_sendQueryInterface(
109 uno_Environment
*pEnvRemote
,
110 remote_Interface
**ppRemoteI
,
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
);
123 (*ppRemoteI
)->release( *ppRemoteI
);
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
;
150 typelib_TypeDescriptionReference
*pRef
= 0;
151 typelib_typedescriptionreference_new( &pRef
,
152 pType
->aBase
.eTypeClass
,
153 pType
->aBase
.pTypeName
);
157 // uno_Any anyException;
158 // uno_Any *pAnyException = &anyException;
160 // do the queryInterface
161 pImpl
->m_sendRequest(
163 (typelib_TypeDescription
* ) pMemberType
,
171 // now release everything
172 typelib_typedescriptionreference_release( pRef
);
173 typelib_typedescription_release( (typelib_TypeDescription
* ) pMemberType
);
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
)
200 ::bridges_remote::Remote2RemoteStub
*pStub
= (::bridges_remote::Remote2RemoteStub
* ) pRemoteI
;
201 rtl_uString_newFromString( ppOid
, pStub
->m_sOid
.pData
);
206 ::bridges_remote::Uno2RemoteStub
*pStub
= (::bridges_remote::Uno2RemoteStub
* ) pRemoteI
;
207 rtl_uString_newFromString( ppOid
, pStub
->m_sOid
.pData
);
208 pRemoteI
->acquire( pRemoteI
);