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 .
22 #include <com/sun/star/sdbc/XDriver.hpp>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/frame/XTerminateListener.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <cppuhelper/compbase.hxx>
28 #include <osl/module.h>
30 // the address book driver's version
31 #define MACAB_DRIVER_VERSION "0.1"
32 #define MACAB_DRIVER_VERSION_MAJOR 0
33 #define MACAB_DRIVER_VERSION_MINOR 1
35 namespace connectivity::macab
37 class MacabConnection
;
40 typedef void* (SAL_CALL
* ConnectionFactoryFunction
)( void* _pDriver
);
42 typedef std::vector
< css::uno::WeakReferenceHelper
> OWeakRefArray
;
50 /// Did we already attempt to load the module and to retrieve the symbols?
51 bool m_bAttemptedLoadModule
;
52 oslModule m_hConnectorModule
;
53 ConnectionFactoryFunction m_pConnectionFactoryFunc
;
58 /** determines whether there is a mac OS present in the environment
60 bool isMacOSPresent();
62 /** initializes the implementation module.
64 @throws css::uno::RuntimeException
65 if the module could be loaded, but required symbols are missing
66 @throws css::sdbc::SQLException
67 if no Mac OS was found at all
71 /** shuts down the impl module
75 /** creates a new connection
77 <member>init</member> has been called before
78 @throws css::uno::RuntimeException
79 if no connection object could be created (which is a severe error, normally impossible)
81 MacabConnection
* createConnection( MacabDriver
* _pDriver
) const;
84 /** loads the implementation module and retrieves the needed symbols
86 Save against being called multiple times.
88 @return <TRUE/> if the module could be loaded successfully.
90 @throws css::uno::RuntimeException
91 if the module could be loaded, but required symbols are missing
93 bool impl_loadModule();
95 /** unloads the implementation module, and resets all function pointers to <NULL/>
96 @precond m_hConnectorModule is not <NULL/>
98 void impl_unloadModule();
104 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XDriver
,
105 css::lang::XServiceInfo
,
106 css::frame::XTerminateListener
> MacabDriver_BASE
;
107 class MacabDriver
: public MacabDriver_BASE
110 ::osl::Mutex m_aMutex
; // mutex is need to control member access
111 OWeakRefArray m_xConnections
; // vector containing a list of all the
112 // MacabConnection objects for this Driver
113 css::uno::Reference
< css::uno::XComponentContext
>
114 m_xContext
; // the multi-service factory
115 MacabImplModule m_aImplModule
;
118 css::uno::Reference
< css::uno::XComponentContext
> const &
119 getComponentContext() const { return m_xContext
; }
121 /** returns the path of our configuration settings
123 static OUString
impl_getConfigurationSettingsPath();
125 explicit MacabDriver(const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
129 virtual void SAL_CALL
disposing() override
;
132 virtual OUString SAL_CALL
getImplementationName( ) override
;
133 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
134 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
137 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
connect( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
138 virtual sal_Bool SAL_CALL
acceptsURL( const OUString
& url
) override
;
139 virtual css::uno::Sequence
< css::sdbc::DriverPropertyInfo
> SAL_CALL
getPropertyInfo( const OUString
& url
, const css::uno::Sequence
< css::beans::PropertyValue
>& info
) override
;
140 virtual sal_Int32 SAL_CALL
getMajorVersion() override
;
141 virtual sal_Int32 SAL_CALL
getMinorVersion() override
;
143 // XTerminateListener
144 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& Event
) override
;
145 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& Event
) override
;
148 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
151 /** shuts down the library which contains the real implementations
153 This method is safe against being called multiple times
155 @precond our mutex is locked
157 void impl_shutdownImplementationModule();
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */