aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/NotificationCenter.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/poco/Foundation/src/NotificationCenter.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/poco/Foundation/src/NotificationCenter.cpp')
-rw-r--r--contrib/libs/poco/Foundation/src/NotificationCenter.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/contrib/libs/poco/Foundation/src/NotificationCenter.cpp b/contrib/libs/poco/Foundation/src/NotificationCenter.cpp
new file mode 100644
index 0000000000..3b024fa730
--- /dev/null
+++ b/contrib/libs/poco/Foundation/src/NotificationCenter.cpp
@@ -0,0 +1,109 @@
+//
+// NotificationCenter.cpp
+//
+// Library: Foundation
+// Package: Notifications
+// Module: NotificationCenter
+//
+// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// SPDX-License-Identifier: BSL-1.0
+//
+
+
+#include "Poco/NotificationCenter.h"
+#include "Poco/Notification.h"
+#include "Poco/Observer.h"
+#include "Poco/AutoPtr.h"
+#include "Poco/SingletonHolder.h"
+
+
+namespace Poco {
+
+
+NotificationCenter::NotificationCenter()
+{
+}
+
+
+NotificationCenter::~NotificationCenter()
+{
+}
+
+
+void NotificationCenter::addObserver(const AbstractObserver& observer)
+{
+ Mutex::ScopedLock lock(_mutex);
+ _observers.push_back(observer.clone());
+}
+
+
+void NotificationCenter::removeObserver(const AbstractObserver& observer)
+{
+ Mutex::ScopedLock lock(_mutex);
+ for (ObserverList::iterator it = _observers.begin(); it != _observers.end(); ++it)
+ {
+ if (observer.equals(**it))
+ {
+ (*it)->disable();
+ _observers.erase(it);
+ return;
+ }
+ }
+}
+
+
+bool NotificationCenter::hasObserver(const AbstractObserver& observer) const
+{
+ Mutex::ScopedLock lock(_mutex);
+ for (ObserverList::const_iterator it = _observers.begin(); it != _observers.end(); ++it)
+ if (observer.equals(**it)) return true;
+
+ return false;
+}
+
+
+void NotificationCenter::postNotification(Notification::Ptr pNotification)
+{
+ poco_check_ptr (pNotification);
+
+ ScopedLockWithUnlock<Mutex> lock(_mutex);
+ ObserverList observersToNotify(_observers);
+ lock.unlock();
+ for (ObserverList::iterator it = observersToNotify.begin(); it != observersToNotify.end(); ++it)
+ {
+ (*it)->notify(pNotification);
+ }
+}
+
+
+bool NotificationCenter::hasObservers() const
+{
+ Mutex::ScopedLock lock(_mutex);
+
+ return !_observers.empty();
+}
+
+
+std::size_t NotificationCenter::countObservers() const
+{
+ Mutex::ScopedLock lock(_mutex);
+
+ return _observers.size();
+}
+
+
+namespace
+{
+ static SingletonHolder<NotificationCenter> sh;
+}
+
+
+NotificationCenter& NotificationCenter::defaultCenter()
+{
+ return *sh.get();
+}
+
+
+} // namespace Poco