mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 06:17:15 +01:00
trunk/branch integration: observer::disable()
This commit is contained in:
parent
58064f8284
commit
275013ed5e
@ -59,9 +59,10 @@ public:
|
||||
AbstractObserver& operator = (const AbstractObserver& observer);
|
||||
|
||||
virtual void notify(Notification* pNf) const = 0;
|
||||
virtual bool equals(const AbstractObserver& observer) const = 0;
|
||||
virtual bool accepts(Notification* pNf) const = 0;
|
||||
virtual AbstractObserver* clone() const = 0;
|
||||
virtual bool equals(const AbstractObserver& observer) const = 0;
|
||||
virtual bool accepts(Notification* pNf) const = 0;
|
||||
virtual AbstractObserver* clone() const = 0;
|
||||
virtual void disable() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
@ -93,19 +94,24 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void notify(Notification* pNf) const
|
||||
{
|
||||
N* pCastNf = dynamic_cast<N*>(pNf);
|
||||
if (pCastNf)
|
||||
{
|
||||
NotificationPtr ptr(pCastNf, true);
|
||||
(_pObject->*_method)(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
NotificationPtr ptr(pCastNf, true);
|
||||
(_pObject->*_method)(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool equals(const AbstractObserver& abstractObserver) const
|
||||
{
|
||||
const NObserver* pObs = dynamic_cast<const NObserver*>(&abstractObserver);
|
||||
return pObs && pObs->_pObject == _pObject && pObs->_method == _method;
|
||||
}
|
||||
@ -117,14 +123,22 @@ public:
|
||||
|
||||
AbstractObserver* clone() const
|
||||
{
|
||||
return new NObserver(*this);
|
||||
}
|
||||
|
||||
private:
|
||||
NObserver();
|
||||
return new NObserver(*this);
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
Poco::Mutex::ScopedLock lock(_mutex);
|
||||
|
||||
_pObject = 0;
|
||||
}
|
||||
|
||||
C* _pObject;
|
||||
Callback _method;
|
||||
private:
|
||||
NObserver();
|
||||
|
||||
C* _pObject;
|
||||
Callback _method;
|
||||
mutable Poco::Mutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user