mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-05 22:41:18 +12:00
Add all the files
This commit is contained in:
parent
e3db07a16a
commit
d60742f52b
1445 changed files with 430238 additions and 0 deletions
66
src/util/EventService.h
Normal file
66
src/util/EventService.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/helpers/Singleton.h"
|
||||
|
||||
#include <boost/signals2.hpp>
|
||||
#include <boost/bind/placeholders.hpp>
|
||||
|
||||
enum class Events : int32_t
|
||||
{
|
||||
ControllerChanged,
|
||||
};
|
||||
|
||||
using ControllerChangedFunc = void(void);
|
||||
|
||||
class EventService : public Singleton<EventService>
|
||||
{
|
||||
friend class Singleton<EventService>;
|
||||
EventService() = default;
|
||||
|
||||
public:
|
||||
template <Events event, typename TFunc, typename TClass>
|
||||
boost::signals2::connection connect(TFunc function, TClass thisptr)
|
||||
{
|
||||
using namespace boost::placeholders;
|
||||
if constexpr (event == Events::ControllerChanged)
|
||||
return m_controller_changed_signal.connect(boost::bind(function, thisptr));
|
||||
else
|
||||
{
|
||||
cemu_assert_suspicious();
|
||||
}
|
||||
}
|
||||
|
||||
template <Events event>
|
||||
void disconnect(const boost::signals2::connection& slot)
|
||||
{
|
||||
using namespace boost::placeholders;
|
||||
if constexpr (event == Events::ControllerChanged)
|
||||
m_controller_changed_signal.disconnect(slot);
|
||||
else
|
||||
{
|
||||
cemu_assert_suspicious();
|
||||
}
|
||||
}
|
||||
|
||||
template <Events event, typename ... TArgs>
|
||||
void signal(TArgs&&... args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if constexpr (event == Events::ControllerChanged)
|
||||
m_controller_changed_signal(std::forward<TArgs>(args)...);
|
||||
else
|
||||
{
|
||||
cemu_assert_suspicious();
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
cemuLog_force("error when signaling {}: {}", event, ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
boost::signals2::signal<ControllerChangedFunc> m_controller_changed_signal;
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue