Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/comphelper/propmultiplex2.hxx
Line
Count
Source
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
#pragma once
20
21
#include <config_options.h>
22
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
23
#include <cppuhelper/implbase.hxx>
24
#include <comphelper/comphelperdllapi.h>
25
#include <rtl/ref.hxx>
26
#include <mutex>
27
#include <vector>
28
29
namespace com::sun::star::beans
30
{
31
class XPropertySet;
32
}
33
34
//= property helper classes
35
36
namespace comphelper
37
{
38
class OPropertyChangeMultiplexer2;
39
40
//= OPropertyChangeListener
41
42
/// simple listener adapter for property sets
43
class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OPropertyChangeListener2
44
{
45
    friend class OPropertyChangeMultiplexer2;
46
47
    rtl::Reference<OPropertyChangeMultiplexer2> m_xAdapter;
48
49
public:
50
    virtual ~OPropertyChangeListener2();
51
52
    /// @throws css::uno::RuntimeException
53
    virtual void _propertyChanged(const css::beans::PropertyChangeEvent& _rEvent) = 0;
54
55
protected:
56
    /** If the derivee also owns the mutex which we know as reference, then call this within your
57
            derivee's dtor.
58
        */
59
    void disposeAdapter(std::unique_lock<std::mutex>& rGuard);
60
61
private:
62
    void setAdapter(std::unique_lock<std::mutex>& rGuard, OPropertyChangeMultiplexer2* _pAdapter);
63
};
64
65
//= OPropertyChangeMultiplexer2
66
// A copy of OPropertyChangeMultiplexer except that it uses std::mutex instead osl::Mutex
67
68
/// multiplexer for property changes
69
// workaround for incremental linking bugs in MSVC2019
70
class SAL_DLLPUBLIC_TEMPLATE OPropertyChangeMultiplexer_Base2
71
    : public cppu::WeakImplHelper<css::beans::XPropertyChangeListener>
72
{
73
};
74
class UNLESS_MERGELIBS(COMPHELPER_DLLPUBLIC) OPropertyChangeMultiplexer2 final
75
    : public OPropertyChangeMultiplexer_Base2
76
{
77
    friend class OPropertyChangeListener2;
78
    std::mutex& m_rMutex;
79
    std::vector<OUString> m_aProperties;
80
    css::uno::Reference<css::beans::XPropertySet> m_xSet;
81
    OPropertyChangeListener2* m_pListener;
82
    sal_Int32 m_nLockCount;
83
    bool m_bListening : 1;
84
85
    void onListenerDestruction();
86
    virtual ~OPropertyChangeMultiplexer2() override;
87
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
93
    // XEventListener
94
    virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
95
96
    // XPropertyChangeListener
97
    virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
98
99
    /// incremental lock
100
    void lock();
101
    /// incremental unlock
102
    void unlock();
103
    /// get the lock count
104
0
    sal_Int32 locked() const { return m_nLockCount; }
105
106
    void addProperty(const OUString& aPropertyName);
107
    void dispose(std::unique_lock<std::mutex>& rGuard);
108
};
109
110
} // namespace comphelper
111
112
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */