Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / mysqlc / source / mysqlc_services.cxx
blob47a5ffdbb80182e47810454baf2c89a418ccba31
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "mysqlc_driver.hxx"
22 #include <cppuhelper/factory.hxx>
23 #include <osl/diagnose.h>
24 #include <rtl/ustrbuf.hxx>
26 using namespace connectivity::mysqlc;
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;
34 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
36 const Reference< XMultiServiceFactory > & rServiceManager,
37 const OUString & rComponentName,
38 ::cppu::ComponentInstantiation pCreateFunction,
39 const Sequence< OUString > & rServiceNames,
40 rtl_ModuleCount* _pTemp
43 //***************************************************************************************
45 // Die vorgeschriebene C-API muss erfuellt werden!
46 // Sie besteht aus drei Funktionen, die von dem Modul exportiert werden muessen.
49 //---------------------------------------------------------------------------------------
50 void REGISTER_PROVIDER(
51 const OUString& aServiceImplName,
52 const Sequence< OUString>& Services,
53 const Reference< XRegistryKey > & xKey)
55 ::rtl::OUStringBuffer aMainKeyName;
56 aMainKeyName.append( sal_Unicode( '/' ) );
57 aMainKeyName.append( aServiceImplName );
58 aMainKeyName.appendAscii( "/UNO/SERVICES" );
60 Reference< XRegistryKey > xNewKey( xKey->createKey( aMainKeyName.makeStringAndClear() ) );
61 OSL_ENSURE(xNewKey.is(), "SKELETON::component_writeInfo : could not create a registry key !");
63 for (sal_Int32 i = 0; i < Services.getLength(); ++i) {
64 xNewKey->createKey(Services[i]);
69 //---------------------------------------------------------------------------------------
70 struct ProviderRequest
72 Reference< XSingleServiceFactory > xRet;
73 Reference< XMultiServiceFactory > const xServiceManager;
74 OUString const sImplementationName;
76 ProviderRequest(
77 void* pServiceManager,
78 sal_Char const* pImplementationName
79 ) : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
80 , sImplementationName(OUString::createFromAscii(pImplementationName))
84 /* {{{ CREATE_PROVIDER -I- */
85 inline sal_Bool CREATE_PROVIDER(
86 const OUString& Implname,
87 const Sequence< OUString > & Services,
88 ::cppu::ComponentInstantiation Factory,
89 createFactoryFunc creator
92 if (!xRet.is() && (Implname == sImplementationName)) {
93 try {
94 xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
95 } catch (...) {
98 return xRet.is();
101 void* getProvider() const { return xRet.get(); }
103 /* }}} */
106 /* {{{ component_writeInfo -I- */
107 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */, void * pRegistryKey)
109 if (pRegistryKey) {
110 try {
111 Reference< XRegistryKey > xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey));
113 REGISTER_PROVIDER(
114 MysqlCDriver::getImplementationName_Static(),
115 MysqlCDriver::getSupportedServiceNames_Static(), xKey);
117 return sal_True;
118 } catch (::com::sun::star::registry::InvalidRegistryException& ) {
119 OSL_FAIL("SKELETON::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
122 return sal_False;
124 /* }}} */
127 /* {{{ component_getFactory -I- */
128 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
129 const sal_Char * pImplementationName,
130 void * pServiceManager,
131 void * /* pRegistryKey */)
133 void* pRet = 0;
134 if (pServiceManager) {
135 ProviderRequest aReq(pServiceManager,pImplementationName);
137 aReq.CREATE_PROVIDER(
138 MysqlCDriver::getImplementationName_Static(),
139 MysqlCDriver::getSupportedServiceNames_Static(),
140 MysqlCDriver_CreateInstance, ::cppu::createSingleFactory)
143 if(aReq.xRet.is()) {
144 aReq.xRet->acquire();
147 pRet = aReq.getProvider();
150 return pRet;
152 /* }}} */
156 * Local variables:
157 * tab-width: 4
158 * c-basic-offset: 4
159 * End:
160 * vim600: noet sw=4 ts=4 fdm=marker
161 * vim<600: noet sw=4 ts=4
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */