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

@ -62,6 +62,7 @@ public:
virtual bool equals(const AbstractObserver& observer) const = 0;
virtual bool accepts(Notification* pNf) const = 0;
virtual AbstractObserver* clone() const = 0;
virtual void disable() = 0;
};

View File

@ -1,7 +1,7 @@
//
// NObserver.h
//
// $Id: //poco/Main/Foundation/include/Poco/NObserver.h#3 $
// $Id: //poco/1.4/Foundation/include/Poco/NObserver.h#2 $
//
// Library: Foundation
// Package: Notifications
@ -42,6 +42,7 @@
#include "Poco/Foundation.h"
#include "Poco/AbstractObserver.h"
#include "Poco/Mutex.h"
namespace Poco {
@ -95,6 +96,10 @@ public:
}
void notify(Notification* pNf) const
{
Poco::Mutex::ScopedLock lock(_mutex);
if (_pObject)
{
N* pCastNf = dynamic_cast<N*>(pNf);
if (pCastNf)
@ -103,6 +108,7 @@ public:
(_pObject->*_method)(ptr);
}
}
}
bool equals(const AbstractObserver& abstractObserver) const
{
@ -120,11 +126,19 @@ public:
return new NObserver(*this);
}
void disable()
{
Poco::Mutex::ScopedLock lock(_mutex);
_pObject = 0;
}
private:
NObserver();
C* _pObject;
Callback _method;
mutable Poco::Mutex _mutex;
};

View File

@ -42,6 +42,7 @@
#include "Poco/Foundation.h"
#include "Poco/AbstractObserver.h"
#include "Poco/Mutex.h"
namespace Poco {
@ -93,6 +94,10 @@ public:
}
void notify(Notification* pNf) const
{
Poco::Mutex::ScopedLock lock(_mutex);
if (_pObject)
{
N* pCastNf = dynamic_cast<N*>(pNf);
if (pCastNf)
@ -101,6 +106,7 @@ public:
(_pObject->*_method)(pCastNf);
}
}
}
bool equals(const AbstractObserver& abstractObserver) const
{
@ -118,11 +124,19 @@ public:
return new Observer(*this);
}
void disable()
{
Poco::Mutex::ScopedLock lock(_mutex);
_pObject = 0;
}
private:
Observer();
C* _pObject;
Callback _method;
mutable Poco::Mutex _mutex;
};