1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 #include <sal/types.h>
37 #include "SDriver.hxx"
38 #include <cppuhelper/factory.hxx>
39 #include <osl/diagnose.h>
40 #include <uno/lbnames.h>
41 #include <com/sun/star/registry/XRegistryKey.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
44 using namespace connectivity::skeleton
;
45 using ::rtl::OUString
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::Sequence
;
48 using ::com::sun::star::registry::XRegistryKey
;
49 using ::com::sun::star::lang::XSingleServiceFactory
;
50 using ::com::sun::star::lang::XMultiServiceFactory
;
52 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
54 const Reference
< XMultiServiceFactory
> & rServiceManager
,
55 const OUString
& rComponentName
,
56 ::cppu::ComponentInstantiation pCreateFunction
,
57 const Sequence
< OUString
> & rServiceNames
,
62 // The required C-Api must be provided!
63 // It contains of 3 special functions that have to be exported.
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
+= aServiceImplName
;
73 aMainKeyName
+= "/UNO/SERVICES";
75 Reference
< ::com::sun::star::registry::XRegistryKey
> xNewKey( xKey
->createKey(aMainKeyName
) );
76 OSL_ENSURE(xNewKey
.is(), "SKELETON::component_writeInfo : could not create a registry key !");
78 for (sal_uInt32 i
=0; i
<Services
.getLength(); ++i
)
79 xNewKey
->createKey(Services
[i
]);
83 struct ProviderRequest
85 Reference
< XSingleServiceFactory
> xRet
;
86 Reference
< XMultiServiceFactory
> const xServiceManager
;
87 OUString
const sImplementationName
;
90 void* pServiceManager
,
91 char const* pImplementationName
93 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
94 , sImplementationName(OUString::createFromAscii(pImplementationName
))
99 sal_Bool
CREATE_PROVIDER(
100 const OUString
& Implname
,
101 const Sequence
< OUString
> & Services
,
102 ::cppu::ComponentInstantiation Factory
,
103 createFactoryFunc creator
106 if (!xRet
.is() && (Implname
== sImplementationName
))
109 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
117 void* getProvider() const { return xRet
.get(); }
121 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
122 const char* pImplementationName
,
123 void* pServiceManager
,
129 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
131 aReq
.CREATE_PROVIDER(
132 SkeletonDriver::getImplementationName_Static(),
133 SkeletonDriver::getSupportedServiceNames_Static(),
134 SkeletonDriver_CreateInstance
, ::cppu::createSingleFactory
)
138 aReq
.xRet
->acquire();
140 pRet
= aReq
.getProvider();
146 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
147 component_getImplementationEnvironment(
148 char const ** ppEnvTypeName
, uno_Environment
**)
150 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */