mirror of
https://github.com/libretro/MesenCE.git
synced 2026-11-10 11:11:32 -10:00
* Code: Add auto-formatting rules for C++ projects (clang-format) and enforce code style via "clang-format" and "dotnet format" * fix ui format warnings
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include "pch.h"
|
|
#include <algorithm>
|
|
#include "Shared/NotificationManager.h"
|
|
|
|
void NotificationManager::RegisterNotificationListener(shared_ptr<INotificationListener> notificationListener)
|
|
{
|
|
auto lock = _lock.AcquireSafe();
|
|
|
|
for(weak_ptr<INotificationListener> listener : _listeners) {
|
|
if(listener.lock() == notificationListener) {
|
|
//This listener is already registered, do nothing
|
|
return;
|
|
}
|
|
}
|
|
|
|
_listeners.push_back(notificationListener);
|
|
}
|
|
|
|
void NotificationManager::CleanupNotificationListeners()
|
|
{
|
|
auto lock = _lock.AcquireSafe();
|
|
|
|
auto predicate = [](weak_ptr<INotificationListener> ptr) { return ptr.expired(); };
|
|
|
|
//Remove expired listeners
|
|
_listeners.erase(std::remove_if(_listeners.begin(), _listeners.end(), predicate), _listeners.end());
|
|
}
|
|
|
|
void NotificationManager::SendNotification(ConsoleNotificationType type, void* parameter)
|
|
{
|
|
vector<weak_ptr<INotificationListener>> listeners;
|
|
{
|
|
auto lock = _lock.AcquireSafe();
|
|
CleanupNotificationListeners();
|
|
listeners = _listeners;
|
|
}
|
|
|
|
//Iterate on a copy without using a lock
|
|
for(weak_ptr<INotificationListener> notificationListener : listeners) {
|
|
shared_ptr<INotificationListener> listener = notificationListener.lock();
|
|
if(listener) {
|
|
listener->ProcessNotification(type, parameter);
|
|
}
|
|
}
|
|
}
|