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 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
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>
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::registry::XRegistryKey
;
39 using ::com::sun::star::lang::XSingleServiceFactory
;
40 using ::com::sun::star::lang::XMultiServiceFactory
;
42 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
44 const Reference
< XMultiServiceFactory
> & rServiceManager
,
45 const OUString
& rComponentName
,
46 ::cppu::ComponentInstantiation pCreateFunction
,
47 const Sequence
< OUString
> & rServiceNames
,
51 //***************************************************************************************
53 // Die vorgeschriebene C-Api muss erfuellt werden!
54 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
57 //---------------------------------------------------------------------------------------
58 void REGISTER_PROVIDER(
59 const OUString
& aServiceImplName
,
60 const Sequence
< OUString
>& Services
,
61 const Reference
< ::com::sun::star::registry::XRegistryKey
> & xKey
)
63 OUString aMainKeyName
;
64 aMainKeyName
= OUString::createFromAscii("/");
65 aMainKeyName
+= aServiceImplName
;
66 aMainKeyName
+= OUString::createFromAscii("/UNO/SERVICES");
68 Reference
< ::com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
) );
69 OSL_ENSURE(xNewKey
.is(), "EVOAB::component_writeInfo : could not create a registry key !");
71 for (sal_Int32 i
=0; i
<Services
.getLength(); ++i
)
72 xNewKey
->createKey(Services
[i
]);
76 //---------------------------------------------------------------------------------------
77 struct ProviderRequest
79 Reference
< XSingleServiceFactory
> xRet
;
80 Reference
< XMultiServiceFactory
> const xServiceManager
;
81 OUString
const sImplementationName
;
84 void* pServiceManager
,
85 sal_Char
const* pImplementationName
87 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
88 , sImplementationName(OUString::createFromAscii(pImplementationName
))
93 sal_Bool
CREATE_PROVIDER(
94 const OUString
& Implname
,
95 const Sequence
< OUString
> & Services
,
96 ::cppu::ComponentInstantiation Factory
,
97 createFactoryFunc creator
100 if (!xRet
.is() && (Implname
== sImplementationName
))
103 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
105 catch(::com::sun::star::uno::Exception
)
107 OSL_ENSURE(0,"Service Creation Exception");
112 void* getProvider() const { return xRet
.get(); }
115 //---------------------------------------------------------------------------------------
117 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironment(
118 const sal_Char
**ppEnvTypeName
,
119 uno_Environment
** /*ppEnv*/
122 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
125 //---------------------------------------------------------------------------------------
126 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(
127 void* /*pServiceManager*/,
134 Reference
< ::com::sun::star::registry::XRegistryKey
> xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey
*>(pRegistryKey
));
137 OEvoabDriver::getImplementationName_Static(),
138 OEvoabDriver::getSupportedServiceNames_Static(), xKey
);
142 catch (::com::sun::star::registry::InvalidRegistryException
& )
144 OSL_ENSURE(sal_False
, "FILE::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
150 //---------------------------------------------------------------------------------------
151 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
152 const sal_Char
* pImplementationName
,
153 void* pServiceManager
,
154 void* /*pRegistryKey*/)
159 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
161 aReq
.CREATE_PROVIDER(
162 OEvoabDriver::getImplementationName_Static(),
163 OEvoabDriver::getSupportedServiceNames_Static(),
164 OEvoabDriver_CreateInstance
, ::cppu::createSingleFactory
)
168 aReq
.xRet
->acquire();
170 pRet
= aReq
.getProvider();