Skip to content

Commit

Permalink
fix(AsyncNotificationCenter); remove default #4414
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-f committed Feb 15, 2024
1 parent 71560b0 commit 98eae38
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
7 changes: 2 additions & 5 deletions Foundation/include/Poco/AsyncNotificationCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ class Foundation_API AsyncNotificationCenter: public NotificationCenter
/// Enqueues notification into the notification queue.

virtual int backlog() const;
/// Rteurns the numbner of notifications in the notification queue.
/// Returns the numbner of notifications in the notification queue.

static AsyncNotificationCenter& defaultCenter();

// TODO: see testDefaultAsyncNotificationCenter for details
//private:
private:
void start();
void stop();
void dequeue();
Expand Down
7 changes: 0 additions & 7 deletions Foundation/src/AsyncNotificationCenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,4 @@ void AsyncNotificationCenter::dequeue()
}


AsyncNotificationCenter& AsyncNotificationCenter::defaultCenter()
{
static AsyncNotificationCenter nc;
return nc;
}


} // namespace Poco
16 changes: 6 additions & 10 deletions Foundation/testsuite/src/NotificationCenterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,32 +227,28 @@ void NotificationCenterTest::testDefaultNotificationCenter()
}


void NotificationCenterTest::testDefaultAsyncNotificationCenter()
void NotificationCenterTest::testMixedObservers()
{
using ObserverT = AsyncObserver<NotificationCenterTest, TestNotification>::Type;
using AObserverT = AsyncObserver<NotificationCenterTest, TestNotification>::Type;

AsyncNotificationCenter& nc = AsyncNotificationCenter::defaultCenter();
AsyncNotificationCenter nc;
nc.addObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
nc.addObserver(NObserver<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handleAuto));
nc.addObserver(ObserverT(*this, &NotificationCenterTest::handleAsync1, &NotificationCenterTest::matchAsync));
nc.addObserver(AObserverT(*this, &NotificationCenterTest::handleAsync1, &NotificationCenterTest::matchAsync));
nc.postNotification(new Notification);
nc.postNotification(new TestNotification("asyncNotification"));

while (!_handle1Done || !_handleAuto1Done || !_handleAsync1Done)
Poco::Thread::sleep(100);

nc.removeObserver(ObserverT(*this, &NotificationCenterTest::handleAsync1, &NotificationCenterTest::matchAsync));
nc.removeObserver(AObserverT(*this, &NotificationCenterTest::handleAsync1, &NotificationCenterTest::matchAsync));
nc.removeObserver(NObserver<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handleAuto));
nc.removeObserver(Observer<NotificationCenterTest, Notification>(*this, &NotificationCenterTest::handle1));
Poco::Mutex::ScopedLock l(_mutex);
assertTrue (_set.size() == 3);
assertTrue (_set.find("handle1") != _set.end());
assertTrue (_set.find("handleAuto") != _set.end());
assertTrue (_set.find("handleAsync1") != _set.end());
// TODO: static object thread hangs without this on windows
// for explanation/solution, see
// https://stackoverflow.com/questions/10441048/exit-thread-upon-deleting-static-object-during-unload-dll-causes-deadlock
nc.stop();
}


Expand Down Expand Up @@ -344,7 +340,7 @@ CppUnit::Test* NotificationCenterTest::suite()
CppUnit_addTest(pSuite, NotificationCenterTest, testAsyncObserver);
CppUnit_addTest(pSuite, NotificationCenterTest, testAsyncNotificationCenter);
CppUnit_addTest(pSuite, NotificationCenterTest, testDefaultNotificationCenter);
CppUnit_addTest(pSuite, NotificationCenterTest, testDefaultAsyncNotificationCenter);
CppUnit_addTest(pSuite, NotificationCenterTest, testMixedObservers);

return pSuite;
}
2 changes: 1 addition & 1 deletion Foundation/testsuite/src/NotificationCenterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NotificationCenterTest: public CppUnit::TestCase
void testAsyncObserver();
void testAsyncNotificationCenter();
void testDefaultNotificationCenter();
void testDefaultAsyncNotificationCenter();
void testMixedObservers();

void setUp();
void tearDown();
Expand Down

0 comments on commit 98eae38

Please sign in to comment.