Line data Source code
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 : // be included in other cxx files
21 :
22 : #ifndef _REGISTRATIONHELPER_CXX_INCLUDED_INDIRECTLY_
23 : #error "don't build this file directly! use dbu_reghelper.cxx instead!"
24 : #endif
25 :
26 : using namespace ::com::sun::star;
27 : using namespace ::comphelper;
28 : using namespace ::cppu;
29 :
30 : uno::Sequence< OUString >* OModuleRegistration::s_pImplementationNames = NULL;
31 : uno::Sequence< uno::Sequence< OUString > >* OModuleRegistration::s_pSupportedServices = NULL;
32 : uno::Sequence< sal_Int64 >* OModuleRegistration::s_pCreationFunctionPointers = NULL;
33 : uno::Sequence< sal_Int64 >* OModuleRegistration::s_pFactoryFunctionPointers = NULL;
34 :
35 462 : void OModuleRegistration::registerComponent(
36 : const OUString& _rImplementationName,
37 : const uno::Sequence< OUString >& _rServiceNames,
38 : ComponentInstantiation _pCreateFunction,
39 : FactoryInstantiation _pFactoryFunction)
40 : {
41 462 : if (!s_pImplementationNames)
42 : {
43 : OSL_ENSURE(!s_pSupportedServices && !s_pCreationFunctionPointers && !s_pFactoryFunctionPointers,
44 : "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !");
45 35 : s_pImplementationNames = new uno::Sequence< OUString >;
46 35 : s_pSupportedServices = new uno::Sequence< uno::Sequence< OUString > >;
47 35 : s_pCreationFunctionPointers = new uno::Sequence< sal_Int64 >;
48 35 : s_pFactoryFunctionPointers = new uno::Sequence< sal_Int64 >;
49 : }
50 : OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
51 : "OModuleRegistration::registerComponent : inconsistent state (the pointers (2)) !");
52 :
53 : OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
54 : && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
55 : && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
56 : "OModuleRegistration::registerComponent : inconsistent state !");
57 :
58 462 : sal_Int32 nOldLen = s_pImplementationNames->getLength();
59 462 : s_pImplementationNames->realloc(nOldLen + 1);
60 462 : s_pSupportedServices->realloc(nOldLen + 1);
61 462 : s_pCreationFunctionPointers->realloc(nOldLen + 1);
62 462 : s_pFactoryFunctionPointers->realloc(nOldLen + 1);
63 :
64 462 : s_pImplementationNames->getArray()[nOldLen] = _rImplementationName;
65 462 : s_pSupportedServices->getArray()[nOldLen] = _rServiceNames;
66 462 : s_pCreationFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pCreateFunction);
67 462 : s_pFactoryFunctionPointers->getArray()[nOldLen] = reinterpret_cast<sal_Int64>(_pFactoryFunction);
68 462 : }
69 :
70 462 : void OModuleRegistration::revokeComponent(const OUString& _rImplementationName)
71 : {
72 462 : if (!s_pImplementationNames)
73 : {
74 : OSL_FAIL("OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
75 462 : return;
76 : }
77 : OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
78 : "OModuleRegistration::revokeComponent : inconsistent state (the pointers) !");
79 : OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
80 : && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
81 : && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
82 : "OModuleRegistration::revokeComponent : inconsistent state !");
83 :
84 462 : sal_Int32 nLen = s_pImplementationNames->getLength();
85 462 : const OUString* pImplNames = s_pImplementationNames->getConstArray();
86 5019 : for (sal_Int32 i=0; i<nLen; ++i, ++pImplNames)
87 : {
88 5019 : if (pImplNames->equals(_rImplementationName))
89 : {
90 462 : removeElementAt(*s_pImplementationNames, i);
91 462 : removeElementAt(*s_pSupportedServices, i);
92 462 : removeElementAt(*s_pCreationFunctionPointers, i);
93 462 : removeElementAt(*s_pFactoryFunctionPointers, i);
94 462 : break;
95 : }
96 : }
97 :
98 462 : if (s_pImplementationNames->getLength() == 0)
99 : {
100 35 : delete s_pImplementationNames; s_pImplementationNames = NULL;
101 35 : delete s_pSupportedServices; s_pSupportedServices = NULL;
102 35 : delete s_pCreationFunctionPointers; s_pCreationFunctionPointers = NULL;
103 35 : delete s_pFactoryFunctionPointers; s_pFactoryFunctionPointers = NULL;
104 : }
105 : }
106 :
107 90 : uno::Reference< uno::XInterface > OModuleRegistration::getComponentFactory(
108 : const OUString& _rImplementationName,
109 : const uno::Reference< lang::XMultiServiceFactory >& _rxServiceManager)
110 : {
111 : OSL_ENSURE(_rxServiceManager.is(), "OModuleRegistration::getComponentFactory : invalid argument (service manager) !");
112 : OSL_ENSURE(!_rImplementationName.isEmpty(), "OModuleRegistration::getComponentFactory : invalid argument (implementation name) !");
113 :
114 90 : if (!s_pImplementationNames)
115 : {
116 : OSL_FAIL("OModuleRegistration::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
117 0 : return NULL;
118 : }
119 : OSL_ENSURE(s_pImplementationNames && s_pSupportedServices && s_pCreationFunctionPointers && s_pFactoryFunctionPointers,
120 : "OModuleRegistration::getComponentFactory : inconsistent state (the pointers) !");
121 : OSL_ENSURE( (s_pImplementationNames->getLength() == s_pSupportedServices->getLength())
122 : && (s_pImplementationNames->getLength() == s_pCreationFunctionPointers->getLength())
123 : && (s_pImplementationNames->getLength() == s_pFactoryFunctionPointers->getLength()),
124 : "OModuleRegistration::getComponentFactory : inconsistent state !");
125 :
126 90 : uno::Reference< uno::XInterface > xReturn;
127 :
128 90 : sal_Int32 nLen = s_pImplementationNames->getLength();
129 90 : const OUString* pImplName = s_pImplementationNames->getConstArray();
130 90 : const uno::Sequence< OUString >* pServices = s_pSupportedServices->getConstArray();
131 90 : const sal_Int64* pComponentFunction = s_pCreationFunctionPointers->getConstArray();
132 90 : const sal_Int64* pFactoryFunction = s_pFactoryFunctionPointers->getConstArray();
133 :
134 575 : for (sal_Int32 i=0; i<nLen; ++i, ++pImplName, ++pServices, ++pComponentFunction, ++pFactoryFunction)
135 : {
136 575 : if (pImplName->equals(_rImplementationName))
137 : {
138 90 : const FactoryInstantiation FactoryInstantiationFunction = reinterpret_cast<const FactoryInstantiation>(*pFactoryFunction);
139 90 : const ComponentInstantiation ComponentInstantiationFunction = reinterpret_cast<const ComponentInstantiation>(*pComponentFunction);
140 :
141 90 : xReturn = FactoryInstantiationFunction( _rxServiceManager, *pImplName, ComponentInstantiationFunction, *pServices, NULL);
142 90 : if (xReturn.is())
143 : {
144 90 : return xReturn.get();
145 : }
146 : }
147 : }
148 :
149 0 : return NULL;
150 : }
151 :
152 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|