1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MacabDriver.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONNECTIVITY_MACAB_DRIVER_HXX_
32 #define _CONNECTIVITY_MACAB_DRIVER_HXX_
34 /** === begin UNO includes === **/
35 #include <com/sun/star/sdbc/XDriver.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/frame/XTerminateListener.hpp>
38 /** === end UNO includes === **/
39 #include <cppuhelper/compbase3.hxx>
40 #include <osl/module.h>
42 // the address book driver's version
43 #define MACAB_DRIVER_VERSION "0.1"
44 #define MACAB_DRIVER_VERSION_MAJOR 0
45 #define MACAB_DRIVER_VERSION_MINOR 1
47 namespace connectivity
51 class MacabConnection
;
54 typedef void* (SAL_CALL
* ConnectionFactoryFunction
)( void* _pDriver
);
56 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
58 // ===============================================================
60 // ===============================================================
64 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>
67 /// Did we already attempt to load the module and to retrieve the symbols?
68 bool m_bAttemptedLoadModule
;
69 oslModule m_hConnectorModule
;
70 ConnectionFactoryFunction m_pConnectionFactoryFunc
;
73 MacabImplModule( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
);
75 /** determines whether there is a mac OS present in the environment
77 bool isMacOSPresent();
79 /** initializes the implementation module.
81 @raises ::com::sun::star::uno::RuntimeException
82 if the module could be loaded, but required symbols are missing
83 @raises ::com::sun::star::sdbc::SQLException
84 if no Mac OS was found at all
88 /** shuts down the impl module
92 /** creates a new connection
94 <member>init</member> has been called before
95 @raises ::com::sun::star::uno::RuntimeException
96 if no connection object could be created (which is a severe error, normally impossible)
98 MacabConnection
* createConnection( MacabDriver
* _pDriver
) const;
101 /** loads the implementation module and retrieves the needed symbols
103 Save against being called multiple times.
105 @return <TRUE/> if the module could be loaded successfully.
107 @raises ::com::sun::star::uno::RuntimeException
108 if the module could be loaded, but required symbols are missing
110 bool impl_loadModule();
112 /** unloads the implementation module, and resets all function pointers to <NULL/>
113 @precond m_hConnectorModule is not <NULL/>
115 void impl_unloadModule();
117 /** throws an SQLException saying than no Mac OS installation was found
119 void impl_throwNoMacOSException();
121 /** throws a generic SQL exception with SQLState S1000 and error code 0
123 void impl_throwGenericSQLException( const ::rtl::OUString
& _rMessage
);
127 // ===============================================================
129 // ===============================================================
130 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XDriver
,
131 ::com::sun::star::lang::XServiceInfo
,
132 ::com::sun::star::frame::XTerminateListener
> MacabDriver_BASE
;
133 class MacabDriver
: public MacabDriver_BASE
136 ::osl::Mutex m_aMutex
; // mutex is need to control member access
137 OWeakRefArray m_xConnections
; // vector containing a list of all the
138 // MacabConnection objects for this Driver
139 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>
140 m_xMSFactory
; // the multi-service factory
141 MacabImplModule m_aImplModule
;
144 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
);
146 // XServiceInfo - static versions
147 static ::rtl::OUString
getImplementationName_Static( ) throw(::com::sun::star::uno::RuntimeException
);
148 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_Static( ) throw (::com::sun::star::uno::RuntimeException
);
150 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&
151 getMSFactory() const { return m_xMSFactory
; }
153 /** returns the driver's implementation name (being pure ASCII) for reference in various places
155 static const sal_Char
* impl_getAsciiImplementationName();
157 /** returns the path of our configuration settings
159 static ::rtl::OUString
impl_getConfigurationSettingsPath();
162 MacabDriver(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
);
165 virtual void SAL_CALL
disposing(void);
168 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
169 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
170 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
173 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
connect( const ::rtl::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
);
174 virtual sal_Bool SAL_CALL
acceptsURL( const ::rtl::OUString
& url
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
175 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::sdbc::DriverPropertyInfo
> SAL_CALL
getPropertyInfo( const ::rtl::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
);
176 virtual sal_Int32 SAL_CALL
getMajorVersion() throw(::com::sun::star::uno::RuntimeException
);
177 virtual sal_Int32 SAL_CALL
getMinorVersion() throw(::com::sun::star::uno::RuntimeException
);
179 // XTerminateListener
180 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
);
181 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::uno::RuntimeException
);
184 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
187 /** shuts down the library which contains the real implementations
189 This method is safe against being called multiple times
191 @precond our mutex is locked
193 void impl_shutdownImplementationModule();
199 #endif // _CONNECTIVITY_MACAB_DRIVER_HXX_