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