diff options
author | Jörg Budischewski <jbu@openoffice.org> | 2000-09-28 07:47:31 +0000 |
---|---|---|
committer | Jörg Budischewski <jbu@openoffice.org> | 2000-09-28 07:47:31 +0000 |
commit | a79f59580613591fb3e0f91a53dcc4e1c3bd4265 (patch) | |
tree | 8f0c1fd9d8ecb6860a1a923b09e92bb121147fae /remotebridges/source | |
parent | c968024c4b1302b224ac8d03f80c74106266c509 (diff) |
moved here from ../iiop
Diffstat (limited to 'remotebridges/source')
-rw-r--r-- | remotebridges/source/bridge/bridge_connection.cxx | 164 | ||||
-rw-r--r-- | remotebridges/source/bridge/bridge_connection.hxx | 90 | ||||
-rw-r--r-- | remotebridges/source/bridge/bridge_provider.cxx | 167 | ||||
-rw-r--r-- | remotebridges/source/bridge/makefile.mk | 107 | ||||
-rw-r--r-- | remotebridges/source/bridge/remote_bridge.cxx | 468 | ||||
-rw-r--r-- | remotebridges/source/bridge/remote_bridge.hxx | 179 | ||||
-rw-r--r-- | remotebridges/source/bridge/remotebridge.xml | 59 |
7 files changed, 1234 insertions, 0 deletions
diff --git a/remotebridges/source/bridge/bridge_connection.cxx b/remotebridges/source/bridge/bridge_connection.cxx new file mode 100644 index 000000000000..4a1744e3d3ae --- /dev/null +++ b/remotebridges/source/bridge/bridge_connection.cxx @@ -0,0 +1,164 @@ +/************************************************************************* + * + * $RCSfile: bridge_connection.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jbu $ $Date: 2000-09-28 08:47:30 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include "bridge_connection.hxx" +#include <rtl/byteseq.hxx> +#include <string.h> + +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::connection; + +namespace remotebridges_bridge +{ + OConnectionWrapper::OConnectionWrapper( const Reference < XConnection > &r ) : + m_r( r ), + m_nRef( 0 ) + { + acquire = thisAcquire; + release = thisRelease; + read = thisRead; + write = thisWrite; + flush = thisFlush; + close = thisClose; + } + + + void OConnectionWrapper::thisAcquire( remote_Connection *p) + { + OConnectionWrapper * m = ( OConnectionWrapper * ) p; + osl_incrementInterlockedCount( &(m->m_nRef ) ); + } + + void OConnectionWrapper::thisRelease( remote_Connection * p) + { + OConnectionWrapper * m = ( OConnectionWrapper * ) p; + if( ! osl_decrementInterlockedCount( &( m->m_nRef ) ) ) + { + delete m; + } + } + + sal_Int32 OConnectionWrapper::thisRead( remote_Connection *p , sal_Int8 *pDest , sal_Int32 nSize ) + { + // guard the C-Code + OConnectionWrapper * m = ( OConnectionWrapper * ) p; + try + { + // TODO possible optimization : give + ::rtl::ByteSequence seq( nSize , ::rtl::BYTESEQ_NODEFAULT ); + sal_Int32 nRead = m->m_r->read( *(Sequence<sal_Int8>*)&seq , nSize ); + memcpy( pDest , seq.getConstArray() , nRead ); + return nRead; + } + catch ( Exception & ) + { + return 0; + } + + } + + sal_Int32 OConnectionWrapper::thisWrite( remote_Connection *p , + const sal_Int8 *pSource , + sal_Int32 nSize ) + { + // guard the C-Code + OConnectionWrapper * m = ( OConnectionWrapper * ) p; + try + { + Sequence< sal_Int8 > seq( pSource , nSize ); + m->m_r->write( seq ); + return nSize; + } + catch ( Exception & ) + { + return 0; + } + } + + void OConnectionWrapper::thisFlush( remote_Connection *p ) + { + // guard the C-Code + try + { + OConnectionWrapper * m = ( OConnectionWrapper * ) p; + m->m_r->flush(); + } + catch ( Exception & ) + { + } + } + + void OConnectionWrapper::thisClose( remote_Connection * p) + { + // guard the C-Code + try + { + OConnectionWrapper * m = ( OConnectionWrapper * ) p; + m->m_r->close(); + } + catch( Exception & ) + { + + } + } +} + + + diff --git a/remotebridges/source/bridge/bridge_connection.hxx b/remotebridges/source/bridge/bridge_connection.hxx new file mode 100644 index 000000000000..d6f190c13d16 --- /dev/null +++ b/remotebridges/source/bridge/bridge_connection.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * $RCSfile: bridge_connection.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jbu $ $Date: 2000-09-28 08:47:30 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <osl/interlck.h> + +#include <bridges/remote/connection.h> + +#include <com/sun/star/connection/XConnection.hpp> + +namespace remotebridges_bridge +{ + + class OConnectionWrapper : + public remote_Connection + { + public: + OConnectionWrapper( const ::com::sun::star::uno::Reference < + ::com::sun::star::connection::XConnection > & ); + + static void SAL_CALL thisAcquire( remote_Connection *); + static void SAL_CALL thisRelease( remote_Connection *); + static sal_Int32 SAL_CALL thisRead( remote_Connection * , sal_Int8 *pDest , sal_Int32 nSize ); + static sal_Int32 SAL_CALL thisWrite( remote_Connection * , + const sal_Int8 *pSource , + sal_Int32 nSize ); + static void SAL_CALL thisFlush( remote_Connection * ); + static void SAL_CALL thisClose( remote_Connection * ); + + ::com::sun::star::uno::Reference < ::com::sun::star::connection::XConnection > m_r; + oslInterlockedCount m_nRef; + }; +} + diff --git a/remotebridges/source/bridge/bridge_provider.cxx b/remotebridges/source/bridge/bridge_provider.cxx new file mode 100644 index 000000000000..10b1b6806718 --- /dev/null +++ b/remotebridges/source/bridge/bridge_provider.cxx @@ -0,0 +1,167 @@ +/************************************************************************* + * + * $RCSfile: bridge_provider.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jbu $ $Date: 2000-09-28 08:47:30 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> + +#include "remote_bridge.hxx" + +#include <osl/diagnose.h> + +#include <uno/mapping.hxx> +#include <uno/environment.h> + +#include <bridges/remote/remote.h> + +using namespace ::rtl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::bridge; + +namespace remotebridges_bridge +{ + + OInstanceProviderWrapper::OInstanceProviderWrapper( + const Reference <XInstanceProvider > & rProvider, + ORemoteBridge * pBridgeCallback ) : + m_rProvider( rProvider ), + m_pBridgeCallback( pBridgeCallback ), + m_nRef( 0 ) + { + acquire = thisAcquire; + release = thisRelease; + getInstance = thisGetInstance; + } + + OInstanceProviderWrapper::~OInstanceProviderWrapper() + { +#ifdef VERBOSE + printf( "Instance Provider Wrapper dies\n" ); +#endif + } + + void OInstanceProviderWrapper::thisAcquire( remote_InstanceProvider *p ) + { + OInstanceProviderWrapper * m = (OInstanceProviderWrapper *) p; + osl_incrementInterlockedCount( &(m->m_nRef ) ); + } + + void OInstanceProviderWrapper::thisRelease( remote_InstanceProvider *p ) + { + OInstanceProviderWrapper * m = ( OInstanceProviderWrapper *) p; + if( ! osl_decrementInterlockedCount( &(m->m_nRef ) ) ) + { + delete m; + } + } + + void OInstanceProviderWrapper::thisGetInstance( + remote_InstanceProvider * pProvider , + uno_Environment *pEnvRemote, + remote_Interface **ppRemoteI, + rtl_uString *pInstanceName, + typelib_InterfaceTypeDescription *pType + ) + { + OInstanceProviderWrapper * m = (OInstanceProviderWrapper *)pProvider; + + OSL_ASSERT( ppRemoteI ); + if( *ppRemoteI ) + { + (*ppRemoteI)->release( *ppRemoteI ); + *ppRemoteI = 0; + } + + if( OUString( pType->aBase.pTypeName ) == + getCppuType( (Reference<XInterface>*)0).getTypeName() ) + { + try + { + Reference< XInterface > r = m->m_rProvider->getInstance( + OUString( pInstanceName ) ); + + OUString sCppuName( RTL_CONSTASCII_USTRINGPARAM( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) ); + uno_Environment *pEnvThis = 0; + uno_getEnvironment( &pEnvThis , + sCppuName.pData , + 0 ); + + Mapping map( pEnvThis , pEnvRemote ); + + *ppRemoteI = (remote_Interface*) map.mapInterface ( + r.get(), + getCppuType( (Reference< XInterface > *) 0 ) + ); + + pEnvThis->release( pEnvThis ); + + if( *ppRemoteI && m->m_pBridgeCallback ) + { + m->m_pBridgeCallback->objectMappedSuccesfully(); + m->m_pBridgeCallback = 0; + } + } + catch( ::com::sun::star::container::NoSuchElementException & ) + { + // simply pass a null reference + } + + } + } +} diff --git a/remotebridges/source/bridge/makefile.mk b/remotebridges/source/bridge/makefile.mk new file mode 100644 index 000000000000..8d3b5887e53a --- /dev/null +++ b/remotebridges/source/bridge/makefile.mk @@ -0,0 +1,107 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: jbu $ $Date: 2000-09-28 08:47:31 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=remotebridges +TARGET=remotebridge +ENABLE_EXCEPTIONS=TRUE +COMP1TYPELIST=$(TARGET) +COMPRDB=$(SOLARBINDIR)$/applicat.rdb + +# --- Settings ----------------------------------------------------- +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk +# ------------------------------------------------------------------ +UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb +UNOUCROUT=$(OUT)$/inc$/bridge +INCPRE+= $(UNOUCROUT) +UNOTYPES=$($(TARGET)_XML2CMPTYPES) + + +SLOFILES= \ + $(SLO)$/remote_bridge.obj \ + $(SLO)$/bridge_connection.obj\ + $(SLO)$/bridge_provider.obj \ + $(SLO)$/$(COMP1TYPELIST)_description.obj + +SHL1TARGET= $(TARGET) + +SHL1STDLIBS= \ + $(SALLIB) \ + $(VOSLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(RMCXTLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET) +SHL1LIBS= $(SLB)$/$(TARGET).lib +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) +DEF1EXPORTFILE= exports.dxp + +# --- Targets ------------------------------------------------------ +.INCLUDE : target.mk diff --git a/remotebridges/source/bridge/remote_bridge.cxx b/remotebridges/source/bridge/remote_bridge.cxx new file mode 100644 index 000000000000..7e3f6cb92ae3 --- /dev/null +++ b/remotebridges/source/bridge/remote_bridge.cxx @@ -0,0 +1,468 @@ +/************************************************************************* + * + * $RCSfile: remote_bridge.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jbu $ $Date: 2000-09-28 08:47:31 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ +#include <stdio.h> + +#include "remote_bridge.hxx" +#include "bridge_connection.hxx" + +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/bridge/BridgeExistsException.hpp> + +#define IMPLEMENTATION_NAME "com.sun.star.comp.remotebridges.Bridge.various" + + +using namespace ::rtl; +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::bridge; +using namespace ::com::sun::star::registry; +using namespace ::com::sun::star::connection; + +namespace remotebridges_bridge +{ + ORemoteBridge::ORemoteBridge() : + OComponentHelper( m_mutex ), + m_pContext( 0 ), + m_pEnvRemote(0 ) + { + remote_DisposingListener::acquire = thisAcquire; + remote_DisposingListener::release = thisRelease; + remote_DisposingListener::disposing = thisDisposing; + } + + ORemoteBridge::~ORemoteBridge() + { + if( m_pContext ) + { + m_pContext->aBase.release( (uno_Context *) m_pContext ); + } + if( m_pEnvRemote ) + { + m_pEnvRemote->release( m_pEnvRemote ); + } + } + + void ORemoteBridge::objectMappedSuccesfully() + { + MutexGuard guard( m_mutex ); + + if( m_pEnvRemote ) + { + m_pEnvRemote->release( m_pEnvRemote ); + m_pEnvRemote = 0; + } + } + + Any ORemoteBridge::queryInterface( const Type & aType ) + { + Any a = ::cppu::queryInterface( + aType , + SAL_STATIC_CAST( XInitialization * , this ) , + SAL_STATIC_CAST( XBridge * , this ), + SAL_STATIC_CAST( XTypeProvider * , this ) ); + if( a.hasValue() ) + { + return a; + } + + return OComponentHelper::queryInterface( aType ); + } + + + void ORemoteBridge::initialize( const Sequence< Any >& aArguments ) + throw( Exception, RuntimeException) + { + + MutexGuard guard( m_mutex ); + + if( 4 != aArguments.getLength() ) + { + throw IllegalArgumentException( rtl::OUString::createFromAscii("wrong number of arguments") , + Reference< XInterface >(), + 0 ); + } + + OUString swName; + OUString swProtocol; + Reference < XConnection > rConnection; + Reference < XInstanceProvider > rProvider; + + aArguments.getConstArray()[0] >>= swName; + aArguments.getConstArray()[1] >>= swProtocol; + aArguments.getConstArray()[2] >>= rConnection; + aArguments.getConstArray()[3] >>= rProvider; + + if( ! rConnection.is() ) + { + throw IllegalArgumentException( rtl::OUString::createFromAscii("connection is missing") , + Reference < XInterface > (), + 2 ); + } + + remote_Connection *pConnection = new OConnectionWrapper( rConnection ); + remote_InstanceProvider *pProvider = 0; + if( rProvider.is( )) + { + pProvider = new OInstanceProviderWrapper( rProvider , this ); + } + + OUString sName = swName; + m_sDescription = swProtocol; + m_sDescription += OUString( RTL_CONSTASCII_USTRINGPARAM(":")); + m_sDescription += rConnection->getDescription(); + + if( 0 == sName.getLength() ) + { + sName = m_sDescription; + } + else + { + m_sName = sName; + } + + m_pContext = remote_createContext( pConnection, + sName.pData, + m_sDescription.pData, + swProtocol.pData, + pProvider ); + if( ! m_pContext ) + { + throw BridgeExistsException(); + } + + m_pContext->addDisposingListener( m_pContext , + (remote_DisposingListener *) this ); + + // environment will be released by the first succesfull mapping + OUString sRemoteEnv; + if( swProtocol.indexOf( ',') == -1 ) + { + sRemoteEnv = swProtocol; + } + else + { + sRemoteEnv = swProtocol.copy( 0 , swProtocol.indexOf( ',' ) ); + } + m_sProtocol = sRemoteEnv; + uno_getEnvironment( &m_pEnvRemote , + sRemoteEnv.pData , + m_pContext ); + if( ! m_pEnvRemote ) + { + m_pContext->removeDisposingListener( m_pContext , + (remote_DisposingListener*) this ); + m_pContext->aBase.release( (uno_Context * ) m_pContext ); + m_pContext = 0; + + // forgotten exception when specifying the interface + throw RuntimeException( rtl::OUString::createFromAscii("couldn't create uno-remote-environment") , + Reference < XInterface > () ); + } + } + + Reference< XInterface > ORemoteBridge::getInstance( const ::rtl::OUString& sInstanceName ) + throw(::com::sun::star::uno::RuntimeException) + { + Reference < XInterface > rReturn; + + if( m_pContext && m_pContext->getRemoteInstance ) + { + // get the appropriate remote environment + uno_Environment *pEnvRemote = 0; + uno_getEnvironment( &pEnvRemote , m_sProtocol.pData , m_pContext ); + + if( ! pEnvRemote ) + { + return Reference< XInterface > (); + } + + Type type = getCppuType( (Reference < XInterface > * ) 0 ); + + remote_Interface *pRemoteI = 0; + m_pContext->getRemoteInstance( + pEnvRemote, + &pRemoteI, + sInstanceName.pData, + type.getTypeLibType() ); + + if( pRemoteI ) + { + // got an interface ! + uno_Environment *pEnvCpp =0; + OUString sCppuName( RTL_CONSTASCII_USTRINGPARAM( CPPU_CURRENT_LANGUAGE_BINDING_NAME ) ); + uno_getEnvironment( &pEnvCpp , + sCppuName.pData , + 0 ); + + Mapping map( pEnvRemote , pEnvCpp ); + + XInterface * pCppI = ( XInterface * ) map.mapInterface( pRemoteI, type ); + + rReturn = Reference<XInterface > ( pCppI ); + + pCppI->release( ); + + pRemoteI->release( pRemoteI ); + pEnvCpp->release( pEnvCpp ); + objectMappedSuccesfully(); + } + + pEnvRemote->release( pEnvRemote ); + } + return rReturn; + } + + + ::rtl::OUString SAL_CALL ORemoteBridge::getName( ) + throw(::com::sun::star::uno::RuntimeException) + { + return m_sName; + } + + ::rtl::OUString SAL_CALL ORemoteBridge::getDescription( ) + throw(::com::sun::star::uno::RuntimeException) + { + return m_sDescription; + } + + // XTypeProvider + Sequence< Type > SAL_CALL ORemoteBridge::getTypes(void) throw( RuntimeException ) + { + static OTypeCollection *pCollection = 0; + if( ! pCollection ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pCollection ) + { + static OTypeCollection collection( + getCppuType( (Reference< XTypeProvider> * )0), + getCppuType( (Reference< XBridge > * ) 0 ), + getCppuType( (Reference< XInitialization > * ) 0 ), + OComponentHelper::getTypes() ); + pCollection = &collection; + } + } + + return (*pCollection).getTypes(); + } + + Sequence< sal_Int8 > SAL_CALL ORemoteBridge::getImplementationId( ) throw( RuntimeException) + { + static OImplementationId *pId = 0; + if( ! pId ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pId ) + { + static OImplementationId id( sal_False ); + pId = &id; + } + } + return (*pId).getImplementationId(); + } + + void ORemoteBridge::disposing() + { + MutexGuard guard( m_mutex ); + if( m_pContext ) + { + m_pContext->removeDisposingListener( m_pContext , ( remote_DisposingListener * )this); + if( ! m_pEnvRemote ) + { + if( m_pContext->m_pConnection ) + { + OUString sProtocol = OUString( m_pContext->m_pProtocol ).getToken( 0 , ',' ); + uno_getEnvironment( &m_pEnvRemote , sProtocol.pData , m_pContext ); + OSL_ASSERT( m_pEnvRemote ); + } + else + { + // within disposing from the context, no further dispose necessary ! + } + } + + if( m_pEnvRemote ) + { + m_pEnvRemote->dispose( m_pEnvRemote ); + m_pEnvRemote->release( m_pEnvRemote ); + m_pEnvRemote = 0; + } + + m_pContext->aBase.release( (uno_Context*)m_pContext ); + m_pContext = 0; + } + } + + + //---------------------- + // static methods + //---------------------- + void ORemoteBridge::thisAcquire( remote_DisposingListener *p ) + { + ORemoteBridge *m = (ORemoteBridge * ) p; + m->acquire(); + } + + void ORemoteBridge::thisRelease( remote_DisposingListener *p ) + { + ORemoteBridge *m = (ORemoteBridge * ) p; + m->release(); + } + + void ORemoteBridge::thisDisposing( remote_DisposingListener * p, + rtl_uString *pString ) + { + ORemoteBridge *m = (ORemoteBridge * ) p; + m->dispose(); + } + + //--------------------------------- + // + //--------------------------------- + Reference< XInterface > SAL_CALL CreateInstance( const Reference< XMultiServiceFactory > &) + { + return Reference< XInterface > ( ( OWeakObject * ) new ORemoteBridge ); + } + + Sequence< OUString > getSupportedServiceNames() + { + static Sequence < OUString > *pNames = 0; + if( ! pNames ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( !pNames ) + { + static Sequence< OUString > seqNames(2); + seqNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.bridge.Bridge.iiop" ); + seqNames.getArray()[1] = OUString::createFromAscii( "com.sun.star.bridge.Bridge.urp" ); + + pNames = &seqNames; + } + } + return *pNames; + } +} + +using namespace remotebridges_bridge; + +extern "C" +{ +//================================================================================================== +void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +sal_Bool SAL_CALL component_writeInfo( + void * pServiceManager, void * pRegistryKey ) +{ + if (pRegistryKey) + { + try + { + Reference< XRegistryKey > xNewKey( + reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( + OUString::createFromAscii( "/" IMPLEMENTATION_NAME "/UNO/SERVICES" ) ) ); + + const Sequence< OUString > & rSNL = getSupportedServiceNames(); + const OUString * pArray = rSNL.getConstArray(); + for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) + xNewKey->createKey( pArray[nPos] ); + + return sal_True; + } + catch (InvalidRegistryException &) + { + OSL_ENSHURE( sal_False, "### InvalidRegistryException!" ); + } + } + return sal_False; +} +//================================================================================================== +void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pRet = 0; + + if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) + { + Reference< XSingleServiceFactory > xFactory( createSingleFactory( + reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), + OUString::createFromAscii( pImplName ), + CreateInstance, getSupportedServiceNames() ) ); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} +} + + + + diff --git a/remotebridges/source/bridge/remote_bridge.hxx b/remotebridges/source/bridge/remote_bridge.hxx new file mode 100644 index 000000000000..d0ab56c1adf6 --- /dev/null +++ b/remotebridges/source/bridge/remote_bridge.hxx @@ -0,0 +1,179 @@ +/************************************************************************* + * + * $RCSfile: remote_bridge.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jbu $ $Date: 2000-09-28 08:47:31 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <osl/mutex.hxx> +#include <osl/diagnose.h> + +#include <uno/mapping.hxx> +#include <uno/environment.h> + +#include <bridges/remote/context.h> +#include <bridges/remote/remote.h> + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/component.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XInitialization.hpp> + +#include <com/sun/star/bridge/XBridge.hpp> +#include <com/sun/star/bridge/XInstanceProvider.hpp> + + +namespace remotebridges_bridge +{ + struct MyMutex + { + ::osl::Mutex m_mutex; + }; + + class ORemoteBridge : + public MyMutex, + public remote_DisposingListener, + public ::com::sun::star::lang::XInitialization, + public ::com::sun::star::bridge::XBridge, + public ::cppu::OComponentHelper + { + public: + ORemoteBridge(); + ~ORemoteBridge(); + + // XInterface + public: + ::com::sun::star::uno::Any SAL_CALL + queryInterface( const ::com::sun::star::uno::Type & aType ); + + void SAL_CALL acquire() + { OComponentHelper::acquire(); } + void SAL_CALL release() + { OComponentHelper::release(); } + + public: + virtual void SAL_CALL disposing(); // called by OComponentHelper + + public: + // Methods + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any >& aArguments ) + throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + public: + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + getInstance( const ::rtl::OUString& sInstanceName ) + throw(::com::sun::star::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL getName( ) + throw(::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getDescription( ) + throw(::com::sun::star::uno::RuntimeException); + + public: + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL + getTypes( ) throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL + getImplementationId( ) throw(::com::sun::star::uno::RuntimeException); + + public: + static void SAL_CALL thisAcquire( remote_DisposingListener * ); + static void SAL_CALL thisRelease( remote_DisposingListener * ); + static void SAL_CALL thisDisposing( remote_DisposingListener * , + rtl_uString * pBridgeName ); + + public: + void objectMappedSuccesfully(); + + public: + remote_Context *m_pContext; + uno_Environment *m_pEnvRemote; + ::rtl::OUString m_sName; + ::rtl::OUString m_sDescription; + ::rtl::OUString m_sProtocol; + }; + + class OInstanceProviderWrapper : + public remote_InstanceProvider + { + public: + OInstanceProviderWrapper( const ::com::sun::star::uno::Reference < + ::com::sun::star::bridge::XInstanceProvider > & rProvider , + ORemoteBridge * pBridgeCallback ); + + ~OInstanceProviderWrapper(); + public: + static void SAL_CALL thisAcquire( remote_InstanceProvider * ); + static void SAL_CALL thisRelease( remote_InstanceProvider * ); + static void SAL_CALL thisGetInstance( remote_InstanceProvider * pProvider , + uno_Environment *pEnvRemote, + remote_Interface **ppRemoteI, + rtl_uString *pInstanceName, + typelib_InterfaceTypeDescription *pType + ); + + private: + ::com::sun::star::uno::Reference < + ::com::sun::star::bridge::XInstanceProvider > m_rProvider; + oslInterlockedCount m_nRef; + ORemoteBridge *m_pBridgeCallback; + }; + +} + diff --git a/remotebridges/source/bridge/remotebridge.xml b/remotebridges/source/bridge/remotebridge.xml new file mode 100644 index 000000000000..c9b98188e12a --- /dev/null +++ b/remotebridges/source/bridge/remotebridge.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE COMPONENTDESCRIPTION PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "componentdescription.dtd"> + +<COMPONENTDESCRIPTION + xmlns:xlink="http://www.w3.org/1999/xlink/Namespace" > + +<Author> Joerg Budischewski </Author> + +<Name> com.sun.star.comp.remotebridges.Bridge.various </Name> + +<Description> + This component initializes the bridge between two processes + using either iiop or urp (UnoRemoteProtocol) protocol. +</Description> + +<ModuleName> remotebridge </ModuleName> + +<LoaderName> com.sun.star.loader.SharedLibrary </LoaderName> + +<Language> c++ </Language> + +<Status StatusValue="final"/> + +<SupportedService> com.sun.star.bridge.Bridge.iiop </SupportedService> +<SupportedService> com.sun.star.bridge.Bridge.urp </SupportedService> + +<ServiceDependency> ... </ServiceDependency> + +<ProjectBuildDependency> cppuhelper </ProjectBuildDependency> +<ProjectBuildDependency> cppu </ProjectBuildDependency> +<ProjectBuildDependency> sal </ProjectBuildDependency> +<RuntimeModuleDependency> rmcxt </RuntimeModuleDependency> + + +<RuntimeModuleDependency> cppuhelper2 </RuntimeModuleDependency> +<RuntimeModuleDependency> cppu2 </RuntimeModuleDependency> +<RuntimeModuleDependency> sal2 </RuntimeModuleDependency> +<RuntimeModuleDependency> rmcxt2 </RuntimeModuleDependency> + + +<Type> com.sun.star.bridge.XBridgeFactory </Type> +<Type> com.sun.star.bridge.XInstanceProvider </Type> +<Type> com.sun.star.bridge.XBridge </Type> +<Type> com.sun.star.bridge.BridgeExistsException </Type> +<Type> com.sun.star.lang.XMultiServiceFactory </Type> +<Type> com.sun.star.lang.XSingleServiceFactory </Type> +<Type> com.sun.star.lang.XInitialization </Type> +<Type> com.sun.star.lang.XComponent </Type> +<Type> com.sun.star.lang.XServiceInfo </Type> +<Type> com.sun.star.lang.XTypeProvider </Type> +<Type> com.sun.star.lang.IllegalArgumentException </Type> +<Type> com.sun.star.lang.XInitialization </Type> +<Type> com.sun.star.registry.XRegistryKey </Type> +<Type> com.sun.star.uno.XWeak </Type> +<Type> com.sun.star.uno.TypeClass </Type> +<Type> com.sun.star.uno.XAggregation </Type> + +</COMPONENTDESCRIPTION> + |