xref: /trunk/main/connectivity/source/drivers/mysql/Yservices.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "mysql/YDriver.hxx"
31 #include <cppuhelper/factory.hxx>
32 
33 using namespace connectivity::mysql;
34 using ::rtl::OUString;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::lang::XSingleServiceFactory;
38 using ::com::sun::star::lang::XMultiServiceFactory;
39 
40 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
41         (
42             const Reference< XMultiServiceFactory > & rServiceManager,
43             const OUString & rComponentName,
44             ::cppu::ComponentInstantiation pCreateFunction,
45             const Sequence< OUString > & rServiceNames,
46             rtl_ModuleCount* _pT
47         );
48 
49 //---------------------------------------------------------------------------------------
50 struct ProviderRequest
51 {
52     Reference< XSingleServiceFactory > xRet;
53     Reference< XMultiServiceFactory > const xServiceManager;
54     OUString const sImplementationName;
55 
56     ProviderRequest(
57         void* pServiceManager,
58         sal_Char const* pImplementationName
59     )
60     : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
61     , sImplementationName(OUString::createFromAscii(pImplementationName))
62     {
63     }
64 
65     inline
66     sal_Bool CREATE_PROVIDER(
67                 const OUString& Implname,
68                 const Sequence< OUString > & Services,
69                 ::cppu::ComponentInstantiation Factory,
70                 createFactoryFunc creator
71             )
72     {
73         if (!xRet.is() && (Implname == sImplementationName))
74         try
75         {
76             xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
77         }
78         catch(...)
79         {
80         }
81         return xRet.is();
82     }
83 
84     void* getProvider() const { return xRet.get(); }
85 };
86 
87 //---------------------------------------------------------------------------------------
88 
89 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
90 component_getImplementationEnvironment(
91                 const sal_Char  **ppEnvTypeName,
92                 uno_Environment ** /*ppEnv*/
93             )
94 {
95     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
96 }
97 
98 //---------------------------------------------------------------------------------------
99 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
100                     const sal_Char* pImplementationName,
101                     void* pServiceManager,
102                     void* /*pRegistryKey*/)
103 {
104     void* pRet = 0;
105     if (pServiceManager)
106     {
107         ProviderRequest aReq(pServiceManager,pImplementationName);
108 
109         aReq.CREATE_PROVIDER(
110             ODriverDelegator::getImplementationName_Static(),
111             ODriverDelegator::getSupportedServiceNames_Static(),
112             ODriverDelegator_CreateInstance, ::cppu::createSingleFactory)
113         ;
114 
115         if(aReq.xRet.is())
116             aReq.xRet->acquire();
117 
118         pRet = aReq.getProvider();
119     }
120 
121     return pRet;
122 };
123 
124 
125