mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-21 14:42:51 +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);
|
AbstractObserver& operator = (const AbstractObserver& observer);
|
||||||
|
|
||||||
virtual void notify(Notification* pNf) const = 0;
|
virtual void notify(Notification* pNf) const = 0;
|
||||||
virtual bool equals(const AbstractObserver& observer) const = 0;
|
virtual bool equals(const AbstractObserver& observer) const = 0;
|
||||||
virtual bool accepts(Notification* pNf) const = 0;
|
virtual bool accepts(Notification* pNf) const = 0;
|
||||||
virtual AbstractObserver* clone() const = 0;
|
virtual AbstractObserver* clone() const = 0;
|
||||||
|
virtual void disable() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// NObserver.h
|
// NObserver.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Foundation/include/Poco/NObserver.h#3 $
|
// $Id: //poco/1.4/Foundation/include/Poco/NObserver.h#2 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: Notifications
|
// Package: Notifications
|
||||||
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/AbstractObserver.h"
|
#include "Poco/AbstractObserver.h"
|
||||||
|
#include "Poco/Mutex.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -93,19 +94,24 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void notify(Notification* pNf) const
|
void notify(Notification* pNf) const
|
||||||
{
|
{
|
||||||
N* pCastNf = dynamic_cast<N*>(pNf);
|
Poco::Mutex::ScopedLock lock(_mutex);
|
||||||
if (pCastNf)
|
|
||||||
{
|
if (_pObject)
|
||||||
NotificationPtr ptr(pCastNf, true);
|
{
|
||||||
(_pObject->*_method)(ptr);
|
N* pCastNf = dynamic_cast<N*>(pNf);
|
||||||
}
|
if (pCastNf)
|
||||||
}
|
{
|
||||||
|
NotificationPtr ptr(pCastNf, true);
|
||||||
bool equals(const AbstractObserver& abstractObserver) const
|
(_pObject->*_method)(ptr);
|
||||||
{
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool equals(const AbstractObserver& abstractObserver) const
|
||||||
|
{
|
||||||
const NObserver* pObs = dynamic_cast<const NObserver*>(&abstractObserver);
|
const NObserver* pObs = dynamic_cast<const NObserver*>(&abstractObserver);
|
||||||
return pObs && pObs->_pObject == _pObject && pObs->_method == _method;
|
return pObs && pObs->_pObject == _pObject && pObs->_method == _method;
|
||||||
}
|
}
|
||||||
@ -117,14 +123,22 @@ public:
|
|||||||
|
|
||||||
AbstractObserver* clone() const
|
AbstractObserver* clone() const
|
||||||
{
|
{
|
||||||
return new NObserver(*this);
|
return new NObserver(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
void disable()
|
||||||
NObserver();
|
{
|
||||||
|
Poco::Mutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
|
_pObject = 0;
|
||||||
|
}
|
||||||
|
|
||||||
C* _pObject;
|
private:
|
||||||
Callback _method;
|
NObserver();
|
||||||
|
|
||||||
|
C* _pObject;
|
||||||
|
Callback _method;
|
||||||
|
mutable Poco::Mutex _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/AbstractObserver.h"
|
#include "Poco/AbstractObserver.h"
|
||||||
|
#include "Poco/Mutex.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -91,19 +92,24 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void notify(Notification* pNf) const
|
void notify(Notification* pNf) const
|
||||||
{
|
{
|
||||||
N* pCastNf = dynamic_cast<N*>(pNf);
|
Poco::Mutex::ScopedLock lock(_mutex);
|
||||||
if (pCastNf)
|
|
||||||
{
|
if (_pObject)
|
||||||
pCastNf->duplicate();
|
{
|
||||||
(_pObject->*_method)(pCastNf);
|
N* pCastNf = dynamic_cast<N*>(pNf);
|
||||||
}
|
if (pCastNf)
|
||||||
}
|
{
|
||||||
|
pCastNf->duplicate();
|
||||||
bool equals(const AbstractObserver& abstractObserver) const
|
(_pObject->*_method)(pCastNf);
|
||||||
{
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool equals(const AbstractObserver& abstractObserver) const
|
||||||
|
{
|
||||||
const Observer* pObs = dynamic_cast<const Observer*>(&abstractObserver);
|
const Observer* pObs = dynamic_cast<const Observer*>(&abstractObserver);
|
||||||
return pObs && pObs->_pObject == _pObject && pObs->_method == _method;
|
return pObs && pObs->_pObject == _pObject && pObs->_method == _method;
|
||||||
}
|
}
|
||||||
@ -115,14 +121,22 @@ public:
|
|||||||
|
|
||||||
AbstractObserver* clone() const
|
AbstractObserver* clone() const
|
||||||
{
|
{
|
||||||
return new Observer(*this);
|
return new Observer(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void disable()
|
||||||
|
{
|
||||||
|
Poco::Mutex::ScopedLock lock(_mutex);
|
||||||
|
|
||||||
|
_pObject = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Observer();
|
Observer();
|
||||||
|
|
||||||
C* _pObject;
|
C* _pObject;
|
||||||
Callback _method;
|
Callback _method;
|
||||||
|
mutable Poco::Mutex _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user