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: cachemulticaster.cxx,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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "cachemulticaster.hxx"
35 #include "treemanager.hxx"
37 #ifndef INCLUDED_ALGORITHM
39 #define INCLUDED_ALGORITHM
41 #ifndef INCLUDED_FUNCTIONAL
43 #define INCLUDED_FUNCTIONAL
48 // ---------------------------------------------------------------------------
51 // ---------------------------------------------------------------------------
54 // manually implemented helpers, as rtl::References don't work well with std binders
56 // ---------------------------------------------------------------------------
58 // replacing std::bind2nd( std::mem_fun(&TreeManager::componentCreated), _aComponentName )
59 struct NotifyCreated
: std::unary_function
<rtl::Reference
<TreeManager
>,void>
61 ComponentRequest
const & m_arg
;
63 NotifyCreated(ComponentRequest
const * _pComponent
) SAL_THROW(())
67 void operator()(rtl::Reference
<TreeManager
> const & _xListener
) const SAL_THROW(())
68 { _xListener
->componentCreated(m_arg
); }
70 // ---------------------------------------------------------------------------
72 // replacing std::bind2nd( std::mem_fun(&TreeManager::componentChanged), _aComponentName )
73 struct NotifyChanged
: std::unary_function
<rtl::Reference
<TreeManager
>,void>
75 UpdateRequest
const & m_arg
;
77 NotifyChanged(UpdateRequest
const * _pUpdate
) SAL_THROW(())
81 void operator()(rtl::Reference
<TreeManager
> const & _xListener
) const SAL_THROW(())
82 { _xListener
->componentChanged(m_arg
); }
84 // ---------------------------------------------------------------------------
85 } // anonymous namespace
86 //----------------------------------------------------------------------------
88 CacheChangeMulticaster::CacheChangeMulticaster()
93 // ---------------------------------------------------------------------------
95 CacheChangeMulticaster::~CacheChangeMulticaster()
97 OSL_ENSURE( m_aListeners
.empty(), "Forgot to dispose multicaster" );
99 // ---------------------------------------------------------------------------
101 inline std::list
< rtl::Reference
<TreeManager
> > CacheChangeMulticaster::copyListenerList()
103 osl::MutexGuard
aListGuard(m_aMutex
);
106 // ---------------------------------------------------------------------------
108 void CacheChangeMulticaster::notifyCreated(ComponentRequest
const & _aComponent
) SAL_THROW(())
110 std::list
< rtl::Reference
<TreeManager
> > aNotifyListeners( this->copyListenerList() );
112 std::for_each( aNotifyListeners
.begin(), aNotifyListeners
.end(), NotifyCreated(&_aComponent
) );
114 // ---------------------------------------------------------------------------
116 void CacheChangeMulticaster::notifyChanged(UpdateRequest
const & _anUpdate
) SAL_THROW(())
118 std::list
< rtl::Reference
<TreeManager
> > aNotifyListeners( this->copyListenerList() );
120 std::for_each( aNotifyListeners
.begin(), aNotifyListeners
.end(), NotifyChanged(&_anUpdate
) );
122 // ---------------------------------------------------------------------------
124 void CacheChangeMulticaster::addListener(rtl::Reference
<TreeManager
> _xListener
) SAL_THROW(())
126 osl::MutexGuard
aListGuard(m_aMutex
);
128 OSL_PRECOND(std::find(m_aListeners
.begin(),m_aListeners
.end(),_xListener
) == m_aListeners
.end(),
129 "WARNING: Cache Change Listener was already registered - will be notified multiply.");
131 OSL_PRECOND(_xListener
.is(), "ERROR: trying to register a NULL listener");
134 m_aListeners
.push_front(_xListener
);
136 // ---------------------------------------------------------------------------
138 void CacheChangeMulticaster::removeListener(rtl::Reference
<TreeManager
> _xListener
) SAL_THROW(())
140 osl::MutexGuard
aListGuard(m_aMutex
);
141 m_aListeners
.remove(_xListener
);
143 // ---------------------------------------------------------------------------
144 } // namespace backend
146 // ---------------------------------------------------------------------------
147 } // namespace configmgr