14 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
18 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
26 : m_mode(other.m_mode),
30 m_delegate(*
FileInterface::getDelegate(m_handle_storage, &other.m_delegate)) {
31 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
42 this->m_mode = other.m_mode;
43 this->m_hash = other.m_hash;
45 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
51 return this->
open(filepath, requested_mode, OverwriteType::NO_OVERWRITE);
60 return this->
open(filepath, length, requested_mode, OverwriteType::NO_OVERWRITE);
67 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
70 FW_ASSERT(string_len < length, static_cast<FwAssertArgType>(string_len), static_cast<FwAssertArgType>(length));
71 FW_ASSERT(File::Mode::OPEN_NO_MODE < requested_mode && File::Mode::MAX_OPEN_MODE > requested_mode);
72 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
73 FW_ASSERT((0 <= overwrite) && (overwrite < OverwriteType::MAX_OVERWRITE_TYPE));
76 return File::Status::INVALID_MODE;
78 File::Status status = this->m_delegate.
open(filepath, requested_mode, overwrite);
80 this->m_mode = requested_mode;
90 OverwriteType::NO_OVERWRITE);
98 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
99 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
100 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
101 this->m_delegate.
close();
102 this->m_mode = Mode::OPEN_NO_MODE;
106 FW_ASSERT(&this->m_delegate == reinterpret_cast<const FileInterface*>(&this->m_handle_storage[0]));
107 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
108 return this->m_mode != Mode::OPEN_NO_MODE;
112 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
113 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
115 return File::Status::NOT_OPENED;
117 return this->m_delegate.
size(size_result);
121 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
122 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
125 return File::Status::NOT_OPENED;
127 return this->m_delegate.
position(position_result);
131 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
132 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
135 return File::Status::NOT_OPENED;
137 return File::Status::INVALID_MODE;
139 return this->m_delegate.
preallocate(offset, length);
143 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
144 FW_ASSERT((0 <= seekType) && (seekType < SeekType::MAX_SEEK_TYPE));
146 FW_ASSERT((seekType == File::SeekType::RELATIVE) || (offset >= 0));
147 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
150 return File::Status::NOT_OPENED;
152 return this->m_delegate.
seek(offset, seekType);
158 if (static_cast<FwSizeType>(std::numeric_limits<FwSignedSizeType>::max()) >= offset) {
160 FW_ASSERT(static_cast<FwSignedSizeType>(offset) >= 0);
161 status = this->
seek(static_cast<FwSignedSizeType>(offset), File::SeekType::ABSOLUTE);
170 bool is_odd = (offset % 2) == 1;
171 status = this->
seek(half_offset, File::SeekType::ABSOLUTE);
173 status = this->
seek(half_offset, File::SeekType::RELATIVE);
176 status = this->
seek((is_odd) ? 1 : 0, File::SeekType::RELATIVE);
183 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
184 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
187 return File::Status::NOT_OPENED;
189 return File::Status::INVALID_MODE;
191 return this->m_delegate.
flush();
195 return this->
read(buffer,
size, WaitType::WAIT);
199 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
201 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
205 return File::Status::NOT_OPENED;
208 return File::Status::INVALID_MODE;
210 return this->m_delegate.
read(buffer,
size, wait);
214 return this->
write(buffer,
size, WaitType::WAIT);
218 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
220 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
224 return File::Status::NOT_OPENED;
227 return File::Status::INVALID_MODE;
229 return this->m_delegate.
write(buffer,
size, wait);
233 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
241 for (
FwSizeType i = 0; i < std::numeric_limits<FwSizeType>::max(); i++) {
259 status = File::Status::NOT_OPENED;
261 status = File::Status::INVALID_MODE;
264 status = this->
read(this->m_crc_buffer,
size, File::WaitType::NO_WAIT);
265 if (
OP_OK == status) {
267 this->m_hash.
update(this->m_crc_buffer,
size);
285 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
287 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
291 return File::Status::NOT_OPENED;
294 return File::Status::INVALID_MODE;
308 read = current_chunk_size;
309 status = this->
read(buffer + i,
read, wait);
325 if (buffer[j] ==
'\n') {
329 FW_ASSERT(std::numeric_limits<FwSizeType>::max() -
size >= original_location);
void update(const void *const data, const FwSizeType len)
virtual Status open(const char *path, Mode mode, OverwriteType overwrite)=0
open file with supplied path and mode
Status incrementalCrc(FwSizeType &size)
calculate the CRC32 of the next section of data
base implementation of FileHandle
Status calculateCrc(U32 &crc)
calculate the CRC32 of the entire file
A catch-all for other errors. Have to look in implementation-specific code.
PlatformSizeType FwSizeType
File mode not yet selected.
Status preallocate(FwSizeType offset, FwSizeType length) override
pre-allocate file storage
Status position(FwSizeType &position_result) override
get file pointer position of the currently open file
Status seek_absolute(FwSizeType offset_unsigned)
seek the file pointer to the given offset absolutely with the full range
virtual void close()=0
close the file, if not opened then do nothing
Status size(FwSizeType &size_result) override
get size of currently open file
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
PlatformSignedSizeType FwSignedSizeType
virtual FileHandle * getHandle()=0
returns the raw file handle
virtual ~FileInterface()=default
virtual Status size(FwSizeType &size_result)=0
get size of currently open file
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
virtual Status flush()=0
flush file contents to storage
virtual Status seek(FwSignedSizeType offset, SeekType seekType)=0
seek the file pointer to the given offset
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
FileHandle * getHandle() override
returns the raw file handle
void close() override
close the file, if not opened then do nothing
Status write(const U8 *buffer, FwSizeType &size)
write data to this file from the supplied buffer bounded by size
virtual SizeType getCapacity() const =0
Return the size of the buffer.
uint8_t U8
8-bit unsigned integer
Status read(U8 *buffer, FwSizeType &size)
read data from this file into supplied buffer bounded by size
Status flush() override
flush file contents to storage
static U32 min(const U32 a, const U32 b)
virtual Status write(const U8 *buffer, FwSizeType &size, WaitType wait)=0
read data from this file into supplied buffer bounded by size
Status readline(U8 *buffer, FwSizeType &size, WaitType wait)
read a line from the file using \n as the delimiter
Operation was successful.
A read-only abstract superclass for StringBase.
Status finalizeCrc(U32 &crc)
finalize and retrieve the CRC value
static FileInterface * getDelegate(FileHandleStorage &aligned_placement_new_memory, const FileInterface *to_copy=nullptr)
provide a pointer to a file delegate object
virtual Status preallocate(FwSizeType offset, FwSizeType length)=0
pre-allocate file storage
File & operator=(const File &other)
assignment operator that copies the internal representation
void finalize(HashBuffer &buffer) const
virtual Status position(FwSizeType &position_result)=0
get file pointer position of the currently open file
bool isOpen() const
determine if the file is open
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
virtual Status read(U8 *buffer, FwSizeType &size, WaitType wait)=0
read data from this file into supplied buffer bounded by size
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string