Tag: cws_src680_dba202e User: fs Date: 06/01/10 06:23:42 Modified: /dba/connectivity/source/drivers/kab/ KConnection.cxx, KConnection.hxx, KDriver.cxx, KDriver.hxx, KServices.cxx, makefile.mk
Log: copying fixes for #i59673# and #i60062# to this (earlier) CWS 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.14.1 Delta lines: +30 -15 --------------------- --- KConnection.cxx 19 Dec 2005 16:48:35 -0000 1.2 +++ KConnection.cxx 10 Jan 2006 14:23:16 -0000 1.2.14.1 @@ -4,9 +4,9 @@ * * $RCSfile: KConnection.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.14.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:48:35 $ + * last change: $Author: fs $ $Date: 2006/01/10 14:23:16 $ * * 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.14.1 Delta lines: +9 -4 ------------------- --- KConnection.hxx 19 Dec 2005 16:49:11 -0000 1.2 +++ KConnection.hxx 10 Jan 2006 14:23:17 -0000 1.2.14.1 @@ -4,9 +4,9 @@ * * $RCSfile: KConnection.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.14.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:49:11 $ + * last change: $Author: fs $ $Date: 2006/01/10 14:23:17 $ * * 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.14.1 Delta lines: +354 -64 ---------------------- --- KDriver.cxx 19 Dec 2005 16:49:48 -0000 1.2 +++ KDriver.cxx 10 Jan 2006 14:23:20 -0000 1.2.14.1 @@ -4,9 +4,9 @@ * * $RCSfile: KDriver.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.14.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:49:48 $ + * last change: $Author: fs $ $Date: 2006/01/10 14:23:20 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -34,48 +34,319 @@ ************************************************************************/ #include "KDriver.hxx" + +#ifndef CONNECTIVITY_KAB_KDEINIT_H +#include "KDEInit.h" +#endif #ifndef _CONNECTIVITY_KAB_CONNECTION_HXX_ #include "KConnection.hxx" #endif -#include <kcmdlineargs.h> -#include <kglobal.h> -#include <klocale.h> +/** === begin UNO includes === **/ +#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_ +#include <com/sun/star/sdb/SQLContext.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_NULLPOINTEREXCEPTION_HPP_ +#include <com/sun/star/lang/NullPointerException.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_ +#include <com/sun/star/frame/XDesktop.hpp> +#endif +/** === end UNO includes === **/ -#ifndef _OSL_PROCESS_H_ -#include <osl/process.h> +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif +#ifndef TOOLS_DIAGNOSE_EX_H +#include <tools/diagnose_ex.h> #endif using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdb; +using namespace com::sun::star::frame; using namespace connectivity::kab; +// ======================================================================= +// = KabImplModule +// ======================================================================= +// -------------------------------------------------------------------------------- +KabImplModule::KabImplModule( const Reference< XMultiServiceFactory >& _rxFactory ) + :m_xORB(_rxFactory) + ,m_hConnectorModule(NULL) + ,m_bAttemptedLoadModule(false) + ,m_bAttemptedInitialize(false) + ,m_pConnectionFactoryFunc(NULL) + ,m_pApplicationInitFunc(NULL) + ,m_pApplicationShutdownFunc(NULL) + ,m_pKDEVersionCheckFunc(NULL) +{ + if ( !m_xORB.is() ) + throw NullPointerException(); +} + +// -------------------------------------------------------------------------------- +bool KabImplModule::isKDEPresent() +{ + if ( !impl_loadModule() ) + return false; + + return true; +} + +// -------------------------------------------------------------------------------- +KabImplModule::KDEVersionType KabImplModule::matchKDEVersion() +{ + OSL_PRECOND( m_pKDEVersionCheckFunc, "KabImplModule::matchKDEVersion: module not loaded!" ); + + int nVersionInfo = (*m_pKDEVersionCheckFunc)(); + if ( nVersionInfo < 0 ) + return eTooOld; + if ( nVersionInfo > 0 ) + return eToNew; + return eSupported; +} + +// -------------------------------------------------------------------------------- +namespace +{ + 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; + } + } + } +} + +// -------------------------------------------------------------------------------- +bool KabImplModule::impl_loadModule() +{ + if ( m_bAttemptedLoadModule ) + return ( m_hConnectorModule != NULL ); + m_bAttemptedLoadModule = true; + + OSL_ENSURE( !m_hConnectorModule && !m_pConnectionFactoryFunc && !m_pApplicationInitFunc && !m_pApplicationShutdownFunc && !m_pKDEVersionCheckFunc, + "KabImplModule::impl_loadModule: inconsistence: inconsistency (never attempted load before, but some values already set)!"); + + const ::rtl::OUString sModuleName = ::rtl::OUString::createFromAscii( SAL_MODULENAME( "kabdrv1" ) ); + m_hConnectorModule = osl_loadModule( sModuleName.pData, 0 ); + OSL_ENSURE( m_hConnectorModule, "KabImplModule::impl_loadModule: 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 ); + lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "matchKDEVersion", m_pKDEVersionCheckFunc ); + + if ( !m_hConnectorModule ) + // one of the symbols did not exist + throw RuntimeException(); + + return true; +} + +// -------------------------------------------------------------------------------- +void KabImplModule::impl_unloadModule() +{ + OSL_PRECOND( m_hConnectorModule != NULL, "KabImplModule::impl_unloadModule: no module!" ); + + osl_unloadModule( m_hConnectorModule ); + m_hConnectorModule = NULL; + + m_pConnectionFactoryFunc = NULL; + m_pApplicationInitFunc = NULL; + m_pApplicationShutdownFunc = NULL; + m_pKDEVersionCheckFunc = NULL; + + m_bAttemptedLoadModule = false; +} + +// -------------------------------------------------------------------------------- +void KabImplModule::init() +{ + if ( !impl_loadModule() ) + impl_throwNoKdeException(); + + // if we're not running on a supported version, throw + KabImplModule::KDEVersionType eKDEVersion = matchKDEVersion(); + + if ( eKDEVersion == eTooOld ) + impl_throwKdeTooOldException(); + + if ( ( eKDEVersion == eToNew ) && !impl_doAllowNewKDEVersion() ) + impl_throwKdeTooNewException(); + + if ( !m_bAttemptedInitialize ) + { + m_bAttemptedInitialize = true; + (*m_pApplicationInitFunc)(); + } +} + +// -------------------------------------------------------------------------------- +bool KabImplModule::impl_doAllowNewKDEVersion() +{ + try + { + Reference< XMultiServiceFactory > xConfigProvider( + m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ) ), + UNO_QUERY_THROW ); + Sequence< Any > aCreationArgs(1); + aCreationArgs[0] <<= PropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ), + 0, + makeAny( KabDriver::impl_getConfigurationSettingsPath() ), + PropertyState_DIRECT_VALUE ); + Reference< XPropertySet > xSettings( xConfigProvider->createInstanceWithArguments( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ), + aCreationArgs ), + UNO_QUERY_THROW ); + + sal_Bool bDisableCheck = sal_False; + xSettings->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DisableKDEMaximumVersionCheck" ) ) ) >>= bDisableCheck; + + fprintf( stderr, "---- disable: %i", (int)bDisableCheck ); + fflush( stderr ); + return bDisableCheck != sal_False; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return false; +} + +// -------------------------------------------------------------------------------- +void KabImplModule::impl_throwNoKdeException() +{ + impl_throwGenericSQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No suitable KDE installation was found." ) ) ); +} + +// -------------------------------------------------------------------------------- +void KabImplModule::impl_throwKdeTooOldException() +{ + ::rtl::OUStringBuffer aMessage; + aMessage.appendAscii( "KDE version " ); + aMessage.append( (sal_Int32)MIN_KDE_VERSION_MAJOR ); + aMessage.append( (sal_Unicode)'.' ); + aMessage.append( (sal_Int32)MIN_KDE_VERSION_MINOR ); + aMessage.appendAscii( " or higher is required to access the KDE Address Book." ); + + impl_throwGenericSQLException( aMessage.makeStringAndClear() ); +} + +// -------------------------------------------------------------------------------- +void KabImplModule::impl_throwGenericSQLException( const ::rtl::OUString& _rMessage ) +{ + SQLException aError; + aError.Message = _rMessage; + aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ); + aError.ErrorCode = 0; + throw aError; +} + +// -------------------------------------------------------------------------------- +void KabImplModule::impl_throwKdeTooNewException() +{ + ::rtl::OUStringBuffer aMessage; + aMessage.appendAscii( "The found KDE version is too new. Only KDE up to version " ); + aMessage.append( (sal_Int32)MAX_KDE_VERSION_MAJOR ); + aMessage.append( (sal_Unicode)'.' ); + aMessage.append( (sal_Int32)MAX_KDE_VERSION_MINOR ); + aMessage.appendAscii( " is known to work with this product.\n" ); + + SQLException aError; + aError.Message = aMessage.makeStringAndClear(); + aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ); + aError.ErrorCode = 0; + + SQLContext aDetails; + aMessage.appendAscii( "If you are sure that your KDE version works, " ); + aMessage.appendAscii( "you might execute the following Basic macro to disable this version check:\n\n" ); + + aMessage.appendAscii( "Sub disableKDEMaxVersionCheck\n" ); + aMessage.appendAscii( " BasicLibraries.LoadLibrary( \"Tools\" )\n" ); + + aMessage.appendAscii( " Dim configNode as Object\n" ); + aMessage.appendAscii( " configNode = GetRegistryKeyContent( \"" ); + aMessage.append( KabDriver::impl_getConfigurationSettingsPath() ); + aMessage.appendAscii( "\", true )\n" ); + + aMessage.appendAscii( " configNode.DisableKDEMaximumVersionCheck = TRUE\n" ); + aMessage.appendAscii( " configNode.commitChanges\n" ); + aMessage.appendAscii( "End Sub\n" ); + + aDetails.Message = aMessage.makeStringAndClear(); + + aError.NextException <<= aDetails; + + throw aError; +} + +// -------------------------------------------------------------------------------- +KabConnection* KabImplModule::createConnection( KabDriver* _pDriver ) const +{ + OSL_PRECOND( m_hConnectorModule, "KabImplModule::createConnection: not initialized!" ); + + void* pUntypedConnection = (*m_pConnectionFactoryFunc)( _pDriver ); + if ( !pUntypedConnection ) + throw RuntimeException(); + + return static_cast< KabConnection* >( pUntypedConnection ); +} + +// -------------------------------------------------------------------------------- +void KabImplModule::shutdown() +{ + if ( !m_hConnectorModule ) + return; + + (*m_pApplicationShutdownFunc)(); + m_bAttemptedInitialize = false; + + impl_unloadModule(); +} + +// ======================================================================= +// = KabDriver +// ======================================================================= 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_aImplModule(_rxFactory) { - // 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"); + if ( !m_xMSFactory.is() ) + throw NullPointerException(); - m_pKApplication = new KApplication(false, false); + osl_incrementInterlockedCount( &m_refCount ); + try + { + Reference< XDesktop > xDesktop( + m_xMSFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ), + UNO_QUERY_THROW ); + xDesktop->addTerminateListener( this ); } - - // 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); + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + osl_decrementInterlockedCount( &m_refCount ); } // -------------------------------------------------------------------------------- void KabDriver::disposing() @@ -91,21 +362,13 @@ } m_xConnections.clear(); - if (m_pKApplication != NULL) - { - delete m_pKApplication; - m_pKApplication = NULL; - } - - KDriver_BASE::disposing(); + WeakComponentImplHelperBase::disposing(); } // static ServiceInfo //------------------------------------------------------------------------------ rtl::OUString KabDriver::getImplementationName_Static( ) throw(RuntimeException) { - return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.kab.Driver"); - // this name is referenced in the configuration and in the kab.xml - // Please be careful when changing it. + return rtl::OUString::createFromAscii( impl_getAsciiImplementationName() ); } //------------------------------------------------------------------------------ Sequence< ::rtl::OUString > KabDriver::getSupportedServiceNames_Static( ) throw (RuntimeException) @@ -141,18 +404,35 @@ // -------------------------------------------------------------------------------- Reference< XConnection > SAL_CALL KabDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + + m_aImplModule.init(); + // 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)); + KabConnection* pConnection = m_aImplModule.createConnection( this ); + OSL_POSTCOND( pConnection, "KabDriver::connect: no connection has been created by the factory!" ); + + // 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 ); + + // remember it + m_xConnections.push_back( WeakReferenceHelper( *pConnection ) ); - return xCon; + return xConnection; } // -------------------------------------------------------------------------------- sal_Bool SAL_CALL KabDriver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException) { + ::osl::MutexGuard aGuard(m_aMutex); + + if ( !m_aImplModule.isKDEPresent() ) + 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 +455,38 @@ return 1; } // -------------------------------------------------------------------------------- - -//......................................................................... -namespace connectivity +void SAL_CALL KabDriver::queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException) { - 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 ) + // nothing to do, nothing to veto +} +// -------------------------------------------------------------------------------- +void SAL_CALL KabDriver::notifyTermination( const EventObject& Event ) throw (RuntimeException) { - return *(new KabDriver(_rxFactory)); + m_aImplModule.shutdown(); } - -void checkDisposed(sal_Bool _bThrow) throw ( DisposedException ) +// -------------------------------------------------------------------------------- +void SAL_CALL KabDriver::disposing( const EventObject& Source ) throw (RuntimeException) { - if (_bThrow) - throw DisposedException(); + // not interested in (this is the disposing of the desktop, if any) } - -//......................................................................... - } +// -------------------------------------------------------------------------------- +const sal_Char* KabDriver::impl_getAsciiImplementationName() +{ + return "com.sun.star.comp.sdbc.kab.Driver"; + // this name is referenced in the configuration and in the kab.xml + // Please be careful when changing it. } -//......................................................................... +// -------------------------------------------------------------------------------- +::rtl::OUString KabDriver::impl_getConfigurationSettingsPath() +{ + ::rtl::OUStringBuffer aPath; + aPath.appendAscii( "/org.openoffice.Office.DataAccess/DriverSettings/" ); + aPath.appendAscii( "com.sun.star.comp.sdbc.kab.Driver" ); + return aPath.makeStringAndClear(); +} +// -------------------------------------------------------------------------------- +Reference< XInterface > SAL_CALL KabDriver::Create( const Reference< XMultiServiceFactory >& _rxFactory ) throw( Exception ) +{ + return *(new KabDriver(_rxFactory)); +} + File [changed]: KDriver.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDriver.hxx?r1=1.2&r2=1.2.14.1 Delta lines: +163 -21 ---------------------- --- KDriver.hxx 19 Dec 2005 16:49:58 -0000 1.2 +++ KDriver.hxx 10 Jan 2006 14:23:20 -0000 1.2.14.1 @@ -4,9 +4,9 @@ * * $RCSfile: KDriver.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.14.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:49:58 $ + * last change: $Author: fs $ $Date: 2006/01/10 14:23:20 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -36,49 +36,178 @@ #ifndef _CONNECTIVITY_KAB_DRIVER_HXX_ #define _CONNECTIVITY_KAB_DRIVER_HXX_ -#ifndef _CONNECTIVITY_KAB_CONNECTION_HXX_ -#include "KConnection.hxx" -#endif - -#include <kapplication.h> - +/** === begin UNO includes === **/ #ifndef _COM_SUN_STAR_SDBC_XDRIVER_HPP_ #include <com/sun/star/sdbc/XDriver.hpp> #endif -#ifndef _CPPUHELPER_COMPBASE2_HXX_ -#include <cppuhelper/compbase2.hxx> +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ +#include <com/sun/star/lang/XServiceInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_ +#include <com/sun/star/frame/XTerminateListener.hpp> +#endif +/** === end UNO includes === **/ + +#ifndef _CPPUHELPER_COMPBASE3_HXX_ +#include <cppuhelper/compbase3.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 ); + class KabConnection; + class KabDriver; - typedef ::cppu::WeakComponentImplHelper2< ::com::sun::star::sdbc::XDriver, - ::com::sun::star::lang::XServiceInfo > KDriver_BASE; + typedef void* (SAL_CALL * ConnectionFactoryFunction)( void* _pDriver ); + typedef void (SAL_CALL * ApplicationInitFunction)( void ); + typedef void (SAL_CALL * ApplicationShutdownFunction)( void ); + typedef int (SAL_CALL * KDEVersionCheckFunction)( void ); + + typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; + + // =============================================================== + // = KabImplModule + // =============================================================== + class KabImplModule + { + private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + m_xORB; + + /// Did we already attempt to load the module and to retrieve the symbols? + bool m_bAttemptedLoadModule; + /// Did we already check the KDE version and initialize the impl module (or at least attempted to)? + bool m_bAttemptedInitialize; + + oslModule m_hConnectorModule; + ConnectionFactoryFunction m_pConnectionFactoryFunc; + ApplicationInitFunction m_pApplicationInitFunc; + ApplicationShutdownFunction m_pApplicationShutdownFunc; + KDEVersionCheckFunction m_pKDEVersionCheckFunc; + + public: + KabImplModule( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory ); + + /** determines whether there is a KDE present in the environment + */ + bool isKDEPresent(); + enum KDEVersionType + { + eTooOld, + eSupported, + eToNew + }; + /** checks whether the KDE version we're running against is supported + @precond + the module is loaded, i.e impl_loadModule has successfully been called + */ + KDEVersionType matchKDEVersion(); + + /** initializes the implementation module. + + @raises ::com::sun::star::uno::RuntimeException + if the module could be loaded, but required symbols are missing + @raises ::com::sun::star::sdbc::SQLException + if the KDE version we're running against is not supported, or no KDE was found at all + */ + void init(); + + /** shuts down the impl module (and the KDE application, if we own it) + */ + void shutdown(); + + /** creates a new connection + @precond + <member>init</member> has been called before + @raises ::com::sun::star::uno::RuntimeException + if no connection object could be created (which is a severe error, normally impossible) + */ + KabConnection* createConnection( KabDriver* _pDriver ) const; + + private: + /** loads the implementation module and retrieves the needed symbols + + Save against being called multiple times. + + @return <TRUE/> if the module could be loaded successfully. + + @raises ::com::sun::star::uno::RuntimeException + if the module could be loaded, but required symbols are missing + */ + bool impl_loadModule(); + + /** unloads the implementation module, and resets all function pointers to <NULL/> + @precond m_hConnectorModule is not <NULL/> + */ + void impl_unloadModule(); + + /** throws an SQLException saying than no KDE installation was found + */ + void impl_throwNoKdeException(); + + /** throws an SQLException saying that the found KDE version is too old + */ + void impl_throwKdeTooOldException(); + + /** throws an SQLException saying that the found KDE version is too new + */ + void impl_throwKdeTooNewException(); + + /** throws a generic SQL exception with SQLState S1000 and error code 0 + */ + void impl_throwGenericSQLException( const ::rtl::OUString& _rMessage ); + + /** determines whether it's allowed to run on a too-new (not confirmed to work) version + */ + bool impl_doAllowNewKDEVersion(); + }; + + // =============================================================== + // = KabDriver + // =============================================================== + typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XDriver, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::frame::XTerminateListener > 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 + KabImplModule m_aImplModule; 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; } + + /** returns the driver's implementation name (being pure ASCII) for reference in various places + */ + static const sal_Char* impl_getAsciiImplementationName(); + + /** returns the path of our configuration settings + */ + static ::rtl::OUString impl_getConfigurationSettingsPath(); + 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 +220,21 @@ 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; } + // XTerminateListener + virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + private: + /** shuts down the library which contains the real implementations + + This method is safe against being called multiple times + + @precond our mutex is locked + */ + 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.14.1 Delta lines: +18 -18 --------------------- --- KServices.cxx 19 Dec 2005 16:51:10 -0000 1.2 +++ KServices.cxx 10 Jan 2006 14:23:23 -0000 1.2.14.1 @@ -4,9 +4,9 @@ * * $RCSfile: KServices.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.14.1 $ * - * last change: $Author: obo $ $Date: 2005/12/19 16:51:10 $ + * last change: $Author: fs $ $Date: 2006/01/10 14:23:23 $ * * 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.14.1 Delta lines: +65 -48 --------------------- --- makefile.mk 19 Dec 2005 16:54:12 -0000 1.2 +++ makefile.mk 10 Jan 2006 14:23:26 -0000 1.2.14.1 @@ -4,9 +4,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.2.14.1 $ # -# last change: $Author: obo $ $Date: 2005/12/19 16:54:12 $ +# last change: $Author: fs $ $Date: 2006/01/10 14:23:26 $ # # 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,56 +92,41 @@ $(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" dummy: - @echo KDE disabled - nothing to build + @echo KDE Addressbook disabled - nothing to build .ENDIF .ELSE # "$(GUI)" == "UNX" --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]