Tag: cws_src680_kabrefine User: fs Date: 06/01/04 03:23:03 Modified: /dba/connectivity/source/drivers/kab/ KConnection.cxx, KConnection.hxx, KDriver.cxx, KDriver.hxx, KServices.cxx, makefile.mk
Log: #i59673# split into two libraries, one small independent UNO component, and one implementation library File Changes: Directory: /dba/connectivity/source/drivers/kab/ ================================================ File [changed]: KConnection.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KConnection.cxx?r1=1.2&r2=1.2.10.1 Delta lines: +30 -15 --------------------- --- KConnection.cxx 19 Dec 2005 16:48:35 -0000 1.2 +++ KConnection.cxx 4 Jan 2006 11:22:58 -0000 1.2.10.1 @@ -4,9 +4,9 @@ * * $RCSfile: KConnection.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.10.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:48:35 $ + * last change: $Author: fs $ $Date: 2006/01/04 11:22:58 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -57,6 +57,8 @@ #include <com/sun/star/sdbc/TransactionIsolation.hpp> #endif +#include <kabc/stdaddressbook.h> + using namespace connectivity::kab; using namespace com::sun::star::uno; using namespace com::sun::star::lang; @@ -331,4 +333,17 @@ m_xCatalog = xTab; } return xTab; +} +// ----------------------------------------------------------------------------- +::KABC::AddressBook* KabConnection::getAddressBook() const +{ + return m_pAddressBook; +} +// ----------------------------------------------------------------------------- +extern "C" void* SAL_CALL createKabConnection( void* _pDriver ) +{ + KabConnection* pConnection = new KabConnection( static_cast< KabDriver* >( _pDriver ) ); + // by definition, the pointer crossing library boundaries as void ptr is acquired once + pConnection->acquire(); + return pConnection; } File [changed]: KConnection.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KConnection.hxx?r1=1.2&r2=1.2.10.1 Delta lines: +9 -4 ------------------- --- KConnection.hxx 19 Dec 2005 16:49:11 -0000 1.2 +++ KConnection.hxx 4 Jan 2006 11:22:58 -0000 1.2.10.1 @@ -4,9 +4,9 @@ * * $RCSfile: KConnection.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.10.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:49:11 $ + * last change: $Author: fs $ $Date: 2006/01/04 11:22:58 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -37,7 +37,6 @@ #define _CONNECTIVITY_KAB_CONNECTION_HXX_ #include <map> -#include <kabc/stdaddressbook.h> #ifndef _CONNECTIVITY_OSUBCOMPONENT_HXX_ #include "OSubComponent.hxx" @@ -67,6 +66,12 @@ #include <cppuhelper/compbase3.hxx> #endif +namespace KABC +{ + class StdAddressBook; + class AddressBook; +} + namespace connectivity { namespace kab @@ -153,7 +158,7 @@ // accessors inline KabDriver* getDriver() const { return m_pDriver;} - inline ::KABC::AddressBook* getAddressBook() const { return m_pAddressBook; } + ::KABC::AddressBook* getAddressBook() const; }; } } File [changed]: KDriver.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDriver.cxx?r1=1.2&r2=1.2.10.1 Delta lines: +97 -61 --------------------- --- KDriver.cxx 19 Dec 2005 16:49:48 -0000 1.2 +++ KDriver.cxx 4 Jan 2006 11:22:58 -0000 1.2.10.1 @@ -4,9 +4,9 @@ * * $RCSfile: KDriver.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.10.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:49:48 $ + * last change: $Author: fs $ $Date: 2006/01/04 11:22:58 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -34,18 +34,11 @@ ************************************************************************/ #include "KDriver.hxx" + #ifndef _CONNECTIVITY_KAB_CONNECTION_HXX_ #include "KConnection.hxx" #endif -#include <kcmdlineargs.h> -#include <kglobal.h> -#include <klocale.h> - -#ifndef _OSL_PROCESS_H_ -#include <osl/process.h> -#endif - using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; @@ -53,29 +46,14 @@ using namespace connectivity::kab; KabDriver::KabDriver( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) + const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) : KDriver_BASE(m_aMutex), m_xMSFactory(_rxFactory), - m_pKApplication(NULL) + m_hConnectorModule(NULL), + m_pConnectionFactoryFunc(NULL), + m_pApplicationInitFunc(NULL), + m_pApplicationShutdownFunc(NULL) { - // we create a KDE application only if it is not already done - if (KApplication::kApplication() == NULL) - { - // version 0.1 - char *kabargs[1] = {"libkab1"}; - KCmdLineArgs::init(1, kabargs, "KAddressBook", *kabargs, "Address Book driver", "0.1"); - - m_pKApplication = new KApplication(false, false); - } - - // set language - rtl_Locale *pProcessLocale; - osl_getProcessLocale(&pProcessLocale); - // sal_Unicode and QChar are (currently) both 16 bits characters - QString aLanguage( - (const QChar *) pProcessLocale->Language->buffer, - (int) pProcessLocale->Language->length); - KGlobal::locale()->setLanguage(aLanguage); } // -------------------------------------------------------------------------------- void KabDriver::disposing() @@ -91,13 +69,9 @@ } m_xConnections.clear(); - if (m_pKApplication != NULL) - { - delete m_pKApplication; - m_pKApplication = NULL; - } - KDriver_BASE::disposing(); + + impl_shutdownImplementationModule(); } // static ServiceInfo //------------------------------------------------------------------------------ @@ -141,18 +115,35 @@ // -------------------------------------------------------------------------------- Reference< XConnection > SAL_CALL KabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) { + if ( !impl_initImplementationModule() ) + return NULL; + // create a new connection with the given properties and append it to our vector - KabConnection* pCon = new KabConnection(this); - Reference< XConnection > xCon = pCon; // important here because otherwise the connection could be deleted inside (refcount goes -> 0) - pCon->construct(url,info); // late constructor call which can throw exception and allows a correct dtor call when so - m_xConnections.push_back(WeakReferenceHelper(*pCon)); + void* pUntypedConnection = (*m_pConnectionFactoryFunc)( this ); + KabConnection* pConnection = static_cast< KabConnection* >( pUntypedConnection ); + OSL_ENSURE( pConnection, "KabDriver::connect: no connection has been created by the factory!" ); + if ( !pConnection ) + throw RuntimeException( ::rtl::OUString(), *this ); + + // by definition, the factory function returned an object which was acquired once + Reference< XConnection > xConnection = pConnection; + pConnection->release(); + + // late constructor call which can throw exception and allows a correct dtor call when so + pConnection->construct( url, info ); - return xCon; + // remember it + m_xConnections.push_back( WeakReferenceHelper( *pConnection ) ); + + return xConnection; } // -------------------------------------------------------------------------------- sal_Bool SAL_CALL KabDriver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException) { + if ( !impl_initImplementationModule() ) + return sal_False; + // here we have to look whether we support this URL format return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:address:kab:"), 16)); } @@ -175,28 +166,73 @@ return 1; } // -------------------------------------------------------------------------------- - -//......................................................................... -namespace connectivity +Reference< XInterface > SAL_CALL KabDriver::Create( const Reference< XMultiServiceFactory >& _rxFactory ) throw( Exception ) { - namespace kab - { -//......................................................................... + return *(new KabDriver(_rxFactory)); +} -::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL KabDriver_CreateInstance( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory - ) throw( ::com::sun::star::uno::Exception ) +// -------------------------------------------------------------------------------- +namespace { - return *(new KabDriver(_rxFactory)); + template< typename FUNCTION > + void lcl_getFunctionFromModuleOrUnload( oslModule& _rModule, const sal_Char* _pAsciiSymbolName, FUNCTION& _rFunction ) + { + _rFunction = NULL; + if ( _rModule ) + { + // + const ::rtl::OUString sSymbolName = ::rtl::OUString::createFromAscii( _pAsciiSymbolName ); + _rFunction = (FUNCTION)( osl_getSymbol( _rModule, sSymbolName.pData ) ); + + if ( !_rFunction ) + { // did not find the symbol + OSL_ENSURE( false, ::rtl::OString( "lcl_getFunctionFromModuleOrUnload: could not find the symbol " ) + ::rtl::OString( _pAsciiSymbolName ) ); + osl_unloadModule( _rModule ); + _rModule = NULL; + } + } + } } -void checkDisposed(sal_Bool _bThrow) throw ( DisposedException ) +// -------------------------------------------------------------------------------- +bool KabDriver::impl_initImplementationModule() { - if (_bThrow) - throw DisposedException(); + // TODO: this is not thread-safe + + if ( !m_hConnectorModule ) + { + OSL_ENSURE( !m_pConnectionFactoryFunc && !m_pApplicationInitFunc && !m_pApplicationShutdownFunc, + "KabDriver::impl_initImplementationModule: inconsistence: function pointers already intialized, but no module!"); + + const ::rtl::OUString sModuleName = ::rtl::OUString::createFromAscii( SAL_MODULENAME( "kabdrv1" ) ); + m_hConnectorModule = osl_loadModule( sModuleName.pData, 0 ); + OSL_ENSURE( m_hConnectorModule, "KabDriver::impl_initImplementationModule: could not load the implementation library!" ); + if ( !m_hConnectorModule ) + return false; + + lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "createKabConnection", m_pConnectionFactoryFunc ); + lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "initKApplication", m_pApplicationInitFunc ); + lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "shutdownKApplication", m_pApplicationShutdownFunc ); + } + + if ( m_pApplicationInitFunc ) + (*m_pApplicationInitFunc)(); + + return ( m_hConnectorModule != NULL ); } +// -------------------------------------------------------------------------------- +void KabDriver::impl_shutdownImplementationModule() +{ + if ( m_pApplicationShutdownFunc ) + (*m_pApplicationShutdownFunc)(); -//......................................................................... + if ( m_hConnectorModule ) + { + osl_unloadModule( m_hConnectorModule ); + m_hConnectorModule = NULL; } + + m_pConnectionFactoryFunc = NULL; + m_pApplicationInitFunc = NULL; + m_pApplicationShutdownFunc = NULL; } -//......................................................................... File [changed]: KDriver.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDriver.hxx?r1=1.2&r2=1.2.10.1 Delta lines: +48 -20 --------------------- --- KDriver.hxx 19 Dec 2005 16:49:58 -0000 1.2 +++ KDriver.hxx 4 Jan 2006 11:22:58 -0000 1.2.10.1 @@ -4,9 +4,9 @@ * * $RCSfile: KDriver.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.10.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:49:58 $ + * last change: $Author: fs $ $Date: 2006/01/04 11:22:58 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -36,49 +36,67 @@ #ifndef _CONNECTIVITY_KAB_DRIVER_HXX_ #define _CONNECTIVITY_KAB_DRIVER_HXX_ -#ifndef _CONNECTIVITY_KAB_CONNECTION_HXX_ -#include "KConnection.hxx" -#endif - -#include <kapplication.h> - #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_ #include <com/sun/star/sdbc/XDriver.hpp> #endif +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif + #ifndef _CPPUHELPER_COMPBASE2_HXX_ #include <cppuhelper/compbase2.hxx> #endif +#ifndef _OSL_MODULE_H_ +#include <osl/module.h> +#endif + namespace connectivity { namespace kab { - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL KabDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ); - + typedef void* (SAL_CALL * ConnectionFactoryFunction)( void* _pDriver ); + typedef void (SAL_CALL * ApplicationInitFunction)( void ); + typedef void (SAL_CALL * ApplicationShutdownFunction)( void ); + + typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; + + // =============================================================== + // = KabDriver + // =============================================================== typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::sdbc::XDriver, ::com::sun::star::lang::XServiceInfo > KDriver_BASE; - class KabDriver : public KDriver_BASE { protected: - KApplication* m_pKApplication; // KDE application if we own it ::osl::Mutex m_aMutex; // mutex is need to control member access OWeakRefArray m_xConnections; // vector containing a list of all the // KabConnection objects for this Driver ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xMSFactory; // the multi-service factory + // dynamic access to the library which implements the "real" functionality + oslModule m_hConnectorModule; + ConnectionFactoryFunction m_pConnectionFactoryFunc; + ApplicationInitFunction m_pApplicationInitFunc; + ApplicationShutdownFunction m_pApplicationShutdownFunc; + public: + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception ); + // XServiceInfo - static versions + static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); + + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& + getMSFactory() const { return m_xMSFactory; } + + protected: KabDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); // OComponentHelper virtual void SAL_CALL disposing(void); - // XInterface - static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); - static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); - // XServiceInfo virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); @@ -91,8 +109,18 @@ virtual sal_Int32 SAL_CALL getMajorVersion() throw(::com::sun::star::uno::RuntimeException); virtual sal_Int32 SAL_CALL getMinorVersion() throw(::com::sun::star::uno::RuntimeException); - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& - getMSFactory() const { return m_xMSFactory; } + private: + /** initializes the library which contains the real implementations + + @return <TRUE/> if and only if loading the library succeeded, and <em>all</em> needed symbols were found + */ + bool impl_initImplementationModule(); + + /** shuts down the library which contains the real implementations + + This method is safe against being called multiple times + */ + void impl_shutdownImplementationModule(); }; } File [changed]: KServices.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KServices.cxx?r1=1.2&r2=1.2.10.1 Delta lines: +18 -18 --------------------- --- KServices.cxx 19 Dec 2005 16:51:10 -0000 1.2 +++ KServices.cxx 4 Jan 2006 11:22:59 -0000 1.2.10.1 @@ -4,9 +4,9 @@ * * $RCSfile: KServices.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.10.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:51:10 $ + * last change: $Author: fs $ $Date: 2006/01/04 11:22:59 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -171,7 +171,7 @@ aReq.CREATE_PROVIDER( KabDriver::getImplementationName_Static(), KabDriver::getSupportedServiceNames_Static(), - KabDriver_CreateInstance, + &KabDriver::Create, ::cppu::createSingleFactory) ; File [changed]: makefile.mk Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/makefile.mk?r1=1.2&r2=1.2.10.1 Delta lines: +64 -47 --------------------- --- makefile.mk 19 Dec 2005 16:54:12 -0000 1.2 +++ makefile.mk 4 Jan 2006 11:22:59 -0000 1.2.10.1 @@ -4,9 +4,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.2.10.1 $ # -# last change: $Author: obo $ $Date: 2005/12/19 16:54:12 $ +# last change: $Author: fs $ $Date: 2006/01/04 11:22:59 $ # # The Contents of this file are made available subject to # the terms of GNU Lesser General Public License Version 2.1. @@ -37,20 +37,52 @@ PRJINC=..$/.. PRJNAME=connectivity TARGET=kab +TARGET2=$(TARGET)drv + +ENABLE_EXCEPTIONS=TRUE # --- Settings ---------------------------------- -.IF "$(DBGUTIL_OJ)"!="" -ENVCFLAGS+=/FR$(SLO)$/ -.ENDIF .INCLUDE : settings.mk .INCLUDE : $(PRJ)$/version.mk .IF "$(GUI)" == "UNX" .IF "$(ENABLE_KDE)" == "TRUE" + +CFLAGS+=$(KDE_CFLAGS) + +# === KAB base library ========================== + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/KDriver.obj \ + $(SLO)$/KServices.obj + +# --- Library ----------------------------------- + +SHL1VERSIONMAP=$(TARGET).map + +SHL1TARGET= $(TARGET)$(KAB_MAJOR) +SHL1OBJS=$(SLOFILES) +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(OSLLIB) \ + $(SALLIB) + +SHL1DEPN= +SHL1IMPLIB= i$(TARGET) + +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME= $(SHL1TARGET) + +# === KAB impl library ========================== + # --- Files ------------------------------------- -EXCEPTIONSFILES=\ +SLO2FILES=\ $(SLO)$/KColumns.obj \ $(SLO)$/KTable.obj \ $(SLO)$/KTables.obj \ @@ -60,51 +92,36 @@ $(SLO)$/KPreparedStatement.obj \ $(SLO)$/KDatabaseMetaData.obj \ $(SLO)$/KConnection.obj \ - $(SLO)$/KServices.obj \ $(SLO)$/KResultSetMetaData.obj \ - $(SLO)$/KDriver.obj \ $(SLO)$/kcondition.obj \ $(SLO)$/korder.obj \ $(SLO)$/kfields.obj \ - -CFLAGS+=$(KDE_CFLAGS) - -SLOFILES=\ - $(EXCEPTIONSFILES) + $(SLO)$/KDEInit.obj KAB_LIB=$(KDE_LIBS) -lkabc -SHL1VERSIONMAP=$(TARGET).map - - # --- Library ----------------------------------- -SHL1TARGET= $(KAB_TARGET)$(KAB_MAJOR) -SHL1OBJS=$(SLOFILES) -SHL1STDLIBS=\ +SHL2VERSIONMAP=$(TARGET2).map + +SHL2TARGET= $(TARGET2)$(KAB_MAJOR) +SHL2OBJS=$(SLO2FILES) +SHL2STDLIBS=\ $(CPPULIB) \ $(CPPUHELPERLIB) \ $(VOSLIB) \ $(OSLLIB) \ - $(SVLLIB) \ - $(SVLIB) \ - $(TOOLSLIB) \ - $(SVTOOLLIB) \ - $(SVTLIB) \ - $(UNOTOOLSLIB) \ - $(UCBHELPERLIB) \ $(SALLIB) \ $(DBTOOLSLIB) \ $(COMPHELPERLIB) \ $(KAB_LIB) -SHL1DEPN= -SHL1IMPLIB= i$(TARGET) +SHL2DEPN= +SHL2IMPLIB= i$(TARGET2) -SHL1DEF= $(MISC)$/$(SHL1TARGET).def - -DEF1NAME= $(SHL1TARGET) +SHL2DEF= $(MISC)$/$(SHL2TARGET).def +DEF2NAME= $(SHL2TARGET) # --- Targets ----------------------------------- .ELSE # "$(ENABLE_KDE)" == "TRUE" --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
