diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Foundation/src/NotificationCenter.cpp | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/src/NotificationCenter.cpp')
-rw-r--r-- | contrib/libs/poco/Foundation/src/NotificationCenter.cpp | 218 |
1 files changed, 109 insertions, 109 deletions
diff --git a/contrib/libs/poco/Foundation/src/NotificationCenter.cpp b/contrib/libs/poco/Foundation/src/NotificationCenter.cpp index 124a4a9c2b..3b024fa730 100644 --- a/contrib/libs/poco/Foundation/src/NotificationCenter.cpp +++ b/contrib/libs/poco/Foundation/src/NotificationCenter.cpp @@ -1,109 +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 +// +// 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 |