2018-04-17 23:41:57 +00:00
|
|
|
#include "ldr_launch_queue.hpp"
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
2018-04-18 00:04:41 +00:00
|
|
|
namespace LaunchQueue {
|
|
|
|
static LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE];
|
2018-04-18 00:05:19 +00:00
|
|
|
|
|
|
|
Result add(LaunchItem *item) {
|
|
|
|
if(item->arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {
|
|
|
|
return 0x209;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = get_free_index(item->tid);
|
|
|
|
if(idx == LAUNCH_QUEUE_FULL)
|
|
|
|
return 0x409;
|
2018-04-18 00:04:41 +00:00
|
|
|
|
2018-04-18 00:05:19 +00:00
|
|
|
g_launch_queue[idx] = *item;
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
|
2018-04-18 00:04:41 +00:00
|
|
|
int get_index(u64 tid) {
|
|
|
|
for(unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
|
|
|
if(g_launch_queue[i].tid == tid) {
|
|
|
|
return i;
|
|
|
|
}
|
2018-04-17 23:41:57 +00:00
|
|
|
}
|
2018-04-18 00:04:41 +00:00
|
|
|
return LAUNCH_QUEUE_FULL;
|
2018-04-17 23:41:57 +00:00
|
|
|
}
|
2018-04-18 00:04:41 +00:00
|
|
|
|
|
|
|
int get_free_index(u64 tid) {
|
|
|
|
for(unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
|
|
|
if(g_launch_queue[i].tid == tid || g_launch_queue[i].tid == 0x0) {
|
|
|
|
return i;
|
|
|
|
}
|
2018-04-17 23:41:57 +00:00
|
|
|
}
|
2018-04-18 00:04:41 +00:00
|
|
|
return LAUNCH_QUEUE_FULL;
|
2018-04-17 23:41:57 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 00:04:41 +00:00
|
|
|
bool contains(u64 tid) {
|
|
|
|
return get_index(tid) != LAUNCH_QUEUE_FULL;
|
|
|
|
}
|
2018-04-17 23:41:57 +00:00
|
|
|
|
2018-04-18 00:04:41 +00:00
|
|
|
void clear() {
|
|
|
|
for (unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
|
|
|
g_launch_queue[i].tid = 0;
|
|
|
|
}
|
2018-04-17 23:41:57 +00:00
|
|
|
}
|
|
|
|
}
|