1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_KAB_KDRIVER_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_KAB_KDRIVER_HXX
23 #include <com/sun/star/sdbc/XDriver.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/frame/XTerminateListener.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <cppuhelper/compbase3.hxx>
28 #include <osl/module.h>
30 namespace connectivity
37 typedef void* (SAL_CALL
* ConnectionFactoryFunction
)( void* _pDriver
);
38 typedef void (SAL_CALL
* ApplicationInitFunction
)( void );
39 typedef void (SAL_CALL
* ApplicationShutdownFunction
)( void );
40 typedef int (SAL_CALL
* KDEVersionCheckFunction
)( void );
42 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
50 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
53 /// Did we already attempt to load the module and to retrieve the symbols?
54 bool m_bAttemptedLoadModule
;
55 /// Did we already check the KDE version and initialize the impl module (or at least attempted to)?
56 bool m_bAttemptedInitialize
;
58 oslModule m_hConnectorModule
;
59 ConnectionFactoryFunction m_pConnectionFactoryFunc
;
60 ApplicationInitFunction m_pApplicationInitFunc
;
61 ApplicationShutdownFunction m_pApplicationShutdownFunc
;
62 KDEVersionCheckFunction m_pKDEVersionCheckFunc
;
65 KabImplModule( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
67 /** determines whether there is a KDE present in the environment
77 /** checks whether the KDE version we're running against is supported
79 the module is loaded, i.e impl_loadModule has successfully been called
81 KDEVersionType
matchKDEVersion();
83 /** initializes the implementation module.
85 @raises ::com::sun::star::uno::RuntimeException
86 if the module could be loaded, but required symbols are missing
87 @raises ::com::sun::star::sdbc::SQLException
88 if the KDE version we're running against is not supported, or no KDE was found at all
92 /** shuts down the impl module (and the KDE application, if we own it)
96 /** creates a new connection
98 <member>init</member> has been called before
99 @raises ::com::sun::star::uno::RuntimeException
100 if no connection object could be created (which is a severe error, normally impossible)
102 KabConnection
* createConnection( KabDriver
* _pDriver
) const;
105 /** loads the implementation module and retrieves the needed symbols
107 Save against being called multiple times.
109 @return <TRUE/> if the module could be loaded successfully.
111 @raises ::com::sun::star::uno::RuntimeException
112 if the module could be loaded, but required symbols are missing
114 bool impl_loadModule();
116 /** unloads the implementation module, and resets all function pointers to <NULL/>
117 @precond m_hConnectorModule is not <NULL/>
119 void impl_unloadModule();
121 /** throws an SQLException saying than no KDE installation was found
123 void impl_throwNoKdeException();
125 /** throws an SQLException saying that the found KDE version is too old
127 void impl_throwKdeTooOldException();
129 /** throws an SQLException saying that the found KDE version is too new
131 void impl_throwKdeTooNewException();
133 /** throws a generic SQL exception with SQLState S1000 and error code 0
135 void impl_throwGenericSQLException( const OUString
& _rMessage
);
137 /** determines whether it's allowed to run on a too-new (not confirmed to work) version
139 bool impl_doAllowNewKDEVersion();
145 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XDriver
,
146 ::com::sun::star::lang::XServiceInfo
,
147 ::com::sun::star::frame::XTerminateListener
> KDriver_BASE
;
148 class KabDriver
: public KDriver_BASE
151 ::osl::Mutex m_aMutex
; // mutex is need to control member access
152 OWeakRefArray m_xConnections
; // vector containing a list of all the
153 // KabConnection objects for this Driver
154 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
155 m_xContext
; // the multi-service factory
156 KabImplModule m_aImplModule
;
159 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
);
161 // XServiceInfo - static versions
162 static OUString
getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException
);
163 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException
);
165 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
166 getComponentContext() const { return m_xContext
; }
168 /** returns the driver's implementation name (being pure ASCII) for reference in various places
170 static const sal_Char
* impl_getAsciiImplementationName();
172 /** returns the path of our configuration settings
174 static OUString
impl_getConfigurationSettingsPath();
177 KabDriver(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
180 virtual void SAL_CALL
disposing(void) SAL_OVERRIDE
;
183 virtual OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
184 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
185 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
188 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
connect( const 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
, std::exception
) SAL_OVERRIDE
;
189 virtual sal_Bool SAL_CALL
acceptsURL( const OUString
& url
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
190 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::sdbc::DriverPropertyInfo
> SAL_CALL
getPropertyInfo( const 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
, std::exception
) SAL_OVERRIDE
;
191 virtual sal_Int32 SAL_CALL
getMajorVersion() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
192 virtual sal_Int32 SAL_CALL
getMinorVersion() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
194 // XTerminateListener
195 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
196 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
199 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
202 /** shuts down the library which contains the real implementations
204 This method is safe against being called multiple times
206 @precond our mutex is locked
208 void impl_shutdownImplementationModule();
214 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_KAB_KDRIVER_HXX
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */