LibreOffice Module ucbhelper (master) 1
resultsethelper.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
21/* TODO
22 - This implementation is far away from completion. It has no interface
23 for changes notifications etc.
24 */
25
26#include <com/sun/star/ucb/ListActionType.hpp>
27#include <com/sun/star/ucb/ListenerAlreadySetException.hpp>
28#include <com/sun/star/ucb/ServiceNotFoundException.hpp>
29#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp>
30#include <com/sun/star/ucb/CachedDynamicResultSetStubFactory.hpp>
31#include <com/sun/star/ucb/XSourceInitialization.hpp>
34#include <utility>
35
36#include <osl/diagnose.h>
37
38using namespace com::sun::star;
39
40
41// ResultSetImplHelper Implementation.
42
43
44namespace ucbhelper {
45
46
48 uno::Reference< uno::XComponentContext > xContext,
49 css::ucb::OpenCommandArgument2 aCommand )
50: m_bStatic( false ),
51 m_bInitDone( false ),
52 m_aCommand(std::move( aCommand )),
53 m_xContext(std::move( xContext ))
54{
55}
56
57
58// virtual
60{
61}
62
63
64// XServiceInfo methods.
65
67{
68 return "ResultSetImplHelper";
69}
70
71sal_Bool SAL_CALL ResultSetImplHelper::supportsService( const OUString& ServiceName )
72{
73 return cppu::supportsService( this, ServiceName );
74}
75
76css::uno::Sequence< OUString > SAL_CALL ResultSetImplHelper::getSupportedServiceNames()
77{
79}
80
81// XComponent methods.
82
83
84// virtual
86{
87 std::unique_lock aGuard( m_aMutex );
88
90 {
91 lang::EventObject aEvt;
92 aEvt.Source = static_cast< lang::XComponent * >( this );
94 }
95}
96
97
98// virtual
100 const uno::Reference< lang::XEventListener >& Listener )
101{
102 std::unique_lock aGuard( m_aMutex );
103
104 m_aDisposeEventListeners.addInterface( aGuard, Listener );
105}
106
107
108// virtual
110 const uno::Reference< lang::XEventListener >& Listener )
111{
112 std::unique_lock aGuard( m_aMutex );
113
114 m_aDisposeEventListeners.removeInterface( aGuard, Listener );
115}
116
117
118// XDynamicResultSet methods.
119
120
121// virtual
122uno::Reference< sdbc::XResultSet > SAL_CALL
124{
125 std::unique_lock aGuard( m_aMutex );
126
127 if ( m_xListener.is() )
128 throw css::ucb::ListenerAlreadySetException();
129
130 init( true );
131 return m_xResultSet1;
132}
133
134
135// virtual
137 const uno::Reference< css::ucb::XDynamicResultSetListener >& Listener )
138{
139 std::unique_lock aGuard( m_aMutex );
140
141 if ( m_bStatic || m_xListener.is() )
142 throw css::ucb::ListenerAlreadySetException();
143
144 m_xListener = Listener;
145
146
147 // Create "welcome event" and send it to listener.
148
149
150 // Note: We only have the implementation for a static result set at the
151 // moment (src590). The dynamic result sets passed to the listener
152 // are a fake. This implementation will never call "notify" at the
153 // listener to propagate any changes!!!
154
155 init( false );
156
157 uno::Any aInfo;
158 aInfo <<= css::ucb::WelcomeDynamicResultSetStruct(
159 m_xResultSet1 /* "old" */,
160 m_xResultSet2 /* "new" */ );
161
162 uno::Sequence< css::ucb::ListAction > aActions {
163 css::ucb::ListAction(
164 0, // Position; not used
165 0, // Count; not used
166 css::ucb::ListActionType::WELCOME,
167 aInfo ) };
168 aGuard.unlock();
169
170 Listener->notify(
171 css::ucb::ListEvent(
172 getXWeak(), aActions ) );
173}
174
175
176// virtual
178{
179 // ! css::ucb::ContentResultSetCapability::SORTED
180 return 0;
181}
182
183
184// virtual
186 const uno::Reference< css::ucb::XDynamicResultSet > & xCache )
187{
188 if ( m_xListener.is() )
189 throw css::ucb::ListenerAlreadySetException();
190
191 if ( m_bStatic )
192 throw css::ucb::ListenerAlreadySetException();
193
194 uno::Reference< css::ucb::XSourceInitialization > xTarget( xCache, uno::UNO_QUERY );
195 if ( xTarget.is() )
196 {
197 uno::Reference< css::ucb::XCachedDynamicResultSetStubFactory > xStubFactory;
198 try
199 {
200 xStubFactory
201 = css::ucb::CachedDynamicResultSetStubFactory::create(
202 m_xContext );
203 }
204 catch ( uno::Exception const & )
205 {
206 }
207
208 if ( xStubFactory.is() )
209 {
210 xStubFactory->connectToCache(
211 this, xCache, m_aCommand.SortingInfo, nullptr );
212 return;
213 }
214 }
215 throw css::ucb::ServiceNotFoundException();
216}
217
218
219// Non-interface methods.
220
221
222void ResultSetImplHelper::init( bool bStatic )
223{
224 if ( m_bInitDone )
225 return;
226
227 if ( bStatic )
228 {
229 // virtual... derived class fills m_xResultSet1
230 initStatic();
231
232 OSL_ENSURE( m_xResultSet1.is(),
233 "ResultSetImplHelper::init - No 1st result set!" );
234 m_bStatic = true;
235 }
236 else
237 {
238 // virtual... derived class fills m_xResultSet1 and m_xResultSet2
239 initDynamic();
240
241 OSL_ENSURE( m_xResultSet1.is(),
242 "ResultSetImplHelper::init - No 1st result set!" );
243 OSL_ENSURE( m_xResultSet2.is(),
244 "ResultSetImplHelper::init - No 2nd result set!" );
245 m_bStatic = false;
246 }
247 m_bInitDone = true;
248}
249
250} // namespace ucbhelper
251
252/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 getLength(std::unique_lock< std::mutex > &rGuard) const
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual UCBHELPER_DLLPRIVATE void initStatic()=0
Your implementation of this method has to fill the protected member m_xResultSet1.
css::ucb::OpenCommandArgument2 m_aCommand
virtual UCBHELPER_DLLPRIVATE void initDynamic()=0
Your implementation of this method has to fill the protected members m_xResultSet1 and m_xResultSet2 ...
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
UCBHELPER_DLLPRIVATE void init(bool bStatic)
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aDisposeEventListeners
virtual void SAL_CALL dispose() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
virtual ~ResultSetImplHelper() override
Destructor.
virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getStaticResultSet() override
virtual void SAL_CALL setListener(const css::uno::Reference< css::ucb::XDynamicResultSetListener > &Listener) override
css::uno::Reference< css::ucb::XDynamicResultSetListener > m_xListener
virtual void SAL_CALL connectToCache(const css::uno::Reference< css::ucb::XDynamicResultSet > &xCache) override
ResultSetImplHelper(css::uno::Reference< css::uno::XComponentContext > xContext, css::ucb::OpenCommandArgument2 aCommand)
Constructor.
virtual sal_Int16 SAL_CALL getCapabilities() override
The implementation of this method always returns 0.
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet2
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet1
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Reference< XInterface > xTarget
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral DYNAMICRESULTSET_SERVICE_NAME
OUString aCommand
unsigned char sal_Bool