pgl: update to use tipc (untested)

This commit is contained in:
Michael Scire
2021-04-11 01:07:55 -07:00
committed by SciresM
parent 1118421fa6
commit b2b0c50802
16 changed files with 600 additions and 130 deletions

View File

@@ -19,19 +19,79 @@
#include <stratosphere/pm.hpp>
#include <stratosphere/pgl/pgl_types.hpp>
#include <stratosphere/pgl/sf/pgl_sf_i_event_observer.hpp>
#include <stratosphere/pgl/tipc/pgl_tipc_i_event_observer.hpp>
namespace ams::pgl {
namespace impl {
class EventObserverInterface {
NON_COPYABLE(EventObserverInterface);
NON_MOVEABLE(EventObserverInterface);
public:
constexpr EventObserverInterface() = default;
virtual ~EventObserverInterface() { /* ... */ }
virtual Result GetSystemEvent(os::SystemEventType *out) = 0;
virtual Result GetProcessEventInfo(pm::ProcessEventInfo *out) = 0;
};
class EventObserverByCmif final : public EventObserverInterface {
NON_COPYABLE(EventObserverByCmif);
NON_MOVEABLE(EventObserverByCmif);
private:
ams::sf::SharedPointer<pgl::sf::IEventObserver> m_cmif_interface;
public:
explicit EventObserverByCmif(ams::sf::SharedPointer<pgl::sf::IEventObserver> intf) : m_cmif_interface(intf) { /* ... */ }
public:
virtual Result GetSystemEvent(os::SystemEventType *out) override {
ams::sf::CopyHandle handle;
R_TRY(m_cmif_interface->GetProcessEventHandle(std::addressof(handle)));
os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear);
return ResultSuccess();
}
virtual Result GetProcessEventInfo(pm::ProcessEventInfo *out) override {
return m_cmif_interface->GetProcessEventInfo(out);
}
};
template<typename T> requires tipc::IsIEventObserver<T>
class EventObserverByTipc final : public EventObserverInterface {
NON_COPYABLE(EventObserverByTipc);
NON_MOVEABLE(EventObserverByTipc);
private:
T m_tipc_interface;
public:
template<typename... Args>
explicit EventObserverByTipc(Args &&... args) : m_tipc_interface(std::forward<Args>(args)...) { /* ... */ }
public:
virtual Result GetSystemEvent(os::SystemEventType *out) override {
ams::tipc::CopyHandle handle;
R_TRY(m_tipc_interface.GetProcessEventHandle(std::addressof(handle)));
os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear);
return ResultSuccess();
}
virtual Result GetProcessEventInfo(pm::ProcessEventInfo *out) override {
return m_tipc_interface.GetProcessEventInfo(ams::tipc::Out<pm::ProcessEventInfo>(out));
}
};
}
class EventObserver {
NON_COPYABLE(EventObserver);
private:
ams::sf::SharedPointer<pgl::sf::IEventObserver> interface;
std::unique_ptr<impl::EventObserverInterface> m_impl;
public:
EventObserver() { /* ... */ }
explicit EventObserver(ams::sf::SharedPointer<pgl::sf::IEventObserver> intf) : interface(intf) { /* ... */ }
explicit EventObserver(std::unique_ptr<impl::EventObserverInterface> impl) : m_impl(std::move(impl)) { /* ... */ }
EventObserver(EventObserver &&rhs) {
this->interface = std::move(rhs.interface);
m_impl = std::move(rhs.m_impl);
}
EventObserver &operator=(EventObserver &&rhs) {
@@ -40,18 +100,15 @@ namespace ams::pgl {
}
void Swap(EventObserver &rhs) {
std::swap(this->interface, rhs.interface);
std::swap(m_impl, rhs.m_impl);
}
public:
Result GetSystemEvent(os::SystemEventType *out) {
ams::sf::CopyHandle handle;
R_TRY(this->interface->GetProcessEventHandle(std::addressof(handle)));
os::AttachSystemEvent(out, handle.GetValue(), true, svc::InvalidHandle, false, os::EventClearMode_AutoClear);
return ResultSuccess();
return m_impl->GetSystemEvent(out);
}
Result GetProcessEventInfo(pm::ProcessEventInfo *out) {
return this->interface->GetProcessEventInfo(out);
return m_impl->GetProcessEventInfo(out);
}
};