1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
  
     | 
    
      /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
#define INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
#include "sal/config.h"
#include <cassert>
#include <map>
#include <vector>
#include "boost/noncopyable.hpp"
#include "boost/shared_ptr.hpp"
#include "com/sun/star/beans/XPropertySet.hpp"
#include "com/sun/star/beans/XPropertySetInfo.hpp"
#include "com/sun/star/container/XContentEnumerationAccess.hpp"
#include "com/sun/star/container/XSet.hpp"
#include "com/sun/star/lang/XEventListener.hpp"
#include "com/sun/star/lang/XMultiComponentFactory.hpp"
#include "com/sun/star/lang/XMultiServiceFactory.hpp"
#include "com/sun/star/lang/XServiceInfo.hpp"
#include "com/sun/star/lang/XSingleServiceFactory.hpp"
#include "com/sun/star/uno/XComponentContext.hpp"
#include "com/sun/star/uno/Reference.hxx"
#include "cppuhelper/basemutex.hxx"
#include "cppuhelper/compbase8.hxx"
#include "osl/mutex.hxx"
#include "registry/registry.hxx"
#include "rtl/ustring.hxx"
#include "cppuhelper/weak.hxx"
namespace com { namespace sun { namespace star { namespace lang {
    class XSingleComponentFactory;
} } } }
namespace cppu { struct ContextEntry_Init; }
namespace cppuhelper {
extern "C" {
typedef css::uno::XInterface * SAL_CALL ImplementationConstructorFn(
    css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const &);
}
typedef cppu::WeakComponentImplHelper8<
    css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
    css::lang::XMultiComponentFactory, css::container::XSet,
    css::container::XContentEnumerationAccess, css::beans::XPropertySet,
    css::beans::XPropertySetInfo, css::lang::XEventListener >
ServiceManagerBase;
class ServiceManager:
    private cppu::BaseMutex, public ServiceManagerBase,
    private boost::noncopyable
{
public:
    struct Data: private boost::noncopyable {
        struct ImplementationInfo: private boost::noncopyable {
            ImplementationInfo(
                rtl::OUString const & theName, rtl::OUString const & theLoader,
                rtl::OUString const & theUri,
                rtl::OUString const & theEnvironment,
                rtl::OUString const & theConstructor,
                rtl::OUString const & thePrefix,
                css::uno::Reference< css::uno::XComponentContext > const &
                    theAlienContext,
                rtl::OUString const & theRdbFile):
                name(theName), loader(theLoader), uri(theUri),
                environment(theEnvironment), constructor(theConstructor),
                prefix(thePrefix), alienContext(theAlienContext),
                rdbFile(theRdbFile)
            {}
            explicit ImplementationInfo(rtl::OUString const & theName):
                name(theName) {}
            rtl::OUString const name;
            rtl::OUString const loader;
            rtl::OUString const uri;
            rtl::OUString const environment;
            rtl::OUString const constructor;
            rtl::OUString const prefix;
            css::uno::Reference< css::uno::XComponentContext > const
                alienContext;
            rtl::OUString const rdbFile;
            std::vector< rtl::OUString > services;
            std::vector< rtl::OUString > singletons;
        };
        struct Implementation: private boost::noncopyable {
            Implementation(
                rtl::OUString const & name, rtl::OUString const & loader,
                rtl::OUString const & uri, rtl::OUString const & environment,
                rtl::OUString const & constructorName,
                rtl::OUString const & prefix,
                css::uno::Reference< css::uno::XComponentContext > const &
                    alienContext,
                rtl::OUString const & rdbFile):
                info(
                    new ImplementationInfo(
                        name, loader, uri, environment, constructorName, prefix,
                        alienContext, rdbFile)),
                constructor(0), status(STATUS_NEW), dispose(true)
            {}
            Implementation(
                rtl::OUString const & name,
                css::uno::Reference< css::lang::XSingleComponentFactory >
                    const & theFactory1,
                css::uno::Reference< css::lang::XSingleServiceFactory > const &
                    theFactory2,
                css::uno::Reference< css::lang::XComponent > const &
                    theComponent):
                info(new ImplementationInfo(name)), constructor(0),
                factory1(theFactory1), factory2(theFactory2),
                component(theComponent), status(STATUS_LOADED), dispose(true)
            { assert(theFactory1.is() || theFactory2.is()); }
            css::uno::Reference<css::uno::XInterface> createInstance(
                css::uno::Reference<css::uno::XComponentContext> const &
                    context,
                bool singletonRequest);
            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);
            enum Status { STATUS_NEW, STATUS_WRAPPER, STATUS_LOADED };
            boost::shared_ptr< ImplementationInfo > info;
            ImplementationConstructorFn * constructor;
            css::uno::Reference< css::lang::XSingleComponentFactory > factory1;
            css::uno::Reference< css::lang::XSingleServiceFactory > factory2;
            css::uno::Reference< css::lang::XComponent > component;
            Status status;
            osl::Mutex mutex;
            css::uno::Reference< css::lang::XComponent > disposeSingleton;
            bool dispose;
        private:
            void updateDisposeSingleton(
                bool singletonRequest,
                css::uno::Reference<css::uno::XInterface> const & instance);
        };
        typedef std::map< rtl::OUString, boost::shared_ptr< Implementation > >
            NamedImplementations;
        typedef
            std::map<
                css::uno::Reference< css::lang::XServiceInfo >,
                boost::shared_ptr< Implementation > >
            DynamicImplementations;
        typedef
            std::map<
                rtl::OUString,
                std::vector< boost::shared_ptr< Implementation > > >
            ImplementationMap;
        NamedImplementations namedImplementations;
        DynamicImplementations dynamicImplementations;
        ImplementationMap services;
        ImplementationMap singletons;
    };
    ServiceManager(): ServiceManagerBase(m_aMutex) {}
    using ServiceManagerBase::acquire;
    using ServiceManagerBase::release;
    void init(rtl::OUString const & rdbUris) { readRdbs(rdbUris); }
    void setContext(
        css::uno::Reference< css::uno::XComponentContext > const & context)
    {
        assert(context.is());
        assert(!context_.is());
        context_ = context;
    }
    void addSingletonContextEntries(
        std::vector< cppu::ContextEntry_Init > * entries);
    css::uno::Reference< css::uno::XComponentContext > getContext() const {
        assert(context_.is());
        return context_;
    }
    void loadImplementation(
        css::uno::Reference< css::uno::XComponentContext > const & context,
        boost::shared_ptr< Data::Implementation > & implementation);
private:
    virtual ~ServiceManager() {}
    virtual void SAL_CALL disposing() SAL_OVERRIDE;
    virtual rtl::OUString SAL_CALL getImplementationName()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Sequence< rtl::OUString > SAL_CALL
    getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
        rtl::OUString const & aServiceSpecifier)
        throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
    createInstanceWithArguments(
        rtl::OUString const & ServiceSpecifier,
        css::uno::Sequence< css::uno::Any > const & Arguments)
        throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Sequence< rtl::OUString > SAL_CALL
    getAvailableServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
    createInstanceWithContext(
        rtl::OUString const & aServiceSpecifier,
        css::uno::Reference< css::uno::XComponentContext > const & Context)
        throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
    createInstanceWithArgumentsAndContext(
        rtl::OUString const & ServiceSpecifier,
        css::uno::Sequence< css::uno::Any > const & Arguments,
        css::uno::Reference< css::uno::XComponentContext > const & Context)
        throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Type SAL_CALL getElementType()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
    createEnumeration() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual sal_Bool SAL_CALL has(css::uno::Any const & aElement)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL insert(css::uno::Any const & aElement)
        throw (
            css::lang::IllegalArgumentException,
            css::container::ElementExistException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL remove(css::uno::Any const & aElement)
        throw (
            css::lang::IllegalArgumentException,
            css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
    createContentEnumeration(rtl::OUString const & aServiceName)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
    getPropertySetInfo() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL setPropertyValue(
        rtl::OUString const & aPropertyName, css::uno::Any const & aValue)
        throw (
            css::beans::UnknownPropertyException,
            css::beans::PropertyVetoException,
            css::lang::IllegalArgumentException,
            css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Any SAL_CALL getPropertyValue(
        rtl::OUString const & PropertyName)
        throw (
            css::beans::UnknownPropertyException,
            css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL addPropertyChangeListener(
        rtl::OUString const & aPropertyName,
        css::uno::Reference< css::beans::XPropertyChangeListener > const &
            xListener)
        throw (
            css::beans::UnknownPropertyException,
            css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL removePropertyChangeListener(
        rtl::OUString const & aPropertyName,
        css::uno::Reference< css::beans::XPropertyChangeListener > const &
            aListener)
        throw (
            css::beans::UnknownPropertyException,
            css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL addVetoableChangeListener(
        rtl::OUString const & PropertyName,
        css::uno::Reference< css::beans::XVetoableChangeListener > const &
            aListener)
        throw (
            css::beans::UnknownPropertyException,
            css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL removeVetoableChangeListener(
        rtl::OUString const & PropertyName,
        css::uno::Reference< css::beans::XVetoableChangeListener > const &
            aListener)
        throw (
            css::beans::UnknownPropertyException,
            css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties()
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual css::beans::Property SAL_CALL getPropertyByName(
        rtl::OUString const & aName)
        throw (
            css::beans::UnknownPropertyException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual sal_Bool SAL_CALL hasPropertyByName(rtl::OUString const & Name)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL disposing(css::lang::EventObject const & Source)
        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
    // needs to be called with rBHelper.rMutex locked:
    bool isDisposed() { return rBHelper.bDisposed || rBHelper.bInDispose; }
    void removeEventListenerFromComponent(
        css::uno::Reference< css::lang::XComponent > const & component);
    void readRdbs(rtl::OUString const & uris);
    void readRdbDirectory(rtl::OUString const & uri, bool optional);
    void readRdbFile(rtl::OUString const & uri, bool optional);
    bool readLegacyRdbFile(rtl::OUString const & uri);
    rtl::OUString readLegacyRdbString(
        rtl::OUString const & uri, RegistryKey & key,
        rtl::OUString const & path);
    void readLegacyRdbStrings(
        rtl::OUString const & uri, RegistryKey & key,
        rtl::OUString const & path, std::vector< rtl::OUString > * strings);
    void insertRdbFiles(
        std::vector< rtl::OUString > const & uris,
        css::uno::Reference< css::uno::XComponentContext > const &
            alientContext);
    void insertLegacyFactory(
        css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo);
    bool insertExtraData(Data const & extra);
    void removeRdbFiles(std::vector< rtl::OUString > const & uris);
    bool removeLegacyFactory(
        css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo,
        bool removeListener);
    void removeImplementation(const rtl::OUString & name);
    boost::shared_ptr< Data::Implementation > findServiceImplementation(
        css::uno::Reference< css::uno::XComponentContext > const & context,
        rtl::OUString const & specifier);
    css::uno::Reference< css::uno::XComponentContext > context_;
    Data data_;
};
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 
     |