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 <stdint.h>
31
32#include <coroutine>
33
34#include "psyqo/buffer.hh"
36#include "psyqo/task.hh"
37
38namespace psyqo::paths {
39
55 struct ReadFileAwaiter {
56 ReadFileAwaiter(eastl::string_view path, ISO9660Parser &parser, CDRomLoader &loader)
57 : m_path(path), m_parser(parser), m_loader(loader) {}
58 ~ReadFileAwaiter() {}
59 constexpr bool await_ready() const { return false; }
60 template <typename U>
61 void await_suspend(std::coroutine_handle<U> handle) {
62 m_loader.readFile(m_path, m_parser, [handle, this](Buffer<uint8_t> &&data) {
63 m_data = eastl::move(data);
64 handle.resume();
65 });
66 }
67 Buffer<uint8_t> await_resume() { return eastl::move(m_data); }
68
69 private:
70 eastl::string_view m_path;
71 ISO9660Parser &m_parser;
72 CDRomLoader &m_loader;
73 Buffer<uint8_t> m_data;
74 };
75
76 public:
88 void setBuffer(Buffer<uint8_t> &&buffer) { m_data = eastl::move(buffer); }
89
100 void readFile(eastl::string_view path, ISO9660Parser &parser,
101 eastl::function<void(Buffer<uint8_t> &&)> &&callback) {
102 setupQueue(path, parser, eastl::move(callback));
103 m_queue.run();
104 }
105 psyqo::TaskQueue::Task scheduleReadFile(eastl::string_view path, ISO9660Parser &parser) {
106 setupQueue(path, parser, {});
107 return m_queue.schedule();
108 }
109 ReadFileAwaiter readFile(eastl::string_view path, ISO9660Parser &parser) {
110 return {path, parser, *this};
111 }
112
113 private:
114 void setupQueue(eastl::string_view path, ISO9660Parser &parser,
115 eastl::function<void(Buffer<uint8_t> &&)> &&callback);
116 eastl::function<void(Buffer<uint8_t> &&)> m_callback;
117 psyqo::TaskQueue m_queue;
119 Buffer<uint8_t> m_data;
120 bool m_pending = false;
121};
122
123} // namespace psyqo::paths
A class that manages a buffer of data.
Definition buffer.hh:63
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:54
ReadFileAwaiter readFile(eastl::string_view path, ISO9660Parser &parser)
Definition cdrom-loader.hh:109
psyqo::TaskQueue::Task scheduleReadFile(eastl::string_view path, ISO9660Parser &parser)
Definition cdrom-loader.hh:105
void readFile(eastl::string_view path, ISO9660Parser &parser, eastl::function< void(Buffer< uint8_t > &&)> &&callback)
Reads a file from the CDRom.
Definition cdrom-loader.hh:100
void setBuffer(Buffer< uint8_t > &&buffer)
Set the Buffer object for the next read operation.
Definition cdrom-loader.hh:88
Definition archive-manager.hh:43
An asynchronous read request.
Definition iso9660-parser.hh:74
static void * buffer
Definition syscalls.h:230
void void(ptr, size)