Mesen-SX/InteropDLL/InteropNotificationListeners.h

38 lines
1.3 KiB
C
Raw Normal View History

2019-02-15 21:33:13 -05:00
#pragma once
#include "stdafx.h"
#include "../Core/INotificationListener.h"
#include "../Core/NotificationManager.h"
#include "../Core/Console.h"
#include "../Utilities/SimpleLock.h"
#include "InteropNotificationListener.h"
typedef void(__stdcall *NotificationListenerCallback)(int, void*);
2019-02-15 21:33:13 -05:00
class InteropNotificationListeners
{
SimpleLock _externalNotificationListenerLock;
vector<shared_ptr<INotificationListener>> _externalNotificationListeners;
public:
INotificationListener* RegisterNotificationCallback(NotificationListenerCallback callback, shared_ptr<Console> console)
2019-02-15 21:33:13 -05:00
{
auto lock = _externalNotificationListenerLock.AcquireSafe();
auto listener = shared_ptr<INotificationListener>(new InteropNotificationListener(callback));
_externalNotificationListeners.push_back(listener);
console->GetNotificationManager()->RegisterNotificationListener(listener);
return listener.get();
}
void UnregisterNotificationCallback(INotificationListener *listener)
2019-02-15 21:33:13 -05:00
{
auto lock = _externalNotificationListenerLock.AcquireSafe();
_externalNotificationListeners.erase(
std::remove_if(
_externalNotificationListeners.begin(),
_externalNotificationListeners.end(),
[=](shared_ptr<INotificationListener> ptr) { return ptr.get() == listener; }
),
_externalNotificationListeners.end()
);
}
};