Branch data Line data Source code
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 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <comphelper/componentmodule.hxx>
21 : :
22 : : #include <comphelper/sequence.hxx>
23 : : #include <osl/diagnose.h>
24 : :
25 : : #include <vector>
26 : :
27 : : //........................................................................
28 : : namespace comphelper
29 : : {
30 : : //........................................................................
31 : :
32 : : using namespace ::cppu;
33 : : /** === being UNO using === **/
34 : : using ::com::sun::star::uno::Sequence;
35 : : using ::com::sun::star::uno::RuntimeException;
36 : : using ::com::sun::star::uno::Reference;
37 : : using ::com::sun::star::lang::XMultiServiceFactory;
38 : : using ::com::sun::star::registry::XRegistryKey;
39 : : using ::com::sun::star::uno::Exception;
40 : : using ::com::sun::star::uno::XInterface;
41 : : /** === end UNO using === **/
42 : :
43 : : typedef ::std::vector< ComponentDescription > ComponentDescriptions;
44 : :
45 : : //=========================================================================
46 : : //= OModuleImpl
47 : : //=========================================================================
48 : : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
49 : : */
50 : : class OModuleImpl
51 : : {
52 : : public:
53 : : ComponentDescriptions m_aRegisteredComponents;
54 : :
55 : : OModuleImpl();
56 : : ~OModuleImpl();
57 : : };
58 : :
59 : : //-------------------------------------------------------------------------
60 : 365 : OModuleImpl::OModuleImpl()
61 : : {
62 : 365 : }
63 : :
64 : : //-------------------------------------------------------------------------
65 : 333 : OModuleImpl::~OModuleImpl()
66 : : {
67 : 333 : }
68 : :
69 : : //=========================================================================
70 : : //= OModule
71 : : //=========================================================================
72 : : //-------------------------------------------------------------------------
73 : 365 : OModule::OModule()
74 : : : m_nClients(0)
75 [ + - ]: 365 : , m_pImpl(new OModuleImpl)
76 : : {
77 : 365 : }
78 : :
79 : 333 : OModule::~OModule()
80 : : {
81 [ + - ]: 333 : delete m_pImpl;
82 [ - + ]: 333 : }
83 : :
84 : : //-------------------------------------------------------------------------
85 : 0 : void OModule::registerClient( OModule::ClientAccess )
86 : : {
87 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
88 [ # # ][ # # ]: 0 : if ( 1 == osl_incrementInterlockedCount( &m_nClients ) )
89 [ # # ][ # # ]: 0 : onFirstClient();
90 : 0 : }
91 : :
92 : : //-------------------------------------------------------------------------
93 : 0 : void OModule::revokeClient( OModule::ClientAccess )
94 : : {
95 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
96 [ # # ][ # # ]: 0 : if ( 0 == osl_decrementInterlockedCount( &m_nClients ) )
97 [ # # ][ # # ]: 0 : onLastClient();
98 : 0 : }
99 : :
100 : : //--------------------------------------------------------------------------
101 : 0 : void OModule::onFirstClient()
102 : : {
103 : 0 : }
104 : :
105 : : //--------------------------------------------------------------------------
106 : 0 : void OModule::onLastClient()
107 : : {
108 : 0 : }
109 : :
110 : : //--------------------------------------------------------------------------
111 : 3609 : void OModule::registerImplementation( const ComponentDescription& _rComp )
112 : : {
113 [ + - ]: 3609 : ::osl::MutexGuard aGuard( m_aMutex );
114 [ - + ]: 3609 : if ( !m_pImpl )
115 [ # # ]: 0 : throw RuntimeException();
116 : :
117 [ + - ][ + - ]: 3609 : m_pImpl->m_aRegisteredComponents.push_back( _rComp );
118 : 3609 : }
119 : :
120 : : //--------------------------------------------------------------------------
121 : 2887 : void OModule::registerImplementation( const ::rtl::OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
122 : : ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
123 : : {
124 [ + - ]: 2887 : ComponentDescription aComponent( _rImplementationName, _rServiceNames, ::rtl::OUString(), _pCreateFunction, _pFactoryFunction );
125 [ + - ][ + - ]: 2887 : registerImplementation( aComponent );
126 : 2887 : }
127 : :
128 : : //--------------------------------------------------------------------------
129 : 821 : void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
130 : : {
131 : : Reference< XInterface > xFactory( getComponentFactory(
132 [ + - ]: 821 : ::rtl::OUString::createFromAscii( _pImplementationName ) ) );
133 [ + - ]: 821 : return xFactory.get();
134 : : }
135 : :
136 : : //--------------------------------------------------------------------------
137 : 877 : Reference< XInterface > OModule::getComponentFactory( const ::rtl::OUString& _rImplementationName )
138 : : {
139 : 877 : Reference< XInterface > xReturn;
140 : :
141 [ + - + - ]: 11130 : for ( ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
[ + + ][ + - ]
142 : 5565 : component != m_pImpl->m_aRegisteredComponents.end();
143 : : ++component
144 : : )
145 : : {
146 [ + - ][ + + ]: 5556 : if ( component->sImplementationName == _rImplementationName )
147 : : {
148 [ + - ]: 868 : xReturn = component->pFactoryCreationFunc(
149 [ + - ]: 868 : component->pComponentCreationFunc,
150 [ + - ]: 868 : component->sImplementationName,
151 [ + - ]: 868 : component->aSupportedServices,
152 : : NULL
153 [ + - ][ + - ]: 868 : );
154 [ + - ]: 868 : if ( xReturn.is() )
155 : : {
156 [ + - ]: 868 : xReturn->acquire();
157 [ + - ][ + - ]: 868 : return xReturn.get();
158 : : }
159 : : }
160 : : }
161 : :
162 [ + - ]: 877 : return NULL;
163 : : }
164 : :
165 : : //........................................................................
166 : : } // namespace comphelper
167 : : //........................................................................
168 : :
169 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|