LibreOffice Module ucb (master) 1
provprox.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
21#include <osl/thread.h>
22#include <rtl/strbuf.hxx>
24#include "provprox.hxx"
25#include <com/sun/star/lang/XInitialization.hpp>
26#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
28#include <cppuhelper/weak.hxx>
29#include <ucbhelper/macros.hxx>
30#include <utility>
31
32using namespace com::sun::star::lang;
33using namespace com::sun::star::ucb;
34using namespace com::sun::star::uno;
35
36// UcbContentProviderProxyFactory Implementation.
37
38
40 const Reference< XComponentContext >& rxContext )
41: m_xContext( rxContext )
42{
43}
44
45
46// virtual
48{
49}
50
51// XServiceInfo methods.
52
54{
55 return "com.sun.star.comp.ucb.UcbContentProviderProxyFactory";
56}
57sal_Bool SAL_CALL UcbContentProviderProxyFactory::supportsService( const OUString& ServiceName )
58{
59 return cppu::supportsService( this, ServiceName );
60}
61css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxyFactory::getSupportedServiceNames()
62{
63 return { "com.sun.star.ucb.ContentProviderProxyFactory" };
64}
65
66// Service factory implementation.
67
68
69extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
71 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
72{
73 return cppu::acquire(new UcbContentProviderProxyFactory(context));
74}
75
76
77// XContentProviderFactory methods.
78
79
80// virtual
83 const OUString& Service )
84{
87}
88
89
90// UcbContentProviderProxy Implementation.
91
92
94 const Reference< XComponentContext >& rxContext,
95 OUString Service )
96: m_aService(std::move( Service )),
97 m_bReplace( false ),
98 m_bRegister( false ),
99 m_xContext( rxContext )
100{
101}
102
103
104// virtual
106{
107}
108
109
110// XInterface methods.
112 noexcept
113{
114 OWeakObject::acquire();
115}
116
118 noexcept
119{
120 OWeakObject::release();
121}
122
123// virtual
124Any SAL_CALL
126{
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 ) );
133
134 if ( !aRet.hasValue() )
135 aRet = OWeakObject::queryInterface( rType );
136
137 if ( !aRet.hasValue() )
138 {
139 // Get original provider and forward the call...
141 if ( xProvider.is() )
142 aRet = xProvider->queryInterface( rType );
143 }
144
145 return aRet;
146}
147
148
149// XTypeProvider methods.
150
151
153
154
156{
157 // Get original provider and forward the call...
158 Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
159 if ( xProvider.is() )
160 {
161 return xProvider->getTypes();
162 }
163 else
164 {
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();
172 }
173}
174
175
176// XServiceInfo methods.
177
179{
180 return "com.sun.star.comp.ucb.UcbContentProviderProxy";
181}
182
183sal_Bool SAL_CALL UcbContentProviderProxy::supportsService( const OUString& ServiceName )
184{
185 return cppu::supportsService( this, ServiceName );
186}
187
188css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxy::getSupportedServiceNames()
189{
190 return { "com.sun.star.ucb.ContentProviderProxy" };
191}
192
193
194// XContentProvider methods.
195
196
197// virtual
199 const Reference< XContentIdentifier >& Identifier )
200{
201 // Get original provider and forward the call...
202
204 if ( xProvider.is() )
205 return xProvider->queryContent( Identifier );
206
207 return Reference< XContent >();
208}
209
210
211// virtual
215{
216 // Get original provider and forward the call...
217
219 if ( xProvider.is() )
220 return xProvider->compareContentIds( Id1, Id2 );
221
222 // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
223
224 // @@@ What else?
225 return 0;
226}
227
228
229// XParameterizedContentProvider methods.
230
231
232// virtual
235 const OUString& Arguments,
236 sal_Bool ReplaceExisting )
237{
238 // Just remember that this method was called ( and the params ).
239
240 std::scoped_lock aGuard( m_aMutex );
241
242 if ( !m_bRegister )
243 {
244// m_xTargetProvider = 0;
246 m_aArguments = Arguments;
247 m_bReplace = ReplaceExisting;
248
249 m_bRegister = true;
250 }
251 return this;
252}
253
254
255// virtual
258 const OUString& Arguments )
259{
260 std::scoped_lock aGuard( m_aMutex );
261
262 // registerInstance called at proxy and at original?
263 if ( m_bRegister && m_xTargetProvider.is() )
264 {
265 m_bRegister = false;
266 m_xTargetProvider = nullptr;
267
269 xParamProvider( m_xProvider, UNO_QUERY );
270 if ( xParamProvider.is() )
271 {
272 try
273 {
274 xParamProvider->deregisterInstance( Template, Arguments );
275 }
276 catch ( IllegalIdentifierException const & )
277 {
278 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
279 "Caught IllegalIdentifierException!" );
280 }
281 }
282 }
283
284 return this;
285}
286
287
288// XContentProviderSupplier methods.
289
290
291// virtual
294{
295 std::scoped_lock aGuard( m_aMutex );
296 if ( !m_xProvider.is() )
297 {
298 try
299 {
300 m_xProvider.set( m_xContext->getServiceManager()->createInstanceWithContext( m_aService,m_xContext ), UNO_QUERY );
301 if ( m_aArguments == "NoConfig" )
302 {
304 if(xInit.is()) {
305 xInit->initialize({ Any(m_aArguments) });
306 }
307 }
308 }
309 catch ( RuntimeException const & )
310 {
311 throw;
312 }
313 catch ( Exception const & )
314 {
315 TOOLS_INFO_EXCEPTION( "ucb.core", "Exception getting content provider");
316 }
317
318 // registerInstance called at proxy, but not yet at original?
319 if ( m_xProvider.is() && m_bRegister )
320 {
322 xParamProvider( m_xProvider, UNO_QUERY );
323 if ( xParamProvider.is() )
324 {
325 try
326 {
328 = xParamProvider->registerInstance( m_aTemplate,
330 m_bReplace );
331 }
332 catch ( IllegalIdentifierException const & )
333 {
334 OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
335 "Caught IllegalIdentifierException!" );
336 }
337
338 OSL_ENSURE( m_xTargetProvider.is(),
339 "UcbContentProviderProxy::getContentProvider - "
340 "No provider!" );
341 }
342 }
343 if ( !m_xTargetProvider.is() )
345 }
346
347 OSL_ENSURE( m_xProvider.is(),
348 OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '" +
349 OUStringToOString(m_aService, osl_getThreadTextEncoding()) +
350 ".").getStr() );
351 return m_xTargetProvider;
352}
353
354/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: provprox.cxx:57
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: provprox.cxx:61
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL createContentProvider(const OUString &Service) override
Definition: provprox.cxx:82
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: provprox.hxx:39
virtual ~UcbContentProviderProxyFactory() override
Definition: provprox.cxx:47
virtual OUString SAL_CALL getImplementationName() override
Definition: provprox.cxx:53
UcbContentProviderProxyFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
Definition: provprox.cxx:39
virtual ~UcbContentProviderProxy() override
Definition: provprox.cxx:105
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: provprox.cxx:125
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: provprox.cxx:183
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: provprox.hxx:75
UcbContentProviderProxy(const css::uno::Reference< css::uno::XComponentContext > &rxContext, OUString Service)
Definition: provprox.cxx:93
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
Definition: provprox.cxx:198
virtual sal_Int32 SAL_CALL compareContentIds(const css::uno::Reference< css::ucb::XContentIdentifier > &Id1, const css::uno::Reference< css::ucb::XContentIdentifier > &Id2) override
Definition: provprox.cxx:212
css::uno::Reference< css::ucb::XContentProvider > m_xProvider
Definition: provprox.hxx:77
virtual OUString SAL_CALL getImplementationName() override
Definition: provprox.cxx:178
virtual void SAL_CALL release() noexcept override
Definition: provprox.cxx:117
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL registerInstance(const OUString &Template, const OUString &Arguments, sal_Bool ReplaceExisting) override
Definition: provprox.cxx:234
css::uno::Reference< css::ucb::XContentProvider > m_xTargetProvider
Definition: provprox.hxx:79
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL deregisterInstance(const OUString &Template, const OUString &Arguments) override
Definition: provprox.cxx:257
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: provprox.cxx:155
virtual void SAL_CALL acquire() noexcept override
Definition: provprox.cxx:111
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL getContentProvider() override
Definition: provprox.cxx:293
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: provprox.cxx:188
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
#define TOOLS_INFO_EXCEPTION(area, stream)
#define CPPU_TYPE_REF(T)
@ Exception
Type
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_UcbContentProviderProxyFactory_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: provprox.cxx:70
XTYPEPROVIDER_COMMON_IMPL(UcbContentProviderProxy)
unsigned char sal_Bool