1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _CONNECTIVITY_KAB_DRIVER_HXX_ 25cdf0e10cSrcweir #define _CONNECTIVITY_KAB_DRIVER_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp> 29cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 30cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp> 31cdf0e10cSrcweir /** === end UNO includes === **/ 32cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx> 33cdf0e10cSrcweir #include <osl/module.h> 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace connectivity 36cdf0e10cSrcweir { 37cdf0e10cSrcweir namespace kab 38cdf0e10cSrcweir { 39cdf0e10cSrcweir class KabConnection; 40cdf0e10cSrcweir class KabDriver; 41cdf0e10cSrcweir 42cdf0e10cSrcweir typedef void* (SAL_CALL * ConnectionFactoryFunction)( void* _pDriver ); 43cdf0e10cSrcweir typedef void (SAL_CALL * ApplicationInitFunction)( void ); 44cdf0e10cSrcweir typedef void (SAL_CALL * ApplicationShutdownFunction)( void ); 45cdf0e10cSrcweir typedef int (SAL_CALL * KDEVersionCheckFunction)( void ); 46cdf0e10cSrcweir 47cdf0e10cSrcweir typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; 48cdf0e10cSrcweir 49cdf0e10cSrcweir // =============================================================== 50cdf0e10cSrcweir // = KabImplModule 51cdf0e10cSrcweir // =============================================================== 52cdf0e10cSrcweir class KabImplModule 53cdf0e10cSrcweir { 54cdf0e10cSrcweir private: 55cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > 56cdf0e10cSrcweir m_xORB; 57cdf0e10cSrcweir 58cdf0e10cSrcweir /// Did we already attempt to load the module and to retrieve the symbols? 59cdf0e10cSrcweir bool m_bAttemptedLoadModule; 60cdf0e10cSrcweir /// Did we already check the KDE version and initialize the impl module (or at least attempted to)? 61cdf0e10cSrcweir bool m_bAttemptedInitialize; 62cdf0e10cSrcweir 63cdf0e10cSrcweir oslModule m_hConnectorModule; 64cdf0e10cSrcweir ConnectionFactoryFunction m_pConnectionFactoryFunc; 65cdf0e10cSrcweir ApplicationInitFunction m_pApplicationInitFunc; 66cdf0e10cSrcweir ApplicationShutdownFunction m_pApplicationShutdownFunc; 67cdf0e10cSrcweir KDEVersionCheckFunction m_pKDEVersionCheckFunc; 68cdf0e10cSrcweir 69cdf0e10cSrcweir public: 70cdf0e10cSrcweir KabImplModule( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** determines whether there is a KDE present in the environment 73cdf0e10cSrcweir */ 74cdf0e10cSrcweir bool isKDEPresent(); 75cdf0e10cSrcweir 76cdf0e10cSrcweir enum KDEVersionType 77cdf0e10cSrcweir { 78cdf0e10cSrcweir eTooOld, 79cdf0e10cSrcweir eSupported, 80cdf0e10cSrcweir eToNew 81cdf0e10cSrcweir }; 82cdf0e10cSrcweir /** checks whether the KDE version we're running against is supported 83cdf0e10cSrcweir @precond 84cdf0e10cSrcweir the module is loaded, i.e impl_loadModule has successfully been called 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir KDEVersionType matchKDEVersion(); 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** initializes the implementation module. 89cdf0e10cSrcweir 90cdf0e10cSrcweir @raises ::com::sun::star::uno::RuntimeException 91cdf0e10cSrcweir if the module could be loaded, but required symbols are missing 92cdf0e10cSrcweir @raises ::com::sun::star::sdbc::SQLException 93cdf0e10cSrcweir if the KDE version we're running against is not supported, or no KDE was found at all 94cdf0e10cSrcweir */ 95cdf0e10cSrcweir void init(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** shuts down the impl module (and the KDE application, if we own it) 98cdf0e10cSrcweir */ 99cdf0e10cSrcweir void shutdown(); 100cdf0e10cSrcweir 101cdf0e10cSrcweir /** creates a new connection 102cdf0e10cSrcweir @precond 103cdf0e10cSrcweir <member>init</member> has been called before 104cdf0e10cSrcweir @raises ::com::sun::star::uno::RuntimeException 105cdf0e10cSrcweir if no connection object could be created (which is a severe error, normally impossible) 106cdf0e10cSrcweir */ 107cdf0e10cSrcweir KabConnection* createConnection( KabDriver* _pDriver ) const; 108cdf0e10cSrcweir 109cdf0e10cSrcweir private: 110cdf0e10cSrcweir /** loads the implementation module and retrieves the needed symbols 111cdf0e10cSrcweir 112cdf0e10cSrcweir Save against being called multiple times. 113cdf0e10cSrcweir 114cdf0e10cSrcweir @return <TRUE/> if the module could be loaded successfully. 115cdf0e10cSrcweir 116cdf0e10cSrcweir @raises ::com::sun::star::uno::RuntimeException 117cdf0e10cSrcweir if the module could be loaded, but required symbols are missing 118cdf0e10cSrcweir */ 119cdf0e10cSrcweir bool impl_loadModule(); 120cdf0e10cSrcweir 121cdf0e10cSrcweir /** unloads the implementation module, and resets all function pointers to <NULL/> 122cdf0e10cSrcweir @precond m_hConnectorModule is not <NULL/> 123cdf0e10cSrcweir */ 124cdf0e10cSrcweir void impl_unloadModule(); 125cdf0e10cSrcweir 126cdf0e10cSrcweir /** throws an SQLException saying than no KDE installation was found 127cdf0e10cSrcweir */ 128cdf0e10cSrcweir void impl_throwNoKdeException(); 129cdf0e10cSrcweir 130cdf0e10cSrcweir /** throws an SQLException saying that the found KDE version is too old 131cdf0e10cSrcweir */ 132cdf0e10cSrcweir void impl_throwKdeTooOldException(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir /** throws an SQLException saying that the found KDE version is too new 135cdf0e10cSrcweir */ 136cdf0e10cSrcweir void impl_throwKdeTooNewException(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir /** throws a generic SQL exception with SQLState S1000 and error code 0 139cdf0e10cSrcweir */ 140cdf0e10cSrcweir void impl_throwGenericSQLException( const ::rtl::OUString& _rMessage ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir /** determines whether it's allowed to run on a too-new (not confirmed to work) version 143cdf0e10cSrcweir */ 144cdf0e10cSrcweir bool impl_doAllowNewKDEVersion(); 145cdf0e10cSrcweir }; 146cdf0e10cSrcweir 147cdf0e10cSrcweir // =============================================================== 148cdf0e10cSrcweir // = KabDriver 149cdf0e10cSrcweir // =============================================================== 150cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XDriver, 151cdf0e10cSrcweir ::com::sun::star::lang::XServiceInfo, 152cdf0e10cSrcweir ::com::sun::star::frame::XTerminateListener > KDriver_BASE; 153cdf0e10cSrcweir class KabDriver : public KDriver_BASE 154cdf0e10cSrcweir { 155cdf0e10cSrcweir protected: 156cdf0e10cSrcweir ::osl::Mutex m_aMutex; // mutex is need to control member access 157cdf0e10cSrcweir OWeakRefArray m_xConnections; // vector containing a list of all the 158cdf0e10cSrcweir // KabConnection objects for this Driver 159cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > 160cdf0e10cSrcweir m_xMSFactory; // the multi-service factory 161cdf0e10cSrcweir KabImplModule m_aImplModule; 162cdf0e10cSrcweir 163cdf0e10cSrcweir public: 164cdf0e10cSrcweir 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 ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir // XServiceInfo - static versions 167cdf0e10cSrcweir static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException); 168cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException); 169cdf0e10cSrcweir 170cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getMSFactory() const171cdf0e10cSrcweir getMSFactory() const { return m_xMSFactory; } 172cdf0e10cSrcweir 173cdf0e10cSrcweir /** returns the driver's implementation name (being pure ASCII) for reference in various places 174cdf0e10cSrcweir */ 175cdf0e10cSrcweir static const sal_Char* impl_getAsciiImplementationName(); 176cdf0e10cSrcweir 177cdf0e10cSrcweir /** returns the path of our configuration settings 178cdf0e10cSrcweir */ 179cdf0e10cSrcweir static ::rtl::OUString impl_getConfigurationSettingsPath(); 180cdf0e10cSrcweir 181cdf0e10cSrcweir protected: 182cdf0e10cSrcweir KabDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 183cdf0e10cSrcweir 184cdf0e10cSrcweir // OComponentHelper 185cdf0e10cSrcweir virtual void SAL_CALL disposing(void); 186cdf0e10cSrcweir 187cdf0e10cSrcweir // XServiceInfo 188cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); 189cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); 190cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); 191cdf0e10cSrcweir 192cdf0e10cSrcweir // XDriver 193cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connect( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 194cdf0e10cSrcweir virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 195cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const ::rtl::OUString& url, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 196cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getMajorVersion() throw(::com::sun::star::uno::RuntimeException); 197cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getMinorVersion() throw(::com::sun::star::uno::RuntimeException); 198cdf0e10cSrcweir 199cdf0e10cSrcweir // XTerminateListener 200cdf0e10cSrcweir virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException); 201cdf0e10cSrcweir virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException); 202cdf0e10cSrcweir 203cdf0e10cSrcweir // XEventListener 204cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 205cdf0e10cSrcweir 206cdf0e10cSrcweir private: 207cdf0e10cSrcweir /** shuts down the library which contains the real implementations 208cdf0e10cSrcweir 209cdf0e10cSrcweir This method is safe against being called multiple times 210cdf0e10cSrcweir 211cdf0e10cSrcweir @precond our mutex is locked 212cdf0e10cSrcweir */ 213cdf0e10cSrcweir void impl_shutdownImplementationModule(); 214cdf0e10cSrcweir }; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir #endif // _CONNECTIVITY_KAB_DRIVER_HXX_ 220