ProcessManager: Fill out ProcessTracking::Initialize()

This commit is contained in:
Michael Scire 2018-05-03 16:15:00 -06:00
parent 90c7f03a9d
commit af6d60d06c
3 changed files with 98 additions and 0 deletions

View File

@ -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"

View File

@ -0,0 +1,68 @@
#pragma once
#include <switch.h>
#include <vector>
#include "iwaitable.hpp"
typedef Result (*EventCallback)(Handle *handles, size_t num_handles, u64 timeout);
class IEvent : IWaitable {
protected:
std::vector<Handle> 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;
}
};

View File

@ -0,0 +1,26 @@
#pragma once
#include <switch.h>
#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]);
}
};