1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 // be included in other cxx files
22 #ifndef _REGISTRATIONHELPER_CXX_INCLUDED_INDIRECTLY_
23 #error "don't build this file directly! use dbu_reghelper.cxx instead!"
26 using namespace ::com::sun::star
;
27 using namespace ::comphelper
;
28 using namespace ::cppu
;
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
;
35 void OModuleRegistration::registerComponent(
36 const OUString
& _rImplementationName
,
37 const uno::Sequence
< OUString
>& _rServiceNames
,
38 ComponentInstantiation _pCreateFunction
,
39 FactoryInstantiation _pFactoryFunction
)
41 if (!s_pImplementationNames
)
43 OSL_ENSURE(!s_pSupportedServices
&& !s_pCreationFunctionPointers
&& !s_pFactoryFunctionPointers
,
44 "OModuleRegistration::registerComponent : inconsistent state (the pointers (1)) !");
45 s_pImplementationNames
= new uno::Sequence
< OUString
>;
46 s_pSupportedServices
= new uno::Sequence
< uno::Sequence
< OUString
> >;
47 s_pCreationFunctionPointers
= new uno::Sequence
< sal_Int64
>;
48 s_pFactoryFunctionPointers
= new uno::Sequence
< sal_Int64
>;
50 OSL_ENSURE(s_pImplementationNames
&& s_pSupportedServices
&& s_pCreationFunctionPointers
&& s_pFactoryFunctionPointers
,
51 "OModuleRegistration::registerComponent : inconsistent state (the pointers (2)) !");
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 !");
58 sal_Int32 nOldLen
= s_pImplementationNames
->getLength();
59 s_pImplementationNames
->realloc(nOldLen
+ 1);
60 s_pSupportedServices
->realloc(nOldLen
+ 1);
61 s_pCreationFunctionPointers
->realloc(nOldLen
+ 1);
62 s_pFactoryFunctionPointers
->realloc(nOldLen
+ 1);
64 s_pImplementationNames
->getArray()[nOldLen
] = _rImplementationName
;
65 s_pSupportedServices
->getArray()[nOldLen
] = _rServiceNames
;
66 s_pCreationFunctionPointers
->getArray()[nOldLen
] = reinterpret_cast<sal_Int64
>(_pCreateFunction
);
67 s_pFactoryFunctionPointers
->getArray()[nOldLen
] = reinterpret_cast<sal_Int64
>(_pFactoryFunction
);
70 void OModuleRegistration::revokeComponent(const OUString
& _rImplementationName
)
72 if (!s_pImplementationNames
)
74 OSL_FAIL("OModuleRegistration::revokeComponent : have no class infos ! Are you sure called this method at the right time ?");
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 !");
84 sal_Int32 nLen
= s_pImplementationNames
->getLength();
85 const OUString
* pImplNames
= s_pImplementationNames
->getConstArray();
86 for (sal_Int32 i
=0; i
<nLen
; ++i
, ++pImplNames
)
88 if (pImplNames
->equals(_rImplementationName
))
90 removeElementAt(*s_pImplementationNames
, i
);
91 removeElementAt(*s_pSupportedServices
, i
);
92 removeElementAt(*s_pCreationFunctionPointers
, i
);
93 removeElementAt(*s_pFactoryFunctionPointers
, i
);
98 if (s_pImplementationNames
->getLength() == 0)
100 delete s_pImplementationNames
; s_pImplementationNames
= NULL
;
101 delete s_pSupportedServices
; s_pSupportedServices
= NULL
;
102 delete s_pCreationFunctionPointers
; s_pCreationFunctionPointers
= NULL
;
103 delete s_pFactoryFunctionPointers
; s_pFactoryFunctionPointers
= NULL
;
107 uno::Reference
< uno::XInterface
> OModuleRegistration::getComponentFactory(
108 const OUString
& _rImplementationName
,
109 const uno::Reference
< lang::XMultiServiceFactory
>& _rxServiceManager
)
111 OSL_ENSURE(_rxServiceManager
.is(), "OModuleRegistration::getComponentFactory : invalid argument (service manager) !");
112 OSL_ENSURE(!_rImplementationName
.isEmpty(), "OModuleRegistration::getComponentFactory : invalid argument (implementation name) !");
114 if (!s_pImplementationNames
)
116 OSL_FAIL("OModuleRegistration::getComponentFactory : have no class infos ! Are you sure called this method at the right time ?");
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 !");
126 uno::Reference
< uno::XInterface
> xReturn
;
128 sal_Int32 nLen
= s_pImplementationNames
->getLength();
129 const OUString
* pImplName
= s_pImplementationNames
->getConstArray();
130 const uno::Sequence
< OUString
>* pServices
= s_pSupportedServices
->getConstArray();
131 const sal_Int64
* pComponentFunction
= s_pCreationFunctionPointers
->getConstArray();
132 const sal_Int64
* pFactoryFunction
= s_pFactoryFunctionPointers
->getConstArray();
134 for (sal_Int32 i
=0; i
<nLen
; ++i
, ++pImplName
, ++pServices
, ++pComponentFunction
, ++pFactoryFunction
)
136 if (pImplName
->equals(_rImplementationName
))
138 const FactoryInstantiation FactoryInstantiationFunction
= reinterpret_cast<const FactoryInstantiation
>(*pFactoryFunction
);
139 const ComponentInstantiation ComponentInstantiationFunction
= reinterpret_cast<const ComponentInstantiation
>(*pComponentFunction
);
141 xReturn
= FactoryInstantiationFunction( _rxServiceManager
, *pImplName
, ComponentInstantiationFunction
, *pServices
, NULL
);
144 return xReturn
.get();
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */