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 
70 
71 
72 // XContentProviderFactory methods.
73 
74 
75 // virtual
78  const OUString& Service )
79 {
81  new UcbContentProviderProxy( m_xSMgr, Service ) );
82 }
83 
84 
85 // UcbContentProviderProxy Implementation.
86 
87 
90  const OUString& Service )
91 : m_aService( Service ),
92  m_bReplace( false ),
93  m_bRegister( false ),
94  m_xSMgr( rxSMgr )
95 {
96 }
97 
98 
99 // virtual
101 {
102 }
103 
104 
105 // XInterface methods.
107  throw()
108 {
109  OWeakObject::acquire();
110 }
111 
113  throw()
114 {
115  OWeakObject::release();
116 }
117 
118 // virtual
119 Any SAL_CALL
121 {
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 ) );
128 
129  if ( !aRet.hasValue() )
130  aRet = OWeakObject::queryInterface( rType );
131 
132  if ( !aRet.hasValue() )
133  {
134  // Get original provider and forward the call...
135  osl::Guard< osl::Mutex > aGuard( m_aMutex );
137  if ( xProvider.is() )
138  aRet = xProvider->queryInterface( rType );
139  }
140 
141  return aRet;
142 }
143 
144 
145 // XTypeProvider methods.
146 
147 
149 
150 
152 {
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() )
157  {
158  return xProvider->getTypes();
159  }
160  else
161  {
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();
169  }
170 }
171 
172 
173 // XServiceInfo methods.
174 
176 {
177  return "com.sun.star.comp.ucb.UcbContentProviderProxy";
178 }
179 
180 sal_Bool SAL_CALL UcbContentProviderProxy::supportsService( const OUString& ServiceName )
181 {
182  return cppu::supportsService( this, ServiceName );
183 }
184 
185 css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxy::getSupportedServiceNames()
186 {
187  return { "com.sun.star.ucb.ContentProviderProxy" };
188 }
189 
190 
191 // XContentProvider methods.
192 
193 
194 // virtual
196  const Reference< XContentIdentifier >& Identifier )
197 {
198  // Get original provider and forward the call...
199 
200  osl::Guard< osl::Mutex > aGuard( m_aMutex );
201 
203  if ( xProvider.is() )
204  return xProvider->queryContent( Identifier );
205 
206  return Reference< XContent >();
207 }
208 
209 
210 // virtual
214 {
215  // Get original provider and forward the call...
216 
217  osl::Guard< osl::Mutex > aGuard( m_aMutex );
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  osl::Guard< osl::Mutex > aGuard( m_aMutex );
241 
242  if ( !m_bRegister )
243  {
244 // m_xTargetProvider = 0;
245  m_aTemplate = Template;
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  osl::Guard< osl::Mutex > 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  osl::Guard< osl::Mutex > aGuard( m_aMutex );
296  if ( !m_xProvider.is() )
297  {
298  try
299  {
300  m_xProvider.set( m_xSMgr->createInstance( m_aService ), UNO_QUERY );
301  if ( m_aArguments == "NoConfig" )
302  {
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);
308  }
309  }
310  }
311  catch ( RuntimeException const & )
312  {
313  throw;
314  }
315  catch ( Exception const & )
316  {
317  TOOLS_INFO_EXCEPTION( "ucb.core", "Exception getting content provider");
318  }
319 
320  // registerInstance called at proxy, but not yet at original?
321  if ( m_xProvider.is() && m_bRegister )
322  {
324  xParamProvider( m_xProvider, UNO_QUERY );
325  if ( xParamProvider.is() )
326  {
327  try
328  {
330  = xParamProvider->registerInstance( m_aTemplate,
331  m_aArguments,
332  m_bReplace );
333  }
334  catch ( IllegalIdentifierException const & )
335  {
336  OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
337  "Caught IllegalIdentifierException!" );
338  }
339 
340  OSL_ENSURE( m_xTargetProvider.is(),
341  "UcbContentProviderProxy::getContentProvider - "
342  "No provider!" );
343  }
344  }
345  if ( !m_xTargetProvider.is() )
347  }
348 
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;
352 }
353 
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
css::uno::Reference< css::ucb::XContentProvider > m_xProvider
Definition: provprox.hxx:90
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL getContentProvider() override
Definition: provprox.cxx:293
UcbContentProviderProxy(const css::uno::Reference< css::lang::XMultiServiceFactory > &rxSMgr, const OUString &Service)
Definition: provprox.cxx:88
css::uno::Reference< css::ucb::XContentProvider > m_xTargetProvider
Definition: provprox.hxx:92
virtual ~UcbContentProviderProxy() override
Definition: provprox.cxx:100
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: provprox.cxx:120
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL registerInstance(const OUString &Template, const OUString &Arguments, sal_Bool ReplaceExisting) override
Definition: provprox.cxx:234
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
::osl::Mutex m_aMutex
Definition: provprox.hxx:80
virtual ~UcbContentProviderProxyFactory() override
Definition: provprox.cxx:46
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: provprox.cxx:151
ONE_INSTANCE_SERVICE_FACTORY_IMPL(UcbContentProviderProxyFactory)
unsigned char sal_Bool
css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMgr
Definition: provprox.hxx:88
XTYPEPROVIDER_COMMON_IMPL(UcbContentProviderProxy)
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL createContentProvider(const OUString &Service) override
Definition: provprox.cxx:77
virtual void SAL_CALL acquire() override
Definition: provprox.cxx:106
virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL deregisterInstance(const OUString &Template, const OUString &Arguments) override
Definition: provprox.cxx:257
static css::uno::Sequence< OUString > getSupportedServiceNames_Static()
Definition: provprox.cxx:61
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:195
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:211
#define CPPU_TYPE_REF(T)
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
virtual OUString SAL_CALL getImplementationName() override
Definition: provprox.cxx:175
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: provprox.cxx:180
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:44
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:185
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual void SAL_CALL release() override
Definition: provprox.cxx:112