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