1*079eb577SAndrew Rist /**************************************************************
2*079eb577SAndrew Rist  *
3*079eb577SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*079eb577SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*079eb577SAndrew Rist  * distributed with this work for additional information
6*079eb577SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*079eb577SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*079eb577SAndrew Rist  * "License"); you may not use this file except in compliance
9*079eb577SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*079eb577SAndrew Rist  *
11*079eb577SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*079eb577SAndrew Rist  *
13*079eb577SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*079eb577SAndrew Rist  * software distributed under the License is distributed on an
15*079eb577SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*079eb577SAndrew Rist  * KIND, either express or implied.  See the License for the
17*079eb577SAndrew Rist  * specific language governing permissions and limitations
18*079eb577SAndrew Rist  * under the License.
19*079eb577SAndrew Rist  *
20*079eb577SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir #include "mysqlc_driver.hxx"
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
25cdf0e10cSrcweir #include <osl/diagnose.h>
26cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir using namespace connectivity::mysqlc;
29cdf0e10cSrcweir using ::rtl::OUString;
30cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
31cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
32cdf0e10cSrcweir using ::com::sun::star::registry::XRegistryKey;
33cdf0e10cSrcweir using ::com::sun::star::lang::XSingleServiceFactory;
34cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
37cdf0e10cSrcweir 		(
38cdf0e10cSrcweir 			const Reference< XMultiServiceFactory > & rServiceManager,
39cdf0e10cSrcweir 			const OUString & rComponentName,
40cdf0e10cSrcweir 			::cppu::ComponentInstantiation pCreateFunction,
41cdf0e10cSrcweir 			const Sequence< OUString > & rServiceNames,
42cdf0e10cSrcweir 			rtl_ModuleCount* _pTemp
43cdf0e10cSrcweir 		);
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //***************************************************************************************
46cdf0e10cSrcweir //
47cdf0e10cSrcweir // Die vorgeschriebene C-API muss erfuellt werden!
48cdf0e10cSrcweir // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
49cdf0e10cSrcweir //
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //---------------------------------------------------------------------------------------
REGISTER_PROVIDER(const OUString & aServiceImplName,const Sequence<OUString> & Services,const Reference<XRegistryKey> & xKey)52cdf0e10cSrcweir void REGISTER_PROVIDER(
53cdf0e10cSrcweir 		const OUString& aServiceImplName,
54cdf0e10cSrcweir 		const Sequence< OUString>& Services,
55cdf0e10cSrcweir 		const Reference< XRegistryKey > & xKey)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     ::rtl::OUStringBuffer aMainKeyName;
58cdf0e10cSrcweir     aMainKeyName.append( sal_Unicode( '/' ) );
59cdf0e10cSrcweir     aMainKeyName.append( aServiceImplName );
60cdf0e10cSrcweir     aMainKeyName.appendAscii( "/UNO/SERVICES" );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	Reference< XRegistryKey > xNewKey( xKey->createKey( aMainKeyName.makeStringAndClear() ) );
63cdf0e10cSrcweir 	OSL_ENSURE(xNewKey.is(), "SKELETON::component_writeInfo : could not create a registry key !");
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	for (sal_Int32 i = 0; i < Services.getLength(); ++i) {
66cdf0e10cSrcweir 		xNewKey->createKey(Services[i]);
67cdf0e10cSrcweir 	}
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //---------------------------------------------------------------------------------------
72cdf0e10cSrcweir struct ProviderRequest
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	Reference< XSingleServiceFactory > xRet;
75cdf0e10cSrcweir 	Reference< XMultiServiceFactory > const xServiceManager;
76cdf0e10cSrcweir 	OUString const sImplementationName;
77cdf0e10cSrcweir 
ProviderRequestProviderRequest78cdf0e10cSrcweir 	ProviderRequest(
79cdf0e10cSrcweir 		void* pServiceManager,
80cdf0e10cSrcweir 		sal_Char const* pImplementationName
81cdf0e10cSrcweir 	) : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
82cdf0e10cSrcweir 	  , sImplementationName(OUString::createFromAscii(pImplementationName))
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	/* {{{ CREATE_PROVIDER -I- */
CREATE_PROVIDERProviderRequest87cdf0e10cSrcweir 	inline sal_Bool CREATE_PROVIDER(
88cdf0e10cSrcweir 				const OUString& Implname,
89cdf0e10cSrcweir 				const Sequence< OUString > & Services,
90cdf0e10cSrcweir 				::cppu::ComponentInstantiation Factory,
91cdf0e10cSrcweir 				createFactoryFunc creator
92cdf0e10cSrcweir 			)
93cdf0e10cSrcweir 	{
94cdf0e10cSrcweir 		if (!xRet.is() && (Implname == sImplementationName)) {
95cdf0e10cSrcweir 			try {
96cdf0e10cSrcweir 				xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
97cdf0e10cSrcweir 			} catch (...) {
98cdf0e10cSrcweir 			}
99cdf0e10cSrcweir 		}
100cdf0e10cSrcweir 		return xRet.is();
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 
getProviderProviderRequest103cdf0e10cSrcweir 	void* getProvider() const { return xRet.get(); }
104cdf0e10cSrcweir };
105cdf0e10cSrcweir /* }}} */
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir /* {{{ component_getImplementationEnvironment -I- */
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)109cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
110cdf0e10cSrcweir 				const sal_Char	**ppEnvTypeName,
111cdf0e10cSrcweir 				uno_Environment	** /* ppEnv */
112cdf0e10cSrcweir 			)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir /* }}} */
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir /* {{{ component_writeInfo -I- */
component_writeInfo(void *,void * pRegistryKey)120cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */, void * pRegistryKey)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	if (pRegistryKey) {
123cdf0e10cSrcweir 		try	{
124cdf0e10cSrcweir 			Reference< XRegistryKey > xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey));
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 			REGISTER_PROVIDER(
127cdf0e10cSrcweir 				MysqlCDriver::getImplementationName_Static(),
128cdf0e10cSrcweir 				MysqlCDriver::getSupportedServiceNames_Static(), xKey);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 			return sal_True;
131cdf0e10cSrcweir 		} catch (::com::sun::star::registry::InvalidRegistryException& ) {
132cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "SKELETON::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
133cdf0e10cSrcweir 		}
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 	return sal_False;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir /* }}} */
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 
140cdf0e10cSrcweir /* {{{ component_getFactory -I- */
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)141cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
142cdf0e10cSrcweir 					const sal_Char * pImplementationName,
143cdf0e10cSrcweir 					void * pServiceManager,
144cdf0e10cSrcweir 					void * /* pRegistryKey */)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	void* pRet = 0;
147cdf0e10cSrcweir 	if (pServiceManager) {
148cdf0e10cSrcweir 		ProviderRequest aReq(pServiceManager,pImplementationName);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		aReq.CREATE_PROVIDER(
151cdf0e10cSrcweir 			MysqlCDriver::getImplementationName_Static(),
152cdf0e10cSrcweir 			MysqlCDriver::getSupportedServiceNames_Static(),
153cdf0e10cSrcweir 			MysqlCDriver_CreateInstance, ::cppu::createSingleFactory)
154cdf0e10cSrcweir 		;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		if(aReq.xRet.is()) {
157cdf0e10cSrcweir 			aReq.xRet->acquire();
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		pRet = aReq.getProvider();
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	return pRet;
164cdf0e10cSrcweir };
165cdf0e10cSrcweir /* }}} */
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir /*
169cdf0e10cSrcweir  * Local variables:
170cdf0e10cSrcweir  * tab-width: 4
171cdf0e10cSrcweir  * c-basic-offset: 4
172cdf0e10cSrcweir  * End:
173cdf0e10cSrcweir  * vim600: noet sw=4 ts=4 fdm=marker
174cdf0e10cSrcweir  * vim<600: noet sw=4 ts=4
175cdf0e10cSrcweir  */
176