Nugget
Loading...
Searching...
No Matches
cdrom-loader.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2023 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <EASTL/string_view.h>
30#include <EASTL/vector.h>
31#include <stdint.h>
32
33#include <coroutine>
34
35#include "psyqo/gpu.hh"
37#include "psyqo/task.hh"
38
39namespace psyqo::paths {
40
56 struct ReadFileAwaiter {
57 ReadFileAwaiter(eastl::string_view path, GPU &gpu, ISO9660Parser &parser, CDRomLoader &loader)
58 : m_path(path), m_gpu(gpu), m_parser(parser), m_loader(loader) {}
59 ~ReadFileAwaiter() {}
60 constexpr bool await_ready() const { return false; }
61 template <typename U>
62 void await_suspend(std::coroutine_handle<U> handle) {
63 m_loader.readFile(m_path, m_gpu, m_parser, [handle, this](eastl::vector<uint8_t> &&data) {
64 m_data = eastl::move(data);
65 handle.resume();
66 });
67 }
68 eastl::vector<uint8_t> await_resume() { return eastl::move(m_data); }
69
70 private:
71 eastl::string_view m_path;
72 GPU &m_gpu;
73 ISO9660Parser &m_parser;
74 CDRomLoader &m_loader;
75 eastl::vector<uint8_t> m_data;
76 };
77
78 public:
90 void readFile(eastl::string_view path, GPU &gpu, ISO9660Parser &parser,
91 eastl::function<void(eastl::vector<uint8_t> &&)> &&callback) {
92 setupQueue(path, gpu, parser, eastl::move(callback));
93 m_queue.run();
94 }
95 psyqo::TaskQueue::Task scheduleReadFile(eastl::string_view path, GPU &gpu, ISO9660Parser &parser) {
96 setupQueue(path, gpu, parser, {});
97 return m_queue.schedule();
98 }
99 ReadFileAwaiter readFile(eastl::string_view path, GPU &gpu, ISO9660Parser &parser) {
100 return {path, gpu, parser, *this};
101 }
102
103 private:
104 void setupQueue(eastl::string_view path, GPU &gpu, ISO9660Parser &parser,
105 eastl::function<void(eastl::vector<uint8_t> &&)> &&callback);
106 eastl::function<void(eastl::vector<uint8_t> &&)> m_callback;
107 psyqo::TaskQueue m_queue;
109 eastl::vector<uint8_t> m_data;
110 bool m_pending = false;
111};
112
113} // namespace psyqo::paths
The singleton GPU class.
Definition gpu.hh:88
An ISO9660 parser.
Definition iso9660-parser.hh:48
The Task class.
Definition task.hh:140
A task queue for processing tasks sequentially.
Definition task.hh:46
Task schedule()
Schedules the task queue to another task queue.
Definition task.cpp:68
void run()
Runs the task queue.
Definition task.cpp:61
A class that reads files from the CDRom.
Definition cdrom-loader.hh:55
void readFile(eastl::string_view path, GPU &gpu, ISO9660Parser &parser, eastl::function< void(eastl::vector< uint8_t > &&)> &&callback)
Reads a file from the CDRom.
Definition cdrom-loader.hh:90
ReadFileAwaiter readFile(eastl::string_view path, GPU &gpu, ISO9660Parser &parser)
Definition cdrom-loader.hh:99
psyqo::TaskQueue::Task scheduleReadFile(eastl::string_view path, GPU &gpu, ISO9660Parser &parser)
Definition cdrom-loader.hh:95
Definition cdrom-loader.hh:39
An asynchronous read request.
Definition iso9660-parser.hh:74
void void(ptr, size)