Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / ucb / source / core / provprox.cxx
blob252fdaa2277df3bf7357e904d636c8d4c9f32ee9
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 <ucbhelper/macros.hxx>
30 using namespace com::sun::star::lang;
31 using namespace com::sun::star::ucb;
32 using namespace com::sun::star::uno;
35 // UcbContentProviderProxyFactory Implementation.
38 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
39 const Reference< XMultiServiceFactory >& rxSMgr )
40 : m_xSMgr( rxSMgr )
45 // virtual
46 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
50 // XServiceInfo methods.
52 XSERVICEINFO_COMMOM_IMPL( UcbContentProviderProxyFactory,
53 "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" )
54 /// @throws css::uno::Exception
55 static css::uno::Reference< css::uno::XInterface >
56 UcbContentProviderProxyFactory_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
58 return static_cast<css::lang::XServiceInfo*>(new UcbContentProviderProxyFactory(rSMgr));
60 css::uno::Sequence< OUString >
61 UcbContentProviderProxyFactory::getSupportedServiceNames_Static()
63 return { "com.sun.star.ucb.ContentProviderProxyFactory" };
66 // Service factory implementation.
69 ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
72 // XContentProviderFactory methods.
75 // virtual
76 Reference< XContentProvider > SAL_CALL
77 UcbContentProviderProxyFactory::createContentProvider(
78 const OUString& Service )
80 return Reference< XContentProvider >(
81 new UcbContentProviderProxy( m_xSMgr, Service ) );
85 // UcbContentProviderProxy Implementation.
88 UcbContentProviderProxy::UcbContentProviderProxy(
89 const Reference< XMultiServiceFactory >& rxSMgr,
90 const OUString& Service )
91 : m_aService( Service ),
92 m_bReplace( false ),
93 m_bRegister( false ),
94 m_xSMgr( rxSMgr )
99 // virtual
100 UcbContentProviderProxy::~UcbContentProviderProxy()
105 // XInterface methods.
106 void SAL_CALL UcbContentProviderProxy::acquire()
107 throw()
109 OWeakObject::acquire();
112 void SAL_CALL UcbContentProviderProxy::release()
113 throw()
115 OWeakObject::release();
118 // virtual
119 Any SAL_CALL
120 UcbContentProviderProxy::queryInterface( const Type & rType )
122 Any aRet = cppu::queryInterface( rType,
123 static_cast< XTypeProvider * >( this ),
124 static_cast< XServiceInfo * >( this ),
125 static_cast< XContentProvider * >( this ),
126 static_cast< XParameterizedContentProvider * >( this ),
127 static_cast< XContentProviderSupplier * >( this ) );
129 if ( !aRet.hasValue() )
130 aRet = OWeakObject::queryInterface( rType );
132 if ( !aRet.hasValue() )
134 // Get original provider and forward the call...
135 osl::Guard< osl::Mutex > aGuard( m_aMutex );
136 Reference< XContentProvider > xProvider = getContentProvider();
137 if ( xProvider.is() )
138 aRet = xProvider->queryInterface( rType );
141 return aRet;
145 // XTypeProvider methods.
148 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
151 Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes()
153 // Get original provider and forward the call...
154 osl::Guard< osl::Mutex > aGuard( m_aMutex );
155 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
156 if ( xProvider.is() )
158 return xProvider->getTypes();
160 else
162 static cppu::OTypeCollection s_aCollection(
163 CPPU_TYPE_REF( XTypeProvider ),
164 CPPU_TYPE_REF( XServiceInfo ),
165 CPPU_TYPE_REF( XContentProvider ),
166 CPPU_TYPE_REF( XParameterizedContentProvider ),
167 CPPU_TYPE_REF( XContentProviderSupplier ) );
168 return s_aCollection.getTypes();
173 // XServiceInfo methods.
175 OUString SAL_CALL UcbContentProviderProxy::getImplementationName()
177 return "com.sun.star.comp.ucb.UcbContentProviderProxy";
180 sal_Bool SAL_CALL UcbContentProviderProxy::supportsService( const OUString& ServiceName )
182 return cppu::supportsService( this, ServiceName );
185 css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxy::getSupportedServiceNames()
187 return { "com.sun.star.ucb.ContentProviderProxy" };
191 // XContentProvider methods.
194 // virtual
195 Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
196 const Reference< XContentIdentifier >& Identifier )
198 // Get original provider and forward the call...
200 osl::Guard< osl::Mutex > aGuard( m_aMutex );
202 Reference< XContentProvider > xProvider = getContentProvider();
203 if ( xProvider.is() )
204 return xProvider->queryContent( Identifier );
206 return Reference< XContent >();
210 // virtual
211 sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
212 const Reference< XContentIdentifier >& Id1,
213 const Reference< XContentIdentifier >& Id2 )
215 // Get original provider and forward the call...
217 osl::Guard< osl::Mutex > aGuard( m_aMutex );
218 Reference< XContentProvider > xProvider = getContentProvider();
219 if ( xProvider.is() )
220 return xProvider->compareContentIds( Id1, Id2 );
222 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
224 // @@@ What else?
225 return 0;
229 // XParameterizedContentProvider methods.
232 // virtual
233 Reference< XContentProvider > SAL_CALL
234 UcbContentProviderProxy::registerInstance( const OUString& Template,
235 const OUString& Arguments,
236 sal_Bool ReplaceExisting )
238 // Just remember that this method was called ( and the params ).
240 osl::Guard< osl::Mutex > aGuard( m_aMutex );
242 if ( !m_bRegister )
244 // m_xTargetProvider = 0;
245 m_aTemplate = Template;
246 m_aArguments = Arguments;
247 m_bReplace = ReplaceExisting;
249 m_bRegister = true;
251 return this;
255 // virtual
256 Reference< XContentProvider > SAL_CALL
257 UcbContentProviderProxy::deregisterInstance( const OUString& Template,
258 const OUString& Arguments )
260 osl::Guard< osl::Mutex > aGuard( m_aMutex );
262 // registerInstance called at proxy and at original?
263 if ( m_bRegister && m_xTargetProvider.is() )
265 m_bRegister = false;
266 m_xTargetProvider = nullptr;
268 Reference< XParameterizedContentProvider >
269 xParamProvider( m_xProvider, UNO_QUERY );
270 if ( xParamProvider.is() )
274 xParamProvider->deregisterInstance( Template, Arguments );
276 catch ( IllegalIdentifierException const & )
278 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
279 "Caught IllegalIdentifierException!" );
284 return this;
288 // XContentProviderSupplier methods.
291 // virtual
292 Reference< XContentProvider > SAL_CALL
293 UcbContentProviderProxy::getContentProvider()
295 osl::Guard< osl::Mutex > aGuard( m_aMutex );
296 if ( !m_xProvider.is() )
300 m_xProvider.set( m_xSMgr->createInstance( m_aService ), UNO_QUERY );
301 if ( m_aArguments == "NoConfig" )
303 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
304 if(xInit.is()) {
305 Sequence<Any> aArgs(1);
306 aArgs[0] <<= m_aArguments;
307 xInit->initialize(aArgs);
311 catch ( RuntimeException const & )
313 throw;
315 catch ( Exception const & )
317 TOOLS_INFO_EXCEPTION( "ucb.core", "Exception getting content provider");
320 // registerInstance called at proxy, but not yet at original?
321 if ( m_xProvider.is() && m_bRegister )
323 Reference< XParameterizedContentProvider >
324 xParamProvider( m_xProvider, UNO_QUERY );
325 if ( xParamProvider.is() )
329 m_xTargetProvider
330 = xParamProvider->registerInstance( m_aTemplate,
331 m_aArguments,
332 m_bReplace );
334 catch ( IllegalIdentifierException const & )
336 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
337 "Caught IllegalIdentifierException!" );
340 OSL_ENSURE( m_xTargetProvider.is(),
341 "UcbContentProviderProxy::getContentProvider - "
342 "No provider!" );
345 if ( !m_xTargetProvider.is() )
346 m_xTargetProvider = m_xProvider;
349 OSL_ENSURE( m_xProvider.is(),
350 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
351 return m_xTargetProvider;
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */