merge the formfield patch from ooo-build
[ooovba.git] / remotebridges / source / bridge / bridge_provider.cxx
blobb0aab91d082d2004b137758ee9fc4ab2cb18c6b5
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: bridge_provider.cxx,v $
10 * $Revision: 1.7.8.1 $
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 #include <stdio.h>
33 #include "remote_bridge.hxx"
35 #include <osl/diagnose.h>
36 #include <rtl/ustrbuf.hxx>
38 #include <uno/mapping.hxx>
39 #include <uno/environment.h>
41 #include <bridges/remote/remote.h>
43 using namespace ::rtl;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::bridge;
47 namespace remotebridges_bridge
50 OInstanceProviderWrapper::OInstanceProviderWrapper(
51 const Reference <XInstanceProvider > & rProvider,
52 ORemoteBridge * pBridgeCallback ) :
53 m_rProvider( rProvider ),
54 m_nRef( 0 ),
55 m_pBridgeCallback( pBridgeCallback )
57 g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
58 acquire = thisAcquire;
59 release = thisRelease;
60 getInstance = thisGetInstance;
63 OInstanceProviderWrapper::~OInstanceProviderWrapper()
65 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
68 void OInstanceProviderWrapper::thisAcquire( remote_InstanceProvider *p )
70 OInstanceProviderWrapper * m = (OInstanceProviderWrapper *) p;
71 osl_incrementInterlockedCount( &(m->m_nRef ) );
74 void OInstanceProviderWrapper::thisRelease( remote_InstanceProvider *p )
76 OInstanceProviderWrapper * m = ( OInstanceProviderWrapper *) p;
77 if( ! osl_decrementInterlockedCount( &(m->m_nRef ) ) )
79 delete m;
83 static void convertToRemoteRuntimeException ( uno_Any **ppException,
84 const ::rtl::OUString &sMessage,
85 const Reference< XInterface > &rContext,
86 Mapping &map )
89 uno_type_any_construct( *ppException ,
90 0 ,
91 getCppuType( (RuntimeException *)0 ).getTypeLibType() ,
92 0 );
94 typelib_CompoundTypeDescription * pCompType = 0 ;
95 getCppuType( (Exception*)0 ).getDescription( (typelib_TypeDescription **) &pCompType );
96 if( ! ((typelib_TypeDescription *)pCompType)->bComplete )
98 typelib_typedescription_complete( (typelib_TypeDescription**) &pCompType );
101 char *pValue = (char*) (*ppException)->pData;
102 rtl_uString_assign( (rtl_uString ** ) pValue , sMessage.pData );
104 *((remote_Interface**) pValue+pCompType->pMemberOffsets[1]) =
105 (remote_Interface*) map.mapInterface(
106 rContext.get(), getCppuType( &rContext) );
108 typelib_typedescription_release( (typelib_TypeDescription *) pCompType );
111 void OInstanceProviderWrapper::thisGetInstance(
112 remote_InstanceProvider * pProvider ,
113 uno_Environment *pEnvRemote,
114 remote_Interface **ppRemoteI,
115 rtl_uString *pInstanceName,
116 typelib_InterfaceTypeDescription *pType,
117 uno_Any **ppException
120 OInstanceProviderWrapper * m = (OInstanceProviderWrapper *)pProvider;
122 OSL_ASSERT( ppRemoteI );
123 if( *ppRemoteI )
125 (*ppRemoteI)->release( *ppRemoteI );
126 *ppRemoteI = 0;
129 OUString sCppuName( RTL_CONSTASCII_USTRINGPARAM( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) );
131 uno_Environment *pEnvThis = 0;
132 uno_getEnvironment( &pEnvThis ,
133 sCppuName.pData ,
134 0 );
135 Mapping map( pEnvThis , pEnvRemote );
136 pEnvThis->release( pEnvThis );
138 if( OUString( pType->aBase.pTypeName ) ==
139 getCppuType( (Reference<XInterface>*)0).getTypeName() )
143 Reference< XInterface > r = m->m_rProvider->getInstance(
144 OUString( pInstanceName ) );
146 *ppRemoteI = (remote_Interface*) map.mapInterface (
147 r.get(),
148 getCppuType( (Reference< XInterface > *) 0 )
151 if( *ppRemoteI && m->m_pBridgeCallback )
153 m->m_pBridgeCallback->objectMappedSuccesfully();
154 m->m_pBridgeCallback = 0;
156 *ppException = 0;
158 catch( ::com::sun::star::container::NoSuchElementException &e )
160 // NoSuchElementException not specified, so convert it to a runtime exception
161 convertToRemoteRuntimeException(
162 ppException , e.Message.pData , e.Context.get(), map );
164 catch( ::com::sun::star::uno::RuntimeException &e )
166 convertToRemoteRuntimeException(
167 ppException , e.Message.pData , e.Context.get(), map );
171 else
173 OUStringBuffer msg;
174 msg.appendAscii(
175 RTL_CONSTASCII_STRINGPARAM(
176 "getInstance expected XInterface but got "));
177 msg.append(pType->aBase.pTypeName);
178 convertToRemoteRuntimeException(
179 ppException, msg.getStr(), Reference< XInterface >(), map);