Stop leaking all ScPostIt instances.
[LibreOffice.git] / ucb / source / core / provprox.cxx
blobbae3f77b23c577343a714f80f0aed14e6ccb827f
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 <osl/diagnose.h>
21 #include <osl/thread.h>
22 #include <rtl/strbuf.hxx>
23 #include "provprox.hxx"
24 #include <com/sun/star/lang/XInitialization.hpp>
26 using namespace com::sun::star::lang;
27 using namespace com::sun::star::ucb;
28 using namespace com::sun::star::uno;
31 //=========================================================================
32 //=========================================================================
34 // UcbContentProviderProxyFactory Implementation.
36 //=========================================================================
37 //=========================================================================
39 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
40 const Reference< XMultiServiceFactory >& rxSMgr )
41 : m_xSMgr( rxSMgr )
45 //=========================================================================
46 // virtual
47 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
51 //=========================================================================
53 // XInterface methods.
55 //=========================================================================
57 XINTERFACE_IMPL_3( UcbContentProviderProxyFactory,
58 XTypeProvider,
59 XServiceInfo,
60 XContentProviderFactory );
62 //=========================================================================
64 // XTypeProvider methods.
66 //=========================================================================
68 XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory,
69 XTypeProvider,
70 XServiceInfo,
71 XContentProviderFactory );
73 //=========================================================================
75 // XServiceInfo methods.
77 //=========================================================================
79 XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
80 OUString( "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
81 OUString( PROVIDER_FACTORY_SERVICE_NAME ) );
83 //=========================================================================
85 // Service factory implementation.
87 //=========================================================================
89 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
91 //=========================================================================
93 // XContentProviderFactory methods.
95 //=========================================================================
97 // virtual
98 Reference< XContentProvider > SAL_CALL
99 UcbContentProviderProxyFactory::createContentProvider(
100 const OUString& Service )
101 throw( RuntimeException )
103 return Reference< XContentProvider >(
104 new UcbContentProviderProxy( m_xSMgr, Service ) );
107 //=========================================================================
108 //=========================================================================
110 // UcbContentProviderProxy Implementation.
112 //=========================================================================
113 //=========================================================================
115 UcbContentProviderProxy::UcbContentProviderProxy(
116 const Reference< XMultiServiceFactory >& rxSMgr,
117 const OUString& Service )
118 : m_aService( Service ),
119 m_bReplace( sal_False ),
120 m_bRegister( sal_False ),
121 m_xSMgr( rxSMgr )
125 //=========================================================================
126 // virtual
127 UcbContentProviderProxy::~UcbContentProviderProxy()
131 //=========================================================================
133 // XInterface methods.
135 //=========================================================================
137 XINTERFACE_COMMON_IMPL( UcbContentProviderProxy );
139 //============================================================================
140 // virtual
141 Any SAL_CALL
142 UcbContentProviderProxy::queryInterface( const Type & rType )
143 throw ( RuntimeException )
145 Any aRet = cppu::queryInterface( rType,
146 static_cast< XTypeProvider * >( this ),
147 static_cast< XServiceInfo * >( this ),
148 static_cast< XContentProvider * >( this ),
149 static_cast< XParameterizedContentProvider * >( this ),
150 static_cast< XContentProviderSupplier * >( this ) );
152 if ( !aRet.hasValue() )
153 aRet = OWeakObject::queryInterface( rType );
155 if ( !aRet.hasValue() )
157 // Get original provider an forward the call...
158 osl::Guard< osl::Mutex > aGuard( m_aMutex );
159 Reference< XContentProvider > xProvider = getContentProvider();
160 if ( xProvider.is() )
161 aRet = xProvider->queryInterface( rType );
164 return aRet;
167 //=========================================================================
169 // XTypeProvider methods.
171 //=========================================================================
173 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
175 //=========================================================================
177 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes() \
178 throw( RuntimeException )
180 // Get original provider an forward the call...
181 osl::Guard< osl::Mutex > aGuard( m_aMutex );
182 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
183 if ( xProvider.is() )
185 return xProvider->getTypes();
187 else
189 static cppu::OTypeCollection collection(
190 CPPU_TYPE_REF( XTypeProvider ),
191 CPPU_TYPE_REF( XServiceInfo ),
192 CPPU_TYPE_REF( XContentProvider ),
193 CPPU_TYPE_REF( XParameterizedContentProvider ),
194 CPPU_TYPE_REF( XContentProviderSupplier ) );
195 return collection.getTypes();
199 //=========================================================================
201 // XServiceInfo methods.
203 //=========================================================================
205 XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
206 OUString( "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
207 OUString( PROVIDER_PROXY_SERVICE_NAME ) );
209 //=========================================================================
211 // XContentProvider methods.
213 //=========================================================================
215 // virtual
216 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
217 const Reference< XContentIdentifier >& Identifier )
218 throw( IllegalIdentifierException,
219 RuntimeException )
221 // Get original provider an forward the call...
223 osl::Guard< osl::Mutex > aGuard( m_aMutex );
225 Reference< XContentProvider > xProvider = getContentProvider();
226 if ( xProvider.is() )
227 return xProvider->queryContent( Identifier );
229 return Reference< XContent >();
232 //=========================================================================
233 // virtual
234 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
235 const Reference< XContentIdentifier >& Id1,
236 const Reference< XContentIdentifier >& Id2 )
237 throw( RuntimeException )
239 // Get original provider an forward the call...
241 osl::Guard< osl::Mutex > aGuard( m_aMutex );
242 Reference< XContentProvider > xProvider = getContentProvider();
243 if ( xProvider.is() )
244 return xProvider->compareContentIds( Id1, Id2 );
246 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
248 // @@@ What else?
249 return 0;
252 //=========================================================================
254 // XParameterizedContentProvider methods.
256 //=========================================================================
258 // virtual
259 Reference< XContentProvider > SAL_CALL
260 UcbContentProviderProxy::registerInstance( const OUString& Template,
261 const OUString& Arguments,
262 sal_Bool ReplaceExisting )
263 throw( IllegalArgumentException,
264 RuntimeException )
266 // Just remember that this method was called ( and the params ).
268 osl::Guard< osl::Mutex > aGuard( m_aMutex );
270 if ( !m_bRegister )
272 // m_xTargetProvider = 0;
273 m_aTemplate = Template;
274 m_aArguments = Arguments;
275 m_bReplace = ReplaceExisting;
277 m_bRegister = sal_True;
279 return this;
282 //=========================================================================
283 // virtual
284 Reference< XContentProvider > SAL_CALL
285 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
286 const OUString& Arguments )
287 throw( IllegalArgumentException,
288 RuntimeException )
290 osl::Guard< osl::Mutex > aGuard( m_aMutex );
292 // registerInstance called at proxy and at original?
293 if ( m_bRegister && m_xTargetProvider.is() )
295 m_bRegister = sal_False;
296 m_xTargetProvider = 0;
298 Reference< XParameterizedContentProvider >
299 xParamProvider( m_xProvider, UNO_QUERY );
300 if ( xParamProvider.is() )
304 xParamProvider->deregisterInstance( Template, Arguments );
306 catch ( IllegalIdentifierException const & )
308 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
309 "Caught IllegalIdentifierException!" );
314 return this;
317 //=========================================================================
319 // XContentProviderSupplier methods.
321 //=========================================================================
323 // virtual
324 Reference< XContentProvider > SAL_CALL
325 UcbContentProviderProxy::getContentProvider()
326 throw( RuntimeException )
328 osl::Guard< osl::Mutex > aGuard( m_aMutex );
329 if ( !m_xProvider.is() )
333 m_xProvider
334 = Reference< XContentProvider >(
335 m_xSMgr->createInstance( m_aService ), UNO_QUERY );
336 if ( m_aArguments == "NoConfig" )
338 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
339 if(xInit.is()) {
340 Sequence<Any> aArgs(1);
341 aArgs[0] <<= m_aArguments;
342 xInit->initialize(aArgs);
346 catch ( RuntimeException const & )
348 throw;
350 catch ( Exception const & e)
352 SAL_INFO( "ucb.core", "Exception when getting content provider: " << e.Message );
355 // registerInstance called at proxy, but not yet at original?
356 if ( m_xProvider.is() && m_bRegister )
358 Reference< XParameterizedContentProvider >
359 xParamProvider( m_xProvider, UNO_QUERY );
360 if ( xParamProvider.is() )
364 m_xTargetProvider
365 = xParamProvider->registerInstance( m_aTemplate,
366 m_aArguments,
367 m_bReplace );
369 catch ( IllegalIdentifierException const & )
371 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
372 "Caught IllegalIdentifierException!" );
375 OSL_ENSURE( m_xTargetProvider.is(),
376 "UcbContentProviderProxy::getContentProvider - "
377 "No provider!" );
380 if ( !m_xTargetProvider.is() )
381 m_xTargetProvider = m_xProvider;
384 OSL_ENSURE( m_xProvider.is(),
385 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
386 return m_xTargetProvider;
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */