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/.
10 #ifndef INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
11 #define INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
13 #include "sal/config.h"
19 #include "boost/noncopyable.hpp"
20 #include "boost/shared_ptr.hpp"
21 #include "com/sun/star/beans/XPropertySet.hpp"
22 #include "com/sun/star/beans/XPropertySetInfo.hpp"
23 #include "com/sun/star/container/XContentEnumerationAccess.hpp"
24 #include "com/sun/star/container/XSet.hpp"
25 #include "com/sun/star/lang/XEventListener.hpp"
26 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
27 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
28 #include "com/sun/star/lang/XServiceInfo.hpp"
29 #include "com/sun/star/lang/XSingleServiceFactory.hpp"
30 #include "com/sun/star/uno/XComponentContext.hpp"
31 #include "com/sun/star/uno/Reference.hxx"
32 #include "cppuhelper/basemutex.hxx"
33 #include "cppuhelper/compbase8.hxx"
34 #include "osl/mutex.hxx"
35 #include "registry/registry.hxx"
36 #include "rtl/ustring.hxx"
37 #include "cppuhelper/weak.hxx"
39 namespace com
{ namespace sun
{ namespace star
{ namespace lang
{
40 class XSingleComponentFactory
;
42 namespace cppu
{ struct ContextEntry_Init
; }
44 namespace cppuhelper
{
48 typedef css::uno::XInterface
* SAL_CALL
ImplementationConstructorFn(
49 css::uno::XComponentContext
*, css::uno::Sequence
<css::uno::Any
> const &);
53 typedef cppu::WeakComponentImplHelper8
<
54 css::lang::XServiceInfo
, css::lang::XMultiServiceFactory
,
55 css::lang::XMultiComponentFactory
, css::container::XSet
,
56 css::container::XContentEnumerationAccess
, css::beans::XPropertySet
,
57 css::beans::XPropertySetInfo
, css::lang::XEventListener
>
61 private cppu::BaseMutex
, public ServiceManagerBase
,
62 private boost::noncopyable
65 struct Data
: private boost::noncopyable
{
66 struct ImplementationInfo
: private boost::noncopyable
{
68 rtl::OUString
const & theName
, rtl::OUString
const & theLoader
,
69 rtl::OUString
const & theUri
,
70 rtl::OUString
const & theEnvironment
,
71 rtl::OUString
const & theConstructor
,
72 rtl::OUString
const & thePrefix
,
73 css::uno::Reference
< css::uno::XComponentContext
> const &
75 rtl::OUString
const & theRdbFile
):
76 name(theName
), loader(theLoader
), uri(theUri
),
77 environment(theEnvironment
), constructor(theConstructor
),
78 prefix(thePrefix
), alienContext(theAlienContext
),
82 explicit ImplementationInfo(rtl::OUString
const & theName
):
85 rtl::OUString
const name
;
86 rtl::OUString
const loader
;
87 rtl::OUString
const uri
;
88 rtl::OUString
const environment
;
89 rtl::OUString
const constructor
;
90 rtl::OUString
const prefix
;
91 css::uno::Reference
< css::uno::XComponentContext
> const
93 rtl::OUString
const rdbFile
;
94 std::vector
< rtl::OUString
> services
;
95 std::vector
< rtl::OUString
> singletons
;
98 struct Implementation
: private boost::noncopyable
{
100 rtl::OUString
const & name
, rtl::OUString
const & loader
,
101 rtl::OUString
const & uri
, rtl::OUString
const & environment
,
102 rtl::OUString
const & constructorName
,
103 rtl::OUString
const & prefix
,
104 css::uno::Reference
< css::uno::XComponentContext
> const &
106 rtl::OUString
const & rdbFile
):
108 new ImplementationInfo(
109 name
, loader
, uri
, environment
, constructorName
, prefix
,
110 alienContext
, rdbFile
)),
111 constructor(0), status(STATUS_NEW
), dispose(true)
115 rtl::OUString
const & name
,
116 css::uno::Reference
< css::lang::XSingleComponentFactory
>
118 css::uno::Reference
< css::lang::XSingleServiceFactory
> const &
120 css::uno::Reference
< css::lang::XComponent
> const &
122 info(new ImplementationInfo(name
)), constructor(0),
123 factory1(theFactory1
), factory2(theFactory2
),
124 component(theComponent
), status(STATUS_LOADED
), dispose(true)
125 { assert(theFactory1
.is() || theFactory2
.is()); }
127 css::uno::Reference
<css::uno::XInterface
> createInstance(
128 css::uno::Reference
<css::uno::XComponentContext
> const &
130 bool singletonRequest
);
132 css::uno::Reference
<css::uno::XInterface
>
133 createInstanceWithArguments(
134 css::uno::Reference
<css::uno::XComponentContext
> const &
136 bool singletonRequest
,
137 css::uno::Sequence
<css::uno::Any
> const & arguments
);
139 enum Status
{ STATUS_NEW
, STATUS_WRAPPER
, STATUS_LOADED
};
141 boost::shared_ptr
< ImplementationInfo
> info
;
142 ImplementationConstructorFn
* constructor
;
143 css::uno::Reference
< css::lang::XSingleComponentFactory
> factory1
;
144 css::uno::Reference
< css::lang::XSingleServiceFactory
> factory2
;
145 css::uno::Reference
< css::lang::XComponent
> component
;
149 css::uno::Reference
< css::lang::XComponent
> disposeSingleton
;
153 void updateDisposeSingleton(
154 bool singletonRequest
,
155 css::uno::Reference
<css::uno::XInterface
> const & instance
);
158 typedef std::map
< rtl::OUString
, boost::shared_ptr
< Implementation
> >
159 NamedImplementations
;
163 css::uno::Reference
< css::lang::XServiceInfo
>,
164 boost::shared_ptr
< Implementation
> >
165 DynamicImplementations
;
170 std::vector
< boost::shared_ptr
< Implementation
> > >
173 NamedImplementations namedImplementations
;
174 DynamicImplementations dynamicImplementations
;
175 ImplementationMap services
;
176 ImplementationMap singletons
;
179 ServiceManager(): ServiceManagerBase(m_aMutex
) {}
181 using ServiceManagerBase::acquire
;
182 using ServiceManagerBase::release
;
184 void init(rtl::OUString
const & rdbUris
) { readRdbs(rdbUris
); }
187 css::uno::Reference
< css::uno::XComponentContext
> const & context
)
189 assert(context
.is());
190 assert(!context_
.is());
194 void addSingletonContextEntries(
195 std::vector
< cppu::ContextEntry_Init
> * entries
);
197 css::uno::Reference
< css::uno::XComponentContext
> getContext() const {
198 assert(context_
.is());
202 void loadImplementation(
203 css::uno::Reference
< css::uno::XComponentContext
> const & context
,
204 boost::shared_ptr
< Data::Implementation
> & implementation
);
207 virtual ~ServiceManager() {}
209 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
211 virtual rtl::OUString SAL_CALL
getImplementationName()
212 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
214 virtual sal_Bool SAL_CALL
supportsService(rtl::OUString
const & ServiceName
)
215 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
217 virtual css::uno::Sequence
< rtl::OUString
> SAL_CALL
218 getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
220 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance(
221 rtl::OUString
const & aServiceSpecifier
)
222 throw (css::uno::Exception
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
224 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
225 createInstanceWithArguments(
226 rtl::OUString
const & ServiceSpecifier
,
227 css::uno::Sequence
< css::uno::Any
> const & Arguments
)
228 throw (css::uno::Exception
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
230 virtual css::uno::Sequence
< rtl::OUString
> SAL_CALL
231 getAvailableServiceNames() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
233 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
234 createInstanceWithContext(
235 rtl::OUString
const & aServiceSpecifier
,
236 css::uno::Reference
< css::uno::XComponentContext
> const & Context
)
237 throw (css::uno::Exception
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
239 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
240 createInstanceWithArgumentsAndContext(
241 rtl::OUString
const & ServiceSpecifier
,
242 css::uno::Sequence
< css::uno::Any
> const & Arguments
,
243 css::uno::Reference
< css::uno::XComponentContext
> const & Context
)
244 throw (css::uno::Exception
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
246 virtual css::uno::Type SAL_CALL
getElementType()
247 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
249 virtual sal_Bool SAL_CALL
hasElements() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
251 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
252 createEnumeration() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
254 virtual sal_Bool SAL_CALL
has(css::uno::Any
const & aElement
)
255 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
257 virtual void SAL_CALL
insert(css::uno::Any
const & aElement
)
259 css::lang::IllegalArgumentException
,
260 css::container::ElementExistException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
262 virtual void SAL_CALL
remove(css::uno::Any
const & aElement
)
264 css::lang::IllegalArgumentException
,
265 css::container::NoSuchElementException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
267 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
268 createContentEnumeration(rtl::OUString
const & aServiceName
)
269 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
271 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
272 getPropertySetInfo() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
274 virtual void SAL_CALL
setPropertyValue(
275 rtl::OUString
const & aPropertyName
, css::uno::Any
const & aValue
)
277 css::beans::UnknownPropertyException
,
278 css::beans::PropertyVetoException
,
279 css::lang::IllegalArgumentException
,
280 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
282 virtual css::uno::Any SAL_CALL
getPropertyValue(
283 rtl::OUString
const & PropertyName
)
285 css::beans::UnknownPropertyException
,
286 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
288 virtual void SAL_CALL
addPropertyChangeListener(
289 rtl::OUString
const & aPropertyName
,
290 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &
293 css::beans::UnknownPropertyException
,
294 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
296 virtual void SAL_CALL
removePropertyChangeListener(
297 rtl::OUString
const & aPropertyName
,
298 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &
301 css::beans::UnknownPropertyException
,
302 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
304 virtual void SAL_CALL
addVetoableChangeListener(
305 rtl::OUString
const & PropertyName
,
306 css::uno::Reference
< css::beans::XVetoableChangeListener
> const &
309 css::beans::UnknownPropertyException
,
310 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
312 virtual void SAL_CALL
removeVetoableChangeListener(
313 rtl::OUString
const & PropertyName
,
314 css::uno::Reference
< css::beans::XVetoableChangeListener
> const &
317 css::beans::UnknownPropertyException
,
318 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
320 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
getProperties()
321 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
323 virtual css::beans::Property SAL_CALL
getPropertyByName(
324 rtl::OUString
const & aName
)
326 css::beans::UnknownPropertyException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
328 virtual sal_Bool SAL_CALL
hasPropertyByName(rtl::OUString
const & Name
)
329 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
331 virtual void SAL_CALL
disposing(css::lang::EventObject
const & Source
)
332 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
334 // needs to be called with rBHelper.rMutex locked:
335 bool isDisposed() { return rBHelper
.bDisposed
|| rBHelper
.bInDispose
; }
337 void removeEventListenerFromComponent(
338 css::uno::Reference
< css::lang::XComponent
> const & component
);
340 void readRdbs(rtl::OUString
const & uris
);
342 void readRdbDirectory(rtl::OUString
const & uri
, bool optional
);
344 void readRdbFile(rtl::OUString
const & uri
, bool optional
);
346 bool readLegacyRdbFile(rtl::OUString
const & uri
);
348 rtl::OUString
readLegacyRdbString(
349 rtl::OUString
const & uri
, RegistryKey
& key
,
350 rtl::OUString
const & path
);
352 void readLegacyRdbStrings(
353 rtl::OUString
const & uri
, RegistryKey
& key
,
354 rtl::OUString
const & path
, std::vector
< rtl::OUString
> * strings
);
357 std::vector
< rtl::OUString
> const & uris
,
358 css::uno::Reference
< css::uno::XComponentContext
> const &
361 void insertLegacyFactory(
362 css::uno::Reference
< css::lang::XServiceInfo
> const & factoryInfo
);
364 bool insertExtraData(Data
const & extra
);
366 void removeRdbFiles(std::vector
< rtl::OUString
> const & uris
);
368 bool removeLegacyFactory(
369 css::uno::Reference
< css::lang::XServiceInfo
> const & factoryInfo
,
370 bool removeListener
);
372 void removeImplementation(const rtl::OUString
& name
);
374 boost::shared_ptr
< Data::Implementation
> findServiceImplementation(
375 css::uno::Reference
< css::uno::XComponentContext
> const & context
,
376 rtl::OUString
const & specifier
);
378 css::uno::Reference
< css::uno::XComponentContext
> context_
;
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */