Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / comphelper / propmultiplex2.hxx
blob5e6fec1571c30922341a531182e4572ab8260352
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 .
19 #pragma once
21 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
22 #include <cppuhelper/implbase.hxx>
23 #include <comphelper/comphelperdllapi.h>
24 #include <rtl/ref.hxx>
25 #include <mutex>
26 #include <vector>
28 namespace com::sun::star::beans
30 class XPropertySet;
33 //= property helper classes
35 namespace comphelper
37 class OPropertyChangeMultiplexer2;
39 //= OPropertyChangeListener
41 /// simple listener adapter for property sets
42 class COMPHELPER_DLLPUBLIC OPropertyChangeListener2
44 friend class OPropertyChangeMultiplexer2;
46 rtl::Reference<OPropertyChangeMultiplexer2> m_xAdapter;
48 public:
49 virtual ~OPropertyChangeListener2();
51 /// @throws css::uno::RuntimeException
52 virtual void _propertyChanged(const css::beans::PropertyChangeEvent& _rEvent) = 0;
54 protected:
55 /** If the derivee also owns the mutex which we know as reference, then call this within your
56 derivee's dtor.
58 void disposeAdapter(std::unique_lock<std::mutex>& rGuard);
60 private:
61 void setAdapter(std::unique_lock<std::mutex>& rGuard, OPropertyChangeMultiplexer2* _pAdapter);
64 //= OPropertyChangeMultiplexer2
65 // A copy of OPropertyChangeMultiplexer except that it uses std::mutex instead osl::Mutex
67 /// multiplexer for property changes
68 // workaround for incremental linking bugs in MSVC2019
69 class SAL_DLLPUBLIC_TEMPLATE OPropertyChangeMultiplexer_Base2
70 : public cppu::WeakImplHelper<css::beans::XPropertyChangeListener>
73 class COMPHELPER_DLLPUBLIC OPropertyChangeMultiplexer2 final
74 : public OPropertyChangeMultiplexer_Base2
76 friend class OPropertyChangeListener2;
77 std::mutex& m_rMutex;
78 std::vector<OUString> m_aProperties;
79 css::uno::Reference<css::beans::XPropertySet> m_xSet;
80 OPropertyChangeListener2* m_pListener;
81 sal_Int32 m_nLockCount;
82 bool m_bListening : 1;
83 bool const m_bAutoSetRelease : 1;
85 void onListenerDestruction();
86 virtual ~OPropertyChangeMultiplexer2() override;
88 public:
89 OPropertyChangeMultiplexer2(std::mutex& rMutex, std::unique_lock<std::mutex>& rGuard,
90 OPropertyChangeListener2* _pListener,
91 const css::uno::Reference<css::beans::XPropertySet>& _rxSet,
92 bool _bAutoReleaseSet = true);
94 // XEventListener
95 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
97 // XPropertyChangeListener
98 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
100 /// incremental lock
101 void lock();
102 /// incremental unlock
103 void unlock();
104 /// get the lock count
105 sal_Int32 locked() const { return m_nLockCount; }
107 void addProperty(const OUString& aPropertyName);
108 void dispose(std::unique_lock<std::mutex>& rGuard);
111 } // namespace comphelper
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */