Common: Purge EventSource

This commit is contained in:
Stenzek 2022-12-28 16:55:00 +10:00 committed by refractionpcsx2
parent 4cf041f6cb
commit 94226e83ba
6 changed files with 0 additions and 235 deletions

View File

@ -10,12 +10,10 @@ add_library(common)
# x86emitter sources
target_sources(common PRIVATE
AlignedMalloc.cpp
EventSource.inl
SafeArray.inl
Console.cpp
CrashHandler.cpp
DynamicLibrary.cpp
EventSource.cpp
Exceptions.cpp
FastJmp.cpp
FileSystem.cpp
@ -71,7 +69,6 @@ target_sources(common PRIVATE
DynamicLibrary.h
Easing.h
EnumOps.h
EventSource.h
Exceptions.h
FastJmp.h
FileSystem.h

View File

@ -1,20 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2009 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "EventSource.h"
#include "EventSource.inl"
//template class EventSource< int >;

View File

@ -1,94 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <list>
#include <mutex>
// --------------------------------------------------------------------------------------
// EventSource< template EvtType >
// --------------------------------------------------------------------------------------
template <typename ListenerType>
class EventSource
{
public:
typedef typename ListenerType::EvtParams EvtParams;
typedef typename std::list<ListenerType*> ListenerList;
typedef typename ListenerList::iterator ListenerIterator;
protected:
typedef typename ListenerList::const_iterator ConstIterator;
ListenerList m_listeners;
// This is a cached copy of the listener list used to handle standard dispatching, which
// allows for self-modification of the EventSource's listener list by the listeners.
// Translation: The dispatcher uses this copy instead, to avoid iterator invalidation.
ListenerList m_cache_copy;
bool m_cache_valid;
std::mutex m_listeners_lock;
public:
EventSource()
{
m_cache_valid = false;
}
virtual ~EventSource() = default;
virtual ListenerIterator Add(ListenerType& listener);
virtual void Remove(ListenerType& listener);
virtual void Remove(const ListenerIterator& listenerHandle);
void Add(ListenerType* listener)
{
if (listener == NULL)
return;
Add(*listener);
}
void Remove(ListenerType* listener)
{
if (listener == NULL)
return;
Remove(*listener);
}
void Dispatch(const EvtParams& params);
protected:
virtual ListenerIterator _AddFast_without_lock(ListenerType& listener);
virtual void _DispatchRaw(ListenerIterator iter, const ListenerIterator& iend, const EvtParams& params);
};
// --------------------------------------------------------------------------------------
// IEventDispatcher
// --------------------------------------------------------------------------------------
// This class is used as a base interface for EventListeners. It allows the listeners to do
// customized dispatching of several event types into "user friendly" function overrides.
//
template <typename EvtParams>
class IEventDispatcher
{
protected:
IEventDispatcher() {}
public:
virtual ~IEventDispatcher() = default;
virtual void DispatchEvent(const EvtParams& params) = 0;
};

View File

@ -1,110 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common/Pcsx2Defs.h"
#include "common/Exceptions.h"
#include "common/Console.h"
template <typename ListenerType>
typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::Add(ListenerType& listener)
{
std::unique_lock locker(m_listeners_lock);
// Check for duplicates before adding the event.
if (IsDebugBuild)
{
ListenerIterator iter = m_listeners.begin();
while (iter != m_listeners.end())
{
if ((*iter) == &listener)
return iter;
++iter;
}
}
return _AddFast_without_lock(listener);
}
template <typename ListenerType>
void EventSource<ListenerType>::Remove(ListenerType& listener)
{
std::unique_lock locker(m_listeners_lock);
m_cache_valid = false;
m_listeners.remove(&listener);
}
template <typename ListenerType>
void EventSource<ListenerType>::Remove(const ListenerIterator& listenerHandle)
{
std::unique_lock locker(m_listeners_lock);
m_cache_valid = false;
m_listeners.erase(listenerHandle);
}
template <typename ListenerType>
typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::_AddFast_without_lock(ListenerType& listener)
{
m_cache_valid = false;
m_listeners.push_front(&listener);
return m_listeners.begin();
}
template <typename ListenerType>
__fi void EventSource<ListenerType>::_DispatchRaw(ListenerIterator iter, const ListenerIterator& iend, const EvtParams& evtparams)
{
while (iter != iend)
{
try
{
(*iter)->DispatchEvent(evtparams);
}
catch (Exception::RuntimeError& ex)
{
if (IsDevBuild)
{
pxFailDev(("Ignoring runtime error thrown from event listener (event listeners should not throw exceptions!): " + ex.FormatDiagnosticMessage()).c_str());
}
else
{
Console.Error("Ignoring runtime error thrown from event listener: %s", ex.FormatDiagnosticMessage().c_str());
}
}
catch (BaseException& ex)
{
if (IsDevBuild)
{
ex.DiagMsg() = "Non-runtime BaseException thrown from event listener .. " + ex.DiagMsg();
throw;
}
Console.Error("Ignoring non-runtime BaseException thrown from event listener: %s", ex.FormatDiagnosticMessage().c_str());
}
++iter;
}
}
template <typename ListenerType>
void EventSource<ListenerType>::Dispatch(const EvtParams& evtparams)
{
if (!m_cache_valid)
{
m_cache_copy = m_listeners;
m_cache_valid = true;
}
if (m_cache_copy.empty())
return;
_DispatchRaw(m_cache_copy.begin(), m_cache_copy.end(), evtparams);
}

View File

@ -130,7 +130,6 @@
<ClCompile Include="emitter\WinCpuDetect.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="EventSource.inl" />
<MASM Include="FastJmp.asm" />
<None Include="Vulkan\EntryPoints.inl" />
</ItemGroup>
@ -178,7 +177,6 @@
<ClInclude Include="SettingsWrapper.h" />
<ClInclude Include="Assertions.h" />
<ClInclude Include="Console.h" />
<ClInclude Include="EventSource.h" />
<ClInclude Include="Exceptions.h" />
<ClInclude Include="General.h" />
<ClInclude Include="MathUtils.h" />

View File

@ -232,9 +232,6 @@
<ClInclude Include="emitter\implement\dwshift.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventSource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Exceptions.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -530,9 +527,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="EventSource.inl">
<Filter>Source Files</Filter>
</None>
<None Include="Vulkan\EntryPoints.inl">
<Filter>Source Files\Vulkan</Filter>
</None>