Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / kab / KDriver.hxx
blob049381a9e4b6adf84d148a2c18411fdef6fc3ace
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: KDriver.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONNECTIVITY_KAB_DRIVER_HXX_
32 #define _CONNECTIVITY_KAB_DRIVER_HXX_
34 /** === begin UNO includes === **/
35 #include <com/sun/star/sdbc/XDriver.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/frame/XTerminateListener.hpp>
38 /** === end UNO includes === **/
39 #include <cppuhelper/compbase3.hxx>
40 #include <osl/module.h>
42 namespace connectivity
44 namespace kab
46 class KabConnection;
47 class KabDriver;
49 typedef void* (SAL_CALL * ConnectionFactoryFunction)( void* _pDriver );
50 typedef void (SAL_CALL * ApplicationInitFunction)( void );
51 typedef void (SAL_CALL * ApplicationShutdownFunction)( void );
52 typedef int (SAL_CALL * KDEVersionCheckFunction)( void );
54 typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
56 // ===============================================================
57 // = KabImplModule
58 // ===============================================================
59 class KabImplModule
61 private:
62 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
63 m_xORB;
65 /// Did we already attempt to load the module and to retrieve the symbols?
66 bool m_bAttemptedLoadModule;
67 /// Did we already check the KDE version and initialize the impl module (or at least attempted to)?
68 bool m_bAttemptedInitialize;
70 oslModule m_hConnectorModule;
71 ConnectionFactoryFunction m_pConnectionFactoryFunc;
72 ApplicationInitFunction m_pApplicationInitFunc;
73 ApplicationShutdownFunction m_pApplicationShutdownFunc;
74 KDEVersionCheckFunction m_pKDEVersionCheckFunc;
76 public:
77 KabImplModule( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory );
79 /** determines whether there is a KDE present in the environment
81 bool isKDEPresent();
83 enum KDEVersionType
85 eTooOld,
86 eSupported,
87 eToNew
89 /** checks whether the KDE version we're running against is supported
90 @precond
91 the module is loaded, i.e impl_loadModule has successfully been called
93 KDEVersionType matchKDEVersion();
95 /** initializes the implementation module.
97 @raises ::com::sun::star::uno::RuntimeException
98 if the module could be loaded, but required symbols are missing
99 @raises ::com::sun::star::sdbc::SQLException
100 if the KDE version we're running against is not supported, or no KDE was found at all
102 void init();
104 /** shuts down the impl module (and the KDE application, if we own it)
106 void shutdown();
108 /** creates a new connection
109 @precond
110 <member>init</member> has been called before
111 @raises ::com::sun::star::uno::RuntimeException
112 if no connection object could be created (which is a severe error, normally impossible)
114 KabConnection* createConnection( KabDriver* _pDriver ) const;
116 private:
117 /** loads the implementation module and retrieves the needed symbols
119 Save against being called multiple times.
121 @return <TRUE/> if the module could be loaded successfully.
123 @raises ::com::sun::star::uno::RuntimeException
124 if the module could be loaded, but required symbols are missing
126 bool impl_loadModule();
128 /** unloads the implementation module, and resets all function pointers to <NULL/>
129 @precond m_hConnectorModule is not <NULL/>
131 void impl_unloadModule();
133 /** throws an SQLException saying than no KDE installation was found
135 void impl_throwNoKdeException();
137 /** throws an SQLException saying that the found KDE version is too old
139 void impl_throwKdeTooOldException();
141 /** throws an SQLException saying that the found KDE version is too new
143 void impl_throwKdeTooNewException();
145 /** throws a generic SQL exception with SQLState S1000 and error code 0
147 void impl_throwGenericSQLException( const ::rtl::OUString& _rMessage );
149 /** determines whether it's allowed to run on a too-new (not confirmed to work) version
151 bool impl_doAllowNewKDEVersion();
154 // ===============================================================
155 // = KabDriver
156 // ===============================================================
157 typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XDriver,
158 ::com::sun::star::lang::XServiceInfo,
159 ::com::sun::star::frame::XTerminateListener > KDriver_BASE;
160 class KabDriver : public KDriver_BASE
162 protected:
163 ::osl::Mutex m_aMutex; // mutex is need to control member access
164 OWeakRefArray m_xConnections; // vector containing a list of all the
165 // KabConnection objects for this Driver
166 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
167 m_xMSFactory; // the multi-service factory
168 KabImplModule m_aImplModule;
170 public:
171 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 );
173 // XServiceInfo - static versions
174 static ::rtl::OUString getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException);
175 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException);
177 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
178 getMSFactory() const { return m_xMSFactory; }
180 /** returns the driver's implementation name (being pure ASCII) for reference in various places
182 static const sal_Char* impl_getAsciiImplementationName();
184 /** returns the path of our configuration settings
186 static ::rtl::OUString impl_getConfigurationSettingsPath();
188 protected:
189 KabDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory);
191 // OComponentHelper
192 virtual void SAL_CALL disposing(void);
194 // XServiceInfo
195 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException);
196 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
197 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException);
199 // XDriver
200 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);
201 virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
202 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);
203 virtual sal_Int32 SAL_CALL getMajorVersion() throw(::com::sun::star::uno::RuntimeException);
204 virtual sal_Int32 SAL_CALL getMinorVersion() throw(::com::sun::star::uno::RuntimeException);
206 // XTerminateListener
207 virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
208 virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
210 // XEventListener
211 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
213 private:
214 /** shuts down the library which contains the real implementations
216 This method is safe against being called multiple times
218 @precond our mutex is locked
220 void impl_shutdownImplementationModule();
226 #endif // _CONNECTIVITY_KAB_DRIVER_HXX_