merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / backend / backendnotifier.hxx
blob9ab179832c50de8554741aa7c487dd707fe373bd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backendnotifier.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CONFIGMGR_BACKEND_BACKENDNOTIFIER_HXX
31 #define CONFIGMGR_BACKEND_BACKENDNOTIFIER_HXX
33 #include "mergeddataprovider.hxx"
34 #include <com/sun/star/configuration/backend/XBackend.hpp>
35 #include <com/sun/star/configuration/backend/XBackendChangesNotifier.hpp>
36 #include <osl/mutex.hxx>
37 #include <cppuhelper/implbase1.hxx>
39 #ifndef INCLUDED_MAP
40 #include <map>
41 #define INCLUDED_MAP
42 #endif
44 #ifndef INCLUDED_LIST
45 #include <list>
46 #define INCLUDED_LIST
47 #endif
50 namespace configmgr
52 // ---------------------------------------------------------------------------
53 namespace backend
55 namespace uno = ::com::sun::star::uno;
56 namespace lang = ::com::sun::star::lang;
57 namespace backenduno = ::com::sun::star::configuration::backend;
58 // ---------------------------------------------------------------------------
59 struct ComponentListener
61 explicit
62 ComponentListener(INodeDataListener * _xListener, RequestOptions _aOptions):
63 m_aListener( _xListener),
64 m_aOptions(_aOptions)
67 bool operator==(const ComponentListener& _aListener)const
69 return ( (&m_aListener == &_aListener.m_aListener)&&
70 (compareRequestOptions(m_aOptions, _aListener.m_aOptions)== 0) );
73 INodeDataListener * m_aListener;
74 RequestOptions m_aOptions;
77 /** Class used to store ComponentListener(listener and options)
79 class ComponentNotifier
81 public:
82 ComponentNotifier();
83 void addListenerToList(const ComponentListener& _aListener);
84 void removeListenerFromList(const ComponentListener& _aListener);
85 bool isListEmpty(){ return m_aListenerList.empty();}
86 void notifyListeners(const rtl::OUString& _aComponent);
87 private:
88 std::list<ComponentListener> m_aListenerList;
90 // ---------------------------------------------------------------------------
91 /** Interface providing a multicasting service for changes in the backend
93 class BackendChangeNotifier :public cppu::WeakImplHelper1<backenduno::XBackendChangesListener>
95 public:
96 BackendChangeNotifier(const uno::Reference<backenduno::XBackend>& _xBackend);
97 ~BackendChangeNotifier();
99 virtual void SAL_CALL componentDataChanged(const backenduno::ComponentChangeEvent& aEvent)
100 throw (::com::sun::star::uno::RuntimeException);
102 virtual void SAL_CALL disposing( lang::EventObject const & rSource )
103 throw (uno::RuntimeException);
104 // notification support.
105 /// register a listener for observing changes to the cached data
106 void addListener(INodeDataListener * _xListener, const ComponentRequest& _aRequest) SAL_THROW(());
107 /// unregister a listener previously registered
108 void removeListener(INodeDataListener * _xListener, const ComponentRequest& _aRequest) SAL_THROW(());
109 private:
110 osl::Mutex m_aMutex;
111 std::map<rtl::OUString, ComponentNotifier> m_aListeners;
113 /** Backend being accessed */
114 uno::Reference<backenduno::XBackendChangesNotifier> m_aBackend ;
116 // ---------------------------------------------------------------------------
117 } // namespace backend
119 // ---------------------------------------------------------------------------
120 } // namespace configmgr
122 #endif