15 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
19 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
27 : m_mode(other.m_mode),
32 m_delegate(*
FileInterface::getDelegate(m_handle_storage, &other.m_delegate)) {
33 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
38 this->m_mode = other.m_mode;
39 this->m_path = other.m_path;
40 this->m_crc = other.m_crc;
47 return this->
open(filepath, requested_mode, OverwriteType::NO_OVERWRITE);
51 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
53 FW_ASSERT(File::Mode::OPEN_NO_MODE < requested_mode && File::Mode::MAX_OPEN_MODE > requested_mode);
54 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
55 FW_ASSERT((0 <= overwrite) && (overwrite < OverwriteType::MAX_OVERWRITE_TYPE));
58 return File::Status::INVALID_MODE;
60 File::Status status = this->m_delegate.
open(filepath, requested_mode, overwrite);
62 this->m_mode = requested_mode;
63 this->m_path = filepath;
65 this->m_crc = File::INITIAL_CRC;
72 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
73 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
74 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
75 this->m_delegate.
close();
76 this->m_mode = Mode::OPEN_NO_MODE;
77 this->m_path =
nullptr;
81 FW_ASSERT(&this->m_delegate == reinterpret_cast<const FileInterface*>(&this->m_handle_storage[0]));
82 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
83 return this->m_mode != Mode::OPEN_NO_MODE;
87 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
88 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
90 return File::Status::NOT_OPENED;
92 return this->m_delegate.
size(size_result);
96 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
97 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
100 return File::Status::NOT_OPENED;
102 return this->m_delegate.
position(position_result);
106 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
107 FW_ASSERT((0 <= this->m_mode) && (this->m_mode < Mode::MAX_OPEN_MODE));
110 return File::Status::NOT_OPENED;
112 return File::Status::INVALID_MODE;
114 return this->m_delegate.
preallocate(offset, length);
118 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
119 FW_ASSERT((0 <= seekType) && (seekType < SeekType::MAX_SEEK_TYPE));
121 FW_ASSERT((seekType == File::SeekType::RELATIVE) || (offset >= 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.
seek(offset, seekType);
133 if (static_cast<FwSizeType>(std::numeric_limits<FwSignedSizeType>::max()) >= offset) {
135 FW_ASSERT(static_cast<FwSignedSizeType>(offset) >= 0);
136 status = this->
seek(static_cast<FwSignedSizeType>(offset), File::SeekType::ABSOLUTE);
145 bool is_odd = (offset % 2) == 1;
146 status = this->
seek(half_offset, File::SeekType::ABSOLUTE);
148 status = this->
seek(half_offset, File::SeekType::RELATIVE);
151 status = this->
seek((is_odd) ? 1 : 0, File::SeekType::RELATIVE);
158 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
159 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
162 return File::Status::NOT_OPENED;
164 return File::Status::INVALID_MODE;
166 return this->m_delegate.
flush();
170 return this->
read(buffer,
size, WaitType::WAIT);
174 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
176 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
180 return File::Status::NOT_OPENED;
183 return File::Status::INVALID_MODE;
185 return this->m_delegate.
read(buffer,
size, wait);
189 return this->
write(buffer,
size, WaitType::WAIT);
193 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
195 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
199 return File::Status::NOT_OPENED;
202 return File::Status::INVALID_MODE;
204 return this->m_delegate.
write(buffer,
size, wait);
208 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
216 for (
FwSizeType i = 0; i < std::numeric_limits<FwSizeType>::max(); i++) {
234 status = File::Status::NOT_OPENED;
236 status = File::Status::INVALID_MODE;
239 status = this->
read(this->m_crc_buffer,
size, File::WaitType::NO_WAIT);
240 if (
OP_OK == status) {
242 this->m_crc =
static_cast<U32
>(
update_crc_32(this->m_crc, static_cast<CHAR>(this->m_crc_buffer[i])));
252 this->m_crc = File::INITIAL_CRC;
258 FW_ASSERT(&this->m_delegate == reinterpret_cast<FileInterface*>(&this->m_handle_storage[0]));
260 FW_ASSERT(this->m_mode < Mode::MAX_OPEN_MODE);
264 return File::Status::NOT_OPENED;
267 return File::Status::INVALID_MODE;
281 read = current_chunk_size;
282 status = this->
read(buffer + i,
read, wait);
294 if (buffer[j] ==
'\n') {
298 FW_ASSERT(std::numeric_limits<FwSizeType>::max() -
size >= original_location);
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
PlatformSignedSizeType FwSignedSizeType
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
virtual FileHandle * getHandle()=0
returns the raw file handle
virtual ~FileInterface()=default
unsigned long update_crc_32(unsigned long crc, char c)
virtual Status size(FwSizeType &size_result)=0
get size of currently open file
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
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.
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
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
virtual Status read(U8 *buffer, FwSizeType &size, WaitType wait)=0
read data from this file into supplied buffer bounded by size