bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / misc / componentmodule.cxx
blobdd1b2bdfd7b2fa0d3bd6a390505f4ed9ab86a684
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/componentmodule.hxx>
22 #include <comphelper/sequence.hxx>
23 #include <osl/diagnose.h>
25 #include <vector>
28 namespace comphelper
32 using namespace ::cppu;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::RuntimeException;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::lang::XMultiServiceFactory;
37 using ::com::sun::star::registry::XRegistryKey;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::uno::XInterface;
41 typedef ::std::vector< ComponentDescription > ComponentDescriptions;
43 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner
45 class OModuleImpl
47 public:
48 ComponentDescriptions m_aRegisteredComponents;
50 OModuleImpl();
51 ~OModuleImpl();
55 OModuleImpl::OModuleImpl()
60 OModuleImpl::~OModuleImpl()
64 OModule::OModule()
65 : m_nClients(0)
66 , m_pImpl(new OModuleImpl)
70 OModule::~OModule()
72 delete m_pImpl;
76 void OModule::registerClient( OModule::ClientAccess )
78 ::osl::MutexGuard aGuard(m_aMutex);
79 if ( 1 == osl_atomic_increment( &m_nClients ) )
80 onFirstClient();
84 void OModule::revokeClient( OModule::ClientAccess )
86 ::osl::MutexGuard aGuard(m_aMutex);
87 if ( 0 == osl_atomic_decrement( &m_nClients ) )
88 onLastClient();
92 void OModule::onFirstClient()
97 void OModule::onLastClient()
102 void OModule::registerImplementation( const ComponentDescription& _rComp )
104 ::osl::MutexGuard aGuard( m_aMutex );
105 if ( !m_pImpl )
106 throw RuntimeException();
108 m_pImpl->m_aRegisteredComponents.push_back( _rComp );
112 void OModule::registerImplementation( const OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
113 ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
115 ComponentDescription aComponent( _rImplementationName, _rServiceNames, OUString(), _pCreateFunction, _pFactoryFunction );
116 registerImplementation( aComponent );
120 void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
122 Reference< XInterface > xFactory( getComponentFactory(
123 OUString::createFromAscii( _pImplementationName ) ) );
124 return xFactory.get();
128 Reference< XInterface > OModule::getComponentFactory( const OUString& _rImplementationName )
130 Reference< XInterface > xReturn;
132 for ( ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
133 component != m_pImpl->m_aRegisteredComponents.end();
134 ++component
137 if ( component->sImplementationName == _rImplementationName )
139 xReturn = component->pFactoryCreationFunc(
140 component->pComponentCreationFunc,
141 component->sImplementationName,
142 component->aSupportedServices,
143 NULL
145 if ( xReturn.is() )
147 xReturn->acquire();
148 return xReturn.get();
153 return NULL;
157 } // namespace comphelper
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */