The low-level file communication class. More...
#include <iointerfacefile.h>
Public Member Functions | |
XsResultValue | appendData (const XsByteArray &bdata) |
Write data to the end of the file. More... | |
XsResultValue | close () override |
Close the file, overrides IoInterface::close(). More... | |
XsResultValue | closeAndDelete () |
Close the file and delete it. More... | |
XsResultValue | closeFile () |
Close the file. More... | |
XsResultValue | create (const XsString &filename) |
Create an empty file. More... | |
XsResultValue | deleteData (XsFilePos start, XsFilePos length) |
Delete the given data from the file. More... | |
XsResultValue | find (const XsByteArray &data, XsFilePos &pos) |
Find a string of bytes in the file. More... | |
XsResultValue | flushData () override |
Flush all data in the buffers to and from the device. More... | |
XsResultValue | flushFileBuffers () |
Flushes the buffers of a specified file and causes all buffered data to be written to a file. More... | |
XsTimeStamp | getFileDate () const |
Return the creation date of the file. More... | |
XsString | getFileName () const |
Return the filename that was last successfully opened. More... | |
XsFilePos | getFileSize () const |
Return the size of the file. More... | |
XsResultValue | getLastResult () const override |
Return the result code of the last operation. More... | |
XsResultValue | getName (XsString &filename) const |
Retrieve the filename that was last successfully opened. More... | |
XsFilePos | getReadPosition () const |
Return the current read position. More... | |
XsFilePos | getWritePosition () const |
Return the current write position. More... | |
XsResultValue | insertData (XsFilePos start, const XsByteArray &data) |
Insert the given data into the file. More... | |
IoInterfaceFile () | |
bool | isOpen () const override |
Return whether the file is open or not. More... | |
bool | isReadOnly () const |
Return whether the file is read-only or not. More... | |
XsResultValue | open (const XsString &filename, bool createNew, bool readOnly) |
Open a file. More... | |
XsResultValue | readData (XsFilePos maxLength, XsByteArray &data) override |
Read at most maxLength bytes from the device into data. More... | |
XsResultValue | readDataBlocks (XsFilePos blockCount, XsByteArray &data) |
This function will read blocks of data aligned to m_fileBlockSize. More... | |
XsResultValue | readTerminatedData (XsFilePos maxLength, unsigned char terminator, XsByteArray &bdata) |
Read data from the file and put it into the data buffer. More... | |
XsResultValue | reserve (XsFilePos minSize) |
Make sure the file is at least minSize bytes big. More... | |
XsResultValue | setReadPosition (XsFilePos pos) |
Set the new absolute read position. More... | |
XsResultValue | setWritePosition (XsFilePos pos=-1) |
Set the new absolute write position. More... | |
XsResultValue | writeData (const XsByteArray &data, XsFilePos *written=nullptr) override |
Write the data contained in data to the device. More... | |
XSENS_DISABLE_COPY (IoInterfaceFile) | |
~IoInterfaceFile () | |
![]() | |
virtual void | cancelIo (void) const |
Cancel any pending io requests. More... | |
virtual XsResultValue | open (const XsPortInfo &portInfo, XsFilePos readBufSize=XS_DEFAULT_READ_BUFFER_SIZE, XsFilePos writeBufSize=XS_DEFAULT_WRITE_BUFFER_SIZE, PortOptions options=PO_XsensDefaults) |
Open a communication channel to the given port info. More... | |
virtual XsResultValue | setTimeout (uint32_t ms) |
Set the default timeout value to use in blocking operations. More... | |
virtual XsResultValue | waitForData (XsFilePos maxLength, XsByteArray &data) |
Wait for data to arrive or a timeout to occur. More... | |
virtual | ~IoInterface () |
Destructor. More... | |
Static Public Attributes | |
static const XsFilePos | m_fileBlockSize = 4096 |
The default file block size. More... | |
Protected Member Functions | |
void | gotoRead () |
Change from writing to reading mode. More... | |
void | gotoWrite () |
Change from reading to writing mode. More... | |
![]() | |
IoInterface () | |
Constructor. More... | |
XSENS_DISABLE_COPY (IoInterface) | |
Protected Attributes | |
XsString | m_filename |
Contains the name of the file that was last successfully opened. More... | |
XsFilePos | m_fileSize |
Contains the size of the file. More... | |
XsFile * | m_handle |
The file handle, also indicates if the file is open or not. More... | |
XsResultValue | m_lastResult |
The last result of an operation. More... | |
bool | m_reading |
Indicates whether the last operation was a read or write operation. More... | |
bool | m_readOnly |
Indicates if the file was opened in read-only mode. More... | |
XsFilePos | m_readPos |
The last read position in the file. More... | |
XsFilePos | m_writePos |
The last write position in the file. More... | |
Additional Inherited Members | |
![]() | |
enum | PortOptions { PO_NoFlowControl = 0, PO_RtsCtsFlowControl = (1 << 0), PO_DtrDsrFlowControl = (1 << 1), PO_XonXoffFlowControl = (1 << 2), PO_OneStopBit = 0, PO_TwoStopBits = (1 << 3), PO_XsensDefaults = (PO_NoFlowControl | PO_TwoStopBits) } |
Options for flow control and stopbits which must be used when opening a port. More... | |
The low-level file communication class.
Definition at line 74 of file iointerfacefile.h.
IoInterfaceFile::IoInterfaceFile | ( | ) |
Default constructor, initializes all members to their default values.
Definition at line 93 of file iointerfacefile.cpp.
IoInterfaceFile::~IoInterfaceFile | ( | ) |
Destructor
Definition at line 106 of file iointerfacefile.cpp.
|
virtual |
Write data to the end of the file.
The function writes the given data to the file at the end. The current write position is also moved to the end of the file.
bdata | The byte data to append to the file |
Reimplemented from IoInterface.
Definition at line 123 of file iointerfacefile.cpp.
|
overridevirtual |
Close the file, overrides IoInterface::close().
Implements IoInterface.
Definition at line 148 of file iointerfacefile.cpp.
|
virtual |
Close the file and delete it.
Reimplemented from IoInterface.
Definition at line 179 of file iointerfacefile.cpp.
XsResultValue IoInterfaceFile::closeFile | ( | ) |
Close the file.
Definition at line 156 of file iointerfacefile.cpp.
|
virtual |
Create an empty file.
filename | The desired (path+)name of the file |
Reimplemented from IoInterface.
Definition at line 210 of file iointerfacefile.cpp.
|
virtual |
Delete the given data from the file.
The function erases the given data from the file at the given write position. This operation may take a while to complete, but is faster than insertData.
The write position is not changed and the read position is checked for validity upon function exit.
start | The offset of the first byte to delete |
length | The total number of bytes to delete |
Reimplemented from IoInterface.
Definition at line 253 of file iointerfacefile.cpp.
|
virtual |
Find a string of bytes in the file.
The function searches from the current read position until the given needle
is found. If the needle is not found, XsResultValue::NOT_FOUND is returned. The function will update the seek position to the first character of the found needle.
needleV | The byte string to find. |
pos | The position where needleV was found. This will point to the first character of the found needleV. |
Reimplemented from IoInterface.
Definition at line 312 of file iointerfacefile.cpp.
|
overridevirtual |
Flush all data in the buffers to and from the device.
Implements IoInterface.
Definition at line 400 of file iointerfacefile.cpp.
XsResultValue IoInterfaceFile::flushFileBuffers | ( | ) |
Flushes the buffers of a specified file and causes all buffered data to be written to a file.
This will ensure that the metadata is written to the file.
Definition at line 855 of file iointerfacefile.cpp.
XsTimeStamp IoInterfaceFile::getFileDate | ( | ) | const |
Return the creation date of the file.
Definition at line 383 of file iointerfacefile.cpp.
XsString IoInterfaceFile::getFileName | ( | ) | const |
Return the filename that was last successfully opened.
Definition at line 420 of file iointerfacefile.cpp.
|
virtual |
Return the size of the file.
Reimplemented from IoInterface.
Definition at line 375 of file iointerfacefile.cpp.
|
overridevirtual |
Return the result code of the last operation.
Implements IoInterface.
Definition at line 808 of file iointerfacefile.cpp.
|
virtual |
Retrieve the filename that was last successfully opened.
\param filename The XsString which will contain the filename. \returns XRV_OK
Reimplemented from IoInterface.
Definition at line 412 of file iointerfacefile.cpp.
|
virtual |
Return the current read position.
Reimplemented from IoInterface.
Definition at line 792 of file iointerfacefile.cpp.
|
virtual |
Return the current write position.
Reimplemented from IoInterface.
Definition at line 800 of file iointerfacefile.cpp.
|
protected |
Change from writing to reading mode.
Definition at line 426 of file iointerfacefile.cpp.
|
protected |
Change from reading to writing mode.
Definition at line 437 of file iointerfacefile.cpp.
|
virtual |
Insert the given data into the file.
The function writes the given data to the file at the current write position. This operation may take a while to complete.
The write position is placed at the end of the inserted data.
start | The offset in the file to write the first byte |
data | The data to insert in the file |
Reimplemented from IoInterface.
Definition at line 456 of file iointerfacefile.cpp.
|
overridevirtual |
Return whether the file is open or not.
Implements IoInterface.
Definition at line 816 of file iointerfacefile.cpp.
|
virtual |
Return whether the file is read-only or not.
Reimplemented from IoInterface.
Definition at line 824 of file iointerfacefile.cpp.
|
virtual |
Open a file.
filename | The name of the file to open |
createNew | When true, the file will be created if it doesn't exist yet |
readOnly | When true, the file will be marked as read only for IoInterfaceFile, preventing accidental writes to the file. |
Reimplemented from IoInterface.
Definition at line 535 of file iointerfacefile.cpp.
|
overridevirtual |
Read at most maxLength bytes from the device into data.
maxLength | The maximum number of bytes to read. Depending on the device type and timeout settings, the function may return with less than this number of bytes read. |
data | A buffer that will contain the read data. |
Implements IoInterface.
Definition at line 598 of file iointerfacefile.cpp.
XsResultValue IoInterfaceFile::readDataBlocks | ( | XsFilePos | blockCount, |
XsByteArray & | data | ||
) |
This function will read blocks of data aligned to m_fileBlockSize.
The Function will read as much data as is necessary to align to the block size + blockCount blocks. So the given blockCount is an indication for the minimum amount of data read, unless the end of file is encountered.
blockCount | The number of blocks to read. |
data | A buffer for the data that was read from the file |
Definition at line 634 of file iointerfacefile.cpp.
XsResultValue IoInterfaceFile::readTerminatedData | ( | XsFilePos | maxLength, |
unsigned char | terminator, | ||
XsByteArray & | bdata | ||
) |
Read data from the file and put it into the data buffer.
This function reads up to the number of bytes as requested from the file. The function will also stop if the given terminator character is encountered. The terminator is included in the output buffer. \param maxLength The amount of data that will be read. \param terminator A character that will end the read operation if encountered. \param bdata A buffer that will store the read data. \returns XRV_OK if the data was read successfully
Definition at line 656 of file iointerfacefile.cpp.
XsResultValue IoInterfaceFile::reserve | ( | XsFilePos | minSize | ) |
Make sure the file is at least minSize bytes big.
minSize | The minimum file size required |
The file will not be truncated, any added bytes will be filled with '\0' characters
Definition at line 834 of file iointerfacefile.cpp.
|
virtual |
Set the new absolute read position.
The read position is checked against the file size first.
pos | The new read position |
Reimplemented from IoInterface.
Definition at line 701 of file iointerfacefile.cpp.
|
virtual |
Set the new absolute write position.
The write position is checked against the file size first.
pos | The new write position |
Reimplemented from IoInterface.
Definition at line 721 of file iointerfacefile.cpp.
|
overridevirtual |
Write the data contained in data to the device.
data | The data to write to the device. |
written | An optional XsFilePos value that will receive the number of bytes that were actually written. |
Implements IoInterface.
Definition at line 751 of file iointerfacefile.cpp.
IoInterfaceFile::XSENS_DISABLE_COPY | ( | IoInterfaceFile | ) |
|
static |
The default file block size.
Definition at line 136 of file iointerfacefile.h.
|
protected |
Contains the name of the file that was last successfully opened.
Definition at line 88 of file iointerfacefile.h.
|
protected |
Contains the size of the file.
Definition at line 80 of file iointerfacefile.h.
|
protected |
The file handle, also indicates if the file is open or not.
Definition at line 78 of file iointerfacefile.h.
|
mutableprotected |
The last result of an operation.
Definition at line 86 of file iointerfacefile.h.
|
protected |
Indicates whether the last operation was a read or write operation.
This value is used to check whether or not a seek is required to perform a requested read or write operation.
Definition at line 94 of file iointerfacefile.h.
|
protected |
Indicates if the file was opened in read-only mode.
Definition at line 96 of file iointerfacefile.h.
|
protected |
The last read position in the file.
Definition at line 82 of file iointerfacefile.h.
|
protected |
The last write position in the file.
Definition at line 84 of file iointerfacefile.h.