Bump version to 4.3-4
[LibreOffice.git] / cppuhelper / source / servicemanager.hxx
blob644fc21969f08577b1ee162bedb988fe96be40f4
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/.
8 */
10 #ifndef INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
11 #define INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
13 #include "sal/config.h"
15 #include <cassert>
16 #include <map>
17 #include <vector>
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;
41 } } } }
42 namespace cppu { struct ContextEntry_Init; }
44 namespace cppuhelper {
46 extern "C" {
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 >
58 ServiceManagerBase;
60 class ServiceManager:
61 private cppu::BaseMutex, public ServiceManagerBase,
62 private boost::noncopyable
64 public:
65 struct Data: private boost::noncopyable {
66 struct ImplementationInfo: private boost::noncopyable {
67 ImplementationInfo(
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 &
74 theAlienContext,
75 rtl::OUString const & theRdbFile):
76 name(theName), loader(theLoader), uri(theUri),
77 environment(theEnvironment), constructor(theConstructor),
78 prefix(thePrefix), alienContext(theAlienContext),
79 rdbFile(theRdbFile)
82 explicit ImplementationInfo(rtl::OUString const & theName):
83 name(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
92 alienContext;
93 rtl::OUString const rdbFile;
94 std::vector< rtl::OUString > services;
95 std::vector< rtl::OUString > singletons;
98 struct Implementation: private boost::noncopyable {
99 Implementation(
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 &
105 alienContext,
106 rtl::OUString const & rdbFile):
107 info(
108 new ImplementationInfo(
109 name, loader, uri, environment, constructorName, prefix,
110 alienContext, rdbFile)),
111 constructor(0), status(STATUS_NEW), dispose(true)
114 Implementation(
115 rtl::OUString const & name,
116 css::uno::Reference< css::lang::XSingleComponentFactory >
117 const & theFactory1,
118 css::uno::Reference< css::lang::XSingleServiceFactory > const &
119 theFactory2,
120 css::uno::Reference< css::lang::XComponent > const &
121 theComponent):
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 &
129 context,
130 bool singletonRequest);
132 css::uno::Reference<css::uno::XInterface>
133 createInstanceWithArguments(
134 css::uno::Reference<css::uno::XComponentContext> const &
135 context,
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;
146 Status status;
148 osl::Mutex mutex;
149 css::uno::Reference< css::lang::XComponent > disposeSingleton;
150 bool dispose;
152 private:
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;
161 typedef
162 std::map<
163 css::uno::Reference< css::lang::XServiceInfo >,
164 boost::shared_ptr< Implementation > >
165 DynamicImplementations;
167 typedef
168 std::map<
169 rtl::OUString,
170 std::vector< boost::shared_ptr< Implementation > > >
171 ImplementationMap;
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); }
186 void setContext(
187 css::uno::Reference< css::uno::XComponentContext > const & context)
189 assert(context.is());
190 assert(!context_.is());
191 context_ = context;
194 void addSingletonContextEntries(
195 std::vector< cppu::ContextEntry_Init > * entries);
197 css::uno::Reference< css::uno::XComponentContext > getContext() const {
198 assert(context_.is());
199 return context_;
202 void loadImplementation(
203 css::uno::Reference< css::uno::XComponentContext > const & context,
204 boost::shared_ptr< Data::Implementation > & implementation);
206 private:
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)
258 throw (
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)
263 throw (
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)
276 throw (
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)
284 throw (
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 &
291 xListener)
292 throw (
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 &
299 aListener)
300 throw (
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 &
307 aListener)
308 throw (
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 &
315 aListener)
316 throw (
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)
325 throw (
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);
356 void insertRdbFiles(
357 std::vector< rtl::OUString > const & uris,
358 css::uno::Reference< css::uno::XComponentContext > const &
359 alientContext);
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_;
379 Data data_;
384 #endif
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */