cid#1607171 Data race condition
[LibreOffice.git] / ucb / source / cacher / dynamicresultsetwrapper.hxx
blobce4438b5cb4359b744bda7dca83d54b42bc439de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <mutex>
23 #include <osl/conditn.hxx>
24 #include <cppuhelper/weak.hxx>
25 #include <comphelper/interfacecontainer4.hxx>
26 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
27 #include <com/sun/star/ucb/XSourceInitialization.hpp>
28 #include <com/sun/star/ucb/XDynamicResultSetListener.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <rtl/ref.hxx>
32 #include <memory>
34 class DynamicResultSetWrapperListener;
35 class DynamicResultSetWrapper
36 : public cppu::OWeakObject
37 , public css::ucb::XDynamicResultSet
38 , public css::ucb::XSourceInitialization
40 private:
41 //management of listeners
42 bool m_bDisposed; ///Dispose call ready.
43 bool m_bInDispose;///In dispose call
44 comphelper::OInterfaceContainerHelper4<css::lang::XEventListener>
45 m_aDisposeEventListeners;
46 protected:
47 rtl::Reference<DynamicResultSetWrapperListener>
48 m_xMyListenerImpl;
50 css::uno::Reference< css::uno::XComponentContext >
51 m_xContext;
53 std::mutex m_aMutex;
54 bool m_bStatic;
55 bool m_bGotWelcome;
57 //different Interfaces from Origin:
58 css::uno::Reference< css::ucb::XDynamicResultSet >
59 m_xSource;
60 css::uno::Reference< css::sdbc::XResultSet >
61 m_xSourceResultOne;
62 css::uno::Reference< css::sdbc::XResultSet >
63 m_xSourceResultTwo;
65 css::uno::Reference< css::sdbc::XResultSet >
66 m_xMyResultOne;
67 css::uno::Reference< css::sdbc::XResultSet >
68 m_xMyResultTwo;
70 css::uno::Reference< css::ucb::XDynamicResultSetListener >
71 m_xListener;
73 osl::Condition m_aSourceSet;
74 osl::Condition m_aListenerSet;
76 protected:
77 void impl_init();
78 void impl_deinit();
79 /// @throws css::lang::DisposedException
80 /// @throws css::uno::RuntimeException
81 void
82 impl_EnsureNotDisposed(std::unique_lock<std::mutex>& rGuard);
84 virtual void
85 impl_InitResultSetOne( std::unique_lock<std::mutex>& rGuard, const css::uno::Reference<
86 css::sdbc::XResultSet >& xResultSet );
87 virtual void
88 impl_InitResultSetTwo( std::unique_lock<std::mutex>& rGuard, const css::uno::Reference<
89 css::sdbc::XResultSet >& xResultSet );
91 public:
93 DynamicResultSetWrapper(
94 css::uno::Reference< css::ucb::XDynamicResultSet > const & xOrigin
95 , const css::uno::Reference< css::uno::XComponentContext > & rxContext );
97 virtual ~DynamicResultSetWrapper() override;
100 // XInterface
101 virtual css::uno::Any SAL_CALL
102 queryInterface( const css::uno::Type & rType ) override;
105 // XDynamicResultSet
106 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
107 getStaticResultSet() override;
109 virtual void SAL_CALL
110 setListener( const css::uno::Reference< css::ucb::XDynamicResultSetListener > & Listener ) override;
112 virtual void SAL_CALL
113 connectToCache( const css::uno::Reference< css::ucb::XDynamicResultSet > & xCache ) override;
115 virtual sal_Int16 SAL_CALL
116 getCapabilities() override;
119 // XComponent ( base of XDynamicResultSet )
120 virtual void SAL_CALL
121 dispose() override;
123 virtual void SAL_CALL
124 addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
126 virtual void SAL_CALL
127 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
130 // XSourceInitialization
132 virtual void SAL_CALL
133 setSource( const css::uno::Reference< css::uno::XInterface > & Source ) override;
136 // own methods:
137 /// @throws css::uno::RuntimeException
138 virtual void
139 impl_disposing( const css::lang::EventObject& Source );
141 /// @throws css::uno::RuntimeException
142 void
143 impl_notify( const css::ucb::ListEvent& Changes );
147 class DynamicResultSetWrapperListener
148 : public cppu::OWeakObject
149 , public css::ucb::XDynamicResultSetListener
151 DynamicResultSetWrapper* m_pOwner;
152 std::mutex m_aMutex;
154 public:
155 DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner );
157 virtual ~DynamicResultSetWrapperListener() override;
160 // XInterface
161 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
162 virtual void SAL_CALL acquire()
163 noexcept override;
164 virtual void SAL_CALL release()
165 noexcept override;
167 // XEventListener ( base of XDynamicResultSetListener )
169 virtual void SAL_CALL
170 disposing( const css::lang::EventObject& Source ) override;
172 // XDynamicResultSetListener
173 virtual void SAL_CALL
174 notify( const css::ucb::ListEvent& Changes ) override;
177 // own methods:
178 void impl_OwnerDies();
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */