1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "mysql/YDriver.hxx"
27 #include <cppuhelper/factory.hxx>
28
29 using namespace connectivity::mysql;
30 using ::rtl::OUString;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::lang::XSingleServiceFactory;
34 using ::com::sun::star::lang::XMultiServiceFactory;
35
36 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
37 (
38 const Reference< XMultiServiceFactory > & rServiceManager,
39 const OUString & rComponentName,
40 ::cppu::ComponentInstantiation pCreateFunction,
41 const Sequence< OUString > & rServiceNames,
42 rtl_ModuleCount* _pT
43 );
44
45 //---------------------------------------------------------------------------------------
46 struct ProviderRequest
47 {
48 Reference< XSingleServiceFactory > xRet;
49 Reference< XMultiServiceFactory > const xServiceManager;
50 OUString const sImplementationName;
51
ProviderRequestProviderRequest52 ProviderRequest(
53 void* pServiceManager,
54 sal_Char const* pImplementationName
55 )
56 : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
57 , sImplementationName(OUString::createFromAscii(pImplementationName))
58 {
59 }
60
61 inline
CREATE_PROVIDERProviderRequest62 sal_Bool CREATE_PROVIDER(
63 const OUString& Implname,
64 const Sequence< OUString > & Services,
65 ::cppu::ComponentInstantiation Factory,
66 createFactoryFunc creator
67 )
68 {
69 if (!xRet.is() && (Implname == sImplementationName))
70 try
71 {
72 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
73 }
74 catch(...)
75 {
76 }
77 return xRet.is();
78 }
79
getProviderProviderRequest80 void* getProvider() const { return xRet.get(); }
81 };
82
83 //---------------------------------------------------------------------------------------
84
85 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)86 component_getImplementationEnvironment(
87 const sal_Char **ppEnvTypeName,
88 uno_Environment ** /*ppEnv*/
89 )
90 {
91 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
92 }
93
94 //---------------------------------------------------------------------------------------
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)95 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
96 const sal_Char* pImplementationName,
97 void* pServiceManager,
98 void* /*pRegistryKey*/)
99 {
100 void* pRet = 0;
101 if (pServiceManager)
102 {
103 ProviderRequest aReq(pServiceManager,pImplementationName);
104
105 aReq.CREATE_PROVIDER(
106 ODriverDelegator::getImplementationName_Static(),
107 ODriverDelegator::getSupportedServiceNames_Static(),
108 ODriverDelegator_CreateInstance, ::cppu::createSingleFactory)
109 ;
110
111 if(aReq.xRet.is())
112 aReq.xRet->acquire();
113
114 pRet = aReq.getProvider();
115 }
116
117 return pRet;
118 };
119
120
121