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 : #include "Driver.hxx"
21 :
22 : #include <cppuhelper/factory.hxx>
23 : #include <osl/diagnose.h>
24 : #include <sal/types.h>
25 :
26 : using namespace connectivity::firebird;
27 : using ::rtl::OUString;
28 : using ::com::sun::star::uno::Reference;
29 : using ::com::sun::star::uno::Sequence;
30 : using ::com::sun::star::registry::XRegistryKey;
31 : using ::com::sun::star::lang::XSingleServiceFactory;
32 : using ::com::sun::star::lang::XMultiServiceFactory;
33 :
34 : typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
35 : (
36 : const Reference< XMultiServiceFactory > & rServiceManager,
37 : const OUString & rComponentName,
38 : ::cppu::ComponentInstantiation pCreateFunction,
39 : const Sequence< OUString > & rServiceNames,
40 : rtl_ModuleCount* _pTemp
41 : );
42 :
43 2 : struct ProviderRequest
44 : {
45 : Reference< XSingleServiceFactory > xRet;
46 : Reference< XMultiServiceFactory > const xServiceManager;
47 : OUString const sImplementationName;
48 :
49 2 : ProviderRequest(
50 : void* pServiceManager,
51 : sal_Char const* pImplementationName
52 : )
53 : : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
54 2 : , sImplementationName(OUString::createFromAscii(pImplementationName))
55 : {
56 2 : }
57 :
58 : inline
59 2 : bool CREATE_PROVIDER(
60 : const OUString& Implname,
61 : const Sequence< OUString > & Services,
62 : ::cppu::ComponentInstantiation Factory,
63 : createFactoryFunc creator
64 : )
65 : {
66 2 : if (!xRet.is() && (Implname == sImplementationName))
67 : {
68 : try
69 : {
70 2 : xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
71 : }
72 0 : catch(...)
73 : {
74 : }
75 : }
76 2 : return xRet.is();
77 : }
78 :
79 2 : void* getProvider() const { return xRet.get(); }
80 : };
81 :
82 :
83 2 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL firebird_sdbc_component_getFactory(
84 : const sal_Char* pImplementationName,
85 : void* pServiceManager,
86 : void* pRegistryKey)
87 : {
88 : (void) pRegistryKey;
89 2 : void* pRet = 0;
90 2 : if (pServiceManager)
91 : {
92 2 : ProviderRequest aReq(pServiceManager,pImplementationName);
93 :
94 : aReq.CREATE_PROVIDER(
95 : FirebirdDriver::getImplementationName_Static(),
96 : FirebirdDriver::getSupportedServiceNames_Static(),
97 4 : FirebirdDriver_CreateInstance, ::cppu::createSingleFactory)
98 2 : ;
99 :
100 2 : if(aReq.xRet.is())
101 2 : aReq.xRet->acquire();
102 :
103 2 : pRet = aReq.getProvider();
104 : }
105 :
106 2 : return pRet;
107 : };
108 :
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|