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