Nugget
Loading...
Searching...
No Matches
iso9660-parser.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 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/fixed_string.h>
30#include <EASTL/functional.h>
31#include <EASTL/string_view.h>
32
33#include <coroutine>
34
35#include "psyqo/cdrom.hh"
36#include "psyqo/task.hh"
37
38namespace psyqo {
39
49 public:
56 struct DirEntry {
59 eastl::fixed_string<char, 15, false> name;
61 };
62
74 struct ReadRequest {
76 void* buffer = nullptr;
77 };
78
87 ISO9660Parser(CDRom* cdrom) : m_cdrom(cdrom) {}
88
98 void initialize(eastl::function<void(bool success)> callback);
101 InitializeAwaiter(ISO9660Parser& parser) : m_parser(parser) {}
102 bool await_ready() const { return false; }
103 template <typename U>
104 void await_suspend(std::coroutine_handle<U> handle) {
105 m_parser.initialize([handle, this](bool success) {
106 m_success = success;
107 handle.resume();
108 });
109 }
110 bool await_resume() { return m_success; }
111
112 private:
113 ISO9660Parser& m_parser;
114 bool m_success;
115 };
117
129 void getDirentry(eastl::string_view path, DirEntry* entry, eastl::function<void(bool success)> callback);
130 TaskQueue::Task scheduleGetDirentry(eastl::string_view path, DirEntry* entry);
132 GetDirentryAwaiter(ISO9660Parser& parser, eastl::string_view path, DirEntry* entry)
133 : m_parser(parser), m_path(path), m_entry(entry) {}
134 bool await_ready() const { return false; }
135 template <typename U>
136 void await_suspend(std::coroutine_handle<U> handle) {
137 m_parser.getDirentry(m_path, m_entry, [handle, this](bool success) {
138 m_success = success;
139 handle.resume();
140 });
141 }
142 bool await_resume() { return m_success; }
143
144 private:
145 ISO9660Parser& m_parser;
146 eastl::string_view m_path;
147 DirEntry* m_entry;
148 bool m_success;
149 };
150 GetDirentryAwaiter getDirentry(eastl::string_view path, DirEntry* entry) {
151 return GetDirentryAwaiter(*this, path, entry);
152 }
153
166 TaskQueue::Task scheduleReadRequest(ReadRequest* request);
167
176 bool initialized() { return m_initialized; }
177
183 CDRom* getCDRom() { return m_cdrom; }
184
185 private:
186 void parseDirEntry(const uint8_t* data, DirEntry* entry);
187 eastl::string_view getEntryName(const uint8_t* data);
188 void findDirEntry();
189
190 uint8_t m_buffer[2048];
191 eastl::function<void(bool success)> m_callback = nullptr;
192 eastl::string_view m_path;
193 DirEntry* m_dirEntry = nullptr;
194 CDRom* m_cdrom = nullptr;
195 uint32_t m_cachedLBA = 0;
196 DirEntry m_root;
197 DirEntry m_cachedEntry;
198 eastl::fixed_string<char, 128> m_cachedPath;
199 bool m_initialized = false;
200};
201
202} // namespace psyqo
The base CDRom class.
Definition cdrom.hh:46
An ISO9660 parser.
Definition iso9660-parser.hh:48
TaskQueue::Task scheduleInitialize()
Definition iso9660-parser.cpp:68
bool initialized()
Returns the state of the parser.
Definition iso9660-parser.hh:176
TaskQueue::Task scheduleGetDirentry(eastl::string_view path, DirEntry *entry)
Definition iso9660-parser.cpp:109
TaskQueue::Task scheduleReadRequest(ReadRequest *request)
Read a file asynchronously.
Definition iso9660-parser.cpp:116
GetDirentryAwaiter getDirentry(eastl::string_view path, DirEntry *entry)
Definition iso9660-parser.hh:150
ISO9660Parser(CDRom *cdrom)
The ISO9660Parser constructor.
Definition iso9660-parser.hh:87
void initialize(eastl::function< void(bool success)> callback)
Initializes the parser.
Definition iso9660-parser.cpp:32
CDRom * getCDRom()
Returns the CDRom object used by the parser.
Definition iso9660-parser.hh:183
InitializeAwaiter initialize()
Definition iso9660-parser.hh:116
void getDirentry(eastl::string_view path, DirEntry *entry, eastl::function< void(bool success)> callback)
Get the Direntry object for a given path.
Definition iso9660-parser.cpp:72
The Task class.
Definition task.hh:140
Definition cdrom-loader.hh:39
Definition direntry.h:33
An ISO9660 directory entry.
Definition iso9660-parser.hh:56
uint32_t size
Definition iso9660-parser.hh:58
enum psyqo::ISO9660Parser::DirEntry::@20 type
uint32_t LBA
Definition iso9660-parser.hh:57
eastl::fixed_string< char, 15, false > name
Definition iso9660-parser.hh:59
@ PARENT_DIR
Definition iso9660-parser.hh:60
@ INVALID
Definition iso9660-parser.hh:60
@ CURRENT_DIR
Definition iso9660-parser.hh:60
@ FILE
Definition iso9660-parser.hh:60
@ DIRECTORY
Definition iso9660-parser.hh:60
Definition iso9660-parser.hh:131
void await_suspend(std::coroutine_handle< U > handle)
Definition iso9660-parser.hh:136
bool await_ready() const
Definition iso9660-parser.hh:134
GetDirentryAwaiter(ISO9660Parser &parser, eastl::string_view path, DirEntry *entry)
Definition iso9660-parser.hh:132
bool await_resume()
Definition iso9660-parser.hh:142
Definition iso9660-parser.hh:100
void await_suspend(std::coroutine_handle< U > handle)
Definition iso9660-parser.hh:104
bool await_ready() const
Definition iso9660-parser.hh:102
bool await_resume()
Definition iso9660-parser.hh:110
InitializeAwaiter(ISO9660Parser &parser)
Definition iso9660-parser.hh:101
An asynchronous read request.
Definition iso9660-parser.hh:74
void * buffer
Definition iso9660-parser.hh:76
struct DirEntry entry
Definition iso9660-parser.hh:75
void void(ptr, size)
void uint32_t(classId, spec)