build fix
[LibreOffice.git] / connectivity / source / drivers / kab / KDriver.hxx
blobb061b00406680ac6e51da28aaa11e4d6694ee61f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/compbase.hxx>
28 #include <osl/module.h>
30 namespace connectivity
32 namespace kab
34 class KabDriver;
36 extern "C" {
37 typedef css::uno::XInterface * (SAL_CALL * ConnectionFactoryFunction)(
38 css::uno::Reference<css::uno::XComponentContext> const &,
39 css::uno::Reference<css::sdbc::XDriver> const &);
40 typedef void (SAL_CALL * ApplicationInitFunction)( void );
41 typedef void (SAL_CALL * ApplicationShutdownFunction)( void );
42 typedef int (SAL_CALL * KDEVersionCheckFunction)( void );
45 typedef std::vector< css::uno::WeakReferenceHelper > OWeakRefArray;
48 // = KabImplModule
50 class KabImplModule
52 private:
53 css::uno::Reference< css::uno::XComponentContext >
54 m_xContext;
56 /// Did we already attempt to load the module and to retrieve the symbols?
57 bool m_bAttemptedLoadModule;
58 /// Did we already check the KDE version and initialize the impl module (or at least attempted to)?
59 bool m_bAttemptedInitialize;
61 oslModule m_hConnectorModule;
62 ConnectionFactoryFunction m_pConnectionFactoryFunc;
63 ApplicationInitFunction m_pApplicationInitFunc;
64 ApplicationShutdownFunction m_pApplicationShutdownFunc;
65 KDEVersionCheckFunction m_pKDEVersionCheckFunc;
67 public:
68 explicit KabImplModule( const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
70 /** determines whether there is a KDE present in the environment
72 bool isKDEPresent();
74 enum KDEVersionType
76 eTooOld,
77 eSupported,
78 eToNew
80 /** checks whether the KDE version we're running against is supported
81 @precond
82 the module is loaded, i.e impl_loadModule has successfully been called
84 KDEVersionType matchKDEVersion();
86 /** initializes the implementation module.
88 @throws css::uno::RuntimeException
89 if the module could be loaded, but required symbols are missing
90 @throws css::sdbc::SQLException
91 if the KDE version we're running against is not supported, or no KDE was found at all
93 void init();
95 /** shuts down the impl module (and the KDE application, if we own it)
97 void shutdown();
99 /** creates a new connection
100 @precond
101 <member>init</member> has been called before
102 @throws css::uno::RuntimeException
103 if no connection object could be created (which is a severe error, normally impossible)
105 css::uno::Reference<css::sdbc::XConnection> createConnection(
106 KabDriver * driver) const;
108 private:
109 /** loads the implementation module and retrieves the needed symbols
111 Save against being called multiple times.
113 @return <TRUE/> if the module could be loaded successfully.
115 @throws css::uno::RuntimeException
116 if the module could be loaded, but required symbols are missing
118 bool impl_loadModule();
120 /** unloads the implementation module, and resets all function pointers to <nullptr/>
121 @precond m_hConnectorModule is not <nullptr/>
123 void impl_unloadModule();
125 /** determines whether it's allowed to run on a too-new (not confirmed to work) version
127 bool impl_doAllowNewKDEVersion();
131 // = KabDriver
133 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver,
134 css::lang::XServiceInfo,
135 css::frame::XTerminateListener > KDriver_BASE;
136 class KabDriver : public KDriver_BASE
138 protected:
139 ::osl::Mutex m_aMutex; // mutex is need to control member access
140 OWeakRefArray m_xConnections; // vector containing a list of all the
141 // KabConnection objects for this Driver
142 css::uno::Reference< css::uno::XComponentContext >
143 m_xContext; // the multi-service factory
144 KabImplModule m_aImplModule;
146 public:
147 static css::uno::Reference< css::uno::XInterface > SAL_CALL Create(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) throw( css::uno::Exception );
149 // XServiceInfo - static versions
150 static OUString getImplementationName_Static( ) throw(css::uno::RuntimeException);
151 static css::uno::Sequence< OUString > getSupportedServiceNames_Static( ) throw (css::uno::RuntimeException);
153 /** returns the path of our configuration settings
155 static OUString impl_getConfigurationSettingsPath();
157 protected:
158 explicit KabDriver(const css::uno::Reference< css::uno::XComponentContext >& _rxContext);
160 // OComponentHelper
161 virtual void SAL_CALL disposing() override;
163 // XServiceInfo
164 virtual OUString SAL_CALL getImplementationName( ) throw(css::uno::RuntimeException, std::exception) override;
165 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(css::uno::RuntimeException, std::exception) override;
166 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(css::uno::RuntimeException, std::exception) override;
168 // XDriver
169 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override;
170 virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override;
171 virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override;
172 virtual sal_Int32 SAL_CALL getMajorVersion() throw(css::uno::RuntimeException, std::exception) override;
173 virtual sal_Int32 SAL_CALL getMinorVersion() throw(css::uno::RuntimeException, std::exception) override;
175 // XTerminateListener
176 virtual void SAL_CALL queryTermination( const css::lang::EventObject& Event ) throw (css::frame::TerminationVetoException, css::uno::RuntimeException, std::exception) override;
177 virtual void SAL_CALL notifyTermination( const css::lang::EventObject& Event ) throw (css::uno::RuntimeException, std::exception) override;
179 // XEventListener
180 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw (css::uno::RuntimeException, std::exception) override;
182 private:
183 /** shuts down the library which contains the real implementations
185 This method is safe against being called multiple times
187 @precond our mutex is locked
189 void impl_shutdownImplementationModule();
195 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_KAB_KDRIVER_HXX
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */