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 #include "NDriver.hxx" 31 #include <cppuhelper/factory.hxx> 32 #include <osl/diagnose.h> 33 34 using namespace connectivity::evoab; 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* _pT 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(::com::sun::star::uno::Exception) 80 { 81 OSL_ENSURE(0,"Service Creation Exception"); 82 } 83 return xRet.is(); 84 } 85 86 void* getProvider() const { return xRet.get(); } 87 }; 88 89 //--------------------------------------------------------------------------------------- 90 91 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( 92 const sal_Char **ppEnvTypeName, 93 uno_Environment ** /*ppEnv*/ 94 ) 95 { 96 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 97 } 98 99 //--------------------------------------------------------------------------------------- 100 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( 101 const sal_Char* pImplementationName, 102 void* pServiceManager, 103 void* /*pRegistryKey*/) 104 { 105 void* pRet = 0; 106 if (pServiceManager) 107 { 108 ProviderRequest aReq(pServiceManager,pImplementationName); 109 110 aReq.CREATE_PROVIDER( 111 OEvoabDriver::getImplementationName_Static(), 112 OEvoabDriver::getSupportedServiceNames_Static(), 113 OEvoabDriver_CreateInstance, ::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