2014-02-13 12:13:05 +01:00
|
|
|
#include "stdafx.h"
|
2014-06-02 19:27:24 +02:00
|
|
|
#include "Emu/Memory/Memory.h"
|
2014-12-22 01:56:04 +01:00
|
|
|
#include "Emu/Memory/atomic_type.h"
|
|
|
|
|
|
2014-12-23 00:31:11 +01:00
|
|
|
#include "Emu/SysCalls/lv2/sleep_queue_type.h"
|
2014-12-22 01:56:04 +01:00
|
|
|
#include "Emu/SysCalls/lv2/sys_event.h"
|
2014-07-06 18:05:52 +02:00
|
|
|
#include "Event.h"
|
2014-02-13 12:13:05 +01:00
|
|
|
|
|
|
|
|
void EventManager::Init()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventManager::Clear()
|
|
|
|
|
{
|
|
|
|
|
key_map.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventManager::CheckKey(u64 key)
|
|
|
|
|
{
|
|
|
|
|
if (!key) return true;
|
2014-06-20 13:00:36 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_lock);
|
2014-02-13 12:13:05 +01:00
|
|
|
|
|
|
|
|
return key_map.find(key) != key_map.end();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-24 00:38:13 +01:00
|
|
|
bool EventManager::RegisterKey(std::shared_ptr<EventQueue>& data, u64 key)
|
2014-02-13 12:13:05 +01:00
|
|
|
{
|
|
|
|
|
if (!key) return true;
|
2014-06-20 13:00:36 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_lock);
|
2014-02-13 12:13:05 +01:00
|
|
|
|
|
|
|
|
if (key_map.find(key) != key_map.end()) return false;
|
|
|
|
|
|
2014-02-23 20:05:49 +01:00
|
|
|
for (auto& v : key_map)
|
2014-02-22 01:26:50 +01:00
|
|
|
{
|
2014-02-23 20:05:49 +01:00
|
|
|
if (v.second == data) return false;
|
2014-02-22 01:26:50 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-13 12:13:05 +01:00
|
|
|
key_map[key] = data;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-24 00:38:13 +01:00
|
|
|
bool EventManager::GetEventQueue(u64 key, std::shared_ptr<EventQueue>& data)
|
2014-02-13 12:13:05 +01:00
|
|
|
{
|
|
|
|
|
data = nullptr;
|
|
|
|
|
if (!key) return false;
|
2014-06-20 13:00:36 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_lock);
|
2014-02-13 12:13:05 +01:00
|
|
|
|
|
|
|
|
auto f = key_map.find(key);
|
|
|
|
|
if (f != key_map.end())
|
|
|
|
|
{
|
|
|
|
|
data = f->second;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventManager::UnregisterKey(u64 key)
|
|
|
|
|
{
|
|
|
|
|
if (!key) return false;
|
2014-06-20 13:00:36 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_lock);
|
2014-02-13 12:13:05 +01:00
|
|
|
|
|
|
|
|
auto f = key_map.find(key);
|
|
|
|
|
if (f != key_map.end())
|
|
|
|
|
{
|
|
|
|
|
key_map.erase(f);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-02-20 21:47:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EventManager::SendEvent(u64 key, u64 source, u64 d1, u64 d2, u64 d3)
|
|
|
|
|
{
|
|
|
|
|
if (!key) return false;
|
2014-06-20 13:00:36 +02:00
|
|
|
std::lock_guard<std::mutex> lock(m_lock);
|
2014-02-20 21:47:22 +01:00
|
|
|
|
|
|
|
|
auto f = key_map.find(key);
|
|
|
|
|
if (f == key_map.end())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-12-24 00:38:13 +01:00
|
|
|
|
|
|
|
|
f->second->events.push(source, d1, d2, d3);
|
2014-02-20 21:47:22 +01:00
|
|
|
return true;
|
2014-02-23 20:05:49 +01:00
|
|
|
}
|