LibreOffice Module cppuhelper (master) 1
servicemanager.cxx
Go to the documentation of this file.
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#include <sal/config.h>
11
12#include <algorithm>
13#include <cassert>
14#include <iostream>
15#include <mutex>
16#include <string_view>
17#include <utility>
18#include <vector>
19
20#include <com/sun/star/beans/NamedValue.hpp>
21#include <com/sun/star/beans/PropertyAttribute.hpp>
22#include <com/sun/star/container/ElementExistException.hpp>
23#include <com/sun/star/container/XEnumeration.hpp>
24#include <com/sun/star/container/XNameContainer.hpp>
25#include <com/sun/star/lang/XInitialization.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
27#include <com/sun/star/lang/XSingleComponentFactory.hpp>
28#include <com/sun/star/lang/XSingleServiceFactory.hpp>
29#include <com/sun/star/loader/XImplementationLoader.hpp>
30#include <com/sun/star/registry/InvalidRegistryException.hpp>
31#include <com/sun/star/uno/DeploymentException.hpp>
32#include <com/sun/star/uno/Reference.hxx>
33#include <com/sun/star/uno/XComponentContext.hpp>
40#include <o3tl/safeint.hxx>
41#include <osl/file.hxx>
42#include <osl/module.hxx>
43#include <rtl/ref.hxx>
44#include <rtl/uri.hxx>
45#include <rtl/ustring.hxx>
46#include <rtl/ustrbuf.hxx>
47#include <sal/log.hxx>
48#include <uno/environment.hxx>
49#include <uno/mapping.hxx>
50#include <o3tl/string_view.hxx>
51
53
54#include <registry/registry.hxx>
56
57#include "paths.hxx"
58#include "servicemanager.hxx"
59
60namespace {
61
62void insertImplementationMap(
65{
66 assert(destination != nullptr);
67 for (const auto& [rName, rImpls] : source)
68 {
69 std::vector<
70 std::shared_ptr<
72 = (*destination)[rName];
73 impls.insert(impls.end(), rImpls.begin(), rImpls.end());
74 }
75}
76
77void removeFromImplementationMap(
79 std::vector< OUString > const & elements,
80 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation >
81 const & implementation)
82{
83 // The underlying data structures make this function somewhat inefficient,
84 // but the assumption is that it is rarely called:
85 assert(map != nullptr);
86 for (const auto& rElement : elements)
87 {
88 cppuhelper::ServiceManager::Data::ImplementationMap::iterator j(
89 map->find(rElement));
90 assert(j != map->end());
91 std::vector<
92 std::shared_ptr<
94 k(std::find(j->second.begin(), j->second.end(), implementation));
95 assert(k != j->second.end());
96 j->second.erase(k);
97 if (j->second.empty()) {
98 map->erase(j);
99 }
100 }
101}
102
103// For simplicity, this code keeps throwing
104// css::registry::InvalidRegistryException for invalid XML rdbs (even though
105// that does not fit the exception's name):
106class Parser {
107public:
108 Parser(
109 OUString const & uri,
110 css::uno::Reference< css::uno::XComponentContext > alienContext,
112
113 Parser(const Parser&) = delete;
114 const Parser& operator=(const Parser&) = delete;
115
116private:
117 void handleComponent();
118
119 void handleImplementation();
120
121 void handleService();
122
123 void handleSingleton();
124
125 OUString getNameAttribute();
126
127 xmlreader::XmlReader reader_;
128 css::uno::Reference< css::uno::XComponentContext > alienContext_;
130 OUString attrLoader_;
131 OUString attrUri_;
132 OUString attrEnvironment_;
133 OUString attrPrefix_;
134 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation >
135 implementation_;
136};
137
138Parser::Parser(
139 OUString const & uri,
140 css::uno::Reference< css::uno::XComponentContext > alienContext,
142 reader_(uri), alienContext_(std::move(alienContext)), data_(data)
143{
144 assert(data != nullptr);
145 int ucNsId = reader_.registerNamespaceIri(
147 RTL_CONSTASCII_STRINGPARAM(
148 "http://openoffice.org/2010/uno-components")));
149 enum State {
150 STATE_BEGIN, STATE_END, STATE_COMPONENTS, STATE_COMPONENT_INITIAL,
151 STATE_COMPONENT, STATE_IMPLEMENTATION, STATE_SERVICE, STATE_SINGLETON };
152 for (State state = STATE_BEGIN;;) {
154 int nsId;
155 xmlreader::XmlReader::Result res = reader_.nextItem(
156 xmlreader::XmlReader::Text::NONE, &name, &nsId);
157 switch (state) {
158 case STATE_BEGIN:
159 if (res == xmlreader::XmlReader::Result::Begin && nsId == ucNsId
160 && name.equals(RTL_CONSTASCII_STRINGPARAM("components")))
161 {
162 state = STATE_COMPONENTS;
163 break;
164 }
165 throw css::registry::InvalidRegistryException(
166 reader_.getUrl() + ": unexpected item in outer level");
167 case STATE_END:
168 if (res == xmlreader::XmlReader::Result::Done) {
169 return;
170 }
171 throw css::registry::InvalidRegistryException(
172 reader_.getUrl() + ": unexpected item in outer level");
173 case STATE_COMPONENTS:
174 if (res == xmlreader::XmlReader::Result::End) {
175 state = STATE_END;
176 break;
177 }
178 if (res == xmlreader::XmlReader::Result::Begin && nsId == ucNsId
179 && name.equals(RTL_CONSTASCII_STRINGPARAM("component")))
180 {
181 handleComponent();
182 state = STATE_COMPONENT_INITIAL;
183 break;
184 }
185 throw css::registry::InvalidRegistryException(
186 reader_.getUrl() + ": unexpected item in <components>");
187 case STATE_COMPONENT:
188 if (res == xmlreader::XmlReader::Result::End) {
189 state = STATE_COMPONENTS;
190 break;
191 }
192 [[fallthrough]];
193 case STATE_COMPONENT_INITIAL:
194 if (res == xmlreader::XmlReader::Result::Begin && nsId == ucNsId
195 && name.equals(RTL_CONSTASCII_STRINGPARAM("implementation")))
196 {
197 handleImplementation();
198 state = STATE_IMPLEMENTATION;
199 break;
200 }
201 throw css::registry::InvalidRegistryException(
202 reader_.getUrl() + ": unexpected item in <component>");
203 case STATE_IMPLEMENTATION:
204 if (res == xmlreader::XmlReader::Result::End) {
205 state = STATE_COMPONENT;
206 break;
207 }
208 if (res == xmlreader::XmlReader::Result::Begin && nsId == ucNsId
209 && name.equals(RTL_CONSTASCII_STRINGPARAM("service")))
210 {
211 handleService();
212 state = STATE_SERVICE;
213 break;
214 }
215 if (res == xmlreader::XmlReader::Result::Begin && nsId == ucNsId
216 && name.equals(RTL_CONSTASCII_STRINGPARAM("singleton")))
217 {
218 handleSingleton();
219 state = STATE_SINGLETON;
220 break;
221 }
222 throw css::registry::InvalidRegistryException(
223 reader_.getUrl() + ": unexpected item in <implementation>");
224 case STATE_SERVICE:
225 if (res == xmlreader::XmlReader::Result::End) {
226 state = STATE_IMPLEMENTATION;
227 break;
228 }
229 throw css::registry::InvalidRegistryException(
230 reader_.getUrl() + ": unexpected item in <service>");
231 case STATE_SINGLETON:
232 if (res == xmlreader::XmlReader::Result::End) {
233 state = STATE_IMPLEMENTATION;
234 break;
235 }
236 throw css::registry::InvalidRegistryException(
237 reader_.getUrl() + ": unexpected item in <service>");
238 }
239 }
240}
241
242void Parser::handleComponent() {
243 attrLoader_ = OUString();
244 attrUri_ = OUString();
245 attrEnvironment_ = OUString();
246 attrPrefix_ = OUString();
248 int nsId;
249 while (reader_.nextAttribute(&nsId, &name)) {
251 && name.equals(RTL_CONSTASCII_STRINGPARAM("loader")))
252 {
253 if (!attrLoader_.isEmpty()) {
254 throw css::registry::InvalidRegistryException(
255 reader_.getUrl()
256 + ": <component> has multiple \"loader\" attributes");
257 }
258 attrLoader_ = reader_.getAttributeValue(false).convertFromUtf8();
259 if (attrLoader_.isEmpty()) {
260 throw css::registry::InvalidRegistryException(
261 reader_.getUrl()
262 + ": <component> has empty \"loader\" attribute");
263 }
264 } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE
265 && name.equals(RTL_CONSTASCII_STRINGPARAM("uri")))
266 {
267 if (!attrUri_.isEmpty()) {
268 throw css::registry::InvalidRegistryException(
269 reader_.getUrl()
270 + ": <component> has multiple \"uri\" attributes");
271 }
272 attrUri_ = reader_.getAttributeValue(false).convertFromUtf8();
273 if (attrUri_.isEmpty()) {
274 throw css::registry::InvalidRegistryException(
275 reader_.getUrl()
276 + ": <component> has empty \"uri\" attribute");
277 }
278 } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE
279 && name.equals(RTL_CONSTASCII_STRINGPARAM("environment")))
280 {
281 if (!attrEnvironment_.isEmpty()) {
282 throw css::registry::InvalidRegistryException(
283 reader_.getUrl() +
284 ": <component> has multiple \"environment\" attributes");
285 }
286 attrEnvironment_ = reader_.getAttributeValue(false)
287 .convertFromUtf8();
288 if (attrEnvironment_.isEmpty()) {
289 throw css::registry::InvalidRegistryException(
290 reader_.getUrl() +
291 ": <component> has empty \"environment\" attribute");
292 }
293 } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE
294 && name.equals(RTL_CONSTASCII_STRINGPARAM("prefix")))
295 {
296 if (!attrPrefix_.isEmpty()) {
297 throw css::registry::InvalidRegistryException(
298 reader_.getUrl() +
299 ": <component> has multiple \"prefix\" attributes");
300 }
301 attrPrefix_ = reader_.getAttributeValue(false).convertFromUtf8();
302 if (attrPrefix_.isEmpty()) {
303 throw css::registry::InvalidRegistryException(
304 reader_.getUrl() +
305 ": <component> has empty \"prefix\" attribute");
306 }
307 } else {
308 throw css::registry::InvalidRegistryException(
309 reader_.getUrl() + ": unexpected attribute \""
310 + name.convertFromUtf8() + "\" in <component>");
311 }
312 }
313 if (attrLoader_.isEmpty()) {
314 throw css::registry::InvalidRegistryException(
315 reader_.getUrl() + ": <component> is missing \"loader\" attribute");
316 }
317 if (attrUri_.isEmpty()) {
318 throw css::registry::InvalidRegistryException(
319 reader_.getUrl() + ": <component> is missing \"uri\" attribute");
320 }
321#ifndef DISABLE_DYNLOADING
322 try {
323 attrUri_ = rtl::Uri::convertRelToAbs(reader_.getUrl(), attrUri_);
324 } catch (const rtl::MalformedUriException & e) {
325 throw css::registry::InvalidRegistryException(
326 reader_.getUrl() + ": bad \"uri\" attribute: " + e.getMessage());
327 }
328#endif
329}
330
331void Parser::handleImplementation() {
332 OUString attrName;
333 OUString attrConstructor;
334 bool attrSingleInstance = false;
336 int nsId;
337 while (reader_.nextAttribute(&nsId, &name)) {
339 && name.equals(RTL_CONSTASCII_STRINGPARAM("name")))
340 {
341 if (!attrName.isEmpty()) {
342 throw css::registry::InvalidRegistryException(
343 reader_.getUrl()
344 + ": <implementation> has multiple \"name\" attributes");
345 }
346 attrName = reader_.getAttributeValue(false).convertFromUtf8();
347 if (attrName.isEmpty()) {
348 throw css::registry::InvalidRegistryException(
349 reader_.getUrl()
350 + ": <implementation> has empty \"name\" attribute");
351 }
352 } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE
353 && name.equals(RTL_CONSTASCII_STRINGPARAM("constructor")))
354 {
355 if (!attrConstructor.isEmpty()) {
356 throw css::registry::InvalidRegistryException(
357 reader_.getUrl()
358 + ": <implementation> has multiple \"constructor\""
359 " attributes");
360 }
361 attrConstructor = reader_.getAttributeValue(false)
362 .convertFromUtf8();
363 if (attrConstructor.isEmpty()) {
364 throw css::registry::InvalidRegistryException(
365 reader_.getUrl()
366 + ": element has empty \"constructor\" attribute");
367 }
368 if (attrEnvironment_.isEmpty()) {
369 throw css::registry::InvalidRegistryException(
370 reader_.getUrl()
371 + ": <implementation> has \"constructor\" attribute but"
372 " <component> has no \"environment\" attribute");
373 }
374 } else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE
375 && name.equals(RTL_CONSTASCII_STRINGPARAM("single-instance")))
376 {
377 if (attrSingleInstance) {
378 throw css::registry::InvalidRegistryException(
379 reader_.getUrl()
380 + ": <implementation> has multiple \"single-instance\" attributes");
381 }
382 if (!reader_.getAttributeValue(false).equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
383 throw css::registry::InvalidRegistryException(
384 reader_.getUrl() + ": <implementation> has bad \"single-instance\" attribute");
385 }
386 attrSingleInstance = true;
387 } else {
388 throw css::registry::InvalidRegistryException(
389 reader_.getUrl() + ": unexpected element attribute \""
390 + name.convertFromUtf8() + "\" in <implementation>");
391 }
392 }
393 if (attrName.isEmpty()) {
394 throw css::registry::InvalidRegistryException(
395 reader_.getUrl()
396 + ": <implementation> is missing \"name\" attribute");
397 }
398 implementation_ =
399 std::make_shared<cppuhelper::ServiceManager::Data::Implementation>(
400 attrName, attrLoader_, attrUri_, attrEnvironment_, attrConstructor,
401 attrPrefix_, attrSingleInstance, alienContext_, reader_.getUrl());
402 if (!data_->namedImplementations.emplace(attrName, implementation_).
403 second)
404 {
405 throw css::registry::InvalidRegistryException(
406 reader_.getUrl() + ": duplicate <implementation name=\"" + attrName
407 + "\">");
408 }
409}
410
411void Parser::handleService() {
412 OUString name(getNameAttribute());
413 implementation_->services.push_back(name);
414 data_->services[name].push_back(implementation_);
415}
416
417void Parser::handleSingleton() {
418 OUString name(getNameAttribute());
419 implementation_->singletons.push_back(name);
420 data_->singletons[name].push_back(implementation_);
421}
422
423OUString Parser::getNameAttribute() {
424 OUString attrName;
426 int nsId;
427 while (reader_.nextAttribute(&nsId, &name)) {
429 || !name.equals(RTL_CONSTASCII_STRINGPARAM("name")))
430 {
431 throw css::registry::InvalidRegistryException(
432 reader_.getUrl() + ": expected element attribute \"name\"");
433 }
434 if (!attrName.isEmpty()) {
435 throw css::registry::InvalidRegistryException(
436 reader_.getUrl()
437 + ": element has multiple \"name\" attributes");
438 }
439 attrName = reader_.getAttributeValue(false).convertFromUtf8();
440 if (attrName.isEmpty()) {
441 throw css::registry::InvalidRegistryException(
442 reader_.getUrl() + ": element has empty \"name\" attribute");
443 }
444 }
445 if (attrName.isEmpty()) {
446 throw css::registry::InvalidRegistryException(
447 reader_.getUrl() + ": element is missing \"name\" attribute");
448 }
449 return attrName;
450}
451
452class ContentEnumeration:
453 public cppu::WeakImplHelper< css::container::XEnumeration >
454{
455public:
456 explicit ContentEnumeration(std::vector< css::uno::Any >&& factories):
457 factories_(std::move(factories)), iterator_(factories_.begin()) {}
458
459 ContentEnumeration(const ContentEnumeration&) = delete;
460 const ContentEnumeration& operator=(const ContentEnumeration&) = delete;
461
462private:
463 virtual ~ContentEnumeration() override {}
464
465 virtual sal_Bool SAL_CALL hasMoreElements() override;
466
467 virtual css::uno::Any SAL_CALL nextElement() override;
468
469 std::mutex mutex_;
470 std::vector< css::uno::Any > factories_;
471 std::vector< css::uno::Any >::const_iterator iterator_;
472};
473
474sal_Bool ContentEnumeration::hasMoreElements()
475{
476 std::scoped_lock g(mutex_);
477 return iterator_ != factories_.end();
478}
479
480css::uno::Any ContentEnumeration::nextElement()
481{
482 std::scoped_lock g(mutex_);
483 if (iterator_ == factories_.end()) {
484 throw css::container::NoSuchElementException(
485 "Bootstrap service manager service enumerator has no more elements",
486 static_cast< cppu::OWeakObject * >(this));
487 }
488 return *iterator_++;
489}
490
491css::beans::Property getDefaultContextProperty() {
492 return css::beans::Property(
493 "DefaultContext", -1,
495 css::beans::PropertyAttribute::READONLY);
496}
497
498class SingletonFactory:
499 public cppu::WeakImplHelper<css::lang::XSingleComponentFactory>
500{
501public:
502 SingletonFactory(
504 std::shared_ptr<
506 implementation):
507 manager_(manager), implementation_(implementation)
508 { assert(manager.is()); assert(implementation); }
509
510 SingletonFactory(const SingletonFactory&) = delete;
511 const SingletonFactory& operator=(const SingletonFactory&) = delete;
512
513private:
514 virtual ~SingletonFactory() override {}
515
516 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
517 createInstanceWithContext(
518 css::uno::Reference< css::uno::XComponentContext > const & Context) override;
519
520 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
521 createInstanceWithArgumentsAndContext(
522 css::uno::Sequence< css::uno::Any > const & Arguments,
523 css::uno::Reference< css::uno::XComponentContext > const & Context) override;
524
526 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation >
527 implementation_;
528};
529
530css::uno::Reference< css::uno::XInterface >
531SingletonFactory::createInstanceWithContext(
532 css::uno::Reference< css::uno::XComponentContext > const & Context)
533{
534 manager_->loadImplementation(Context, implementation_);
535 return implementation_->createInstance(Context, true);
536}
537
538css::uno::Reference< css::uno::XInterface >
539SingletonFactory::createInstanceWithArgumentsAndContext(
540 css::uno::Sequence< css::uno::Any > const & Arguments,
541 css::uno::Reference< css::uno::XComponentContext > const & Context)
542{
543 manager_->loadImplementation(Context, implementation_);
544 return implementation_->createInstanceWithArguments(
545 Context, true, Arguments);
546}
547
548class ImplementationWrapper:
549 public cppu::WeakImplHelper<
550 css::lang::XSingleComponentFactory, css::lang::XSingleServiceFactory,
551 css::lang::XServiceInfo >
552{
553public:
554 ImplementationWrapper(
556 std::shared_ptr<
558 implementation):
559 manager_(manager), implementation_(implementation)
560 { assert(manager.is()); assert(implementation); }
561
562 ImplementationWrapper(const ImplementationWrapper&) = delete;
563 const ImplementationWrapper& operator=(const ImplementationWrapper&) = delete;
564
565private:
566 virtual ~ImplementationWrapper() override {}
567
568 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
569 createInstanceWithContext(
570 css::uno::Reference< css::uno::XComponentContext > const & Context) override;
571
572 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
573 createInstanceWithArgumentsAndContext(
574 css::uno::Sequence< css::uno::Any > const & Arguments,
575 css::uno::Reference< css::uno::XComponentContext > const & Context) override;
576
577 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
578 createInstance() override;
579
580 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
581 createInstanceWithArguments(
582 css::uno::Sequence< css::uno::Any > const & Arguments) override;
583
584 virtual OUString SAL_CALL getImplementationName() override;
585
586 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
587
588 virtual css::uno::Sequence< OUString > SAL_CALL
589 getSupportedServiceNames() override;
590
592 std::weak_ptr< cppuhelper::ServiceManager::Data::Implementation >
593 implementation_;
594};
595
596css::uno::Reference< css::uno::XInterface >
597ImplementationWrapper::createInstanceWithContext(
598 css::uno::Reference< css::uno::XComponentContext > const & Context)
599{
600 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
601 assert(impl);
602 manager_->loadImplementation(Context, impl);
603 return impl->createInstance(Context, false);
604}
605
606css::uno::Reference< css::uno::XInterface >
607ImplementationWrapper::createInstanceWithArgumentsAndContext(
608 css::uno::Sequence< css::uno::Any > const & Arguments,
609 css::uno::Reference< css::uno::XComponentContext > const & Context)
610{
611 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
612 assert(impl);
613 manager_->loadImplementation(Context, impl);
614 return impl->createInstanceWithArguments(
615 Context, false, Arguments);
616}
617
618css::uno::Reference< css::uno::XInterface >
619ImplementationWrapper::createInstance()
620{
621 return createInstanceWithContext(manager_->getContext());
622}
623
624css::uno::Reference< css::uno::XInterface >
625ImplementationWrapper::createInstanceWithArguments(
626 css::uno::Sequence< css::uno::Any > const & Arguments)
627{
628 return createInstanceWithArgumentsAndContext(
629 Arguments, manager_->getContext());
630}
631
632OUString ImplementationWrapper::getImplementationName()
633{
634 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
635 assert(impl);
636 return impl->name;
637}
638
639sal_Bool ImplementationWrapper::supportsService(OUString const & ServiceName)
640{
641 return cppu::supportsService(this, ServiceName);
642}
643
644css::uno::Sequence< OUString >
645ImplementationWrapper::getSupportedServiceNames()
646{
647 std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
648 assert(impl);
649 if (impl->services.size()
650 > o3tl::make_unsigned(SAL_MAX_INT32))
651 {
652 throw css::uno::RuntimeException(
653 ("Implementation " + impl->name
654 + " supports too many services"),
655 static_cast< cppu::OWeakObject * >(this));
656 }
657 return comphelper::containerToSequence(impl->services);
658}
659
660}
661
662css::uno::Reference<css::uno::XInterface>
664 css::uno::Reference<css::uno::XComponentContext> const & context,
665 bool singletonRequest)
666{
667 css::uno::Reference<css::uno::XInterface> inst;
668 if (isSingleInstance) {
669 std::unique_lock g(mutex);
670 if (!singleInstance.is()) {
672 }
673 inst = singleInstance;
674 } else {
675 inst = doCreateInstance(context);
676 }
677 updateDisposeInstance(singletonRequest, inst);
678 return inst;
679}
680
681css::uno::Reference<css::uno::XInterface>
683 css::uno::Reference<css::uno::XComponentContext> const & context,
684 bool singletonRequest, css::uno::Sequence<css::uno::Any> const & arguments)
685{
686 css::uno::Reference<css::uno::XInterface> inst;
687 if (isSingleInstance) {
688 std::unique_lock g(mutex);
689 if (!singleInstance.is()) {
690 singleInstance = doCreateInstanceWithArguments(context, arguments);
691 }
692 inst = singleInstance;
693 } else {
694 inst = doCreateInstanceWithArguments(context, arguments);
695 }
696 updateDisposeInstance(singletonRequest, inst);
697 return inst;
698}
699
700css::uno::Reference<css::uno::XInterface>
702 css::uno::Reference<css::uno::XComponentContext> const & context)
703{
704 if (constructorFn) {
705 return css::uno::Reference<css::uno::XInterface>(
706 constructorFn(context.get(), css::uno::Sequence<css::uno::Any>()),
707 SAL_NO_ACQUIRE);
708 } else if (factory1.is()) {
709 return factory1->createInstanceWithContext(context);
710 } else {
711 assert(factory2.is());
712 return factory2->createInstance();
713 }
714}
715
716css::uno::Reference<css::uno::XInterface>
718 css::uno::Reference<css::uno::XComponentContext> const & context,
719 css::uno::Sequence<css::uno::Any> const & arguments)
720{
721 if (constructorFn) {
722 css::uno::Reference<css::uno::XInterface> inst(
723 constructorFn(context.get(), arguments), SAL_NO_ACQUIRE);
724 //HACK: The constructor will either observe arguments and return inst
725 // that does not implement XInitialization (or null), or ignore
726 // arguments and return inst that implements XInitialization; this
727 // should be removed again once XInitialization-based implementations
728 // have become rare:
729 css::uno::Reference<css::lang::XInitialization> init(
730 inst, css::uno::UNO_QUERY);
731 if (init.is()) {
732 init->initialize(arguments);
733 }
734 return inst;
735 } else if (factory1.is()) {
736 return factory1->createInstanceWithArgumentsAndContext(
737 arguments, context);
738 } else {
739 assert(factory2.is());
740 return factory2->createInstanceWithArguments(arguments);
741 }
742}
743
745 bool singletonRequest,
746 css::uno::Reference<css::uno::XInterface> const & instance)
747{
748 // This is an optimization, to only call dispose once (from the component
749 // context) on a singleton that is obtained both via the component context
750 // and via the service manager; however, there is a harmless race here that
751 // may cause two calls to dispose nevertheless (also, this calls dispose on
752 // at most one of the instances obtained via the service manager, in case
753 // the implementation hands out different instances):
754 if (singletonRequest) {
755 std::unique_lock g(mutex);
756 disposeInstance.clear();
757 dispose = false;
758 } else if (shallDispose()) {
759 css::uno::Reference<css::lang::XComponent> comp(
760 instance, css::uno::UNO_QUERY);
761 if (comp.is()) {
762 std::unique_lock g(mutex);
763 if (dispose) {
764 disposeInstance = comp;
765 }
766 }
767 }
768}
769
771 std::vector< cppu::ContextEntry_Init > * entries)
772{
773 assert(entries != nullptr);
774 for (const auto& [rName, rImpls] : data_.singletons)
775 {
776 assert(!rImpls.empty());
777 assert(rImpls[0]);
779 rImpls.size() > 1, "cppuhelper",
780 "Arbitrarily choosing " << rImpls[0]->name
781 << " among multiple implementations for " << rName);
782 entries->push_back(
784 "/singletons/" + rName,
785 css::uno::Any(
786 css::uno::Reference<css::lang::XSingleComponentFactory>(
787 new SingletonFactory(this, rImpls[0]))),
788 true));
789 }
790}
791
793 css::uno::Reference< css::uno::XComponentContext > const & context,
794 std::shared_ptr< Data::Implementation > const & implementation)
795{
796 assert(implementation);
797 {
798 std::unique_lock g(m_aMutex);
799 if (implementation->status == Data::Implementation::STATUS_LOADED) {
800 return;
801 }
802 }
803 OUString uri;
804 try {
805 uri = cppu::bootstrap_expandUri(implementation->uri);
806 } catch (css::lang::IllegalArgumentException & e) {
807 throw css::uno::DeploymentException(
808 "Cannot expand URI" + implementation->uri + ": " + e.Message,
809 static_cast< cppu::OWeakObject * >(this));
810 }
812 css::uno::Reference< css::uno::XInterface > f0;
813 // Special handling of SharedLibrary loader, with support for environment,
814 // constructor, and prefix arguments:
815 if (!implementation->alienContext.is()
816 && implementation->loader == "com.sun.star.loader.SharedLibrary")
817 {
819 uri, implementation->environment,
820 implementation->prefix, implementation->name,
821 implementation->constructorName, this, &ctor, &f0);
822 if (ctor) {
823 assert(!implementation->environment.isEmpty());
824 }
825 } else {
827 !implementation->environment.isEmpty(), "cppuhelper",
828 "Loader " << implementation->loader
829 << " and non-empty environment "
830 << implementation->environment);
832 !implementation->prefix.isEmpty(), "cppuhelper",
833 "Loader " << implementation->loader
834 << " and non-empty constructor "
835 << implementation->constructorName);
837 !implementation->prefix.isEmpty(), "cppuhelper",
838 "Loader " << implementation->loader
839 << " and non-empty prefix " << implementation->prefix);
840 css::uno::Reference< css::uno::XComponentContext > ctxt;
841 css::uno::Reference< css::lang::XMultiComponentFactory > smgr;
842 if (implementation->alienContext.is()) {
843 ctxt = implementation->alienContext;
844 smgr.set(ctxt->getServiceManager(), css::uno::UNO_SET_THROW);
845 } else {
846 assert(context.is());
847 ctxt = context;
848 smgr = this;
849 }
850 css::uno::Reference< css::loader::XImplementationLoader > loader(
851 smgr->createInstanceWithContext(implementation->loader, ctxt),
852 css::uno::UNO_QUERY_THROW);
853 f0 = loader->activate(
854 implementation->name, OUString(), uri,
855 css::uno::Reference< css::registry::XRegistryKey >());
856 }
857 css::uno::Reference<css::lang::XSingleComponentFactory> f1;
858 css::uno::Reference<css::lang::XSingleServiceFactory> f2;
859 if (!ctor) {
860 f1.set(f0, css::uno::UNO_QUERY);
861 if (!f1.is()) {
862 f2.set(f0, css::uno::UNO_QUERY);
863 if (!f2.is()) {
864 throw css::uno::DeploymentException(
865 ("Implementation " + implementation->name
866 + " does not provide a constructor or factory"),
867 static_cast< cppu::OWeakObject * >(this));
868 }
869 }
870 }
871 //TODO: There is a race here, as the relevant service factory can be removed
872 // while the mutex is unlocked and loading can thus fail, as the entity from
873 // which to load can disappear once the service factory is removed.
874 std::unique_lock g(m_aMutex);
875 if (!(m_bDisposed
876 || implementation->status == Data::Implementation::STATUS_LOADED))
877 {
878 implementation->status = Data::Implementation::STATUS_LOADED;
879 implementation->constructorFn = ctor;
880 implementation->factory1 = f1;
881 implementation->factory2 = f2;
882 }
883}
884
885void cppuhelper::ServiceManager::disposing(std::unique_lock<std::mutex>& rGuard) {
886 std::vector< css::uno::Reference<css::lang::XComponent> > sngls;
887 std::vector< css::uno::Reference< css::lang::XComponent > > comps;
888 Data clear;
889 {
890 for (const auto& rEntry : data_.namedImplementations)
891 {
892 assert(rEntry.second);
893 if (rEntry.second->shallDispose()) {
894 std::unique_lock g2(rEntry.second->mutex);
895 if (rEntry.second->disposeInstance.is()) {
896 sngls.push_back(rEntry.second->disposeInstance);
897 }
898 }
899 }
900 for (const auto& rEntry : data_.dynamicImplementations)
901 {
902 assert(rEntry.second);
903 if (rEntry.second->shallDispose()) {
904 std::unique_lock g2(rEntry.second->mutex);
905 if (rEntry.second->disposeInstance.is()) {
906 sngls.push_back(rEntry.second->disposeInstance);
907 }
908 }
909 if (rEntry.second->component.is()) {
910 comps.push_back(rEntry.second->component);
911 }
912 }
915 data_.services.swap(clear.services);
916 data_.singletons.swap(clear.singletons);
917 }
918 rGuard.unlock();
919 for (const auto& rxSngl : sngls)
920 {
921 try {
922 rxSngl->dispose();
923 } catch (css::uno::RuntimeException & e) {
924 SAL_WARN("cppuhelper", "Ignoring " << e << " while disposing singleton");
925 }
926 }
927 for (const auto& rxComp : comps)
928 {
930 }
931 rGuard.lock();
932}
933
935 css::uno::Sequence<css::uno::Any> const & aArguments)
936{
937 OUString arg;
938 if (aArguments.getLength() != 1 || !(aArguments[0] >>= arg)
939 || arg != "preload")
940 {
941 throw css::lang::IllegalArgumentException(
942 "invalid ServiceManager::initialize argument",
943 css::uno::Reference<css::uno::XInterface>(), 0);
944 }
946}
947
949{
950 return
951 "com.sun.star.comp.cppuhelper.bootstrap.ServiceManager";
952}
953
955 OUString const & ServiceName)
956{
958}
959
960css::uno::Sequence< OUString >
962{
963 return { "com.sun.star.lang.MultiServiceFactory", "com.sun.star.lang.ServiceManager" };
964}
965
966css::uno::Reference< css::uno::XInterface >
968 OUString const & aServiceSpecifier)
969{
970 assert(context_.is());
971 return createInstanceWithContext(aServiceSpecifier, context_);
972}
973
974css::uno::Reference< css::uno::XInterface >
976 OUString const & ServiceSpecifier,
977 css::uno::Sequence< css::uno::Any > const & Arguments)
978{
979 assert(context_.is());
981 ServiceSpecifier, Arguments, context_);
982}
983
984css::uno::Sequence< OUString >
986{
987 std::unique_lock g(m_aMutex);
988 if (m_bDisposed) {
989 return css::uno::Sequence< OUString >();
990 }
992 throw css::uno::RuntimeException(
993 "getAvailableServiceNames: too many services",
994 static_cast< cppu::OWeakObject * >(this));
995 }
997}
998
999css::uno::Reference< css::uno::XInterface >
1001 OUString const & aServiceSpecifier,
1002 css::uno::Reference< css::uno::XComponentContext > const & Context)
1003{
1004 std::shared_ptr< Data::Implementation > impl(
1005 findServiceImplementation(Context, aServiceSpecifier));
1006 return impl == nullptr ? css::uno::Reference<css::uno::XInterface>()
1007 : impl->createInstance(Context, false);
1008}
1009
1010css::uno::Reference< css::uno::XInterface >
1012 OUString const & ServiceSpecifier,
1013 css::uno::Sequence< css::uno::Any > const & Arguments,
1014 css::uno::Reference< css::uno::XComponentContext > const & Context)
1015{
1016 std::shared_ptr< Data::Implementation > impl(
1017 findServiceImplementation(Context, ServiceSpecifier));
1018 return impl == nullptr ? css::uno::Reference<css::uno::XInterface>()
1019 : impl->createInstanceWithArguments(Context, false, Arguments);
1020}
1021
1023{
1024 return css::uno::Type();
1025}
1026
1028{
1029 std::unique_lock g(m_aMutex);
1030 return
1031 !(data_.namedImplementations.empty()
1032 && data_.dynamicImplementations.empty());
1033}
1034
1035css::uno::Reference< css::container::XEnumeration >
1037{
1038 throw css::uno::RuntimeException(
1039 "ServiceManager createEnumeration: method not supported",
1040 static_cast< cppu::OWeakObject * >(this));
1041}
1042
1044{
1045 throw css::uno::RuntimeException(
1046 "ServiceManager has: method not supported",
1047 static_cast< cppu::OWeakObject * >(this));
1048}
1049
1050void cppuhelper::ServiceManager::insert(css::uno::Any const & aElement)
1051{
1052 css::uno::Sequence< css::beans::NamedValue > args;
1053 if (aElement >>= args) {
1054 std::vector< OUString > uris;
1055 css::uno::Reference< css::uno::XComponentContext > alienContext;
1056 for (const auto & arg : std::as_const(args)) {
1057 if (arg.Name == "uri") {
1058 OUString uri;
1059 if (!(arg.Value >>= uri)) {
1060 throw css::lang::IllegalArgumentException(
1061 "Bad uri argument",
1062 static_cast< cppu::OWeakObject * >(this), 0);
1063 }
1064 uris.push_back(uri);
1065 } else if (arg.Name == "component-context") {
1066 if (alienContext.is()) {
1067 throw css::lang::IllegalArgumentException(
1068 "Multiple component-context arguments",
1069 static_cast< cppu::OWeakObject * >(this), 0);
1070 }
1071 if (!(arg.Value >>= alienContext) || !alienContext.is()) {
1072 throw css::lang::IllegalArgumentException(
1073 "Bad component-context argument",
1074 static_cast< cppu::OWeakObject * >(this), 0);
1075 }
1076 } else {
1077 throw css::lang::IllegalArgumentException(
1078 "Bad argument " + arg.Name,
1079 static_cast< cppu::OWeakObject * >(this), 0);
1080 }
1081 }
1082 insertRdbFiles(uris, alienContext);
1083 return;
1084 }
1085 css::uno::Reference< css::lang::XServiceInfo > info;
1086 if ((aElement >>= info) && info.is()) {
1087 insertLegacyFactory(info);
1088 return;
1089 }
1090
1091 throw css::lang::IllegalArgumentException(
1092 "Bad insert element", static_cast< cppu::OWeakObject * >(this), 0);
1093}
1094
1095void cppuhelper::ServiceManager::remove(css::uno::Any const & aElement)
1096{
1097 css::uno::Sequence< css::beans::NamedValue > args;
1098 if (aElement >>= args) {
1099 std::vector< OUString > uris;
1100 for (const auto & i : std::as_const(args)) {
1101 if (i.Name != "uri") {
1102 throw css::lang::IllegalArgumentException(
1103 "Bad argument " + i.Name,
1104 static_cast< cppu::OWeakObject * >(this), 0);
1105 }
1106 OUString uri;
1107 if (!(i.Value >>= uri)) {
1108 throw css::lang::IllegalArgumentException(
1109 "Bad uri argument",
1110 static_cast< cppu::OWeakObject * >(this), 0);
1111 }
1112 uris.push_back(uri);
1113 }
1114 removeRdbFiles(uris);
1115 return;
1116 }
1117 css::uno::Reference< css::lang::XServiceInfo > info;
1118 if ((aElement >>= info) && info.is()) {
1119 if (!removeLegacyFactory(info, true)) {
1120 throw css::container::NoSuchElementException(
1121 "Remove non-inserted factory object",
1122 static_cast< cppu::OWeakObject * >(this));
1123 }
1124 return;
1125 }
1126 OUString impl;
1127 if (aElement >>= impl) {
1128 // For live-removal of extensions:
1130 return;
1131 }
1132 throw css::lang::IllegalArgumentException(
1133 "Bad remove element", static_cast< cppu::OWeakObject * >(this), 0);
1134}
1135
1136css::uno::Reference< css::container::XEnumeration >
1138 OUString const & aServiceName)
1139{
1140 std::vector< std::shared_ptr< Data::Implementation > > impls;
1141 {
1142 std::unique_lock g(m_aMutex);
1143 Data::ImplementationMap::const_iterator i(
1144 data_.services.find(aServiceName));
1145 if (i != data_.services.end()) {
1146 impls = i->second;
1147 }
1148 }
1149 std::vector< css::uno::Any > factories;
1150 for (const auto& rxImpl : impls)
1151 {
1152 Data::Implementation * impl = rxImpl.get();
1153 assert(impl != nullptr);
1154 {
1155 std::unique_lock g(m_aMutex);
1156 if (m_bDisposed) {
1157 factories.clear();
1158 break;
1159 }
1160 if (impl->status == Data::Implementation::STATUS_NEW) {
1161 // Postpone actual implementation instantiation as long as
1162 // possible (so that e.g. opening LO's "Tools - Macros" menu
1163 // does not try to instantiate a JVM, which can lead to a
1164 // synchronous error dialog when no JVM is specified, and
1165 // showing the dialog while hovering over a menu can cause
1166 // trouble):
1167 impl->factory1 = new ImplementationWrapper(this, rxImpl);
1169 }
1170 if (impl->constructorFn != nullptr && !impl->factory1.is()) {
1171 impl->factory1 = new ImplementationWrapper(this, rxImpl);
1172 }
1173 }
1174 if (impl->factory1.is()) {
1175 factories.push_back(css::uno::Any(impl->factory1));
1176 } else {
1177 assert(impl->factory2.is());
1178 factories.push_back(css::uno::Any(impl->factory2));
1179 }
1180 }
1181 return new ContentEnumeration(std::move(factories));
1182}
1183
1184css::uno::Reference< css::beans::XPropertySetInfo >
1186{
1187 return this;
1188}
1189
1191 OUString const & aPropertyName, css::uno::Any const &)
1192{
1193 if (aPropertyName == "DefaultContext") {
1194 throw css::beans::PropertyVetoException(
1195 aPropertyName, static_cast< cppu::OWeakObject * >(this));
1196 } else {
1197 throw css::beans::UnknownPropertyException(
1198 aPropertyName, static_cast< cppu::OWeakObject * >(this));
1199 }
1200}
1201
1203 OUString const & PropertyName)
1204{
1205 if (PropertyName != "DefaultContext") {
1206 throw css::beans::UnknownPropertyException(
1207 PropertyName, static_cast< cppu::OWeakObject * >(this));
1208 }
1209 assert(context_.is());
1210 return css::uno::Any(context_);
1211}
1212
1214 OUString const & aPropertyName,
1215 css::uno::Reference< css::beans::XPropertyChangeListener > const &
1216 xListener)
1217{
1218 if (!aPropertyName.isEmpty() && aPropertyName != "DefaultContext") {
1219 throw css::beans::UnknownPropertyException(
1220 aPropertyName, static_cast< cppu::OWeakObject * >(this));
1221 }
1222 // DefaultContext does not change, so just treat it as an event listener:
1223 return addEventListener(xListener);
1224}
1225
1227 OUString const & aPropertyName,
1228 css::uno::Reference< css::beans::XPropertyChangeListener > const &
1229 aListener)
1230{
1231 if (!aPropertyName.isEmpty() && aPropertyName != "DefaultContext") {
1232 throw css::beans::UnknownPropertyException(
1233 aPropertyName, static_cast< cppu::OWeakObject * >(this));
1234 }
1235 // DefaultContext does not change, so just treat it as an event listener:
1236 return removeEventListener(aListener);
1237}
1238
1240 OUString const & PropertyName,
1241 css::uno::Reference< css::beans::XVetoableChangeListener > const &
1242 aListener)
1243{
1244 if (!PropertyName.isEmpty() && PropertyName != "DefaultContext") {
1245 throw css::beans::UnknownPropertyException(
1246 PropertyName, static_cast< cppu::OWeakObject * >(this));
1247 }
1248 // DefaultContext does not change, so just treat it as an event listener:
1249 return addEventListener(aListener);
1250}
1251
1253 OUString const & PropertyName,
1254 css::uno::Reference< css::beans::XVetoableChangeListener > const &
1255 aListener)
1256{
1257 if (!PropertyName.isEmpty() && PropertyName != "DefaultContext") {
1258 throw css::beans::UnknownPropertyException(
1259 PropertyName, static_cast< cppu::OWeakObject * >(this));
1260 }
1261 // DefaultContext does not change, so just treat it as an event listener:
1262 return removeEventListener(aListener);
1263}
1264
1265css::uno::Sequence< css::beans::Property >
1267 return { getDefaultContextProperty() };
1268}
1269
1271 OUString const & aName)
1272{
1273 if (aName != "DefaultContext") {
1274 throw css::beans::UnknownPropertyException(
1275 aName, static_cast< cppu::OWeakObject * >(this));
1276 }
1277 return getDefaultContextProperty();
1278}
1279
1281 OUString const & Name)
1282{
1283 return Name == "DefaultContext";
1284}
1285
1287
1289 css::lang::EventObject const & Source)
1290{
1292 css::uno::Reference< css::lang::XServiceInfo >(
1293 Source.Source, css::uno::UNO_QUERY_THROW),
1294 false);
1295}
1296
1298 css::uno::Reference< css::lang::XComponent > const & component)
1299{
1300 assert(component.is());
1301 try {
1302 component->removeEventListener(this);
1303 } catch (css::uno::RuntimeException & e) {
1304 SAL_INFO(
1305 "cppuhelper",
1306 "Ignored removeEventListener RuntimeException " + e.Message);
1307 }
1308}
1309
1310void cppuhelper::ServiceManager::init(std::u16string_view rdbUris) {
1311 for (sal_Int32 i = 0; i != -1;) {
1312 std::u16string_view uri(o3tl::getToken(rdbUris, 0, ' ', i));
1313 if (uri.empty()) {
1314 continue;
1315 }
1316 bool optional;
1317 bool directory;
1318 cppu::decodeRdbUri(&uri, &optional, &directory);
1319 if (directory) {
1320 readRdbDirectory(uri, optional);
1321 } else {
1322 readRdbFile(OUString(uri), optional);
1323 }
1324 }
1325}
1326
1328 std::u16string_view uri, bool optional)
1329{
1330 osl::Directory dir = OUString(uri);
1331 switch (dir.open()) {
1332 case osl::FileBase::E_None:
1333 break;
1334 case osl::FileBase::E_NOENT:
1335 if (optional) {
1336 SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri));
1337 return;
1338 }
1339 [[fallthrough]];
1340 default:
1341 throw css::uno::DeploymentException(
1342 OUString::Concat("Cannot open directory ") + uri,
1343 static_cast< cppu::OWeakObject * >(this));
1344 }
1345 for (;;) {
1346 OUString url;
1347 if (!cppu::nextDirectoryItem(dir, &url)) {
1348 break;
1349 }
1350 readRdbFile(url, false);
1351 }
1352}
1353
1355 OUString const & uri, bool optional)
1356{
1357 try {
1358 Parser(
1359 uri, css::uno::Reference< css::uno::XComponentContext >(), &data_);
1360 } catch (css::container::NoSuchElementException &) {
1361 if (!optional) {
1362 throw css::uno::DeploymentException(
1363 uri + ": no such file",
1364 static_cast< cppu::OWeakObject * >(this));
1365 }
1366 SAL_INFO("cppuhelper", "Ignored optional " << uri);
1367 } catch (css::registry::InvalidRegistryException & e) {
1368 if (!readLegacyRdbFile(uri)) {
1369 throw css::uno::DeploymentException(
1370 "InvalidRegistryException: " + e.Message,
1371 static_cast< cppu::OWeakObject * >(this));
1372 }
1373 } catch (css::uno::RuntimeException &) {
1374 if (!readLegacyRdbFile(uri)) {
1375 throw;
1376 }
1377 }
1378}
1379
1381 Registry reg;
1382 switch (reg.open(uri, RegAccessMode::READONLY)) {
1383 case RegError::NO_ERROR:
1384 break;
1385 case RegError::REGISTRY_NOT_EXISTS:
1386 case RegError::INVALID_REGISTRY:
1387 {
1388 // Ignore empty rdb files (which are at least seen by subordinate
1389 // uno processes during extension registration; Registry::open can
1390 // fail on them if mmap(2) returns EINVAL for a zero length):
1391 osl::DirectoryItem item;
1392 if (osl::DirectoryItem::get(uri, item) == osl::FileBase::E_None) {
1393 osl::FileStatus status(osl_FileStatus_Mask_FileSize);
1394 if (item.getFileStatus(status) == osl::FileBase::E_None
1395 && status.getFileSize() == 0)
1396 {
1397 return true;
1398 }
1399 }
1400 }
1401 [[fallthrough]];
1402 default:
1403 return false;
1404 }
1405 RegistryKey rootKey;
1406 if (reg.openRootKey(rootKey) != RegError::NO_ERROR) {
1407 throw css::uno::DeploymentException(
1408 "Failure reading legacy rdb file " + uri,
1409 static_cast< cppu::OWeakObject * >(this));
1410 }
1411 RegistryKeyArray impls;
1412 switch (rootKey.openSubKeys("IMPLEMENTATIONS", impls)) {
1413 case RegError::NO_ERROR:
1414 break;
1415 case RegError::KEY_NOT_EXISTS:
1416 return true;
1417 default:
1418 throw css::uno::DeploymentException(
1419 "Failure reading legacy rdb file " + uri,
1420 static_cast< cppu::OWeakObject * >(this));
1421 }
1422 for (sal_uInt32 i = 0; i != impls.getLength(); ++i) {
1423 RegistryKey implKey(impls.getElement(i));
1424 assert(implKey.getName().match("/IMPLEMENTATIONS/"));
1425 OUString name(
1426 implKey.getName().copy(RTL_CONSTASCII_LENGTH("/IMPLEMENTATIONS/")));
1427 std::shared_ptr< Data::Implementation > impl =
1428 std::make_shared<Data::Implementation>(
1429 name, readLegacyRdbString(uri, implKey, "UNO/ACTIVATOR"),
1430 readLegacyRdbString(uri, implKey, "UNO/LOCATION"), "", "", "", false,
1431 css::uno::Reference< css::uno::XComponentContext >(), uri);
1432 if (!data_.namedImplementations.emplace(name, impl).second)
1433 {
1434 throw css::registry::InvalidRegistryException(
1435 uri + ": duplicate <implementation name=\"" + name + "\">");
1436 }
1438 uri, implKey, "UNO/SERVICES", &impl->services);
1439 for (const auto& rService : impl->services)
1440 {
1441 data_.services[rService].push_back(impl);
1442 }
1444 uri, implKey, "UNO/SINGLETONS", &impl->singletons);
1445 for (const auto& rSingleton : impl->singletons)
1446 {
1447 data_.singletons[rSingleton].push_back(impl);
1448 }
1449 }
1450 return true;
1451}
1452
1454 std::u16string_view uri, RegistryKey & key, OUString const & path)
1455{
1456 RegistryKey subkey;
1458 sal_uInt32 s(0);
1459 if (key.openKey(path, subkey) != RegError::NO_ERROR
1460 || subkey.getValueInfo(OUString(), &t, &s) != RegError::NO_ERROR
1461 || t != RegValueType::STRING
1462 || s == 0 || s > o3tl::make_unsigned(SAL_MAX_INT32))
1463 {
1464 throw css::uno::DeploymentException(
1465 OUString::Concat("Failure reading legacy rdb file ") + uri,
1466 static_cast< cppu::OWeakObject * >(this));
1467 }
1468 OUString val;
1469 std::vector< char > v(s); // assuming sal_uInt32 fits into vector::size_type
1470 if (subkey.getValue(OUString(), v.data()) != RegError::NO_ERROR
1471 || v.back() != '\0'
1472 || !rtl_convertStringToUString(
1473 &val.pData, v.data(), static_cast< sal_Int32 >(s - 1),
1474 RTL_TEXTENCODING_UTF8,
1475 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
1476 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
1477 | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
1478 {
1479 throw css::uno::DeploymentException(
1480 OUString::Concat("Failure reading legacy rdb file ") + uri,
1481 static_cast< cppu::OWeakObject * >(this));
1482 }
1483 return val;
1484}
1485
1487 std::u16string_view uri, RegistryKey & key, OUString const & path,
1488 std::vector< OUString > * strings)
1489{
1490 assert(strings != nullptr);
1491 RegistryKey subkey;
1492 switch (key.openKey(path, subkey)) {
1493 case RegError::NO_ERROR:
1494 break;
1495 case RegError::KEY_NOT_EXISTS:
1496 return;
1497 default:
1498 throw css::uno::DeploymentException(
1499 OUString::Concat("Failure reading legacy rdb file ") + uri,
1500 static_cast< cppu::OWeakObject * >(this));
1501 }
1502 OUString prefix(subkey.getName() + "/");
1503 RegistryKeyNames names;
1504 if (subkey.getKeyNames(OUString(), names) != RegError::NO_ERROR) {
1505 throw css::uno::DeploymentException(
1506 OUString::Concat("Failure reading legacy rdb file ") + uri,
1507 static_cast< cppu::OWeakObject * >(this));
1508 }
1509 for (sal_uInt32 i = 0; i != names.getLength(); ++i) {
1510 assert(names.getElement(i).match(prefix));
1511 strings->push_back(names.getElement(i).copy(prefix.getLength()));
1512 }
1513}
1514
1516 std::vector< OUString > const & uris,
1517 css::uno::Reference< css::uno::XComponentContext > const & alienContext)
1518{
1519 Data extra;
1520 for (const auto& rUri : uris)
1521 {
1522 try {
1523 Parser(rUri, alienContext, &extra);
1524 } catch (css::container::NoSuchElementException &) {
1525 throw css::lang::IllegalArgumentException(
1526 rUri + ": no such file", static_cast< cppu::OWeakObject * >(this),
1527 0);
1528 } catch (css::registry::InvalidRegistryException & e) {
1529 throw css::lang::IllegalArgumentException(
1530 "InvalidRegistryException: " + e.Message,
1531 static_cast< cppu::OWeakObject * >(this), 0);
1532 }
1533 }
1534 insertExtraData(extra);
1535}
1536
1538 css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo)
1539{
1540 assert(factoryInfo.is());
1541 OUString name(factoryInfo->getImplementationName());
1542 css::uno::Reference< css::lang::XSingleComponentFactory > f1(
1543 factoryInfo, css::uno::UNO_QUERY);
1544 css::uno::Reference< css::lang::XSingleServiceFactory > f2;
1545 if (!f1.is()) {
1546 f2.set(factoryInfo, css::uno::UNO_QUERY);
1547 if (!f2.is()) {
1548 throw css::lang::IllegalArgumentException(
1549 ("Bad XServiceInfo argument implements neither"
1550 " XSingleComponentFactory nor XSingleServiceFactory"),
1551 static_cast< cppu::OWeakObject * >(this), 0);
1552 }
1553 }
1554 css::uno::Reference< css::lang::XComponent > comp(
1555 factoryInfo, css::uno::UNO_QUERY);
1556 std::shared_ptr< Data::Implementation > impl =
1557 std::make_shared<Data::Implementation>(name, f1, f2, comp);
1558 Data extra;
1559 if (!name.isEmpty()) {
1560 extra.namedImplementations.emplace(name, impl);
1561 }
1562 extra.dynamicImplementations.emplace(factoryInfo, impl);
1563 const css::uno::Sequence< OUString > services(
1564 factoryInfo->getSupportedServiceNames());
1565 for (const auto & i : services) {
1566 impl->services.push_back(i);
1567 extra.services[i].push_back(impl);
1568 }
1569 if (insertExtraData(extra) && comp.is()) {
1570 comp->addEventListener(this);
1571 }
1572}
1573
1575 {
1576 std::unique_lock g(m_aMutex);
1577 if (m_bDisposed) {
1578 return false;
1579 }
1580 auto i = std::find_if(extra.namedImplementations.begin(), extra.namedImplementations.end(),
1581 [this](const Data::NamedImplementations::value_type& rEntry) {
1582 return data_.namedImplementations.find(rEntry.first) != data_.namedImplementations.end(); });
1583 if (i != extra.namedImplementations.end())
1584 {
1585 throw css::lang::IllegalArgumentException(
1586 "Insert duplicate implementation name " + i->first,
1587 static_cast< cppu::OWeakObject * >(this), 0);
1588 }
1589 bool bDuplicate = std::any_of(extra.dynamicImplementations.begin(), extra.dynamicImplementations.end(),
1590 [this](const Data::DynamicImplementations::value_type& rEntry) {
1591 return data_.dynamicImplementations.find(rEntry.first) != data_.dynamicImplementations.end(); });
1592 if (bDuplicate)
1593 {
1594 throw css::lang::IllegalArgumentException(
1595 "Insert duplicate factory object",
1596 static_cast< cppu::OWeakObject * >(this), 0);
1597 }
1598 //TODO: The below leaves data_ in an inconsistent state upon exceptions:
1600 extra.namedImplementations.begin(),
1601 extra.namedImplementations.end());
1603 extra.dynamicImplementations.begin(),
1604 extra.dynamicImplementations.end());
1605 insertImplementationMap(&data_.services, extra.services);
1606 insertImplementationMap(&data_.singletons, extra.singletons);
1607 }
1608 //TODO: Updating the component context singleton data should be part of the
1609 // atomic service manager update:
1610 if (extra.singletons.empty())
1611 return true;
1612
1613 assert(context_.is());
1614 css::uno::Reference< css::container::XNameContainer > cont(
1615 context_, css::uno::UNO_QUERY_THROW);
1616 for (const auto& [rName, rImpls] : extra.singletons)
1617 {
1618 OUString name("/singletons/" + rName);
1619 //TODO: Update should be atomic:
1620 try {
1621 cont->removeByName(name + "/arguments");
1622 } catch (const css::container::NoSuchElementException &) {}
1623 assert(!rImpls.empty());
1624 assert(rImpls[0]);
1626 rImpls.size() > 1, "cppuhelper",
1627 "Arbitrarily choosing " << rImpls[0]->name
1628 << " among multiple implementations for singleton "
1629 << rName);
1630 try {
1631 cont->insertByName(
1632 name + "/service", css::uno::Any(rImpls[0]->name));
1633 } catch (css::container::ElementExistException &) {
1634 cont->replaceByName(
1635 name + "/service", css::uno::Any(rImpls[0]->name));
1636 }
1637 try {
1638 cont->insertByName(name, css::uno::Any());
1639 } catch (css::container::ElementExistException &) {
1640 SAL_INFO("cppuhelper", "Overwriting singleton " << rName);
1641 cont->replaceByName(name, css::uno::Any());
1642 }
1643 }
1644 return true;
1645}
1646
1648 std::vector< OUString > const & uris)
1649{
1650 // The underlying data structures make this function somewhat inefficient,
1651 // but the assumption is that it is rarely called (and that if it is called,
1652 // it is called with a uris vector of size one):
1653 std::vector< std::shared_ptr< Data::Implementation > > clear;
1654 {
1655 std::unique_lock g(m_aMutex);
1656 for (const auto& rUri : uris)
1657 {
1658 for (Data::NamedImplementations::iterator j(
1659 data_.namedImplementations.begin());
1660 j != data_.namedImplementations.end();)
1661 {
1662 assert(j->second);
1663 if (j->second->rdbFile == rUri) {
1664 clear.push_back(j->second);
1665 //TODO: The below leaves data_ in an inconsistent state upon
1666 // exceptions:
1667 removeFromImplementationMap(
1668 &data_.services, j->second->services, j->second);
1669 removeFromImplementationMap(
1670 &data_.singletons, j->second->singletons,
1671 j->second);
1672 j = data_.namedImplementations.erase(j);
1673 } else {
1674 ++j;
1675 }
1676 }
1677 }
1678 }
1679 //TODO: Update the component context singleton data
1680}
1681
1683 css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo,
1684 bool removeListener)
1685{
1686 assert(factoryInfo.is());
1687 std::shared_ptr< Data::Implementation > clear;
1688 css::uno::Reference< css::lang::XComponent > comp;
1689 {
1690 std::unique_lock g(m_aMutex);
1691 Data::DynamicImplementations::iterator i(
1692 data_.dynamicImplementations.find(factoryInfo));
1693 if (i == data_.dynamicImplementations.end()) {
1694 return m_bDisposed;
1695 }
1696 assert(i->second);
1697 clear = i->second;
1698 if (removeListener) {
1699 comp = i->second->component;
1700 }
1701 //TODO: The below leaves data_ in an inconsistent state upon exceptions:
1702 removeFromImplementationMap(
1703 &data_.services, i->second->services, i->second);
1704 removeFromImplementationMap(
1705 &data_.singletons, i->second->singletons, i->second);
1706 if (!i->second->name.isEmpty()) {
1707 data_.namedImplementations.erase(i->second->name);
1708 }
1710 }
1711 if (comp.is()) {
1713 }
1714 return true;
1715}
1716
1718 // The underlying data structures make this function somewhat inefficient,
1719 // but the assumption is that it is rarely called:
1720 std::shared_ptr< Data::Implementation > clear;
1721 {
1722 std::unique_lock g(m_aMutex);
1723 if (m_bDisposed) {
1724 return;
1725 }
1726 Data::NamedImplementations::iterator i(
1728 if (i == data_.namedImplementations.end()) {
1729 throw css::container::NoSuchElementException(
1730 "Remove non-inserted implementation " + name,
1731 static_cast< cppu::OWeakObject * >(this));
1732 }
1733 assert(i->second);
1734 clear = i->second;
1735 //TODO: The below leaves data_ in an inconsistent state upon exceptions:
1736 removeFromImplementationMap(
1737 &data_.services, i->second->services, i->second);
1738 removeFromImplementationMap(
1739 &data_.singletons, i->second->singletons, i->second);
1740 auto j = std::find_if(data_.dynamicImplementations.begin(), data_.dynamicImplementations.end(),
1741 [&i](const Data::DynamicImplementations::value_type& rEntry) { return rEntry.second == i->second; });
1742 if (j != data_.dynamicImplementations.end())
1745 }
1746}
1747
1748std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation >
1750 css::uno::Reference< css::uno::XComponentContext > const & context,
1751 OUString const & specifier)
1752{
1753 std::shared_ptr< Data::Implementation > impl;
1754 bool loaded;
1755 {
1756 std::unique_lock g(m_aMutex);
1757 Data::ImplementationMap::const_iterator i(
1758 data_.services.find(specifier));
1759 if (i == data_.services.end()) {
1760 Data::NamedImplementations::const_iterator j(
1761 data_.namedImplementations.find(specifier));
1762 if (j == data_.namedImplementations.end()) {
1763 SAL_INFO("cppuhelper", "No implementation for " << specifier);
1764 return std::shared_ptr< Data::Implementation >();
1765 }
1766 impl = j->second;
1767 } else {
1768 assert(!i->second.empty());
1770 i->second.size() > 1, "cppuhelper",
1771 "Arbitrarily choosing " << i->second[0]->name
1772 << " among multiple implementations for " << i->first);
1773 impl = i->second[0];
1774 }
1775 assert(impl);
1776 loaded = impl->status == Data::Implementation::STATUS_LOADED;
1777 }
1778 if (!loaded) {
1779 loadImplementation(context, impl);
1780 }
1781 return impl;
1782}
1783
1785#ifndef DISABLE_DYNLOADING
1786static OUString simplifyModule(std::u16string_view uri)
1787{
1788 sal_Int32 nIdx;
1789 OUStringBuffer edit(uri);
1790 if ((nIdx = edit.lastIndexOf('/')) > 0)
1791 edit.remove(0,nIdx+1);
1792 if ((nIdx = edit.lastIndexOf(':')) > 0)
1793 edit.remove(0,nIdx+1);
1794 if ((nIdx = edit.lastIndexOf("lo.so")) > 0)
1795 edit.truncate(nIdx);
1796 if ((nIdx = edit.lastIndexOf(".3")) > 0)
1797 edit.truncate(nIdx);
1798 if ((nIdx = edit.lastIndexOf("gcc3.so")) > 0)
1799 edit.truncate(nIdx);
1800 if ((nIdx = edit.lastIndexOf(".so")) > 0)
1801 edit.truncate(nIdx);
1802 if ((nIdx = edit.lastIndexOf("_uno")) > 0)
1803 edit.truncate(nIdx);
1804 if ((nIdx = edit.lastIndexOf(".jar")) > 0)
1805 edit.truncate(nIdx);
1806 if (edit.indexOf("lib") == 0)
1807 edit.remove(0,3);
1808 return edit.makeStringAndClear();
1809}
1810#endif
1811
1814#ifdef DISABLE_DYNLOADING
1815 abort();
1816#else
1817 OUString aUri;
1818 std::unique_lock g(m_aMutex);
1819 css::uno::Environment aSourceEnv(css::uno::Environment::getCurrent());
1820
1821 std::cerr << "preload:";
1822 std::vector<OUString> aReported;
1823 std::vector<OUString> aDisabled;
1824 OUStringBuffer aDisabledMsg;
1825 OUStringBuffer aMissingMsg;
1826
1828 const char *pDisable = getenv("UNODISABLELIBRARY");
1829 if (pDisable)
1830 {
1831 OUString aDisable(pDisable, strlen(pDisable), RTL_TEXTENCODING_UTF8);
1832 for (sal_Int32 i = 0; i >= 0; )
1833 {
1834 OUString tok( aDisable.getToken(0, ' ', i) );
1835 tok = tok.trim();
1836 if (!tok.isEmpty())
1837 aDisabled.push_back(tok);
1838 }
1839 }
1840
1841 // loop all implementations
1842 for (const auto& rEntry : data_.namedImplementations)
1843 {
1844 if (rEntry.second->loader != "com.sun.star.loader.SharedLibrary" ||
1845 rEntry.second->status == Data::Implementation::STATUS_LOADED)
1846 continue;
1847
1848 OUString simplified;
1849 try
1850 {
1851 const OUString &aLibrary = rEntry.second->uri;
1852
1853 if (aLibrary.isEmpty())
1854 continue;
1855
1856 simplified = simplifyModule(aLibrary);
1857
1858 bool bDisabled =
1859 std::find(aDisabled.begin(), aDisabled.end(), simplified) != aDisabled.end();
1860
1861 if (std::find(aReported.begin(), aReported.end(), aLibrary) == aReported.end())
1862 {
1863 if (bDisabled)
1864 {
1865 aDisabledMsg.append(simplified + " ");
1866 }
1867 else
1868 {
1869 std::cerr << " " << simplified;
1870 std::cerr.flush();
1871 }
1872 aReported.push_back(aLibrary);
1873 }
1874
1875 if (bDisabled)
1876 continue;
1877
1878 // expand absolute URI implementation component library
1879 aUri = cppu::bootstrap_expandUri(aLibrary);
1880 }
1881 catch (css::lang::IllegalArgumentException& aError)
1882 {
1883 throw css::uno::DeploymentException(
1884 "Cannot expand URI" + rEntry.second->uri + ": " + aError.Message,
1885 static_cast< cppu::OWeakObject * >(this));
1886 }
1887
1888 // load component library
1889 osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL);
1890
1891 if (!aModule.is())
1892 {
1893 aMissingMsg.append(simplified + " ");
1894 }
1895
1896 if (aModule.is() &&
1897 !rEntry.second->environment.isEmpty())
1898 {
1899 oslGenericFunction fpFactory;
1900 css::uno::Environment aTargetEnv;
1901 css::uno::Reference<css::uno::XInterface> xFactory;
1902
1903 if(rEntry.second->constructorName.isEmpty())
1904 {
1905 OUString aSymFactory;
1906 // expand full name component factory symbol
1907 if (rEntry.second->prefix == "direct")
1908 aSymFactory = rEntry.second->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
1909 else if (!rEntry.second->prefix.isEmpty())
1910 aSymFactory = rEntry.second->prefix + "_" COMPONENT_GETFACTORY;
1911 else
1912 aSymFactory = COMPONENT_GETFACTORY;
1913
1914 // get function symbol component factory
1915 fpFactory = aModule.getFunctionSymbol(aSymFactory);
1916 if (fpFactory == nullptr)
1917 {
1918 throw css::loader::CannotActivateFactoryException(
1919 ("no factory symbol \"" + aSymFactory + "\" in component library :" + aUri),
1920 css::uno::Reference<css::uno::XInterface>());
1921 }
1922
1923 aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->environment, rEntry.second->name);
1924 component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
1925
1926 if (aSourceEnv.get() == aTargetEnv.get())
1927 {
1928 // invoke function component factory
1929 OString aImpl(OUStringToOString(rEntry.second->name, RTL_TEXTENCODING_ASCII_US));
1930 xFactory.set(css::uno::Reference<css::uno::XInterface>(static_cast<css::uno::XInterface *>(
1931 (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE));
1932 }
1933 }
1934 else
1935 {
1936 // get function symbol component factory
1937 aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->environment, rEntry.second->name);
1938 fpFactory = (aSourceEnv.get() == aTargetEnv.get()) ?
1939 aModule.getFunctionSymbol(rEntry.second->constructorName) : nullptr;
1940 }
1941
1942 css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory;
1943 css::uno::Reference<css::lang::XSingleServiceFactory> xSSFactory;
1944
1945 // query interface XSingleComponentFactory or XSingleServiceFactory
1946 if (xFactory.is())
1947 {
1948 xSCFactory.set(xFactory, css::uno::UNO_QUERY);
1949 if (!xSCFactory.is())
1950 {
1951 xSSFactory.set(xFactory, css::uno::UNO_QUERY);
1952 if (!xSSFactory.is())
1953 throw css::uno::DeploymentException(
1954 ("Implementation " + rEntry.second->name
1955 + " does not provide a constructor or factory"),
1956 static_cast< cppu::OWeakObject * >(this));
1957 }
1958 }
1959
1960 if (!rEntry.second->constructorName.isEmpty() && fpFactory)
1961 rEntry.second->constructorFn = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
1962
1963 rEntry.second->factory1 = xSCFactory;
1964 rEntry.second->factory2 = xSSFactory;
1965 rEntry.second->status = Data::Implementation::STATUS_LOADED;
1966
1967 }
1968
1969 // Some libraries use other (non-UNO) libraries requiring preinit
1970 oslGenericFunction fpPreload = aModule.getFunctionSymbol( "lok_preload_hook" );
1971 if (fpPreload)
1972 {
1973 static std::vector<oslGenericFunction> aPreloaded;
1974 if (std::find(aPreloaded.begin(), aPreloaded.end(), fpPreload) == aPreloaded.end())
1975 {
1976 aPreloaded.push_back(fpPreload);
1977 fpPreload();
1978 }
1979 }
1980
1981 // leak aModule
1982 aModule.release();
1983 }
1984 std::cerr << std::endl;
1985
1986 if (aMissingMsg.getLength() > 0)
1987 {
1988 OUString aMsg = aMissingMsg.makeStringAndClear();
1989 std::cerr << "Absent (often optional): " << aMsg << "\n";
1990 }
1991 if (aDisabledMsg.getLength() > 0)
1992 {
1993 OUString aMsg = aDisabledMsg.makeStringAndClear();
1994 std::cerr << "Disabled: " << aMsg << "\n";
1995 }
1996 std::cerr.flush();
1997
1998 // Various rather important uno mappings.
1999 static struct {
2000 const char *mpFrom;
2001 const char *mpTo;
2002 const char *mpPurpose;
2003 } const aMappingLoad[] = {
2004 { "gcc3", "uno", "" },
2005 { "uno", "gcc3", "" },
2006 };
2007
2008 static std::vector<css::uno::Mapping> maMaps;
2009 for (auto &it : aMappingLoad)
2010 {
2011 maMaps.push_back(css::uno::Mapping(
2012 OUString::createFromAscii(it.mpFrom),
2013 OUString::createFromAscii(it.mpTo),
2014 OUString::createFromAscii(it.mpPurpose)));
2015 }
2016#endif
2017}
2018
2019/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
sal_uInt32 getLength() const
RegistryKey getElement(sal_uInt32 index)
OUString getElement(sal_uInt32 index)
sal_uInt32 getLength() const
RegError getKeyNames(const OUString &keyName, RegistryKeyNames &rSubKeyNames)
RegError openKey(const OUString &keyName, RegistryKey &rOpenKey)
OUString getName()
RegError getValueInfo(const OUString &keyName, RegValueType *pValueType, sal_uInt32 *pValueSize)
RegError getValue(const OUString &keyName, RegValue pValue)
RegError openSubKeys(const OUString &keyName, RegistryKeyArray &rSubKeys)
RegError openRootKey(RegistryKey &rRootKey)
RegError open(const OUString &registryName, RegAccessMode accessMode)
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:48
virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties() override
bool readLegacyRdbFile(OUString const &uri)
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
virtual void SAL_CALL removeVetoableChangeListener(OUString const &PropertyName, css::uno::Reference< css::beans::XVetoableChangeListener > const &aListener) override
void loadImplementation(css::uno::Reference< css::uno::XComponentContext > const &context, std::shared_ptr< Data::Implementation > const &implementation)
bool insertExtraData(Data const &extra)
void addSingletonContextEntries(std::vector< cppu::ContextEntry_Init > *entries)
void removeEventListenerFromComponent(css::uno::Reference< css::lang::XComponent > const &component)
virtual void SAL_CALL setPropertyValue(OUString const &aPropertyName, css::uno::Any const &aValue) override
virtual sal_Bool SAL_CALL hasPropertyByName(OUString const &Name) override
virtual void SAL_CALL insert(css::uno::Any const &aElement) override
void insertLegacyFactory(css::uno::Reference< css::lang::XServiceInfo > const &factoryInfo)
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL removePropertyChangeListener(OUString const &aPropertyName, css::uno::Reference< css::beans::XPropertyChangeListener > const &aListener) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual ~ServiceManager() override
void readRdbDirectory(std::u16string_view uri, bool optional)
virtual css::beans::Property SAL_CALL getPropertyByName(OUString const &aName) override
virtual void SAL_CALL addVetoableChangeListener(OUString const &PropertyName, css::uno::Reference< css::beans::XVetoableChangeListener > const &aListener) override
void insertRdbFiles(std::vector< OUString > const &uris, css::uno::Reference< css::uno::XComponentContext > const &alientContext)
void readLegacyRdbStrings(std::u16string_view uri, RegistryKey &key, OUString const &path, std::vector< OUString > *strings)
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext(OUString const &ServiceSpecifier, css::uno::Sequence< css::uno::Any > const &Arguments, css::uno::Reference< css::uno::XComponentContext > const &Context) override
std::shared_ptr< Data::Implementation > findServiceImplementation(css::uno::Reference< css::uno::XComponentContext > const &context, OUString const &specifier)
void removeImplementation(const OUString &name)
virtual void disposing(std::unique_lock< std::mutex > &) override
Called by dispose for subclasses to do dispose() work.
bool removeLegacyFactory(css::uno::Reference< css::lang::XServiceInfo > const &factoryInfo, bool removeListener)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL has(css::uno::Any const &aElement) override
virtual void SAL_CALL remove(css::uno::Any const &aElement) override
void removeRdbFiles(std::vector< OUString > const &uris)
virtual css::uno::Any SAL_CALL getPropertyValue(OUString const &PropertyName) override
void preloadImplementations()
Used only by LibreOfficeKit when used by Online to pre-initialize.
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(OUString const &aServiceSpecifier) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext(OUString const &aServiceSpecifier, css::uno::Reference< css::uno::XComponentContext > const &Context) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(OUString const &ServiceSpecifier, css::uno::Sequence< css::uno::Any > const &Arguments) override
virtual void SAL_CALL initialize(css::uno::Sequence< css::uno::Any > const &aArguments) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createContentEnumeration(OUString const &aServiceName) override
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
void readRdbFile(OUString const &uri, bool optional)
css::uno::Reference< css::uno::XComponentContext > context_
OUString readLegacyRdbString(std::u16string_view uri, RegistryKey &key, OUString const &path)
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL addPropertyChangeListener(OUString const &aPropertyName, css::uno::Reference< css::beans::XPropertyChangeListener > const &xListener) override
void init(std::u16string_view rdbUris)
virtual void SAL_CALL dispose() noexcept final override
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &rxListener) final override
rtl::Reference< ParseManager > manager
std::mutex mutex_
float v
Reference< XSingleServiceFactory > xFactory
Definition: factory.cxx:715
#define COMPONENT_GETFACTORY
Definition: factory.hxx:47
void *(SAL_CALL * component_getFactoryFunc)(const char *pImplName, void *pServiceManager, void *pRegistryKey)
Function pointer declaration.
Definition: factory.hxx:120
const char * name
Sequence< PropertyValue > aArguments
OUString aName
rtl::Reference< Manager > manager_
#define SAL_INFO_IF(condition, area, stream)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
const char * attrName
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
OUString bootstrap_expandUri(OUString const &uri)
Definition: bootstrap.cxx:232
void decodeRdbUri(std::u16string_view *uri, bool *optional, bool *directory)
Definition: paths.cxx:114
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
A helper for implementations of com.sun.star.lang.XServiceInfo.
bool nextDirectoryItem(osl::Directory &directory, OUString *url)
Definition: paths.cxx:81
css::uno::Environment getEnvironment(OUString const &name, std::u16string_view implementation)
Definition: shlib.cxx:49
void loadSharedLibComponentFactory(OUString const &uri, OUString const &environment, OUString const &prefix, OUString const &implementation, OUString const &constructor, css::uno::Reference< css::lang::XMultiServiceFactory > const &serviceManager, WrapperConstructorFn *constructorFunction, css::uno::Reference< css::uno::XInterface > *factory)
Definition: shlib.cxx:240
css::uno::XInterface * ImplementationConstructorFn(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
std::function< css::uno::XInterface *(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)> WrapperConstructorFn
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
enumrange< T >::Iterator begin(enumrange< T >)
args
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
loader
comp
State
enum SAL_DLLPUBLIC_RTTI RegValueType
static OUString simplifyModule(std::u16string_view uri)
Make a simpler unique name for preload / progress reporting.
std::map< OUString, rtl::Reference< Entity > >::const_iterator iterator_
std::map< OUString, rtl::Reference< Entity > > map
Context entries init struct calling createComponentContext().
css::uno::Reference< css::uno::XInterface > createInstanceWithArguments(css::uno::Reference< css::uno::XComponentContext > const &context, bool singletonRequest, css::uno::Sequence< css::uno::Any > const &arguments)
css::uno::Reference< css::uno::XInterface > doCreateInstanceWithArguments(css::uno::Reference< css::uno::XComponentContext > const &context, css::uno::Sequence< css::uno::Any > const &arguments)
css::uno::Reference< css::uno::XInterface > createInstance(css::uno::Reference< css::uno::XComponentContext > const &context, bool singletonRequest)
css::uno::Reference< css::uno::XInterface > doCreateInstance(css::uno::Reference< css::uno::XComponentContext > const &context)
css::uno::Reference< css::uno::XInterface > singleInstance
void updateDisposeInstance(bool singletonRequest, css::uno::Reference< css::uno::XInterface > const &instance)
DynamicImplementations dynamicImplementations
NamedImplementations namedImplementations
std::unordered_map< OUString, std::vector< std::shared_ptr< Implementation > > > ImplementationMap
std::mutex mutex
OUString Name
#define SAL_MAX_INT32
unsigned char sal_Bool