1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
30 #include <comphelper/componentmodule.hxx>
32 /** === begin UNO includes === **/
33 /** === end UNO includes === **/
34 #include <comphelper/sequence.hxx>
35 #include <osl/diagnose.h>
39 //........................................................................
42 //........................................................................
44 using namespace ::cppu
;
45 /** === being UNO using === **/
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::uno::RuntimeException
;
48 using ::com::sun::star::uno::Reference
;
49 using ::com::sun::star::lang::XMultiServiceFactory
;
50 using ::com::sun::star::registry::XRegistryKey
;
51 using ::com::sun::star::uno::Exception
;
52 using ::com::sun::star::uno::XInterface
;
53 /** === end UNO using === **/
55 typedef ::std::vector
< ComponentDescription
> ComponentDescriptions
;
57 //=========================================================================
59 //=========================================================================
60 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
65 ComponentDescriptions m_aRegisteredComponents
;
71 //-------------------------------------------------------------------------
72 OModuleImpl::OModuleImpl()
76 //-------------------------------------------------------------------------
77 OModuleImpl::~OModuleImpl()
81 //=========================================================================
83 //=========================================================================
84 //-------------------------------------------------------------------------
87 ,m_pImpl( new OModuleImpl
)
91 OModule::~OModule() {}
93 //-------------------------------------------------------------------------
94 void OModule::registerClient( OModule::ClientAccess
)
96 ::osl::MutexGuard
aGuard(m_aMutex
);
97 if ( 1 == osl_incrementInterlockedCount( &m_nClients
) )
101 //-------------------------------------------------------------------------
102 void OModule::revokeClient( OModule::ClientAccess
)
104 ::osl::MutexGuard
aGuard(m_aMutex
);
105 if ( 0 == osl_decrementInterlockedCount( &m_nClients
) )
109 //--------------------------------------------------------------------------
110 void OModule::onFirstClient()
114 //--------------------------------------------------------------------------
115 void OModule::onLastClient()
119 //--------------------------------------------------------------------------
120 void OModule::registerImplementation( const ComponentDescription
& _rComp
)
122 ::osl::MutexGuard
aGuard( m_aMutex
);
124 throw RuntimeException();
126 m_pImpl
->m_aRegisteredComponents
.push_back( _rComp
);
129 //--------------------------------------------------------------------------
130 void OModule::registerImplementation( const ::rtl::OUString
& _rImplementationName
, const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& _rServiceNames
,
131 ::cppu::ComponentFactoryFunc _pCreateFunction
, FactoryInstantiation _pFactoryFunction
)
133 ComponentDescription
aComponent( _rImplementationName
, _rServiceNames
, ::rtl::OUString(), _pCreateFunction
, _pFactoryFunction
);
134 registerImplementation( aComponent
);
137 //--------------------------------------------------------------------------
138 void* OModule::getComponentFactory( const sal_Char
* _pImplementationName
, void* _pServiceManager
, void* /*_pRegistryKey*/ )
140 Reference
< XInterface
> xFactory( getComponentFactory(
141 ::rtl::OUString::createFromAscii( _pImplementationName
),
142 Reference
< XMultiServiceFactory
>( static_cast< XMultiServiceFactory
* >( _pServiceManager
) )
144 return xFactory
.get();
147 //--------------------------------------------------------------------------
148 Reference
< XInterface
> OModule::getComponentFactory( const ::rtl::OUString
& _rImplementationName
,
149 const Reference
< XMultiServiceFactory
>& /* _rxServiceManager */ )
151 Reference
< XInterface
> xReturn
;
153 for ( ComponentDescriptions::const_iterator component
= m_pImpl
->m_aRegisteredComponents
.begin();
154 component
!= m_pImpl
->m_aRegisteredComponents
.end();
158 if ( component
->sImplementationName
== _rImplementationName
)
160 xReturn
= component
->pFactoryCreationFunc(
161 component
->pComponentCreationFunc
,
162 component
->sImplementationName
,
163 component
->aSupportedServices
,
169 return xReturn
.get();
177 //........................................................................
178 } // namespace comphelper
179 //........................................................................