From af6d60d06c546534f241e880d0780b357a7e6b94 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 3 May 2018 16:15:00 -0600 Subject: [PATCH] ProcessManager: Fill out ProcessTracking::Initialize() --- include/stratosphere.hpp | 4 ++ include/stratosphere/ievent.hpp | 68 ++++++++++++++++++++++++++++ include/stratosphere/systemevent.hpp | 26 +++++++++++ 3 files changed, 98 insertions(+) create mode 100644 include/stratosphere/ievent.hpp create mode 100644 include/stratosphere/systemevent.hpp diff --git a/include/stratosphere.hpp b/include/stratosphere.hpp index 13eb4ff5..2b460711 100644 --- a/include/stratosphere.hpp +++ b/include/stratosphere.hpp @@ -7,6 +7,10 @@ #include "stratosphere/serviceserver.hpp" #include "stratosphere/managedportserver.hpp" #include "stratosphere/existingportserver.hpp" + +#include "stratosphere/ievent.hpp" +#include "stratosphere/systemevent.hpp" + #include "stratosphere/waitablemanager.hpp" #include "stratosphere/ipc_templating.hpp" \ No newline at end of file diff --git a/include/stratosphere/ievent.hpp b/include/stratosphere/ievent.hpp new file mode 100644 index 00000000..a8f4e46c --- /dev/null +++ b/include/stratosphere/ievent.hpp @@ -0,0 +1,68 @@ +#pragma once +#include +#include + +#include "iwaitable.hpp" + +typedef Result (*EventCallback)(Handle *handles, size_t num_handles, u64 timeout); + +class IEvent : IWaitable { + protected: + std::vector handles; + EventCallback callback; + + public: + IEvent(Handle wait_h, EventCallback callback) { + if (wait_h) { + this->handles.push_back(wait_h); + } + this->callback = callback; + } + + ~IEvent() { + for (auto &h : this->handles) { + svcCloseHandle(h); + } + } + + virtual Result signal_event() = 0; + + /* IWaitable */ + virtual unsigned int get_num_waitables() { + if (handles.size() > 0) { + return 1; + } + return 0; + } + + virtual void get_waitables(IWaitable **dst) { + if (handles.size() > 0) { + dst[0] = this; + } + } + + virtual void delete_child(IWaitable *child) { + /* TODO: Panic, an event can never be a parent. */ + } + + virtual Handle get_handle() { + if (handles.size() > 0) { + return this->handles[0]; + } + return 0; + } + + + virtual void handle_deferred() { + /* TODO: Panic, because we can never defer an event. */ + } + + virtual Result handle_signaled(u64 timeout) { + return this->callback(this->handles.data(), this->handles.size(), timeout); + } + + static Result PanicCallback(Handle *handles, size_t num_handles, u64 timeout) { + /* TODO: Panic. */ + return 0xCAFE; + } +}; \ No newline at end of file diff --git a/include/stratosphere/systemevent.hpp b/include/stratosphere/systemevent.hpp new file mode 100644 index 00000000..23d2139b --- /dev/null +++ b/include/stratosphere/systemevent.hpp @@ -0,0 +1,26 @@ +#pragma once +#include + +#include "iwaitable.hpp" +#include "ievent.hpp" + +#define SYSTEMEVENT_INDEX_WAITHANDLE 0 +#define SYSTEMEVENT_INDEX_SGNLHANDLE 1 + +class SystemEvent : IEvent { + public: + SystemEvent(EventCallback callback) : IEvent(0, callback) { + Handle wait_h; + Handle sig_h; + if (R_FAILED(svcCreateEvent(&wait_h, &sig_h))) { + /* TODO: Panic. */ + } + + this->handles.push_back(wait_h); + this->handles.push_back(sig_h); + } + + virtual Result signal_event() { + return svcSignalEvent(this->handles[SYSTEMEVENT_INDEX_SGNLHANDLE]); + } +}; \ No newline at end of file