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