bump product version to 4.1.6.2
[LibreOffice.git] / comphelper / source / misc / componentmodule.cxx
bloba35a6779cb9d28bf325a8cf8342a0a3021cb81b8
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>
27 //........................................................................
28 namespace comphelper
30 //........................................................................
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 //=========================================================================
44 //= OModuleImpl
45 //=========================================================================
46 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
48 class OModuleImpl
50 public:
51 ComponentDescriptions m_aRegisteredComponents;
53 OModuleImpl();
54 ~OModuleImpl();
57 //-------------------------------------------------------------------------
58 OModuleImpl::OModuleImpl()
62 //-------------------------------------------------------------------------
63 OModuleImpl::~OModuleImpl()
67 //=========================================================================
68 //= OModule
69 //=========================================================================
70 //-------------------------------------------------------------------------
71 OModule::OModule()
72 : m_nClients(0)
73 , m_pImpl(new OModuleImpl)
77 OModule::~OModule()
79 delete m_pImpl;
82 //-------------------------------------------------------------------------
83 void OModule::registerClient( OModule::ClientAccess )
85 ::osl::MutexGuard aGuard(m_aMutex);
86 if ( 1 == osl_atomic_increment( &m_nClients ) )
87 onFirstClient();
90 //-------------------------------------------------------------------------
91 void OModule::revokeClient( OModule::ClientAccess )
93 ::osl::MutexGuard aGuard(m_aMutex);
94 if ( 0 == osl_atomic_decrement( &m_nClients ) )
95 onLastClient();
98 //--------------------------------------------------------------------------
99 void OModule::onFirstClient()
103 //--------------------------------------------------------------------------
104 void OModule::onLastClient()
108 //--------------------------------------------------------------------------
109 void OModule::registerImplementation( const ComponentDescription& _rComp )
111 ::osl::MutexGuard aGuard( m_aMutex );
112 if ( !m_pImpl )
113 throw RuntimeException();
115 m_pImpl->m_aRegisteredComponents.push_back( _rComp );
118 //--------------------------------------------------------------------------
119 void OModule::registerImplementation( const OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
120 ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
122 ComponentDescription aComponent( _rImplementationName, _rServiceNames, OUString(), _pCreateFunction, _pFactoryFunction );
123 registerImplementation( aComponent );
126 //--------------------------------------------------------------------------
127 void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
129 Reference< XInterface > xFactory( getComponentFactory(
130 OUString::createFromAscii( _pImplementationName ) ) );
131 return xFactory.get();
134 //--------------------------------------------------------------------------
135 Reference< XInterface > OModule::getComponentFactory( const OUString& _rImplementationName )
137 Reference< XInterface > xReturn;
139 for ( ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
140 component != m_pImpl->m_aRegisteredComponents.end();
141 ++component
144 if ( component->sImplementationName == _rImplementationName )
146 xReturn = component->pFactoryCreationFunc(
147 component->pComponentCreationFunc,
148 component->sImplementationName,
149 component->aSupportedServices,
150 NULL
152 if ( xReturn.is() )
154 xReturn->acquire();
155 return xReturn.get();
160 return NULL;
163 //........................................................................
164 } // namespace comphelper
165 //........................................................................
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */