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/frame/XTerminateListener.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <cppuhelper/compbase3.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
39 class MacabConnection
;
42 typedef void* (SAL_CALL
* ConnectionFactoryFunction
)( void* _pDriver
);
44 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
52 /// Did we already attempt to load the module and to retrieve the symbols?
53 bool m_bAttemptedLoadModule
;
54 oslModule m_hConnectorModule
;
55 ConnectionFactoryFunction m_pConnectionFactoryFunc
;
60 /** determines whether there is a mac OS present in the environment
62 bool isMacOSPresent();
64 /** initializes the implementation module.
66 @raises ::com::sun::star::uno::RuntimeException
67 if the module could be loaded, but required symbols are missing
68 @raises ::com::sun::star::sdbc::SQLException
69 if no Mac OS was found at all
73 /** shuts down the impl module
77 /** creates a new connection
79 <member>init</member> has been called before
80 @raises ::com::sun::star::uno::RuntimeException
81 if no connection object could be created (which is a severe error, normally impossible)
83 MacabConnection
* createConnection( MacabDriver
* _pDriver
) const;
86 /** loads the implementation module and retrieves the needed symbols
88 Save against being called multiple times.
90 @return <TRUE/> if the module could be loaded successfully.
92 @raises ::com::sun::star::uno::RuntimeException
93 if the module could be loaded, but required symbols are missing
95 bool impl_loadModule();
97 /** unloads the implementation module, and resets all function pointers to <NULL/>
98 @precond m_hConnectorModule is not <NULL/>
100 void impl_unloadModule();
102 /** throws an SQLException saying than no Mac OS installation was found
104 void impl_throwNoMacOSException();
106 /** throws a generic SQL exception with SQLState S1000 and error code 0
108 void impl_throwGenericSQLException( const OUString
& _rMessage
);
115 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XDriver
,
116 ::com::sun::star::lang::XServiceInfo
,
117 ::com::sun::star::frame::XTerminateListener
> MacabDriver_BASE
;
118 class MacabDriver
: public MacabDriver_BASE
121 ::osl::Mutex m_aMutex
; // mutex is need to control member access
122 OWeakRefArray m_xConnections
; // vector containing a list of all the
123 // MacabConnection objects for this Driver
124 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
125 m_xContext
; // the multi-service factory
126 MacabImplModule m_aImplModule
;
129 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
);
131 // XServiceInfo - static versions
132 static OUString
getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException
);
133 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException
);
135 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
136 getComponentContext() const { return m_xContext
; }
138 /** returns the driver's implementation name (being pure ASCII) for reference in various places
140 static const sal_Char
* impl_getAsciiImplementationName();
142 /** returns the path of our configuration settings
144 static OUString
impl_getConfigurationSettingsPath();
147 MacabDriver(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
150 virtual void SAL_CALL
disposing(void) SAL_OVERRIDE
;
153 virtual OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
154 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
155 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
158 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
) SAL_OVERRIDE
;
159 virtual sal_Bool SAL_CALL
acceptsURL( const OUString
& url
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
160 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
) SAL_OVERRIDE
;
161 virtual sal_Int32 SAL_CALL
getMajorVersion() throw(::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
162 virtual sal_Int32 SAL_CALL
getMinorVersion() throw(::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
164 // XTerminateListener
165 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
166 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
169 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
172 /** shuts down the library which contains the real implementations
174 This method is safe against being called multiple times
176 @precond our mutex is locked
178 void impl_shutdownImplementationModule();
184 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABDRIVER_HXX
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */