LeviLamina
Loading...
Searching...
No Matches
FileStorageArea.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/file/FileAccessType.h"
7#include "mc/deps/core/file/FileStats.h"
8#include "mc/deps/core/file/PathBuffer.h"
9#include "mc/deps/core/file/StorageAreaState.h"
10#include "mc/deps/core/file/WriteOperation.h"
11#include "mc/deps/core/file/file_system/TransactionFlags.h"
12#include "mc/deps/core/threading/BasicLockbox.h"
13#include "mc/deps/core/utility/NonOwnerPointer.h"
14#include "mc/deps/core/utility/SingleThreadedLock.h"
15#include "mc/deps/core/utility/Subject.h"
16
17// auto generated forward declare list
18// clang-format off
19namespace Bedrock::Threading { class Mutex; }
20namespace Core { class FileIndexLru; }
21namespace Core { class FileSystemImpl; }
22namespace Core { class FlatFileManifestTracker; }
23namespace Core { class PathView; }
24namespace Core { class Result; }
25namespace Core { class StorageAreasTree; }
26namespace Core { class FileStorageAreaObserver; }
27// clang-format on
28
29namespace Core {
30
31class FileStorageArea : public ::std::enable_shared_from_this<::Core::FileStorageArea> {
32public:
33 // FileStorageArea inner types declare
34 // clang-format off
36 // clang-format on
37
38 // FileStorageArea inner types define
39 enum class FlushableLevelDbEnvType : int {
40 None = 0,
41 InMemory = 1,
42 StorageArea = 2,
43 };
44
45 struct StorageAreaSpaceInfo {
46 public:
47 // member variables
48 // NOLINTBEGIN
53 // NOLINTEND
54
55 public:
56 // prevent constructor by default
57 StorageAreaSpaceInfo& operator=(StorageAreaSpaceInfo const&);
58 StorageAreaSpaceInfo(StorageAreaSpaceInfo const&);
59 StorageAreaSpaceInfo();
60 };
61
62public:
63 // member variables
64 // NOLINTBEGIN
65 ::ll::TypedStorage<8, 80, ::std::recursive_mutex> mLock;
66 ::ll::TypedStorage<8, 24, ::std::vector<::Core::FileSystemImpl*>> mAllTransactions;
67 ::ll::TypedStorage<1, 1, bool> mCanAttemptExtendSave;
68 ::ll::TypedStorage<1, 1, bool> mCachedFileUsageSize;
69 ::ll::TypedStorage<8, 64, ::Core::FileStats> mTransactionStats;
70 ::ll::TypedStorage<8, 64, ::Core::FileStats> mTotalStats;
71 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::Core::FileStorageArea>> mParent;
72 ::ll::TypedStorage<4, 4, ::Core::FileAccessType> mAccessType;
73 ::ll::TypedStorage<8, 32, ::Core::PathBuffer<::std::string>> mRootPath;
74 ::ll::TypedStorage<8, 24, ::std::vector<::Core::FileSystemImpl*>> mWriteTransactions;
75 ::ll::TypedStorage<8, 32, ::Core::Subject<::Core::FileStorageAreaObserver, ::Core::SingleThreadedLock>> mSubject;
76 ::ll::TypedStorage<8, 144, ::Core::StorageAreaState> mState;
77 ::ll::TypedStorage<1, 1, ::std::atomic<bool>> mFileIOSuspended;
78 ::ll::TypedStorage<8, 88, ::std::condition_variable_any> mResumeSignal;
79 ::ll::TypedStorage<1, 1, bool> mLoggingEnabled;
80 ::ll::TypedStorage<8, 16, ::std::shared_ptr<::Core::FlatFileManifestTracker>> mManifestTracker;
81 ::ll::TypedStorage<1, 1, bool> mIsAccessedDirectly;
82 // NOLINTEND
83
84public:
85 // prevent constructor by default
86 FileStorageArea();
87
88public:
89 // virtual functions
90 // NOLINTBEGIN
91 virtual ~FileStorageArea();
92
93 virtual ::std::unique_ptr<::Core::FileSystemImpl> createTransaction(::Core::FileAccessType accessType) = 0;
94
95 virtual ::std::unique_ptr<::Core::FileSystemImpl>
96 createTransaction(::Core::FileAccessType fileAccessType, ::Core::TransactionFlags);
97
98 virtual bool supportsSizeQuery() const = 0;
99
100 virtual uint64 getTotalSize() const = 0;
101
102 virtual ::Core::Result getUsedSize(uint64& outUsedSize) = 0;
103
104 virtual void setUsedSizeOverride(uint64 fileSize);
105
106 virtual void clearUsedSizeOverride();
107
108 virtual void notifyChangeInFileSize(int64 changeInSize, int64 changeInAllocatedSize);
109
110 virtual bool handlesPendingWrites() const;
111
112 virtual void informPendingWriteSize(uint64, bool const);
113
114 virtual uint64 estimatePendingWriteDiskSize(uint64 rawFileSize) const;
115
116 virtual void informStorageAreaCopy(uint64);
117
118 virtual bool supportsExtendSize() const;
119
120 virtual bool canExtendSize() const;
121
122 virtual void resetCanAttemptExtendSize();
123
124 virtual ::Core::Result getExtendSizeThreshold(uint64& outExtendSizeThreshold) const;
125
126 virtual void attemptExtendSize(int64 const& currentFreeSpace, ::std::function<void()> onCompleteCallback);
127
128 virtual void preemptiveExtendSize(
129 uint64 const expectedContentSize,
130 ::std::function<void()> successCallback,
131 ::std::function<void()> failureCallback
132 );
133
134 virtual uint64 getAvailableUserStorageSize();
135
136 virtual void unloadFlatFileManifests(bool shouldClearManifests);
137
138 virtual void tick();
139
140 virtual void flushImmediately(::Core::PathView flushPath);
141
142 virtual void enableFlushToDisk(bool);
143
144 virtual void enableSequentialWrites(bool);
145
146 virtual bool checkCorrupt(bool);
147
148 virtual ::Bedrock::NonOwnerPointer<::Core::FileIndexLru> getFileIndexLru();
149
150 virtual ::Core::FileStorageArea::FlushableLevelDbEnvType getFlushableLevelDbEnvType() const;
151
152 virtual uint64 getTransactionWriteSizeLimit() const;
153
154 virtual ::Core::Result setSaveDataIcon(::Core::PathView);
155
156 virtual bool shouldAllowCommit() const;
157
158 virtual void trackBytesWritten(::Core::PathView targetPath, uint64 amount, ::Core::WriteOperation writeOperation);
159
160 virtual void trackWriteOperation(::Core::PathView targetPath, ::Core::WriteOperation writeOperation);
161
162 virtual ::Core::FileStorageArea::StorageAreaSpaceInfo getStorageAreaSpaceInfo();
163
164 virtual bool shouldRecordFileError(::Core::PathView path, ::std::error_code error) const;
165
166 virtual ::Core::Result _commit();
167
168 virtual ::Core::Result _onTransactionsEmpty(bool);
169
170 virtual void _onTeardown();
171 // NOLINTEND
172
173public:
174 // member functions
175 // NOLINTBEGIN
176 MCAPI FileStorageArea(
177 ::Core::FileAccessType type,
178 ::Core::PathView rootPath,
179 bool usesFlatFiles,
180 bool isAccessedDirectly,
181 ::std::shared_ptr<::Core::FileStorageArea> parent
182 );
183
184 MCAPI void _addReadOperation(bool succeeded, uint64 numBytesRead);
185
186 MCAPI void _addWriteOperation(bool succeeded, uint64 numBytesWritten);
187
188 MCAPI void _beginTransaction(::Core::FileSystemImpl* pTransaction, bool);
189
190 MCAPI ::Core::Result _endTransaction(::Core::FileSystemImpl* pTransaction, bool fromChild);
191
192#ifdef LL_PLAT_C
193 MCAPI void addObserver(::Core::FileStorageAreaObserver& observer);
194#endif
195
196 MCAPI void checkUserStorage();
197 // NOLINTEND
198
199public:
200 // static functions
201 // NOLINTBEGIN
202 MCAPI static ::Core::Result
203 _getStorageAreaForPathImpl(::std::shared_ptr<::Core::FileStorageArea>& fileStorageArea, ::Core::PathView path);
204
205#ifdef LL_PLAT_C
206 MCAPI static void tickStorageAreas();
207#endif
208 // NOLINTEND
209
210public:
211 // static variables
212 // NOLINTBEGIN
213 MCAPI static ::Bedrock::Threading::BasicLockbox<::std::vector<::Core::FileStats*>, ::Bedrock::Threading::Mutex>&
214 sStorageAreaFileStats();
215
216 MCAPI static ::Core::StorageAreasTree& sStorageAreas();
217 // NOLINTEND
218
219public:
220 // constructor thunks
221 // NOLINTBEGIN
222 MCAPI void* $ctor(
223 ::Core::FileAccessType type,
224 ::Core::PathView rootPath,
225 bool usesFlatFiles,
226 bool isAccessedDirectly,
227 ::std::shared_ptr<::Core::FileStorageArea> parent
228 );
229 // NOLINTEND
230
231public:
232 // destructor thunk
233 // NOLINTBEGIN
234 MCAPI void $dtor();
235 // NOLINTEND
236
237public:
238 // virtual function thunks
239 // NOLINTBEGIN
240 MCFOLD ::std::unique_ptr<::Core::FileSystemImpl>
241 $createTransaction(::Core::FileAccessType fileAccessType, ::Core::TransactionFlags);
242
243 MCFOLD void $setUsedSizeOverride(uint64 fileSize);
244
245 MCFOLD void $clearUsedSizeOverride();
246
247 MCAPI void $notifyChangeInFileSize(int64 changeInSize, int64 changeInAllocatedSize);
248
249 MCFOLD bool $handlesPendingWrites() const;
250
251 MCFOLD void $informPendingWriteSize(uint64, bool const);
252
253 MCFOLD uint64 $estimatePendingWriteDiskSize(uint64 rawFileSize) const;
254
255 MCFOLD void $informStorageAreaCopy(uint64);
256
257 MCFOLD bool $supportsExtendSize() const;
258
259 MCFOLD bool $canExtendSize() const;
260
261 MCAPI void $resetCanAttemptExtendSize();
262
263 MCAPI ::Core::Result $getExtendSizeThreshold(uint64& outExtendSizeThreshold) const;
264
265 MCAPI void $attemptExtendSize(int64 const& currentFreeSpace, ::std::function<void()> onCompleteCallback);
266
267 MCAPI void $preemptiveExtendSize(
268 uint64 const expectedContentSize,
269 ::std::function<void()> successCallback,
270 ::std::function<void()> failureCallback
271 );
272
273 MCAPI uint64 $getAvailableUserStorageSize();
274
275 MCAPI void $unloadFlatFileManifests(bool shouldClearManifests);
276
277 MCFOLD void $tick();
278
279 MCFOLD void $flushImmediately(::Core::PathView flushPath);
280
281 MCFOLD void $enableFlushToDisk(bool);
282
283 MCFOLD void $enableSequentialWrites(bool);
284
285 MCFOLD bool $checkCorrupt(bool);
286
287 MCFOLD ::Bedrock::NonOwnerPointer<::Core::FileIndexLru> $getFileIndexLru();
288
289 MCFOLD ::Core::FileStorageArea::FlushableLevelDbEnvType $getFlushableLevelDbEnvType() const;
290
291 MCFOLD uint64 $getTransactionWriteSizeLimit() const;
292
293 MCAPI ::Core::Result $setSaveDataIcon(::Core::PathView);
294
295 MCAPI bool $shouldAllowCommit() const;
296
297 MCAPI void $trackBytesWritten(::Core::PathView targetPath, uint64 amount, ::Core::WriteOperation writeOperation);
298
299 MCAPI void $trackWriteOperation(::Core::PathView targetPath, ::Core::WriteOperation writeOperation);
300
301 MCAPI ::Core::FileStorageArea::StorageAreaSpaceInfo $getStorageAreaSpaceInfo();
302
303 MCFOLD bool $shouldRecordFileError(::Core::PathView path, ::std::error_code error) const;
304
305 MCFOLD ::Core::Result $_commit();
306
307 MCFOLD ::Core::Result $_onTransactionsEmpty(bool);
308
309 MCFOLD void $_onTeardown();
310
311
312 // NOLINTEND
313};
314
315} // namespace Core
Definition Mutex.h:10
Definition FileIndexLru.h:13
Definition FileStorageAreaObserver.h:7
Definition FileSystemImpl.h:30
Definition FlatFileManifestTracker.h:13
Definition PathView.h:19
Definition Result.h:11
Definition StorageAreasTree.h:16
Definition FileStorageArea.h:45
Definition Alias.h:14