xref: /AOO41X/main/connectivity/source/drivers/ado/Aservices.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
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 "ado/ADriver.hxx"
27 #include <cppuhelper/factory.hxx>
28 
29 using namespace connectivity::ado;
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 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)85 extern "C" void SAL_CALL component_getImplementationEnvironment(
86                 const sal_Char  **ppEnvTypeName,
87                 uno_Environment ** /*ppEnv*/
88             )
89 {
90     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ":affine";
91 }
92 
93 //---------------------------------------------------------------------------------------
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)94 extern "C" void* SAL_CALL component_getFactory(
95                     const sal_Char* pImplementationName,
96                     void* pServiceManager,
97                     void* /*pRegistryKey*/)
98 {
99     void* pRet = 0;
100     if (pServiceManager)
101     {
102         ProviderRequest aReq(pServiceManager,pImplementationName);
103 
104         aReq.CREATE_PROVIDER(
105             ODriver::getImplementationName_Static(),
106             ODriver::getSupportedServiceNames_Static(),
107             ODriver_CreateInstance, ::cppu::createSingleFactory)
108         ;
109 
110         if(aReq.xRet.is())
111             aReq.xRet->acquire();
112 
113         pRet = aReq.getProvider();
114     }
115 
116     return pRet;
117 };
118 
119 
120