1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/diagnose_ex.hxx>
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>
32 using namespace com::sun::star::lang
;
33 using namespace com::sun::star::ucb
;
34 using namespace com::sun::star::uno
;
36 // UcbContentProviderProxyFactory Implementation.
39 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
40 const Reference
< XComponentContext
>& rxContext
)
41 : m_xContext( rxContext
)
47 UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
51 // XServiceInfo methods.
53 OUString SAL_CALL
UcbContentProviderProxyFactory::getImplementationName()
55 return "com.sun.star.comp.ucb.UcbContentProviderProxyFactory";
57 sal_Bool SAL_CALL
UcbContentProviderProxyFactory::supportsService( const OUString
& ServiceName
)
59 return cppu::supportsService( this, ServiceName
);
61 css::uno::Sequence
< OUString
> SAL_CALL
UcbContentProviderProxyFactory::getSupportedServiceNames()
63 return { "com.sun.star.ucb.ContentProviderProxyFactory" };
66 // Service factory implementation.
69 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
70 ucb_UcbContentProviderProxyFactory_get_implementation(
71 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
73 return cppu::acquire(new UcbContentProviderProxyFactory(context
));
77 // XContentProviderFactory methods.
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
,
96 : m_aService(std::move( Service
)),
99 m_xContext( rxContext
)
105 UcbContentProviderProxy::~UcbContentProviderProxy()
110 // XInterface methods.
111 void SAL_CALL
UcbContentProviderProxy::acquire()
114 OWeakObject::acquire();
117 void SAL_CALL
UcbContentProviderProxy::release()
120 OWeakObject::release();
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 Reference
< XContentProvider
> xProvider
= getContentProvider();
141 if ( xProvider
.is() )
142 aRet
= xProvider
->queryInterface( rType
);
149 // XTypeProvider methods.
152 XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy
);
155 Sequence
< Type
> SAL_CALL
UcbContentProviderProxy::getTypes()
157 // Get original provider and forward the call...
158 Reference
< XTypeProvider
> xProvider( getContentProvider(), UNO_QUERY
);
159 if ( xProvider
.is() )
161 return xProvider
->getTypes();
165 static cppu::OTypeCollection
s_aCollection(
166 CPPU_TYPE_REF( XTypeProvider
),
167 CPPU_TYPE_REF( XServiceInfo
),
168 CPPU_TYPE_REF( XContentProvider
),
169 CPPU_TYPE_REF( XParameterizedContentProvider
),
170 CPPU_TYPE_REF( XContentProviderSupplier
) );
171 return s_aCollection
.getTypes();
176 // XServiceInfo methods.
178 OUString SAL_CALL
UcbContentProviderProxy::getImplementationName()
180 return "com.sun.star.comp.ucb.UcbContentProviderProxy";
183 sal_Bool SAL_CALL
UcbContentProviderProxy::supportsService( const OUString
& ServiceName
)
185 return cppu::supportsService( this, ServiceName
);
188 css::uno::Sequence
< OUString
> SAL_CALL
UcbContentProviderProxy::getSupportedServiceNames()
190 return { "com.sun.star.ucb.ContentProviderProxy" };
194 // XContentProvider methods.
198 Reference
< XContent
> SAL_CALL
UcbContentProviderProxy::queryContent(
199 const Reference
< XContentIdentifier
>& Identifier
)
201 // Get original provider and forward the call...
203 Reference
< XContentProvider
> xProvider
= getContentProvider();
204 if ( xProvider
.is() )
205 return xProvider
->queryContent( Identifier
);
207 return Reference
< XContent
>();
212 sal_Int32 SAL_CALL
UcbContentProviderProxy::compareContentIds(
213 const Reference
< XContentIdentifier
>& Id1
,
214 const Reference
< XContentIdentifier
>& Id2
)
216 // Get original provider and forward the call...
218 Reference
< XContentProvider
> xProvider
= getContentProvider();
219 if ( xProvider
.is() )
220 return xProvider
->compareContentIds( Id1
, Id2
);
222 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
229 // XParameterizedContentProvider methods.
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 std::scoped_lock
aGuard( m_aMutex
);
244 // m_xTargetProvider = 0;
245 m_aTemplate
= Template
;
246 m_aArguments
= Arguments
;
247 m_bReplace
= ReplaceExisting
;
256 Reference
< XContentProvider
> SAL_CALL
257 UcbContentProviderProxy::deregisterInstance( const OUString
& Template
,
258 const OUString
& Arguments
)
260 std::scoped_lock
aGuard( m_aMutex
);
262 // registerInstance called at proxy and at original?
263 if ( m_bRegister
&& m_xTargetProvider
.is() )
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!" );
288 // XContentProviderSupplier methods.
292 Reference
< XContentProvider
> SAL_CALL
293 UcbContentProviderProxy::getContentProvider()
295 std::scoped_lock
aGuard( m_aMutex
);
296 if ( !m_xProvider
.is() )
300 m_xProvider
.set( m_xContext
->getServiceManager()->createInstanceWithContext( m_aService
,m_xContext
), UNO_QUERY
);
301 if ( m_aArguments
== "NoConfig" )
303 Reference
<XInitialization
> xInit(m_xProvider
,UNO_QUERY
);
305 xInit
->initialize({ Any(m_aArguments
) });
309 catch ( RuntimeException
const & )
313 catch ( Exception
const & )
315 TOOLS_INFO_EXCEPTION( "ucb.core", "Exception getting content provider");
318 // registerInstance called at proxy, but not yet at original?
319 if ( m_xProvider
.is() && m_bRegister
)
321 Reference
< XParameterizedContentProvider
>
322 xParamProvider( m_xProvider
, UNO_QUERY
);
323 if ( xParamProvider
.is() )
328 = xParamProvider
->registerInstance( m_aTemplate
,
332 catch ( IllegalIdentifierException
const & )
334 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
335 "Caught IllegalIdentifierException!" );
338 OSL_ENSURE( m_xTargetProvider
.is(),
339 "UcbContentProviderProxy::getContentProvider - "
343 if ( !m_xTargetProvider
.is() )
344 m_xTargetProvider
= m_xProvider
;
347 OSL_ENSURE( m_xProvider
.is(),
348 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '" +
349 OUStringToOString(m_aService
, osl_getThreadTextEncoding()) +
351 return m_xTargetProvider
;
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */