1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_MACAB_DRIVER_HXX_
29*cdf0e10cSrcweir #define _CONNECTIVITY_MACAB_DRIVER_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir /** === begin UNO includes === **/
32*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriver.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp>
35*cdf0e10cSrcweir /** === end UNO includes === **/
36*cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx>
37*cdf0e10cSrcweir #include <osl/module.h>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir // the address book driver's version
40*cdf0e10cSrcweir #define MACAB_DRIVER_VERSION		"0.1"
41*cdf0e10cSrcweir #define MACAB_DRIVER_VERSION_MAJOR	0
42*cdf0e10cSrcweir #define MACAB_DRIVER_VERSION_MINOR	1
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace connectivity
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 	namespace macab
47*cdf0e10cSrcweir 	{
48*cdf0e10cSrcweir         class MacabConnection;
49*cdf0e10cSrcweir         class MacabDriver;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir         typedef void*   (SAL_CALL * ConnectionFactoryFunction)( void* _pDriver );
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir         typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir         // ===============================================================
56*cdf0e10cSrcweir         // = MacabImplModule
57*cdf0e10cSrcweir         // ===============================================================
58*cdf0e10cSrcweir         class MacabImplModule
59*cdf0e10cSrcweir         {
60*cdf0e10cSrcweir         private:
61*cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
62*cdf0e10cSrcweir 										m_xORB;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir             /// Did we already attempt to load the module and to retrieve the symbols?
65*cdf0e10cSrcweir             bool    m_bAttemptedLoadModule;
66*cdf0e10cSrcweir             oslModule                   m_hConnectorModule;
67*cdf0e10cSrcweir             ConnectionFactoryFunction   m_pConnectionFactoryFunc;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         public:
70*cdf0e10cSrcweir             MacabImplModule( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir             /** determines whether there is a mac OS present in the environment
73*cdf0e10cSrcweir             */
74*cdf0e10cSrcweir             bool isMacOSPresent();
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir             /** initializes the implementation module.
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir                 @raises ::com::sun::star::uno::RuntimeException
79*cdf0e10cSrcweir                     if the module could be loaded, but required symbols are missing
80*cdf0e10cSrcweir                 @raises ::com::sun::star::sdbc::SQLException
81*cdf0e10cSrcweir                     if no Mac OS was found at all
82*cdf0e10cSrcweir             */
83*cdf0e10cSrcweir             void init();
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir             /** shuts down the impl module
86*cdf0e10cSrcweir             */
87*cdf0e10cSrcweir             void shutdown();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir             /** creates a new connection
90*cdf0e10cSrcweir                 @precond
91*cdf0e10cSrcweir                     <member>init</member> has been called before
92*cdf0e10cSrcweir                 @raises ::com::sun::star::uno::RuntimeException
93*cdf0e10cSrcweir                     if no connection object could be created (which is a severe error, normally impossible)
94*cdf0e10cSrcweir             */
95*cdf0e10cSrcweir             MacabConnection*  createConnection( MacabDriver* _pDriver ) const;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         private:
98*cdf0e10cSrcweir             /** loads the implementation module and retrieves the needed symbols
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir                 Save against being called multiple times.
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir                 @return <TRUE/> if the module could be loaded successfully.
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir                 @raises ::com::sun::star::uno::RuntimeException
105*cdf0e10cSrcweir                     if the module could be loaded, but required symbols are missing
106*cdf0e10cSrcweir             */
107*cdf0e10cSrcweir             bool    impl_loadModule();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir             /** unloads the implementation module, and resets all function pointers to <NULL/>
110*cdf0e10cSrcweir                 @precond m_hConnectorModule is not <NULL/>
111*cdf0e10cSrcweir             */
112*cdf0e10cSrcweir             void    impl_unloadModule();
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             /** throws an SQLException saying than no Mac OS installation was found
115*cdf0e10cSrcweir             */
116*cdf0e10cSrcweir             void    impl_throwNoMacOSException();
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir             /** throws a generic SQL exception with SQLState S1000 and error code 0
119*cdf0e10cSrcweir             */
120*cdf0e10cSrcweir             void    impl_throwGenericSQLException( const ::rtl::OUString& _rMessage );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir         };
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         // ===============================================================
125*cdf0e10cSrcweir         // = MacabDriver
126*cdf0e10cSrcweir         // ===============================================================
127*cdf0e10cSrcweir 		typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XDriver,
128*cdf0e10cSrcweir 													::com::sun::star::lang::XServiceInfo,
129*cdf0e10cSrcweir                                                     ::com::sun::star::frame::XTerminateListener > MacabDriver_BASE;
130*cdf0e10cSrcweir 		class MacabDriver : public MacabDriver_BASE
131*cdf0e10cSrcweir 		{
132*cdf0e10cSrcweir 		protected:
133*cdf0e10cSrcweir 			::osl::Mutex				m_aMutex;			// mutex is need to control member access
134*cdf0e10cSrcweir 			OWeakRefArray				m_xConnections;		// vector containing a list of all the
135*cdf0e10cSrcweir 															//  MacabConnection objects for this Driver
136*cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
137*cdf0e10cSrcweir 										m_xMSFactory;		// the multi-service factory
138*cdf0e10cSrcweir             MacabImplModule               m_aImplModule;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         public:
141*cdf0e10cSrcweir             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 );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir             // XServiceInfo - static versions
144*cdf0e10cSrcweir             static ::rtl::OUString getImplementationName_Static(  ) throw(::com::sun::star::uno::RuntimeException);
145*cdf0e10cSrcweir             static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(  ) throw (::com::sun::star::uno::RuntimeException);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
148*cdf0e10cSrcweir                     getMSFactory() const { return m_xMSFactory; }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir             /** returns the driver's implementation name (being pure ASCII) for reference in various places
151*cdf0e10cSrcweir             */
152*cdf0e10cSrcweir             static const sal_Char*  impl_getAsciiImplementationName();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir             /** returns the path of our configuration settings
155*cdf0e10cSrcweir             */
156*cdf0e10cSrcweir             static ::rtl::OUString  impl_getConfigurationSettingsPath();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         protected:
159*cdf0e10cSrcweir 			MacabDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory);
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 			// OComponentHelper
162*cdf0e10cSrcweir 			virtual void SAL_CALL disposing(void);
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 			// XServiceInfo
165*cdf0e10cSrcweir 			virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
166*cdf0e10cSrcweir 			virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
167*cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 			// XDriver
170*cdf0e10cSrcweir 			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);
171*cdf0e10cSrcweir 			virtual sal_Bool SAL_CALL acceptsURL( const ::rtl::OUString& url ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
172*cdf0e10cSrcweir 			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);
173*cdf0e10cSrcweir 			virtual sal_Int32 SAL_CALL getMajorVersion() throw(::com::sun::star::uno::RuntimeException);
174*cdf0e10cSrcweir 			virtual sal_Int32 SAL_CALL getMinorVersion() throw(::com::sun::star::uno::RuntimeException);
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir             // XTerminateListener
177*cdf0e10cSrcweir             virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
178*cdf0e10cSrcweir             virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir             // XEventListener
181*cdf0e10cSrcweir             virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         private:
184*cdf0e10cSrcweir             /** shuts down the library which contains the real implementations
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir                 This method is safe against being called multiple times
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir                 @precond our mutex is locked
189*cdf0e10cSrcweir             */
190*cdf0e10cSrcweir             void impl_shutdownImplementationModule();
191*cdf0e10cSrcweir 		};
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir #endif // _CONNECTIVITY_MACAB_DRIVER_HXX_
197