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: KServices.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 "KDriver.hxx"
35 #include <cppuhelper/factory.hxx>
36 #include <osl/diagnose.h>
38 using namespace connectivity::kab
;
39 using ::rtl::OUString
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Sequence
;
42 using ::com::sun::star::registry::XRegistryKey
;
43 using ::com::sun::star::lang::XSingleServiceFactory
;
44 using ::com::sun::star::lang::XMultiServiceFactory
;
46 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
48 const Reference
< XMultiServiceFactory
> & rServiceManager
,
49 const OUString
& rComponentName
,
50 ::cppu::ComponentInstantiation pCreateFunction
,
51 const Sequence
< OUString
> & rServiceNames
,
52 rtl_ModuleCount
* _pTemp
55 //***************************************************************************************
57 // The following C Api must be provided!
58 // It consists in three functions that must be exported by the module
61 //---------------------------------------------------------------------------------------
62 void REGISTER_PROVIDER(
63 const OUString
& aServiceImplName
,
64 const Sequence
< OUString
>& Services
,
65 const Reference
< ::com::sun::star::registry::XRegistryKey
> & xKey
)
67 OUString aMainKeyName
;
68 aMainKeyName
= OUString::createFromAscii("/");
69 aMainKeyName
+= aServiceImplName
;
70 aMainKeyName
+= OUString::createFromAscii("/UNO/SERVICES");
72 Reference
< ::com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
) );
73 OSL_ENSURE(xNewKey
.is(), "KAB::component_writeInfo : could not create a registry key !");
75 for (sal_Int32 i
=0; i
<Services
.getLength(); ++i
)
76 xNewKey
->createKey(Services
[i
]);
80 //---------------------------------------------------------------------------------------
81 struct ProviderRequest
83 Reference
< XSingleServiceFactory
> xRet
;
84 Reference
< XMultiServiceFactory
> const xServiceManager
;
85 OUString
const sImplementationName
;
88 void* pServiceManager
,
89 sal_Char
const* pImplementationName
91 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
92 , sImplementationName(OUString::createFromAscii(pImplementationName
))
97 sal_Bool
CREATE_PROVIDER(
98 const OUString
& Implname
,
99 const Sequence
< OUString
> & Services
,
100 ::cppu::ComponentInstantiation Factory
,
101 createFactoryFunc creator
104 if (!xRet
.is() && (Implname
== sImplementationName
))
107 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
115 void* getProvider() const { return xRet
.get(); }
118 //---------------------------------------------------------------------------------------
120 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
component_getImplementationEnvironment(
121 const sal_Char
**ppEnvTypeName
,
125 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
128 //---------------------------------------------------------------------------------------
129 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
component_writeInfo(
137 Reference
< ::com::sun::star::registry::XRegistryKey
> xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey
*>(pRegistryKey
));
140 KabDriver::getImplementationName_Static(),
141 KabDriver::getSupportedServiceNames_Static(), xKey
);
145 catch (::com::sun::star::registry::InvalidRegistryException
& )
147 OSL_ENSURE(sal_False
, "KAB::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
153 //---------------------------------------------------------------------------------------
154 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
155 const sal_Char
* pImplementationName
,
156 void* pServiceManager
,
162 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
164 aReq
.CREATE_PROVIDER(
165 KabDriver::getImplementationName_Static(),
166 KabDriver::getSupportedServiceNames_Static(),
168 ::cppu::createSingleFactory
)
172 aReq
.xRet
->acquire();
174 pRet
= aReq
.getProvider();