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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 31 #include "KDriver.hxx" 32 #include <cppuhelper/factory.hxx> 33 34 using namespace connectivity::kab; 35 using ::rtl::OUString; 36 using ::com::sun::star::uno::Reference; 37 using ::com::sun::star::uno::Sequence; 38 using ::com::sun::star::lang::XSingleServiceFactory; 39 using ::com::sun::star::lang::XMultiServiceFactory; 40 41 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc) 42 ( 43 const Reference< XMultiServiceFactory > & rServiceManager, 44 const OUString & rComponentName, 45 ::cppu::ComponentInstantiation pCreateFunction, 46 const Sequence< OUString > & rServiceNames, 47 rtl_ModuleCount* _pTemp 48 ); 49 50 //--------------------------------------------------------------------------------------- 51 struct ProviderRequest 52 { 53 Reference< XSingleServiceFactory > xRet; 54 Reference< XMultiServiceFactory > const xServiceManager; 55 OUString const sImplementationName; 56 57 ProviderRequest( 58 void* pServiceManager, 59 sal_Char const* pImplementationName 60 ) 61 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager)) 62 , sImplementationName(OUString::createFromAscii(pImplementationName)) 63 { 64 } 65 66 inline 67 sal_Bool CREATE_PROVIDER( 68 const OUString& Implname, 69 const Sequence< OUString > & Services, 70 ::cppu::ComponentInstantiation Factory, 71 createFactoryFunc creator 72 ) 73 { 74 if (!xRet.is() && (Implname == sImplementationName)) 75 try 76 { 77 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0); 78 } 79 catch(...) 80 { 81 } 82 return xRet.is(); 83 } 84 85 void* getProvider() const { return xRet.get(); } 86 }; 87 88 //--------------------------------------------------------------------------------------- 89 90 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( 91 const sal_Char **ppEnvTypeName, 92 uno_Environment ** 93 ) 94 { 95 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 96 } 97 98 //--------------------------------------------------------------------------------------- 99 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( 100 const sal_Char* pImplementationName, 101 void* pServiceManager, 102 void*) 103 { 104 void* pRet = 0; 105 if (pServiceManager) 106 { 107 ProviderRequest aReq(pServiceManager,pImplementationName); 108 109 aReq.CREATE_PROVIDER( 110 KabDriver::getImplementationName_Static(), 111 KabDriver::getSupportedServiceNames_Static(), 112 &KabDriver::Create, 113 ::cppu::createSingleFactory) 114 ; 115 116 if (aReq.xRet.is()) 117 aReq.xRet->acquire(); 118 119 pRet = aReq.getProvider(); 120 } 121 122 return pRet; 123 }; 124 125 126