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: Aservices.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"
33 #include "ado/ADriver.hxx"
34 #include <cppuhelper/factory.hxx>
35 #include <osl/diagnose.h>
37 using namespace connectivity::ado
;
38 using ::rtl::OUString
;
39 using ::com::sun::star::uno::Reference
;
40 using ::com::sun::star::uno::Sequence
;
41 using ::com::sun::star::registry::XRegistryKey
;
42 using ::com::sun::star::lang::XSingleServiceFactory
;
43 using ::com::sun::star::lang::XMultiServiceFactory
;
45 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
47 const Reference
< XMultiServiceFactory
> & rServiceManager
,
48 const OUString
& rComponentName
,
49 ::cppu::ComponentInstantiation pCreateFunction
,
50 const Sequence
< OUString
> & rServiceNames
,
54 //***************************************************************************************
56 // Die vorgeschriebene C-Api muss erfuellt werden!
57 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
60 //---------------------------------------------------------------------------------------
61 void REGISTER_PROVIDER(
62 const OUString
& aServiceImplName
,
63 const Sequence
< OUString
>& Services
,
64 const Reference
< ::com::sun::star::registry::XRegistryKey
> & xKey
)
66 OUString aMainKeyName
;
67 aMainKeyName
= OUString::createFromAscii("/");
68 aMainKeyName
+= aServiceImplName
;
69 aMainKeyName
+= OUString::createFromAscii("/UNO/SERVICES");
71 Reference
< ::com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
) );
72 OSL_ENSURE(xNewKey
.is(), "ADO::component_writeInfo : could not create a registry key !");
74 for (sal_Int32 i
=0; i
<Services
.getLength(); ++i
)
75 xNewKey
->createKey(Services
[i
]);
79 //---------------------------------------------------------------------------------------
80 struct ProviderRequest
82 Reference
< XSingleServiceFactory
> xRet
;
83 Reference
< XMultiServiceFactory
> const xServiceManager
;
84 OUString
const sImplementationName
;
87 void* pServiceManager
,
88 sal_Char
const* pImplementationName
90 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
91 , sImplementationName(OUString::createFromAscii(pImplementationName
))
96 sal_Bool
CREATE_PROVIDER(
97 const OUString
& Implname
,
98 const Sequence
< OUString
> & Services
,
99 ::cppu::ComponentInstantiation Factory
,
100 createFactoryFunc creator
103 if (!xRet
.is() && (Implname
== sImplementationName
))
106 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
114 void* getProvider() const { return xRet
.get(); }
117 //---------------------------------------------------------------------------------------
119 extern "C" void SAL_CALL
component_getImplementationEnvironment(
120 const sal_Char
**ppEnvTypeName
,
121 uno_Environment
** /*ppEnv*/
124 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
":affine";
127 //---------------------------------------------------------------------------------------
128 extern "C" sal_Bool SAL_CALL
component_writeInfo(
129 void* /*pServiceManager*/,
136 Reference
< ::com::sun::star::registry::XRegistryKey
> xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey
*>(pRegistryKey
));
139 ODriver::getImplementationName_Static(),
140 ODriver::getSupportedServiceNames_Static(), xKey
);
144 catch (::com::sun::star::registry::InvalidRegistryException
& )
146 OSL_ENSURE(sal_False
, "ADO::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
152 //---------------------------------------------------------------------------------------
153 extern "C" void* SAL_CALL
component_getFactory(
154 const sal_Char
* pImplementationName
,
155 void* pServiceManager
,
156 void* /*pRegistryKey*/)
161 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
163 aReq
.CREATE_PROVIDER(
164 ODriver::getImplementationName_Static(),
165 ODriver::getSupportedServiceNames_Static(),
166 ODriver_CreateInstance
, ::cppu::createSingleFactory
)
170 aReq
.xRet
->acquire();
172 pRet
= aReq
.getProvider();