1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <config_options.h>
#include <comphelper/multiinterfacecontainer4.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XMultiPropertySet.hpp>
#include <com/sun/star/beans/XFastPropertySet.hpp>
#include <comphelper/comphelperdllapi.h>
#include <comphelper/unoimplbase.hxx>
#include <cppuhelper/propshlp.hxx>
namespace comphelper
{
/*************************************************************************
*************************************************************************/
/**
This abstract class maps the methods of the interfaces XMultiPropertySet, XFastPropertySet
and XPropertySet to the methods getInfoHelper, convertFastPropertyValue,
setFastPropertyValue_NoBroadcast and getFastPropertyValue. You must derive from
this class and override the methods.
It provides a standard implementation of the XPropertySetInfo.
This is a modified copy of the cppuhelper::OPropertySetHelper class, except
that is uses std::mutex instead of osl::Mutex.
*/
class COMPHELPER_DLLPUBLIC OPropertySetHelper : public virtual comphelper::UnoImplBase,
public css::beans::XMultiPropertySet,
public css::beans::XFastPropertySet,
public css::beans::XPropertySet
{
public:
OPropertySetHelper();
/** Constructor.
@param bIgnoreRuntimeExceptionsWhileFiring
indicates whether occurring RuntimeExceptions will be
ignored when firing notifications
(vetoableChange(), propertyChange())
to listeners.
PropertyVetoExceptions may still be thrown.
This flag is useful in an inter-process scenario when
remote bridges may break down
(firing DisposedExceptions).
*/
OPropertySetHelper(bool bIgnoreRuntimeExceptionsWhileFiring);
/**
Only returns a reference to XMultiPropertySet, XFastPropertySet, XPropertySet and
XEventListener.
*/
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& rType) override;
/** eases implementing XTypeProvider::getTypes, returns the types of XMultiPropertySet, XFastPropertySet, XPropertySet
@throws css::uno::RuntimeException
*/
static css::uno::Sequence<css::uno::Type> getTypes();
/**
Send a disposing notification to the listeners
@see OComponentHelper
*/
void disposing(std::unique_lock<std::mutex>& rGuard);
/**
Throw UnknownPropertyException or PropertyVetoException if the property with the name
rPropertyName does not exist or is readonly. Otherwise rPropertyName is changed to its handle
value and setFastPropertyValue is called.
*/
virtual void SAL_CALL setPropertyValue(const ::rtl::OUString& rPropertyName,
const css::uno::Any& aValue) override;
/**
Throw UnknownPropertyException if the property with the name
rPropertyName does not exist.
*/
virtual css::uno::Any SAL_CALL getPropertyValue(const ::rtl::OUString& aPropertyName) override;
/** Ignored if the property is not bound. */
virtual void SAL_CALL addPropertyChangeListener(
const ::rtl::OUString& aPropertyName,
const css::uno::Reference<css::beans::XPropertyChangeListener>& aListener) override;
/** Ignored if the property is not bound. */
virtual void SAL_CALL removePropertyChangeListener(
const ::rtl::OUString& aPropertyName,
const css::uno::Reference<css::beans::XPropertyChangeListener>& aListener) override;
/** Ignored if the property is not constrained. */
virtual void SAL_CALL addVetoableChangeListener(
const ::rtl::OUString& aPropertyName,
const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
/** Ignored if the property is not constrained. */
virtual void SAL_CALL removeVetoableChangeListener(
const ::rtl::OUString& aPropertyName,
const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
/**
Throw UnknownPropertyException or PropertyVetoException if the property with the name
rPropertyName does not exist or is readonly. Otherwise the method convertFastPropertyValue
is called, then the vetoable listeners are notified. After this the value of the property
is changed with the setFastPropertyValue_NoBroadcast method and the bound listeners are
notified.
*/
virtual void SAL_CALL setFastPropertyValue(sal_Int32 nHandle,
const css::uno::Any& rValue) override final;
/**
@exception css::beans::UnknownPropertyException
if the property with the handle nHandle does not exist.
*/
virtual css::uno::Any SAL_CALL getFastPropertyValue(sal_Int32 nHandle) override final;
// XMultiPropertySet
virtual void SAL_CALL
setPropertyValues(const css::uno::Sequence<::rtl::OUString>& PropertyNames,
const css::uno::Sequence<css::uno::Any>& Values) override;
virtual css::uno::Sequence<css::uno::Any> SAL_CALL
getPropertyValues(const css::uno::Sequence<::rtl::OUString>& PropertyNames) override final;
virtual void SAL_CALL addPropertiesChangeListener(
const css::uno::Sequence<::rtl::OUString>& PropertyNames,
const css::uno::Reference<css::beans::XPropertiesChangeListener>& Listener) override final;
virtual void SAL_CALL removePropertiesChangeListener(
const css::uno::Reference<css::beans::XPropertiesChangeListener>& Listener) override final;
virtual void SAL_CALL firePropertiesChangeEvent(
const css::uno::Sequence<::rtl::OUString>& PropertyNames,
const css::uno::Reference<css::beans::XPropertiesChangeListener>& Listener) override final;
/**
The property sequence is created in the call. The interface isn't used after the call.
*/
static css::uno::Reference<css::beans::XPropertySetInfo>
createPropertySetInfo(cppu::IPropertyArrayHelper& rProperties);
protected:
/**
You must call disposing() before destruction.
*/
~OPropertySetHelper();
/** Override this if you need to do something special during setFastPropertyValue */
virtual void setFastPropertyValueImpl(std::unique_lock<std::mutex>& rGuard, sal_Int32 nHandle,
const css::uno::Any& rValue);
/** Override this if you need to do something special during getPropertyValue */
virtual css::uno::Any getPropertyValueImpl(std::unique_lock<std::mutex>& rGuard,
const ::rtl::OUString& aPropertyName) final;
/**
This method fire events to all registered property listeners.
@param pnHandles the id's of the properties that changed.
@param pNewValues the new values of the properties.
@param pOldValues the old values of the properties.
@param nCount the number of elements in the arrays pnHandles, pNewValues and pOldValues.
@param bVetoable true means fire to VetoableChangeListener, false means fire to
XPropertyChangedListener and XMultiPropertyChangedListener.
*/
void fire(std::unique_lock<std::mutex>& rGuard, sal_Int32* pnHandles,
const css::uno::Any* pNewValues, const css::uno::Any* pOldValues, sal_Int32 nCount,
bool bVetoable);
/**
Set multiple properties with the handles.
@param nSeqLen the length of the arrays pHandles and Values.
@param pHandles the handles of the properties. The number of elements
in the Values sequence is the length of the handle array. A value of -1
of a handle means invalid property. These are ignored.
@param pValues the values of the properties.
@param nHitCount the number of valid entries in the handle array.
*/
void setFastPropertyValues(std::unique_lock<std::mutex>& rGuard, sal_Int32 nSeqLen,
sal_Int32* pHandles, const css::uno::Any* pValues,
sal_Int32 nHitCount);
/**
This abstract method must return the name to index table. This table contains all property
names and types of this object. The method is not implemented in this class.
*/
virtual cppu::IPropertyArrayHelper& getInfoHelper() = 0;
/**
Converted the value rValue and return the result in rConvertedValue and the
old value in rOldValue. An IllegalArgumentException is thrown.
The method is not implemented in this class. After this call the vetoable
listeners are notified.
@param rConvertedValue the converted value. Only set if return is true.
@param rOldValue the old value. Only set if return is true.
@param nHandle the handle of the property.
@param rValue the value to be converted
@return true if the value converted.
@throws css::lang::IllegalArgumentException
@throws css::beans::UnknownPropertyException
@throws css::uno::RuntimeException
*/
virtual bool convertFastPropertyValue(std::unique_lock<std::mutex>& rGuard,
css::uno::Any& rConvertedValue, css::uno::Any& rOldValue,
sal_Int32 nHandle, const css::uno::Any& rValue)
= 0;
/** The same as setFastPropertyValue; nHandle is always valid.
The changes must not be broadcasted in this method.
The method is implemented in a derived class.
@attention
Although you are permitted to throw any UNO exception, only the following
are valid for usage:
-- css::beans::UnknownPropertyException
-- css::beans::PropertyVetoException
-- css::lang::IllegalArgumentException
-- css::lang::WrappedTargetException
-- css::uno::RuntimeException
@param nHandle
handle
@param rValue
value
@throws css::uno::Exception
*/
virtual void setFastPropertyValue_NoBroadcast(std::unique_lock<std::mutex>& rGuard,
sal_Int32 nHandle, const css::uno::Any& rValue)
= 0;
/**
The same as getFastPropertyValue, but return the value through rValue and nHandle
is always valid.
The method is not implemented in this class.
*/
virtual void getFastPropertyValue(std::unique_lock<std::mutex>& rGuard, css::uno::Any& rValue,
sal_Int32 nHandle) const = 0;
/** sets an dependent property's value
<p>Sometimes setting a given property needs to implicitly modify another property's value. Calling |setPropertyValue|
from within |setFastPropertyValue_NoBroadcast| is not an option here, as it would notify the property listeners
while our mutex is still locked. Setting the dependent property's value directly (e.g. by calling |setFastPropertyValue_NoBroadcast|
recursively) is not an option, too, since it would miss firing the property change event.</p>
<p>So, in such cases, you use |setDependentFastPropertyValue| from within |setFastPropertyValue_NoBroadcast|.
It will convert and actually set the property value (invoking |convertFastPropertyValue| and |setFastPropertyValue_NoBroadcast|
for the given handle and value), and add the property change event to the list of events to be notified
when the bottom-most |setFastPropertyValue_NoBroadcast| on the stack returns.</p>
<p><strong>Note</strong>: The method will <em>not</em> invoke veto listeners for the property.</p>
<p><strong>Note</strong>: It's the caller's responsibility to ensure that our mutex is locked. This is
canonically given when the method is invoked from within |setFastPropertyValue_NoBroadcast|, in other
contexts, you might need to take own measures.</p>
*/
void setDependentFastPropertyValue(std::unique_lock<std::mutex>& rGuard, sal_Int32 i_handle,
const css::uno::Any& i_value);
private:
/**
Container for the XPropertyChangedListener. The listeners are inserted by handle.
*/
OMultiTypeInterfaceContainerHelperVar4<sal_Int32, css::beans::XPropertyChangeListener> aBoundLC;
/**
Container for the XPropertyVetoableListener. The listeners are inserted by handle.
*/
OMultiTypeInterfaceContainerHelperVar4<sal_Int32, css::beans::XVetoableChangeListener>
aVetoableLC;
/**
Container for the XPropertyChangedListener where the listeners want to listen to all properties.
*/
comphelper::OInterfaceContainerHelper4<css::beans::XPropertyChangeListener>
maPropertyChangeListeners;
comphelper::OInterfaceContainerHelper4<css::beans::XPropertiesChangeListener>
maPropertiesChangeListeners;
/**
Container for the XVetoableChangeListener where the listeners want to listen to all properties.
*/
comphelper::OInterfaceContainerHelper4<css::beans::XVetoableChangeListener>
maVetoableChangeListeners;
std::vector<sal_Int32> m_handles;
std::vector<css::uno::Any> m_newValues;
std::vector<css::uno::Any> m_oldValues;
bool m_bIgnoreRuntimeExceptionsWhileFiring = false;
/** notifies the given changes in property's values, <em>plus</em> all property changes collected during recent
|setDependentFastPropertyValue| calls.
*/
void impl_fireAll(std::unique_lock<std::mutex>& rGuard, sal_Int32* i_handles,
const css::uno::Any* i_newValues, const css::uno::Any* i_oldValues,
sal_Int32 i_count);
void fireVetoableChangeListeners(
std::unique_lock<std::mutex>& rGuard,
comphelper::OInterfaceContainerHelper4<css::beans::XVetoableChangeListener>* pListeners,
const css::beans::PropertyChangeEvent& rChangeEvent);
void firePropertyChangeListeners(
std::unique_lock<std::mutex>& rGuard,
comphelper::OInterfaceContainerHelper4<css::beans::XPropertyChangeListener>* pListeners,
const css::beans::PropertyChangeEvent& rChangeEvent);
};
} // end namespace comphelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|