1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * Copyright 2008 by Sun Microsystems, Inc. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * $RCSfile: mysqlc_services.cxx,v $ 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * $Revision: 1.1.2.5 $ 11*cdf0e10cSrcweir * 12*cdf0e10cSrcweir * This file is part of OpenOffice.org. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 15*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 16*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 17*cdf0e10cSrcweir * 18*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 19*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 20*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 22*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 23*cdf0e10cSrcweir * 24*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 25*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 26*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 27*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 28*cdf0e10cSrcweir ************************************************************************/ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "mysqlc_driver.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 33*cdf0e10cSrcweir #include <osl/diagnose.h> 34*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir using namespace connectivity::mysqlc; 37*cdf0e10cSrcweir using ::rtl::OUString; 38*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 39*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 40*cdf0e10cSrcweir using ::com::sun::star::registry::XRegistryKey; 41*cdf0e10cSrcweir using ::com::sun::star::lang::XSingleServiceFactory; 42*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc) 45*cdf0e10cSrcweir ( 46*cdf0e10cSrcweir const Reference< XMultiServiceFactory > & rServiceManager, 47*cdf0e10cSrcweir const OUString & rComponentName, 48*cdf0e10cSrcweir ::cppu::ComponentInstantiation pCreateFunction, 49*cdf0e10cSrcweir const Sequence< OUString > & rServiceNames, 50*cdf0e10cSrcweir rtl_ModuleCount* _pTemp 51*cdf0e10cSrcweir ); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //*************************************************************************************** 54*cdf0e10cSrcweir // 55*cdf0e10cSrcweir // Die vorgeschriebene C-API muss erfuellt werden! 56*cdf0e10cSrcweir // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen. 57*cdf0e10cSrcweir // 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir //--------------------------------------------------------------------------------------- 60*cdf0e10cSrcweir void REGISTER_PROVIDER( 61*cdf0e10cSrcweir const OUString& aServiceImplName, 62*cdf0e10cSrcweir const Sequence< OUString>& Services, 63*cdf0e10cSrcweir const Reference< XRegistryKey > & xKey) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir ::rtl::OUStringBuffer aMainKeyName; 66*cdf0e10cSrcweir aMainKeyName.append( sal_Unicode( '/' ) ); 67*cdf0e10cSrcweir aMainKeyName.append( aServiceImplName ); 68*cdf0e10cSrcweir aMainKeyName.appendAscii( "/UNO/SERVICES" ); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir Reference< XRegistryKey > xNewKey( xKey->createKey( aMainKeyName.makeStringAndClear() ) ); 71*cdf0e10cSrcweir OSL_ENSURE(xNewKey.is(), "SKELETON::component_writeInfo : could not create a registry key !"); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir for (sal_Int32 i = 0; i < Services.getLength(); ++i) { 74*cdf0e10cSrcweir xNewKey->createKey(Services[i]); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //--------------------------------------------------------------------------------------- 80*cdf0e10cSrcweir struct ProviderRequest 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir Reference< XSingleServiceFactory > xRet; 83*cdf0e10cSrcweir Reference< XMultiServiceFactory > const xServiceManager; 84*cdf0e10cSrcweir OUString const sImplementationName; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir ProviderRequest( 87*cdf0e10cSrcweir void* pServiceManager, 88*cdf0e10cSrcweir sal_Char const* pImplementationName 89*cdf0e10cSrcweir ) : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager)) 90*cdf0e10cSrcweir , sImplementationName(OUString::createFromAscii(pImplementationName)) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /* {{{ CREATE_PROVIDER -I- */ 95*cdf0e10cSrcweir inline sal_Bool CREATE_PROVIDER( 96*cdf0e10cSrcweir const OUString& Implname, 97*cdf0e10cSrcweir const Sequence< OUString > & Services, 98*cdf0e10cSrcweir ::cppu::ComponentInstantiation Factory, 99*cdf0e10cSrcweir createFactoryFunc creator 100*cdf0e10cSrcweir ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir if (!xRet.is() && (Implname == sImplementationName)) { 103*cdf0e10cSrcweir try { 104*cdf0e10cSrcweir xRet = creator( xServiceManager, sImplementationName,Factory, Services,0); 105*cdf0e10cSrcweir } catch (...) { 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir return xRet.is(); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir void* getProvider() const { return xRet.get(); } 112*cdf0e10cSrcweir }; 113*cdf0e10cSrcweir /* }}} */ 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir /* {{{ component_getImplementationEnvironment -I- */ 117*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( 118*cdf0e10cSrcweir const sal_Char **ppEnvTypeName, 119*cdf0e10cSrcweir uno_Environment ** /* ppEnv */ 120*cdf0e10cSrcweir ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir /* }}} */ 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir /* {{{ component_writeInfo -I- */ 128*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */, void * pRegistryKey) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir if (pRegistryKey) { 131*cdf0e10cSrcweir try { 132*cdf0e10cSrcweir Reference< XRegistryKey > xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey)); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir REGISTER_PROVIDER( 135*cdf0e10cSrcweir MysqlCDriver::getImplementationName_Static(), 136*cdf0e10cSrcweir MysqlCDriver::getSupportedServiceNames_Static(), xKey); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir return sal_True; 139*cdf0e10cSrcweir } catch (::com::sun::star::registry::InvalidRegistryException& ) { 140*cdf0e10cSrcweir OSL_ENSURE(sal_False, "SKELETON::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !"); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir return sal_False; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir /* }}} */ 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir /* {{{ component_getFactory -I- */ 149*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( 150*cdf0e10cSrcweir const sal_Char * pImplementationName, 151*cdf0e10cSrcweir void * pServiceManager, 152*cdf0e10cSrcweir void * /* pRegistryKey */) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir void* pRet = 0; 155*cdf0e10cSrcweir if (pServiceManager) { 156*cdf0e10cSrcweir ProviderRequest aReq(pServiceManager,pImplementationName); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir aReq.CREATE_PROVIDER( 159*cdf0e10cSrcweir MysqlCDriver::getImplementationName_Static(), 160*cdf0e10cSrcweir MysqlCDriver::getSupportedServiceNames_Static(), 161*cdf0e10cSrcweir MysqlCDriver_CreateInstance, ::cppu::createSingleFactory) 162*cdf0e10cSrcweir ; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir if(aReq.xRet.is()) { 165*cdf0e10cSrcweir aReq.xRet->acquire(); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir pRet = aReq.getProvider(); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir return pRet; 172*cdf0e10cSrcweir }; 173*cdf0e10cSrcweir /* }}} */ 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir /* 177*cdf0e10cSrcweir * Local variables: 178*cdf0e10cSrcweir * tab-width: 4 179*cdf0e10cSrcweir * c-basic-offset: 4 180*cdf0e10cSrcweir * End: 181*cdf0e10cSrcweir * vim600: noet sw=4 ts=4 fdm=marker 182*cdf0e10cSrcweir * vim<600: noet sw=4 ts=4 183*cdf0e10cSrcweir */ 184