1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MServices.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "MDriver.hxx"
35 #include <cppuhelper/factory.hxx>
36 #include <osl/diagnose.h>
37 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
38 #include "bootstrap/MMozillaBootstrap.hxx"
39 #include <tools/solar.h>
41 using namespace connectivity::mozab
;
42 using ::rtl::OUString
;
43 using ::com::sun::star::uno::Reference
;
44 using ::com::sun::star::uno::Sequence
;
45 using ::com::sun::star::registry::XRegistryKey
;
46 using ::com::sun::star::lang::XSingleServiceFactory
;
47 using ::com::sun::star::lang::XMultiServiceFactory
;
48 using ::com::sun::star::mozilla::XMozillaBootstrap
;
50 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
52 const Reference
< XMultiServiceFactory
> & rServiceManager
,
53 const OUString
& rComponentName
,
54 ::cppu::ComponentInstantiation pCreateFunction
,
55 const Sequence
< OUString
> & rServiceNames
,
56 rtl_ModuleCount
* _pTemp
59 //***************************************************************************************
61 // Die vorgeschriebene C-Api muss erfuellt werden!
62 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
65 //---------------------------------------------------------------------------------------
66 void REGISTER_PROVIDER(
67 const OUString
& aServiceImplName
,
68 const Sequence
< OUString
>& Services
,
69 const Reference
< ::com::sun::star::registry::XRegistryKey
> & xKey
)
71 OUString aMainKeyName
;
72 aMainKeyName
= OUString( RTL_CONSTASCII_USTRINGPARAM("/"));
73 aMainKeyName
+= aServiceImplName
;
74 aMainKeyName
+= OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
76 Reference
< ::com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
) );
77 OSL_ENSURE(xNewKey
.is(), "MOZAB::component_writeInfo : could not create a registry key !");
79 for (sal_Int32 i
=0; i
<Services
.getLength(); ++i
)
80 xNewKey
->createKey(Services
[i
]);
84 //---------------------------------------------------------------------------------------
85 struct ProviderRequest
87 Reference
< XSingleServiceFactory
> xRet
;
88 Reference
< XMultiServiceFactory
> const xServiceManager
;
89 OUString
const sImplementationName
;
92 void* pServiceManager
,
93 sal_Char
const* pImplementationName
95 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
96 , sImplementationName(OUString::createFromAscii(pImplementationName
))
101 sal_Bool
CREATE_PROVIDER(
102 const OUString
& Implname
,
103 const Sequence
< OUString
> & Services
,
104 ::cppu::ComponentInstantiation Factory
,
105 createFactoryFunc creator
108 if (!xRet
.is() && (Implname
== sImplementationName
))
111 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
119 void* getProvider() const { return xRet
.get(); }
122 //---------------------------------------------------------------------------------------
124 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
125 component_getImplementationEnvironment(
126 const sal_Char
**ppEnvTypeName
,
127 uno_Environment
** /*ppEnv*/
130 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
133 //---------------------------------------------------------------------------------------
134 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(
135 void* /*pServiceManager*/,
142 Reference
< ::com::sun::star::registry::XRegistryKey
> xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey
*>(pRegistryKey
));
146 MozabDriver::getImplementationName_Static(),
147 MozabDriver::getSupportedServiceNames_Static(), xKey
);
149 Sequence
< ::rtl::OUString
> aSNS( 1 );
150 aSNS
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
152 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.mozilla.MozillaBootstrap")),
157 catch (::com::sun::star::registry::InvalidRegistryException
& )
159 OSL_ENSURE(sal_False
, "Mozab::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
164 typedef void* (SAL_CALL
* OMozillaBootstrap_CreateInstanceFunction
)(const Reference
< XMultiServiceFactory
>& _rxFactory
);
165 ::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
)
167 const ::rtl::OUString sModuleName
= ::rtl::OUString::createFromAscii(SVLIBRARY( "mozabdrv" ));
169 // load the dbtools library
170 oslModule s_hModule
= osl_loadModuleRelative(
171 reinterpret_cast< oslGenericFunction
>(&createMozillaBootstrap
),
172 sModuleName
.pData
, 0);
173 OSL_ENSURE(NULL
!= s_hModule
, "MozabDriver::registerClient: could not load the dbtools library!");
174 if (NULL
!= s_hModule
)
177 // get the symbol for the method creating the factory
178 const ::rtl::OUString sFactoryCreationFunc
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OMozillaBootstrap_CreateInstance"));
179 // reinterpret_cast<OMozabConnection_CreateInstanceFunction> removed GNU C
180 OMozillaBootstrap_CreateInstanceFunction s_pCreationFunc
= (OMozillaBootstrap_CreateInstanceFunction
)osl_getFunctionSymbol(s_hModule
, sFactoryCreationFunc
.pData
);
182 if (NULL
== s_pCreationFunc
)
183 { // did not find the symbol
184 OSL_ENSURE(sal_False
, "MozabDriver::registerClient: could not find the symbol for creating the factory!");
185 osl_unloadModule(s_hModule
);
188 MozillaBootstrap
* pBootstrap
= reinterpret_cast<MozillaBootstrap
*>((*s_pCreationFunc
)(_rxFactory
));
193 //---------------------------------------------------------------------------------------
194 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
195 const sal_Char
* pImplementationName
,
196 void* pServiceManager
,
197 void* /*pRegistryKey*/)
202 OUString
aImplName( OUString::createFromAscii( pImplementationName
) );
203 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
204 if (aImplName
.equals( MozabDriver::getImplementationName_Static() ))
206 aReq
.CREATE_PROVIDER(
207 MozabDriver::getImplementationName_Static(),
208 MozabDriver::getSupportedServiceNames_Static(),
209 MozabDriver_CreateInstance
, ::cppu::createSingleFactory
);
211 else if (aImplName
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.mozilla.MozillaBootstrap")) ))
213 Sequence
< ::rtl::OUString
> aSNS( 1 );
214 aSNS
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
215 aReq
.CREATE_PROVIDER(
218 createMozillaBootstrap
, ::cppu::createSingleFactory
);
221 aReq
.xRet
->acquire();
222 pRet
= aReq
.getProvider();