resonance 1.0.1
Loading...
Searching...
No Matches
async.h
Go to the documentation of this file.
1#pragma once
2
3#include <stddef.h>
4#include <sys/types.h>
5
6class AsyncCallback;
7
9constexpr int kAsyncJobCount = 512;
10
12constexpr int kFileHandleArkStream = 0x4000;
13
15constexpr int kFileHandleSceFile = 0x2000;
16
23
25constexpr unsigned kAsyncRequestCloseFile = 1;
26
33constexpr unsigned kAsyncRequestInflate = 2;
34
36constexpr int kAsyncStatusPending = -1;
37
39constexpr int kAsyncStatusOk = 0;
40
42constexpr int kAsyncStatusOpenFailed = 2;
43
46
48constexpr int kAsyncStatusReadFailed = 4;
49
51constexpr int kAsyncStatusInflateFailed = 5;
52
74
105
118
129
148int AsyncSubmitRequest(int nFile,
149 void *pBuffer,
150 int nLength,
151 int bCloseOnComplete,
152 AsyncCallback *pCallback,
153 int bOwnsBuffer);
154
180int AsyncLoadFileByPath(const char *pszPath,
181 void *pBuffer,
182 unsigned nLength,
183 AsyncCallback *pCallback);
184
202
215void AsyncJobComplete(AsyncRequest *pRequest, int nStatus);
216
228int AsyncGetIdFromFd(int nFile);
229
242int MatchesCurrentAsyncOp(int nFile, int nSector);
243
269void AsyncCheck(int nBlocking);
270
287
299
311void AsyncMediaEventCallback(int nFunction);
312
325int AsyncPollComplete(int nHandle, void **ppBuffer, int *pnLength);
326
338void AsyncCancelRequest(int nHandle);
339
347
361void AsyncStatus(int &nPending, int &nCompleted, int &nFreeJobs);
362
373
386
412int FileOpen(const char *pszPath, int nFlags, ...);
413
429extern "C" ssize_t read(int nFile, void *pBuffer, size_t nLength);
430
445int FileSeek(int nFile, int nOffset, int nOrigin);
446
459extern "C" int close(int nFile);
460
477extern "C" ssize_t write(int nFile, const void *pBuffer, size_t nLength);
478
491extern "C" int isatty(int nFile);
492
504int ArkfileGetCurrAbsOffset(int nStream);
505
519int SeekArkStream(int nStream, int nOffset, int nOrigin);
int AsyncGetIdFromFd(int nFile)
Resolve a file handle to the file the sector cache is keyed by.
void AsyncPumpCompletedRequests()
Service the queue once.
AsyncJobInfo * AsyncGetFreeJobChain()
Take the next job off the free list.
constexpr int kAsyncStatusReadFailed
Stored in AsyncRequest::mStatus when the read itself failed.
Definition async.h:48
int isatty(int nFile)
Report whether a file is an interactive terminal.
constexpr int kAsyncStatusOpenFailed
Stored in AsyncRequest::mStatus when the path could not be opened.
Definition async.h:42
void AsyncDump()
Report the queue to the log.
void AsyncQueueRequest(AsyncRequest request)
Split a request into chunk jobs and put it on the pending list.
void AsyncCheck(int nBlocking)
Advance the operation the media is servicing.
FileSeekOrigin
Origins FileSeek() and SeekArkStream() accept.
Definition async.h:18
@ kFileSeekCur
Definition async.h:20
@ kFileSeekEnd
Definition async.h:21
@ kFileSeekSet
Definition async.h:19
ssize_t read(int nFile, void *pBuffer, size_t nLength)
Read one run of bytes from a file.
int FileSeek(int nFile, int nOffset, int nOrigin)
Move a file's read position.
int FileOpen(const char *pszPath, int nFlags,...)
Open a file by path.
constexpr int kAsyncStatusOk
Stored in AsyncRequest::mStatus once the data is in place.
Definition async.h:39
int close(int nFile)
Close a file.
int MatchesCurrentAsyncOp(int nFile, int nSector)
Report whether the operation the drive is servicing right now covers a chunk.
int SeekArkStream(int nStream, int nOffset, int nOrigin)
Move an ark stream's read position.
void AsyncJobComplete(AsyncRequest *pRequest, int nStatus)
Finish a request and put it on the completed list.
constexpr int kAsyncStatusBufferTooSmall
Stored in AsyncRequest::mStatus when the caller's buffer is smaller than the file.
Definition async.h:45
void ShutdownAsync()
Release the job ring.
constexpr int kFileHandleArkStream
Bit of a file handle that identifies a stream inside a mounted ark rather than a loose file.
Definition async.h:12
constexpr int kAsyncStatusInflateFailed
Stored in AsyncRequest::mStatus when the read succeeded and the inflate did not.
Definition async.h:51
constexpr unsigned kAsyncRequestCloseFile
Bit of AsyncRequest::mFlags that makes completion close the request's file.
Definition async.h:25
void AsyncReturnJobChain(AsyncJobInfo *pChain)
Put a whole chain of jobs back on the free list.
ssize_t write(int nFile, const void *pBuffer, size_t nLength)
Write to a file.
void AsyncMediaEventCallback(int nFunction)
Drive completion callback the async layer installs on disc media.
constexpr int kFileHandleSceFile
Bit of a file handle that identifies a file the host or disc file service opened.
Definition async.h:15
int IsMediaReady()
Report whether the disc is ready to read.
void AsyncCancelRequest(int nHandle)
Abandon a request wherever it sits.
constexpr int kAsyncStatusPending
Stored in AsyncRequest::mStatus while the request has not completed.
Definition async.h:36
int AsyncLoadFileByPath(const char *pszPath, void *pBuffer, unsigned nLength, AsyncCallback *pCallback)
Open a path and queue the whole file as one asynchronous read.
void AsyncStatus(int &nPending, int &nCompleted, int &nFreeJobs)
Report how much work the queue is holding.
int AsyncSubmitRequest(int nFile, void *pBuffer, int nLength, int bCloseOnComplete, AsyncCallback *pCallback, int bOwnsBuffer)
Queue one asynchronous read and report its identifier.
void InitAsync()
Bring up the asynchronous file-I/O layer.
constexpr int kAsyncJobCount
The number of job records the ring is built from.
Definition async.h:9
int ArkfileGetCurrAbsOffset(int nStream)
Report an ark stream's read position.
constexpr unsigned kAsyncRequestInflate
Bit of AsyncRequest::mFlags that makes completion inflate what the read delivered.
Definition async.h:33
int AsyncPollComplete(int nHandle, void **ppBuffer, int *pnLength)
Report a finished request and take it off the completed list.
Receiver notified once a queued asynchronous read has finished.
Definition asynccallback.h:18
One queued asynchronous read.
Definition async.h:65
int mLength
Definition async.h:72
int mSectorCount
Definition async.h:69
int mSectorOffset
Definition async.h:71
void * mBuffer
Definition async.h:70
int mSector
Definition async.h:68
AsyncJobInfo * mNext
Definition async.h:66
AsyncJobInfo * mPrev
Definition async.h:67
One queued or completed asynchronous request.
Definition async.h:91
void * mReadBuffer
Definition async.h:95
int mStreamFile
Definition async.h:98
int mReadLength
Definition async.h:96
AsyncJobInfo * mJobs
Definition async.h:100
int mId
Definition async.h:92
unsigned mFlags
Definition async.h:99
void * mBuffer
Definition async.h:94
int mOwnsBuffer
Definition async.h:103
int mLength
Definition async.h:97
int mFile
Definition async.h:93
AsyncCallback * mCallback
Definition async.h:101
int mStatus
Definition async.h:102