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_MACAB_MACABDRIVER_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDRIVER_HXX
23 #include <com/sun/star/sdbc/XDriver.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/frame/XTerminateListener.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <cppuhelper/compbase.hxx>
29 #include <osl/module.h>
31 // the address book driver's version
32 #define MACAB_DRIVER_VERSION "0.1"
33 #define MACAB_DRIVER_VERSION_MAJOR 0
34 #define MACAB_DRIVER_VERSION_MINOR 1
36 namespace connectivity
40 class MacabConnection
;
43 typedef void* (SAL_CALL
* ConnectionFactoryFunction
)( void* _pDriver
);
45 typedef std::vector
< css::uno::WeakReferenceHelper
> OWeakRefArray
;
53 /// Did we already attempt to load the module and to retrieve the symbols?
54 bool m_bAttemptedLoadModule
;
55 oslModule m_hConnectorModule
;
56 ConnectionFactoryFunction m_pConnectionFactoryFunc
;
61 /** determines whether there is a mac OS present in the environment
63 bool isMacOSPresent();
65 /** initializes the implementation module.
67 @throws css::uno::RuntimeException
68 if the module could be loaded, but required symbols are missing
69 @throws css::sdbc::SQLException
70 if no Mac OS was found at all
74 /** shuts down the impl module
78 /** creates a new connection
80 <member>init</member> has been called before
81 @throws css::uno::RuntimeException
82 if no connection object could be created (which is a severe error, normally impossible)
84 MacabConnection
* createConnection( MacabDriver
* _pDriver
) const;
87 /** loads the implementation module and retrieves the needed symbols
89 Save against being called multiple times.
91 @return <TRUE/> if the module could be loaded successfully.
93 @throws css::uno::RuntimeException
94 if the module could be loaded, but required symbols are missing
96 bool impl_loadModule();
98 /** unloads the implementation module, and resets all function pointers to <NULL/>
99 @precond m_hConnectorModule is not <NULL/>
101 void impl_unloadModule();
107 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XDriver
,
108 css::lang::XServiceInfo
,
109 css::frame::XTerminateListener
> MacabDriver_BASE
;
110 class MacabDriver
: public MacabDriver_BASE
113 ::osl::Mutex m_aMutex
; // mutex is need to control member access
114 OWeakRefArray m_xConnections
; // vector containing a list of all the
115 // MacabConnection objects for this Driver
116 css::uno::Reference
< css::uno::XComponentContext
>
117 m_xContext
; // the multi-service factory
118 MacabImplModule m_aImplModule
;
121 static css::uno::Reference
< css::uno::XInterface
> SAL_CALL
Create(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& _rxFactory
) throw( css::uno::Exception
);
123 // XServiceInfo - static versions
124 static OUString
getImplementationName_Static( ) throw(css::uno::RuntimeException
);
125 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static( ) throw (css::uno::RuntimeException
);
127 css::uno::Reference
< css::uno::XComponentContext
> const &
128 getComponentContext() const { return m_xContext
; }
130 /** returns the path of our configuration settings
132 static OUString
impl_getConfigurationSettingsPath();
135 explicit MacabDriver(const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
138 virtual void SAL_CALL
disposing() override
;
141 virtual OUString SAL_CALL
getImplementationName( ) throw(css::uno::RuntimeException
) override
;
142 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(css::uno::RuntimeException
) override
;
143 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(css::uno::RuntimeException
) override
;
146 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
) override
;
147 virtual sal_Bool SAL_CALL
acceptsURL( const OUString
& url
) throw(css::sdbc::SQLException
, css::uno::RuntimeException
) override
;
148 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
) override
;
149 virtual sal_Int32 SAL_CALL
getMajorVersion() throw(css::uno::RuntimeException
) override
;
150 virtual sal_Int32 SAL_CALL
getMinorVersion() throw(css::uno::RuntimeException
) override
;
152 // XTerminateListener
153 virtual void SAL_CALL
queryTermination( const css::lang::EventObject
& Event
) throw (css::frame::TerminationVetoException
, css::uno::RuntimeException
) override
;
154 virtual void SAL_CALL
notifyTermination( const css::lang::EventObject
& Event
) throw (css::uno::RuntimeException
) override
;
157 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw (css::uno::RuntimeException
) override
;
160 /** shuts down the library which contains the real implementations
162 This method is safe against being called multiple times
164 @precond our mutex is locked
166 void impl_shutdownImplementationModule();
172 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDRIVER_HXX
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */