Bump version to 21.06.18.1
[LibreOffice.git] / ucb / source / core / provprox.cxx
blob2352aebf8e9a433e99bf591f92dc5bdd68939f05
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 <tools/diagnose_ex.h>
24 #include "provprox.hxx"
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <cppuhelper/weak.hxx>
29 #include <ucbhelper/macros.hxx>
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::ucb;
33 using namespace com::sun::star::uno;
35 // UcbContentProviderProxyFactory Implementation.
38 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
39 const Reference< XComponentContext >& rxContext )
40 : UcbContentProviderProxyFactory_Base(m_aMutex), m_xContext( rxContext )
45 // virtual
46 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
50 // XServiceInfo methods.
52 OUString SAL_CALL UcbContentProviderProxyFactory::getImplementationName()
54 return "com.sun.star.comp.ucb.UcbContentProviderProxyFactory";
56 sal_Bool SAL_CALL UcbContentProviderProxyFactory::supportsService( const OUString& ServiceName )
58 return cppu::supportsService( this, ServiceName );
60 css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxyFactory::getSupportedServiceNames()
62 return { "com.sun.star.ucb.ContentProviderProxyFactory" };
65 // Service factory implementation.
68 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
69 ucb_UcbContentProviderProxyFactory_get_implementation(
70 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
72 return cppu::acquire(
73 static_cast<cppu::OWeakObject*>(new UcbContentProviderProxyFactory(context)));
77 // XContentProviderFactory methods.
80 // virtual
81 Reference< XContentProvider > SAL_CALL
82 UcbContentProviderProxyFactory::createContentProvider(
83 const OUString& Service )
85 return Reference< XContentProvider >(
86 new UcbContentProviderProxy( m_xContext, Service ) );
90 // UcbContentProviderProxy Implementation.
93 UcbContentProviderProxy::UcbContentProviderProxy(
94 const Reference< XComponentContext >& rxContext,
95 const OUString& Service )
96 : m_aService( Service ),
97 m_bReplace( false ),
98 m_bRegister( false ),
99 m_xContext( rxContext )
104 // virtual
105 UcbContentProviderProxy::~UcbContentProviderProxy()
110 // XInterface methods.
111 void SAL_CALL UcbContentProviderProxy::acquire()
112 throw()
114 OWeakObject::acquire();
117 void SAL_CALL UcbContentProviderProxy::release()
118 throw()
120 OWeakObject::release();
123 // virtual
124 Any SAL_CALL
125 UcbContentProviderProxy::queryInterface( const Type & rType )
127 Any aRet = cppu::queryInterface( rType,
128 static_cast< XTypeProvider * >( this ),
129 static_cast< XServiceInfo * >( this ),
130 static_cast< XContentProvider * >( this ),
131 static_cast< XParameterizedContentProvider * >( this ),
132 static_cast< XContentProviderSupplier * >( this ) );
134 if ( !aRet.hasValue() )
135 aRet = OWeakObject::queryInterface( rType );
137 if ( !aRet.hasValue() )
139 // Get original provider and forward the call...
140 osl::Guard< osl::Mutex > aGuard( m_aMutex );
141 Reference< XContentProvider > xProvider = getContentProvider();
142 if ( xProvider.is() )
143 aRet = xProvider->queryInterface( rType );
146 return aRet;
150 // XTypeProvider methods.
153 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
156 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes()
158 // Get original provider and forward the call...
159 osl::Guard< osl::Mutex > aGuard( m_aMutex );
160 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
161 if ( xProvider.is() )
163 return xProvider->getTypes();
165 else
167 static cppu::OTypeCollection s_aCollection(
168 CPPU_TYPE_REF( XTypeProvider ),
169 CPPU_TYPE_REF( XServiceInfo ),
170 CPPU_TYPE_REF( XContentProvider ),
171 CPPU_TYPE_REF( XParameterizedContentProvider ),
172 CPPU_TYPE_REF( XContentProviderSupplier ) );
173 return s_aCollection.getTypes();
178 // XServiceInfo methods.
180 OUString SAL_CALL UcbContentProviderProxy::getImplementationName()
182 return "com.sun.star.comp.ucb.UcbContentProviderProxy";
185 sal_Bool SAL_CALL UcbContentProviderProxy::supportsService( const OUString& ServiceName )
187 return cppu::supportsService( this, ServiceName );
190 css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxy::getSupportedServiceNames()
192 return { "com.sun.star.ucb.ContentProviderProxy" };
196 // XContentProvider methods.
199 // virtual
200 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
201 const Reference< XContentIdentifier >& Identifier )
203 // Get original provider and forward the call...
205 osl::Guard< osl::Mutex > aGuard( m_aMutex );
207 Reference< XContentProvider > xProvider = getContentProvider();
208 if ( xProvider.is() )
209 return xProvider->queryContent( Identifier );
211 return Reference< XContent >();
215 // virtual
216 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
217 const Reference< XContentIdentifier >& Id1,
218 const Reference< XContentIdentifier >& Id2 )
220 // Get original provider and forward the call...
222 osl::Guard< osl::Mutex > aGuard( m_aMutex );
223 Reference< XContentProvider > xProvider = getContentProvider();
224 if ( xProvider.is() )
225 return xProvider->compareContentIds( Id1, Id2 );
227 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
229 // @@@ What else?
230 return 0;
234 // XParameterizedContentProvider methods.
237 // virtual
238 Reference< XContentProvider > SAL_CALL
239 UcbContentProviderProxy::registerInstance( const OUString& Template,
240 const OUString& Arguments,
241 sal_Bool ReplaceExisting )
243 // Just remember that this method was called ( and the params ).
245 osl::Guard< osl::Mutex > aGuard( m_aMutex );
247 if ( !m_bRegister )
249 // m_xTargetProvider = 0;
250 m_aTemplate = Template;
251 m_aArguments = Arguments;
252 m_bReplace = ReplaceExisting;
254 m_bRegister = true;
256 return this;
260 // virtual
261 Reference< XContentProvider > SAL_CALL
262 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
263 const OUString& Arguments )
265 osl::Guard< osl::Mutex > aGuard( m_aMutex );
267 // registerInstance called at proxy and at original?
268 if ( m_bRegister && m_xTargetProvider.is() )
270 m_bRegister = false;
271 m_xTargetProvider = nullptr;
273 Reference< XParameterizedContentProvider >
274 xParamProvider( m_xProvider, UNO_QUERY );
275 if ( xParamProvider.is() )
279 xParamProvider->deregisterInstance( Template, Arguments );
281 catch ( IllegalIdentifierException const & )
283 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
284 "Caught IllegalIdentifierException!" );
289 return this;
293 // XContentProviderSupplier methods.
296 // virtual
297 Reference< XContentProvider > SAL_CALL
298 UcbContentProviderProxy::getContentProvider()
300 osl::Guard< osl::Mutex > aGuard( m_aMutex );
301 if ( !m_xProvider.is() )
305 m_xProvider.set( m_xContext->getServiceManager()->createInstanceWithContext( m_aService,m_xContext ), UNO_QUERY );
306 if ( m_aArguments == "NoConfig" )
308 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
309 if(xInit.is()) {
310 Sequence<Any> aArgs(1);
311 aArgs[0] <<= m_aArguments;
312 xInit->initialize(aArgs);
316 catch ( RuntimeException const & )
318 throw;
320 catch ( Exception const & )
322 TOOLS_INFO_EXCEPTION( "ucb.core", "Exception getting content provider");
325 // registerInstance called at proxy, but not yet at original?
326 if ( m_xProvider.is() && m_bRegister )
328 Reference< XParameterizedContentProvider >
329 xParamProvider( m_xProvider, UNO_QUERY );
330 if ( xParamProvider.is() )
334 m_xTargetProvider
335 = xParamProvider->registerInstance( m_aTemplate,
336 m_aArguments,
337 m_bReplace );
339 catch ( IllegalIdentifierException const & )
341 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
342 "Caught IllegalIdentifierException!" );
345 OSL_ENSURE( m_xTargetProvider.is(),
346 "UcbContentProviderProxy::getContentProvider - "
347 "No provider!" );
350 if ( !m_xTargetProvider.is() )
351 m_xTargetProvider = m_xProvider;
354 OSL_ENSURE( m_xProvider.is(),
355 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
356 return m_xTargetProvider;
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */