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 :
10 : #ifndef INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
11 : #define INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
12 :
13 : #include "sal/config.h"
14 :
15 : #include <cassert>
16 : #include <map>
17 : #include <vector>
18 :
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/compbase8.hxx"
33 : #include "osl/mutex.hxx"
34 : #include "registry/registry.hxx"
35 : #include "rtl/ustring.hxx"
36 :
37 : namespace cppu { struct ContextEntry_Init; }
38 :
39 : namespace cppuhelper {
40 :
41 : typedef cppu::WeakComponentImplHelper8<
42 : css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
43 : css::lang::XMultiComponentFactory, css::container::XSet,
44 : css::container::XContentEnumerationAccess, css::beans::XPropertySet,
45 : css::beans::XPropertySetInfo, css::lang::XEventListener >
46 : ServiceManagerBase;
47 :
48 : class ServiceManager:
49 : private osl::Mutex, public ServiceManagerBase, private boost::noncopyable
50 : {
51 : public:
52 1649 : struct Data: private boost::noncopyable {
53 117327 : struct ImplementationInfo: private boost::noncopyable {
54 126974 : ImplementationInfo(
55 : rtl::OUString const & theName, rtl::OUString const & theLoader,
56 : rtl::OUString const & theUri, rtl::OUString const & thePrefix,
57 : css::uno::Reference< css::uno::XComponentContext > const &
58 : theAlienContext,
59 : rtl::OUString const & theRdbFile):
60 : name(theName), loader(theLoader), uri(theUri),
61 : prefix(thePrefix), alienContext(theAlienContext),
62 126974 : rdbFile(theRdbFile)
63 126974 : {}
64 :
65 415 : explicit ImplementationInfo(rtl::OUString const & theName):
66 415 : name(theName) {}
67 :
68 : rtl::OUString const name;
69 : rtl::OUString const loader;
70 : rtl::OUString const uri;
71 : rtl::OUString const prefix;
72 : css::uno::Reference< css::uno::XComponentContext > const
73 : alienContext;
74 : rtl::OUString const rdbFile;
75 : std::vector< rtl::OUString > services;
76 : std::vector< rtl::OUString > singletons;
77 : };
78 :
79 117372 : struct Implementation: private boost::noncopyable {
80 126974 : Implementation(
81 : rtl::OUString const & name, rtl::OUString const & loader,
82 : rtl::OUString const & uri, rtl::OUString const & prefix,
83 : css::uno::Reference< css::uno::XComponentContext > const &
84 : alienContext,
85 : rtl::OUString const & rdbFile):
86 : info(
87 : new ImplementationInfo(
88 126974 : name, loader, uri, prefix, alienContext, rdbFile)),
89 253948 : loaded(false)
90 126974 : {}
91 :
92 415 : Implementation(
93 : rtl::OUString const & name,
94 : css::uno::Reference< css::lang::XSingleComponentFactory >
95 : const & theFactory1,
96 : css::uno::Reference< css::lang::XSingleServiceFactory > const &
97 : theFactory2,
98 : css::uno::Reference< css::lang::XComponent > const &
99 : theComponent):
100 415 : info(new ImplementationInfo(name)), factory1(theFactory1),
101 830 : factory2(theFactory2), component(theComponent), loaded(true)
102 415 : {}
103 :
104 : boost::shared_ptr< ImplementationInfo > info;
105 : css::uno::Reference< css::lang::XSingleComponentFactory > factory1;
106 : css::uno::Reference< css::lang::XSingleServiceFactory > factory2;
107 : css::uno::Reference< css::lang::XComponent > component;
108 : bool loaded;
109 : };
110 :
111 : typedef std::map< rtl::OUString, boost::shared_ptr< Implementation > >
112 : NamedImplementations;
113 :
114 : typedef
115 : std::map<
116 : css::uno::Reference< css::lang::XServiceInfo >,
117 : boost::shared_ptr< Implementation > >
118 : DynamicImplementations;
119 :
120 : typedef
121 : std::map<
122 : rtl::OUString,
123 : std::vector< boost::shared_ptr< Implementation > > >
124 : ImplementationMap;
125 :
126 : NamedImplementations namedImplementations;
127 : DynamicImplementations dynamicImplementations;
128 : ImplementationMap services;
129 : ImplementationMap singletons;
130 : };
131 :
132 391 : ServiceManager(): ServiceManagerBase(*static_cast< osl::Mutex * >(this)) {}
133 :
134 : using ServiceManagerBase::acquire;
135 : using ServiceManagerBase::release;
136 :
137 391 : void init(rtl::OUString const & rdbUris) { readRdbs(rdbUris); }
138 :
139 391 : void setContext(
140 : css::uno::Reference< css::uno::XComponentContext > const & context)
141 : {
142 : assert(context.is());
143 : assert(!context_.is());
144 391 : context_ = context;
145 391 : }
146 :
147 : void addSingletonContextEntries(
148 : std::vector< cppu::ContextEntry_Init > * entries) const;
149 :
150 0 : css::uno::Reference< css::uno::XComponentContext > getContext() const {
151 : assert(context_.is());
152 0 : return context_;
153 : }
154 :
155 : void loadImplementation(
156 : css::uno::Reference< css::uno::XComponentContext > const & context,
157 : boost::shared_ptr< Data::ImplementationInfo > const & info,
158 : css::uno::Reference< css::lang::XSingleComponentFactory > * factory1,
159 : css::uno::Reference< css::lang::XSingleServiceFactory > * factory2);
160 :
161 : private:
162 192 : virtual ~ServiceManager() {}
163 :
164 : virtual void SAL_CALL disposing();
165 :
166 : virtual rtl::OUString SAL_CALL getImplementationName()
167 : throw (css::uno::RuntimeException);
168 :
169 : virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
170 : throw (css::uno::RuntimeException);
171 :
172 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL
173 : getSupportedServiceNames() throw (css::uno::RuntimeException);
174 :
175 : virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
176 : rtl::OUString const & aServiceSpecifier)
177 : throw (css::uno::Exception, css::uno::RuntimeException);
178 :
179 : virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
180 : createInstanceWithArguments(
181 : rtl::OUString const & ServiceSpecifier,
182 : css::uno::Sequence< css::uno::Any > const & Arguments)
183 : throw (css::uno::Exception, css::uno::RuntimeException);
184 :
185 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL
186 : getAvailableServiceNames() throw (css::uno::RuntimeException);
187 :
188 : virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
189 : createInstanceWithContext(
190 : rtl::OUString const & aServiceSpecifier,
191 : css::uno::Reference< css::uno::XComponentContext > const & Context)
192 : throw (css::uno::Exception, css::uno::RuntimeException);
193 :
194 : virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
195 : createInstanceWithArgumentsAndContext(
196 : rtl::OUString const & ServiceSpecifier,
197 : css::uno::Sequence< css::uno::Any > const & Arguments,
198 : css::uno::Reference< css::uno::XComponentContext > const & Context)
199 : throw (css::uno::Exception, css::uno::RuntimeException);
200 :
201 : virtual css::uno::Type SAL_CALL getElementType()
202 : throw (css::uno::RuntimeException);
203 :
204 : virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException);
205 :
206 : virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
207 : createEnumeration() throw (css::uno::RuntimeException);
208 :
209 : virtual sal_Bool SAL_CALL has(css::uno::Any const & aElement)
210 : throw (css::uno::RuntimeException);
211 :
212 : virtual void SAL_CALL insert(css::uno::Any const & aElement)
213 : throw (
214 : css::lang::IllegalArgumentException,
215 : css::container::ElementExistException, css::uno::RuntimeException);
216 :
217 : virtual void SAL_CALL remove(css::uno::Any const & aElement)
218 : throw (
219 : css::lang::IllegalArgumentException,
220 : css::container::NoSuchElementException, css::uno::RuntimeException);
221 :
222 : virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
223 : createContentEnumeration(rtl::OUString const & aServiceName)
224 : throw (css::uno::RuntimeException);
225 :
226 : virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
227 : getPropertySetInfo() throw (css::uno::RuntimeException);
228 :
229 : virtual void SAL_CALL setPropertyValue(
230 : rtl::OUString const & aPropertyName, css::uno::Any const & aValue)
231 : throw (
232 : css::beans::UnknownPropertyException,
233 : css::beans::PropertyVetoException,
234 : css::lang::IllegalArgumentException,
235 : css::lang::WrappedTargetException, css::uno::RuntimeException);
236 :
237 : virtual css::uno::Any SAL_CALL getPropertyValue(
238 : rtl::OUString const & PropertyName)
239 : throw (
240 : css::beans::UnknownPropertyException,
241 : css::lang::WrappedTargetException, css::uno::RuntimeException);
242 :
243 : virtual void SAL_CALL addPropertyChangeListener(
244 : rtl::OUString const & aPropertyName,
245 : css::uno::Reference< css::beans::XPropertyChangeListener > const &
246 : xListener)
247 : throw (
248 : css::beans::UnknownPropertyException,
249 : css::lang::WrappedTargetException, css::uno::RuntimeException);
250 :
251 : virtual void SAL_CALL removePropertyChangeListener(
252 : rtl::OUString const & aPropertyName,
253 : css::uno::Reference< css::beans::XPropertyChangeListener > const &
254 : aListener)
255 : throw (
256 : css::beans::UnknownPropertyException,
257 : css::lang::WrappedTargetException, css::uno::RuntimeException);
258 :
259 : virtual void SAL_CALL addVetoableChangeListener(
260 : rtl::OUString const & PropertyName,
261 : css::uno::Reference< css::beans::XVetoableChangeListener > const &
262 : aListener)
263 : throw (
264 : css::beans::UnknownPropertyException,
265 : css::lang::WrappedTargetException, css::uno::RuntimeException);
266 :
267 : virtual void SAL_CALL removeVetoableChangeListener(
268 : rtl::OUString const & PropertyName,
269 : css::uno::Reference< css::beans::XVetoableChangeListener > const &
270 : aListener)
271 : throw (
272 : css::beans::UnknownPropertyException,
273 : css::lang::WrappedTargetException, css::uno::RuntimeException);
274 :
275 : virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties()
276 : throw (css::uno::RuntimeException);
277 :
278 : virtual css::beans::Property SAL_CALL getPropertyByName(
279 : rtl::OUString const & aName)
280 : throw (
281 : css::beans::UnknownPropertyException, css::uno::RuntimeException);
282 :
283 : virtual sal_Bool SAL_CALL hasPropertyByName(rtl::OUString const & Name)
284 : throw (css::uno::RuntimeException);
285 :
286 : virtual void SAL_CALL disposing(css::lang::EventObject const & Source)
287 : throw (css::uno::RuntimeException);
288 :
289 : // needs to be called with rBHelper.rMutex locked:
290 11088 : bool isDisposed() { return rBHelper.bDisposed || rBHelper.bInDispose; }
291 :
292 : void removeEventListenerFromComponent(
293 : css::uno::Reference< css::lang::XComponent > const & component);
294 :
295 : void readRdbs(rtl::OUString const & uris);
296 :
297 : void readRdbDirectory(rtl::OUString const & uri, bool optional);
298 :
299 : void readRdbFile(rtl::OUString const & uri, bool optional);
300 :
301 : bool readLegacyRdbFile(rtl::OUString const & uri);
302 :
303 : rtl::OUString readLegacyRdbString(
304 : rtl::OUString const & uri, RegistryKey & key,
305 : rtl::OUString const & path);
306 :
307 : void readLegacyRdbStrings(
308 : rtl::OUString const & uri, RegistryKey & key,
309 : rtl::OUString const & path, std::vector< rtl::OUString > * strings);
310 :
311 : void insertRdbFiles(
312 : std::vector< rtl::OUString > const & uris,
313 : css::uno::Reference< css::uno::XComponentContext > const &
314 : alientContext);
315 :
316 : void insertLegacyFactory(
317 : css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo);
318 :
319 : bool insertExtraData(Data const & extra);
320 :
321 : void removeRdbFiles(std::vector< rtl::OUString > const & uris);
322 :
323 : bool removeLegacyFactory(
324 : css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo,
325 : bool removeListener);
326 :
327 : void removeImplementation(rtl::OUString name);
328 :
329 : boost::shared_ptr< Data::Implementation > findServiceImplementation(
330 : css::uno::Reference< css::uno::XComponentContext > const & context,
331 : rtl::OUString const & specifier);
332 :
333 : css::uno::Reference< css::uno::XComponentContext > context_;
334 : Data data_;
335 : };
336 :
337 : }
338 :
339 : #endif
340 :
341 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|