diff --git a/Foundation/Foundation_vs71.vcproj b/Foundation/Foundation_vs71.vcproj
index 2cc004fd6..75bcef9e9 100644
--- a/Foundation/Foundation_vs71.vcproj
+++ b/Foundation/Foundation_vs71.vcproj
@@ -1463,7 +1463,7 @@
RelativePath=".\src\NotificationQueue.cpp">
+ RelativePath=".\src\AbstractObserver.cpp">
+
+
+
+
@@ -1951,10 +1951,18 @@
RelativePath=".\include\Poco\NotificationQueue.h"
>
+
+
+
+
(*this, &NotificationCenterTest::handleAuto));
+ nc.postNotification(new Notification);
+ assert (_set.size() == 1);
+ assert (_set.find("handleAuto") != _set.end());
+ nc.removeObserver(NObserver(*this, &NotificationCenterTest::handleAuto));
+}
+
+
void NotificationCenterTest::testDefaultCenter()
{
NotificationCenter& nc = NotificationCenter::defaultCenter();
@@ -174,6 +187,12 @@ void NotificationCenterTest::handleTest(TestNotification* pNf)
}
+void NotificationCenterTest::handleAuto(const AutoPtr& pNf)
+{
+ _set.insert("handleAuto");
+}
+
+
void NotificationCenterTest::setUp()
{
_set.clear();
@@ -194,6 +213,7 @@ CppUnit::Test* NotificationCenterTest::suite()
CppUnit_addTest(pSuite, NotificationCenterTest, test3);
CppUnit_addTest(pSuite, NotificationCenterTest, test4);
CppUnit_addTest(pSuite, NotificationCenterTest, test5);
+ CppUnit_addTest(pSuite, NotificationCenterTest, testAuto);
CppUnit_addTest(pSuite, NotificationCenterTest, testDefaultCenter);
return pSuite;
diff --git a/Foundation/testsuite/src/NotificationCenterTest.h b/Foundation/testsuite/src/NotificationCenterTest.h
index f59c7e9ef..933fb33a7 100644
--- a/Foundation/testsuite/src/NotificationCenterTest.h
+++ b/Foundation/testsuite/src/NotificationCenterTest.h
@@ -1,7 +1,7 @@
//
// NotificationCenterTest.h
//
-// $Id: //poco/1.2/Foundation/testsuite/src/NotificationCenterTest.h#1 $
+// $Id: //poco/1.2/Foundation/testsuite/src/NotificationCenterTest.h#2 $
//
// Definition of the NotificationCenterTest class.
//
@@ -39,6 +39,7 @@
#include "Poco/Foundation.h"
#include "CppUnit/TestCase.h"
#include "Poco/Notification.h"
+#include "Poco/AutoPtr.h"
#include
@@ -56,6 +57,7 @@ public:
void test3();
void test4();
void test5();
+ void testAuto();
void testDefaultCenter();
void setUp();
@@ -68,6 +70,7 @@ protected:
void handle2(Poco::Notification* pNf);
void handle3(Poco::Notification* pNf);
void handleTest(TestNotification* pNf);
+ void handleAuto(const Poco::AutoPtr& pNf);
private:
std::set _set;
diff --git a/Net/samples/EchoServer/src/EchoServer.cpp b/Net/samples/EchoServer/src/EchoServer.cpp
index f884353e6..b29d817f0 100644
--- a/Net/samples/EchoServer/src/EchoServer.cpp
+++ b/Net/samples/EchoServer/src/EchoServer.cpp
@@ -1,7 +1,7 @@
//
// EchoServer.cpp
//
-// $Id: //poco/1.2/Net/samples/EchoServer/src/EchoServer.cpp#2 $
+// $Id: //poco/1.2/Net/samples/EchoServer/src/EchoServer.cpp#3 $
//
// This sample demonstrates the SocketReactor and SocketAcceptor classes.
//
@@ -37,7 +37,7 @@
#include "Poco/Net/SocketNotification.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/ServerSocket.h"
-#include "Poco/Observer.h"
+#include "Poco/NObserver.h"
#include "Poco/Exception.h"
#include "Poco/Thread.h"
#include "Poco/Util/ServerApplication.h"
@@ -53,7 +53,8 @@ using Poco::Net::ReadableNotification;
using Poco::Net::ShutdownNotification;
using Poco::Net::ServerSocket;
using Poco::Net::StreamSocket;
-using Poco::Observer;
+using Poco::NObserver;
+using Poco::AutoPtr;
using Poco::Thread;
using Poco::Util::ServerApplication;
using Poco::Util::Application;
@@ -73,8 +74,8 @@ public:
Application& app = Application::instance();
app.logger().information("Connection from " + socket.peerAddress().toString());
- _reactor.addEventHandler(_socket, Observer(*this, &EchoServiceHandler::onReadable));
- _reactor.addEventHandler(_socket, Observer(*this, &EchoServiceHandler::onShutdown));
+ _reactor.addEventHandler(_socket, NObserver(*this, &EchoServiceHandler::onReadable));
+ _reactor.addEventHandler(_socket, NObserver(*this, &EchoServiceHandler::onShutdown));
}
~EchoServiceHandler()
@@ -87,14 +88,13 @@ public:
catch (...)
{
}
- _reactor.removeEventHandler(_socket, Observer(*this, &EchoServiceHandler::onReadable));
- _reactor.removeEventHandler(_socket, Observer(*this, &EchoServiceHandler::onShutdown));
+ _reactor.removeEventHandler(_socket, NObserver(*this, &EchoServiceHandler::onReadable));
+ _reactor.removeEventHandler(_socket, NObserver(*this, &EchoServiceHandler::onShutdown));
delete [] _pBuffer;
}
- void onReadable(ReadableNotification* pNf)
+ void onReadable(const AutoPtr& pNf)
{
- pNf->release(); // we get ownership of the notification, but we do not need it, so we kiss it goodbye.
int n = _socket.receiveBytes(_pBuffer, BUFFER_SIZE);
if (n > 0)
_socket.sendBytes(_pBuffer, n);
@@ -102,9 +102,8 @@ public:
delete this;
}
- void onShutdown(ShutdownNotification* pNf)
+ void onShutdown(const AutoPtr& pNf)
{
- pNf->release();
delete this;
}