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