2018-04-18 17:41:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
2018-06-12 22:00:09 +00:00
|
|
|
#include "waitablemanagerbase.hpp"
|
|
|
|
|
|
|
|
class WaitableManager;
|
|
|
|
|
2018-04-18 17:41:17 +00:00
|
|
|
class IWaitable {
|
2018-06-12 22:00:09 +00:00
|
|
|
private:
|
|
|
|
u64 wait_priority = 0;
|
|
|
|
bool is_deferred = false;
|
|
|
|
WaitableManagerBase *manager;
|
2018-04-18 17:41:17 +00:00
|
|
|
public:
|
2018-04-18 18:10:45 +00:00
|
|
|
virtual ~IWaitable() { }
|
|
|
|
|
2018-04-22 09:02:08 +00:00
|
|
|
virtual void handle_deferred() = 0;
|
2018-04-18 17:41:17 +00:00
|
|
|
virtual Handle get_handle() = 0;
|
2018-04-18 18:53:04 +00:00
|
|
|
virtual Result handle_signaled(u64 timeout) = 0;
|
2018-06-12 22:00:09 +00:00
|
|
|
|
|
|
|
WaitableManager *get_manager() {
|
|
|
|
return (WaitableManager *)this->manager;
|
2018-04-18 22:24:40 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 22:00:09 +00:00
|
|
|
void set_manager(WaitableManagerBase *m) {
|
|
|
|
this->manager = m;
|
2018-04-18 17:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_priority() {
|
2018-06-12 22:00:09 +00:00
|
|
|
if (manager) {
|
|
|
|
this->wait_priority = this->manager->get_priority();
|
|
|
|
}
|
2018-04-18 17:41:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 09:02:08 +00:00
|
|
|
bool get_deferred() {
|
|
|
|
return this->is_deferred;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_deferred(bool d) {
|
|
|
|
this->is_deferred = d;
|
|
|
|
}
|
|
|
|
|
2018-04-18 17:41:17 +00:00
|
|
|
static bool compare(IWaitable *a, IWaitable *b) {
|
2018-04-22 09:02:08 +00:00
|
|
|
return (a->wait_priority < b->wait_priority) && !a->is_deferred;
|
2018-04-18 17:41:17 +00:00
|
|
|
}
|
2018-06-12 22:00:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#include "waitablemanager.hpp"
|