1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backendnotifier.hxx,v $
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>
52 // ---------------------------------------------------------------------------
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
62 ComponentListener(INodeDataListener
* _xListener
, RequestOptions _aOptions
):
63 m_aListener( _xListener
),
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
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
);
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
>
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(());
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