1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _COMPHELPER_PROPERTY_MULTIPLEX_HXX_
25 #define _COMPHELPER_PROPERTY_MULTIPLEX_HXX_
26 
27 #include <comphelper/propstate.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include "comphelper/comphelperdllapi.h"
30 
31 //=========================================================================
32 //= property helper classes
33 //=========================================================================
34 
35 //.........................................................................
36 namespace comphelper
37 {
38 //.........................................................................
39 
40 	class OPropertyChangeMultiplexer;
41 
42 	//==================================================================
43 	//= OPropertyChangeListener
44 	//==================================================================
45 	/// simple listener adapter for property sets
46 	class COMPHELPER_DLLPUBLIC OPropertyChangeListener
47 	{
48 		friend class OPropertyChangeMultiplexer;
49 
50 		OPropertyChangeMultiplexer*	m_pAdapter;
51 		::osl::Mutex&				m_rMutex;
52 
53 	public:
OPropertyChangeListener(::osl::Mutex & _rMutex)54 		OPropertyChangeListener(::osl::Mutex& _rMutex)
55 			: m_pAdapter(NULL), m_rMutex(_rMutex) { }
56 		virtual ~OPropertyChangeListener();
57 
58 		virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& _rEvent) throw( ::com::sun::star::uno::RuntimeException) = 0;
59 		virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException);
60 
61 	protected:
62         /** If the derivee also owns the mutex which we know as reference, then call this within your
63             derivee's dtor.
64         */
65         void    disposeAdapter();
66 
67         // pseudo-private. Making it private now could break compatibility
68 		void    setAdapter( OPropertyChangeMultiplexer* _pAdapter );
69 	};
70 
71 	//==================================================================
72 	//= OPropertyChangeMultiplexer
73 	//==================================================================
74 	/// multiplexer for property changes
75 	class COMPHELPER_DLLPUBLIC OPropertyChangeMultiplexer	:public cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertyChangeListener>
76 	{
77 		friend class OPropertyChangeListener;
78 		 ::com::sun::star::uno::Sequence< ::rtl::OUString >		m_aProperties;
79 		 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>	m_xSet;
80 		OPropertyChangeListener*					m_pListener;
81 		sal_Int32									m_nLockCount;
82 		sal_Bool									m_bListening		: 1;
83 		sal_Bool									m_bAutoSetRelease	: 1;
84 
85 
86 		virtual ~OPropertyChangeMultiplexer();
87 	public:
88 		OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const  ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True);
89 
90 	// XEventListener
91 		virtual void SAL_CALL disposing( const  ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException);
92 
93 	// XPropertyChangeListener
94 		virtual void SAL_CALL propertyChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);
95 
96 		/// incremental lock
97 		void		lock();
98 		/// incremental unlock
99 		void		unlock();
100 		/// get the lock count
locked() const101 		sal_Int32	locked() const { return m_nLockCount; }
102 
103 		void addProperty(const ::rtl::OUString& aPropertyName);
104 		void dispose();
105 	};
106 
107 //.........................................................................
108 }	// namespace comphelper
109 //.........................................................................
110 
111 #endif // _COMPHELPER_PROPERTY_MULTIPLEX_HXX_
112 
113