Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "hsqldb/HDriver.hxx"
22 : #include <cppuhelper/factory.hxx>
23 :
24 : using namespace connectivity::hsqldb;
25 : using ::rtl::OUString;
26 : using ::com::sun::star::uno::Reference;
27 : using ::com::sun::star::uno::Sequence;
28 : using ::com::sun::star::lang::XSingleServiceFactory;
29 : using ::com::sun::star::lang::XMultiServiceFactory;
30 :
31 : typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
32 : (
33 : const Reference< XMultiServiceFactory > & rServiceManager,
34 : const OUString & rComponentName,
35 : ::cppu::ComponentInstantiation pCreateFunction,
36 : const Sequence< OUString > & rServiceNames,
37 : rtl_ModuleCount* _pT
38 : );
39 :
40 : //---------------------------------------------------------------------------------------
41 0 : struct ProviderRequest
42 : {
43 : Reference< XSingleServiceFactory > xRet;
44 : Reference< XMultiServiceFactory > const xServiceManager;
45 : OUString const sImplementationName;
46 :
47 0 : ProviderRequest(
48 : void* pServiceManager,
49 : sal_Char const* pImplementationName
50 : )
51 : : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
52 0 : , sImplementationName(OUString::createFromAscii(pImplementationName))
53 : {
54 0 : }
55 :
56 : inline
57 0 : sal_Bool CREATE_PROVIDER(
58 : const OUString& Implname,
59 : const Sequence< OUString > & Services,
60 : ::cppu::ComponentInstantiation Factory,
61 : createFactoryFunc creator
62 : )
63 : {
64 0 : if (!xRet.is() && (Implname == sImplementationName))
65 : try
66 : {
67 0 : xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
68 : }
69 0 : catch(...)
70 : {
71 : }
72 0 : return xRet.is();
73 : }
74 :
75 0 : void* getProvider() const { return xRet.get(); }
76 : };
77 :
78 : //---------------------------------------------------------------------------------------
79 0 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL hsqldb_component_getFactory(
80 : const sal_Char* pImplementationName,
81 : void* pServiceManager,
82 : void* /*pRegistryKey*/)
83 : {
84 0 : void* pRet = 0;
85 0 : if (pServiceManager)
86 : {
87 0 : ProviderRequest aReq(pServiceManager,pImplementationName);
88 :
89 : aReq.CREATE_PROVIDER(
90 : ODriverDelegator::getImplementationName_Static(),
91 : ODriverDelegator::getSupportedServiceNames_Static(),
92 0 : ODriverDelegator_CreateInstance, ::cppu::createSingleFactory)
93 0 : ;
94 :
95 0 : if(aReq.xRet.is())
96 0 : aReq.xRet->acquire();
97 :
98 0 : pRet = aReq.getProvider();
99 : }
100 :
101 0 : return pRet;
102 : };
103 :
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|