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 : 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;
40 :
41 : typedef ::std::vector< ComponentDescription > ComponentDescriptions;
42 :
43 :
44 : //= OModuleImpl
45 :
46 : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner
47 : */
48 : class OModuleImpl
49 : {
50 : public:
51 : ComponentDescriptions m_aRegisteredComponents;
52 :
53 : OModuleImpl();
54 : ~OModuleImpl();
55 : };
56 :
57 :
58 0 : OModuleImpl::OModuleImpl()
59 : {
60 0 : }
61 :
62 :
63 0 : OModuleImpl::~OModuleImpl()
64 : {
65 0 : }
66 :
67 :
68 : //= OModule
69 :
70 :
71 0 : OModule::OModule()
72 : : m_nClients(0)
73 0 : , m_pImpl(new OModuleImpl)
74 : {
75 0 : }
76 :
77 0 : OModule::~OModule()
78 : {
79 0 : delete m_pImpl;
80 0 : }
81 :
82 :
83 0 : void OModule::registerClient( OModule::ClientAccess )
84 : {
85 0 : ::osl::MutexGuard aGuard(m_aMutex);
86 0 : if ( 1 == osl_atomic_increment( &m_nClients ) )
87 0 : onFirstClient();
88 0 : }
89 :
90 :
91 0 : void OModule::revokeClient( OModule::ClientAccess )
92 : {
93 0 : ::osl::MutexGuard aGuard(m_aMutex);
94 0 : if ( 0 == osl_atomic_decrement( &m_nClients ) )
95 0 : onLastClient();
96 0 : }
97 :
98 :
99 0 : void OModule::onFirstClient()
100 : {
101 0 : }
102 :
103 :
104 0 : void OModule::onLastClient()
105 : {
106 0 : }
107 :
108 :
109 0 : void OModule::registerImplementation( const ComponentDescription& _rComp )
110 : {
111 0 : ::osl::MutexGuard aGuard( m_aMutex );
112 0 : if ( !m_pImpl )
113 0 : throw RuntimeException();
114 :
115 0 : m_pImpl->m_aRegisteredComponents.push_back( _rComp );
116 0 : }
117 :
118 :
119 0 : void OModule::registerImplementation( const OUString& _rImplementationName, const ::com::sun::star::uno::Sequence< OUString >& _rServiceNames,
120 : ::cppu::ComponentFactoryFunc _pCreateFunction, FactoryInstantiation _pFactoryFunction )
121 : {
122 0 : ComponentDescription aComponent( _rImplementationName, _rServiceNames, OUString(), _pCreateFunction, _pFactoryFunction );
123 0 : registerImplementation( aComponent );
124 0 : }
125 :
126 :
127 0 : void* OModule::getComponentFactory( const sal_Char* _pImplementationName )
128 : {
129 : Reference< XInterface > xFactory( getComponentFactory(
130 0 : OUString::createFromAscii( _pImplementationName ) ) );
131 0 : return xFactory.get();
132 : }
133 :
134 :
135 0 : Reference< XInterface > OModule::getComponentFactory( const OUString& _rImplementationName )
136 : {
137 0 : Reference< XInterface > xReturn;
138 :
139 0 : for ( ComponentDescriptions::const_iterator component = m_pImpl->m_aRegisteredComponents.begin();
140 0 : component != m_pImpl->m_aRegisteredComponents.end();
141 : ++component
142 : )
143 : {
144 0 : if ( component->sImplementationName == _rImplementationName )
145 : {
146 0 : xReturn = component->pFactoryCreationFunc(
147 0 : component->pComponentCreationFunc,
148 0 : component->sImplementationName,
149 0 : component->aSupportedServices,
150 : NULL
151 0 : );
152 0 : if ( xReturn.is() )
153 : {
154 0 : xReturn->acquire();
155 0 : return xReturn.get();
156 : }
157 : }
158 : }
159 :
160 0 : return NULL;
161 : }
162 :
163 :
164 : } // namespace comphelper
165 :
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|