build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / mysqlc / source / mysqlc_services.cxx
blobaaa4099ae9ec6285ad291734deb7dcd0dae0eab6
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>
25 #include <uno/lbnames.h>
27 using namespace connectivity::mysqlc;
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::Sequence;
30 using ::com::sun::star::lang::XSingleServiceFactory;
31 using ::com::sun::star::lang::XMultiServiceFactory;
33 typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
35 const Reference< XMultiServiceFactory > & rServiceManager,
36 const rtl::OUString & rComponentName,
37 ::cppu::ComponentInstantiation pCreateFunction,
38 const Sequence< rtl::OUString > & rServiceNames,
39 rtl_ModuleCount*
42 struct ProviderRequest
44 Reference< XSingleServiceFactory > xRet;
45 Reference< XMultiServiceFactory > const xServiceManager;
46 rtl::OUString const sImplementationName;
48 ProviderRequest(
49 void* pServiceManager,
50 sal_Char const* pImplementationName
51 ) : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager))
52 , sImplementationName(rtl::OUString::createFromAscii(pImplementationName))
56 inline bool CREATE_PROVIDER(
57 const rtl::OUString& Implname,
58 const Sequence< rtl::OUString > & Services,
59 ::cppu::ComponentInstantiation Factory,
60 createFactoryFunc creator
63 if (!xRet.is() && (Implname == sImplementationName)) {
64 try {
65 xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr);
66 } catch (...) {
69 return xRet.is();
72 void* getProvider() const { return xRet.get(); }
75 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
76 const sal_Char * pImplementationName,
77 void * pServiceManager,
78 void * /* pRegistryKey */)
80 void* pRet = nullptr;
81 if (pServiceManager) {
82 ProviderRequest aReq(pServiceManager,pImplementationName);
84 aReq.CREATE_PROVIDER(
85 MysqlCDriver::getImplementationName_Static(),
86 MysqlCDriver::getSupportedServiceNames_Static(),
87 MysqlCDriver_CreateInstance, ::cppu::createSingleFactory)
90 if(aReq.xRet.is()) {
91 aReq.xRet->acquire();
94 pRet = aReq.getProvider();
97 return pRet;
100 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
101 component_getImplementationEnvironment(
102 char const ** ppEnvTypeName, uno_Environment **)
104 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
108 * Local variables:
109 * tab-width: 4
110 * c-basic-offset: 4
111 * End:
112 * vim600: noet sw=4 ts=4 fdm=marker
113 * vim<600: noet sw=4 ts=4
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */