LibreOffice Module connectivity (master) 1
mysqlc_services.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "mysqlc_driver.hxx"
21
23#include <uno/lbnames.h>
24#include <com/sun/star/lang/XSingleServiceFactory.hpp>
25
26using namespace connectivity::mysqlc;
27using ::com::sun::star::lang::XMultiServiceFactory;
28using ::com::sun::star::lang::XSingleServiceFactory;
29using ::com::sun::star::uno::Reference;
30using ::com::sun::star::uno::Sequence;
31
32typedef Reference<XSingleServiceFactory> (*createFactoryFunc)(
33 const Reference<XMultiServiceFactory>& rServiceManager, const OUString& rComponentName,
34 ::cppu::ComponentInstantiation pCreateFunction, const Sequence<OUString>& rServiceNames,
35 rtl_ModuleCount*);
36
37namespace
38{
39struct ProviderRequest
40{
41 Reference<XSingleServiceFactory> xRet;
42 Reference<XMultiServiceFactory> const xServiceManager;
43 OUString const sImplementationName;
44
45 ProviderRequest(void* pServiceManager, char const* pImplementationName)
46 : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager))
47 , sImplementationName(OUString::createFromAscii(pImplementationName))
48 {
49 }
50
51 bool CREATE_PROVIDER(std::u16string_view Implname, const Sequence<OUString>& Services,
52 ::cppu::ComponentInstantiation Factory, createFactoryFunc creator)
53 {
54 if (!xRet.is() && (Implname == sImplementationName))
55 {
56 try
57 {
58 xRet = creator(xServiceManager, sImplementationName, Factory, Services, nullptr);
59 }
60 catch (...)
61 {
62 }
63 }
64 return xRet.is();
65 }
66
67 void* getProvider() const { return xRet.get(); }
68};
69}
70
71extern "C" SAL_DLLPUBLIC_EXPORT void* component_getFactory(const char* pImplementationName,
72 void* pServiceManager,
73 void* /* pRegistryKey */)
74{
75 void* pRet = nullptr;
76 if (pServiceManager)
77 {
78 ProviderRequest aReq(pServiceManager, pImplementationName);
79
80 aReq.CREATE_PROVIDER(MysqlCDriver::getImplementationName_Static(),
81 MysqlCDriver::getSupportedServiceNames_Static(),
82 MysqlCDriver_CreateInstance, ::cppu::createSingleFactory);
83
84 if (aReq.xRet.is())
85 {
86 aReq.xRet->acquire();
87 }
88
89 pRet = aReq.getProvider();
90 }
91
92 return pRet;
93};
94
95extern "C" SAL_DLLPUBLIC_EXPORT void
97{
98 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
99}
100
101/*
102 * Local variables:
103 * tab-width: 4
104 * c-basic-offset: 4
105 * End:
106 * vim600: noet sw=4 ts=4 fdm=marker
107 * vim<600: noet sw=4 ts=4
108 */
109
110/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sImplementationName
ComponentInstantiation pCreateFunction
struct _uno_Environment uno_Environment
SAL_DLLPUBLIC_EXPORT void * component_getFactory(const char *pImplementationName, void *pServiceManager, void *)
SAL_DLLPUBLIC_EXPORT void component_getImplementationEnvironment(char const **ppEnvTypeName, uno_Environment **)
Reference< XSingleServiceFactory >(* createFactoryFunc)(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rComponentName, ::cppu::ComponentInstantiation pCreateFunction, const Sequence< OUString > &rServiceNames, rtl_ModuleCount *)
Reference< XInterface > MysqlCDriver_CreateInstance(const Reference< XMultiServiceFactory > &_rxFactory)