bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / inc / componentmodule.cxx
blob18f589c77ccca97da2ce15bf583eabed1eec3ffc
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 <memory>
21 #include "componentmodule.hxx"
22 #include <unotools/resmgr.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
25 #include <svl/solar.hrc>
26 #include <tools/debug.hxx>
27 #include <rtl/strbuf.hxx>
28 #include <osl/diagnose.h>
30 namespace compmodule
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::registry;
35 using namespace ::cppu;
37 OUString ModuleRes(const char* pId)
39 return Translate::get(pId, Translate::Create("pcr"));
42 //- registration helper
44 std::vector< OUString >* OModule::s_pImplementationNames = nullptr;
45 std::vector< Sequence< OUString > >* OModule::s_pSupportedServices = nullptr;
46 std::vector< ComponentInstantiation >* OModule::s_pCreationFunctionPointers = nullptr;
47 std::vector< FactoryInstantiation >* OModule::s_pFactoryFunctionPointers = nullptr;
50 void OModule::registerComponent(
51 const OUString& _rImplementationName,
52 const Sequence< OUString >& _rServiceNames,
53 ComponentInstantiation _pCreateFunction,
54 FactoryInstantiation _pFactoryFunction)
56 if (!s_pImplementationNames)
58 OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
59 "OModule::registerComponent : inconsistent state (the pointers (1)) !");
60 s_pImplementationNames = new std::vector< OUString >;
61 s_pSupportedServices = new std::vector< Sequence< OUString > >;
62 s_pCreationFunctionPointers = new std::vector< ComponentInstantiation >;
63 s_pFactoryFunctionPointers = new std::vector< FactoryInstantiation >;
65 OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
66 "OModule::registerComponent : inconsistent state (the pointers (2)) !");
68 OSL_ENSURE( (s_pImplementationNames->size() == s_pSupportedServices->size())
69 && (s_pImplementationNames->size() == s_pCreationFunctionPointers->size())
70 && (s_pImplementationNames->size() == s_pFactoryFunctionPointers->size()),
71 "OModule::registerComponent : inconsistent state !");
73 s_pImplementationNames->push_back(_rImplementationName);
74 s_pSupportedServices->push_back(_rServiceNames);
75 s_pCreationFunctionPointers->push_back(_pCreateFunction);
76 s_pFactoryFunctionPointers->push_back(_pFactoryFunction);
80 void OModule::revokeComponent(const OUString& _rImplementationName)
82 if (!s_pImplementationNames)
84 OSL_FAIL("OModule::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
85 return;
87 OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
88 "OModule::revokeComponent : inconsistent state (the pointers) !");
89 OSL_ENSURE( (s_pImplementationNames->size() == s_pSupportedServices->size())
90 && (s_pImplementationNames->size() == s_pCreationFunctionPointers->size())
91 && (s_pImplementationNames->size() == s_pFactoryFunctionPointers->size()),
92 "OModule::revokeComponent : inconsistent state !");
94 auto it = std::find(s_pImplementationNames->begin(), s_pImplementationNames->end(), _rImplementationName);
95 if (it != s_pImplementationNames->end())
97 sal_Int32 i = static_cast<sal_Int32>(std::distance(s_pImplementationNames->begin(), it));
98 s_pImplementationNames->erase(it);
99 s_pSupportedServices->erase(s_pSupportedServices->begin() + i);
100 s_pCreationFunctionPointers->erase(s_pCreationFunctionPointers->begin() + i);
101 s_pFactoryFunctionPointers->erase(s_pFactoryFunctionPointers->begin() + i);
104 if (s_pImplementationNames->empty())
106 delete s_pImplementationNames; s_pImplementationNames = nullptr;
107 delete s_pSupportedServices; s_pSupportedServices = nullptr;
108 delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = nullptr;
109 delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = nullptr;
114 Reference< XInterface > OModule::getComponentFactory(
115 const OUString& _rImplementationName,
116 const Reference< XMultiServiceFactory >& _rxServiceManager)
118 OSL_ENSURE(_rxServiceManager.is(), "OModule::getComponentFactory : invalid argument (service manager) !");
119 OSL_ENSURE(!_rImplementationName.isEmpty(), "OModule::getComponentFactory : invalid argument (implementation name) !");
121 if (!s_pImplementationNames)
123 OSL_FAIL("OModule::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
124 return nullptr;
126 OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
127 "OModule::getComponentFactory : inconsistent state (the pointers) !");
128 OSL_ENSURE( (s_pImplementationNames->size() == s_pSupportedServices->size())
129 && (s_pImplementationNames->size() == s_pCreationFunctionPointers->size())
130 && (s_pImplementationNames->size() == s_pFactoryFunctionPointers->size()),
131 "OModule::getComponentFactory : inconsistent state !");
134 sal_Int32 nLen = s_pImplementationNames->size();
136 for (sal_Int32 i=0; i<nLen; ++i)
138 if ((*s_pImplementationNames)[i] == _rImplementationName)
140 const FactoryInstantiation FactoryInstantiationFunction = (*s_pFactoryFunctionPointers)[i];
142 Reference< XInterface > xReturn = FactoryInstantiationFunction( _rxServiceManager, _rImplementationName,
143 (*s_pCreationFunctionPointers)[i],
144 (*s_pSupportedServices)[i], nullptr);
145 return xReturn;
149 return nullptr;
153 } // namespace compmodule
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */