Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mozab / MServices.cxx
blobcbe2f70fee1cf770eab5b0b8c08444a1b71a7d3d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "MDriver.hxx"
22 #include <cppuhelper/factory.hxx>
23 #include <osl/diagnose.h>
24 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
25 #include "bootstrap/MMozillaBootstrap.hxx"
26 #include <tools/solar.h>
28 using namespace connectivity::mozab;
29 using ::com::sun::star::uno::Reference;
30 using ::com::sun::star::uno::Sequence;
31 using ::com::sun::star::lang::XSingleServiceFactory;
32 using ::com::sun::star::lang::XMultiServiceFactory;
33 using ::com::sun::star::mozilla::XMozillaBootstrap;
35 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
37 const Reference< XMultiServiceFactory > & rServiceManager,
38 const OUString & rComponentName,
39 ::cppu::ComponentInstantiation pCreateFunction,
40 const Sequence< OUString > & rServiceNames,
41 rtl_ModuleCount*
45 struct ProviderRequest
47 Reference< XSingleServiceFactory > xRet;
48 Reference< XMultiServiceFactory > const xServiceManager;
49 OUString const sImplementationName;
51 ProviderRequest(
52 void* pServiceManager,
53 sal_Char const* pImplementationName
55 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
56 , sImplementationName(OUString::createFromAscii(pImplementationName))
60 inline
61 sal_Bool CREATE_PROVIDER(
62 const OUString& Implname,
63 const Sequence< OUString > & Services,
64 ::cppu::ComponentInstantiation Factory,
65 createFactoryFunc creator
68 if (!xRet.is() && (Implname == sImplementationName))
69 try
71 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
73 catch(...)
76 return xRet.is();
79 void* getProvider() const { return xRet.get(); }
83 typedef void* (SAL_CALL * OMozillaBootstrap_CreateInstanceFunction)(const Reference< XMultiServiceFactory >& _rxFactory );
84 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createMozillaBootstrap(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
86 const OUString sModuleName(SVLIBRARY( "mozabdrv" ));
88 // load the dbtools library
89 oslModule s_hModule = osl_loadModuleRelative(
90 reinterpret_cast< oslGenericFunction >(&createMozillaBootstrap),
91 sModuleName.pData, 0);
92 OSL_ENSURE(NULL != s_hModule, "MozabDriver::registerClient: could not load the dbtools library!");
93 if (NULL != s_hModule)
96 // get the symbol for the method creating the factory
97 const OUString sFactoryCreationFunc = "OMozillaBootstrap_CreateInstance";
98 // reinterpret_cast<OMozabConnection_CreateInstanceFunction> removed GNU C
99 OMozillaBootstrap_CreateInstanceFunction s_pCreationFunc = (OMozillaBootstrap_CreateInstanceFunction)osl_getFunctionSymbol(s_hModule, sFactoryCreationFunc.pData);
101 if (NULL == s_pCreationFunc)
102 { // did not find the symbol
103 OSL_FAIL("MozabDriver::registerClient: could not find the symbol for creating the factory!");
104 osl_unloadModule(s_hModule);
105 s_hModule = NULL;
107 MozillaBootstrap * pBootstrap = reinterpret_cast<MozillaBootstrap*>((*s_pCreationFunc)(_rxFactory));
108 return *pBootstrap;
110 return NULL;
113 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL mozab_component_getFactory(
114 const sal_Char* pImplementationName,
115 void* pServiceManager,
116 void* /*pRegistryKey*/)
118 void* pRet = 0;
119 if (pServiceManager)
121 OUString aImplName( OUString::createFromAscii( pImplementationName ) );
122 ProviderRequest aReq(pServiceManager,pImplementationName);
123 if (aImplName.equals( MozabDriver::getImplementationName_Static() ))
125 aReq.CREATE_PROVIDER(
126 MozabDriver::getImplementationName_Static(),
127 MozabDriver::getSupportedServiceNames_Static(),
128 MozabDriver_CreateInstance, ::cppu::createSingleFactory);
130 else if ( aImplName == "com.sun.star.comp.mozilla.MozillaBootstrap" )
132 Sequence< OUString > aSNS( 1 );
133 aSNS[0] = "com.sun.star.mozilla.MozillaBootstrap";
134 aReq.CREATE_PROVIDER(
135 aImplName,
136 aSNS,
137 createMozillaBootstrap, ::cppu::createSingleFactory);
139 if(aReq.xRet.is())
140 aReq.xRet->acquire();
141 pRet = aReq.getProvider();
144 return pRet;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */