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