trunk/branch integration: observer::disable()

This commit is contained in:
Marian Krivos
2011-08-23 06:36:05 +00:00
parent 58064f8284
commit 275013ed5e
3 changed files with 72 additions and 43 deletions

View File

@@ -42,6 +42,7 @@
#include "Poco/Foundation.h"
#include "Poco/AbstractObserver.h"
#include "Poco/Mutex.h"
namespace Poco {
@@ -91,19 +92,24 @@ public:
}
return *this;
}
void notify(Notification* pNf) const
{
N* pCastNf = dynamic_cast<N*>(pNf);
if (pCastNf)
{
pCastNf->duplicate();
(_pObject->*_method)(pCastNf);
}
}
bool equals(const AbstractObserver& abstractObserver) const
{
void notify(Notification* pNf) const
{
Poco::Mutex::ScopedLock lock(_mutex);
if (_pObject)
{
N* pCastNf = dynamic_cast<N*>(pNf);
if (pCastNf)
{
pCastNf->duplicate();
(_pObject->*_method)(pCastNf);
}
}
}
bool equals(const AbstractObserver& abstractObserver) const
{
const Observer* pObs = dynamic_cast<const Observer*>(&abstractObserver);
return pObs && pObs->_pObject == _pObject && pObs->_method == _method;
}
@@ -115,14 +121,22 @@ public:
AbstractObserver* clone() const
{
return new Observer(*this);
}
return new Observer(*this);
}
void disable()
{
Poco::Mutex::ScopedLock lock(_mutex);
_pObject = 0;
}
private:
Observer();
Observer();
C* _pObject;
Callback _method;
C* _pObject;
Callback _method;
mutable Poco::Mutex _mutex;
};