Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
IoInterfaceFile Class Reference

The low-level file communication class. More...

#include <iointerfacefile.h>

Inheritance diagram for IoInterfaceFile:
Inheritance graph
[legend]

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 ()
 
- Public Member Functions inherited from IoInterface
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...
 
- Protected Member Functions inherited from IoInterface
 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...
 
XsFilem_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

- Public Types inherited from IoInterface
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...
 

Detailed Description

The low-level file communication class.

Definition at line 74 of file iointerfacefile.h.

Constructor & Destructor Documentation

◆ IoInterfaceFile()

IoInterfaceFile::IoInterfaceFile ( )

Default constructor, initializes all members to their default values.

Definition at line 93 of file iointerfacefile.cpp.

◆ ~IoInterfaceFile()

IoInterfaceFile::~IoInterfaceFile ( )

Destructor

Definition at line 106 of file iointerfacefile.cpp.

Member Function Documentation

◆ appendData()

XsResultValue IoInterfaceFile::appendData ( const XsByteArray bdata)
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.

Parameters
bdataThe byte data to append to the file
Returns
XRV_OK if the write was successful

Reimplemented from IoInterface.

Definition at line 123 of file iointerfacefile.cpp.

◆ close()

XsResultValue IoInterfaceFile::close ( )
overridevirtual

Close the file, overrides IoInterface::close().

Returns
XRV_OK if the file was closed successfully

Implements IoInterface.

Definition at line 148 of file iointerfacefile.cpp.

◆ closeAndDelete()

XsResultValue IoInterfaceFile::closeAndDelete ( )
virtual

Close the file and delete it.

Returns
XRV_OK if the file was closed and deleted successfully

Reimplemented from IoInterface.

Definition at line 179 of file iointerfacefile.cpp.

◆ closeFile()

XsResultValue IoInterfaceFile::closeFile ( )

Close the file.

Returns
XRV_OK if the file was closed successfully

Definition at line 156 of file iointerfacefile.cpp.

◆ create()

XsResultValue IoInterfaceFile::create ( const XsString filename)
virtual

Create an empty file.

Parameters
filenameThe desired (path+)name of the file
Returns
XRV_OK if the file was created successfully

Reimplemented from IoInterface.

Definition at line 210 of file iointerfacefile.cpp.

◆ deleteData()

XsResultValue IoInterfaceFile::deleteData ( XsFilePos  start,
XsFilePos  length 
)
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.

Parameters
startThe offset of the first byte to delete
lengthThe total number of bytes to delete
Returns
XRV_OK if the data was deleted successfully

Reimplemented from IoInterface.

Definition at line 253 of file iointerfacefile.cpp.

◆ find()

XsResultValue IoInterfaceFile::find ( const XsByteArray needleV,
XsFilePos pos 
)
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.

Parameters
needleVThe byte string to find.
posThe position where needleV was found. This will point to the first character of the found needleV.
Returns
XRV_OK if the data was found, XRV_ENDOFFILE if it wasn't found

Reimplemented from IoInterface.

Definition at line 312 of file iointerfacefile.cpp.

◆ flushData()

XsResultValue IoInterfaceFile::flushData ( )
overridevirtual

Flush all data in the buffers to and from the device.

Returns
XRV_OK if the data was flushed successfully

Implements IoInterface.

Definition at line 400 of file iointerfacefile.cpp.

◆ flushFileBuffers()

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.

Note
Only for Windows!
Returns
XRV_OK if the buffers were flushed successfully

Definition at line 855 of file iointerfacefile.cpp.

◆ getFileDate()

XsTimeStamp IoInterfaceFile::getFileDate ( ) const

Return the creation date of the file.

Returns
The creation date of the file

Definition at line 383 of file iointerfacefile.cpp.

◆ getFileName()

XsString IoInterfaceFile::getFileName ( ) const

Return the filename that was last successfully opened.

Definition at line 420 of file iointerfacefile.cpp.

◆ getFileSize()

XsFilePos IoInterfaceFile::getFileSize ( ) const
virtual

Return the size of the file.

Returns
The size of the file.

Reimplemented from IoInterface.

Definition at line 375 of file iointerfacefile.cpp.

◆ getLastResult()

XsResultValue IoInterfaceFile::getLastResult ( ) const
overridevirtual

Return the result code of the last operation.

Returns
The result code of the last operation.

Implements IoInterface.

Definition at line 808 of file iointerfacefile.cpp.

◆ getName()

XsResultValue IoInterfaceFile::getName ( XsString filename) const
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.

◆ getReadPosition()

XsFilePos IoInterfaceFile::getReadPosition ( ) const
virtual

Return the current read position.

Returns
The current read position.

Reimplemented from IoInterface.

Definition at line 792 of file iointerfacefile.cpp.

◆ getWritePosition()

XsFilePos IoInterfaceFile::getWritePosition ( ) const
virtual

Return the current write position.

Returns
The current write position.

Reimplemented from IoInterface.

Definition at line 800 of file iointerfacefile.cpp.

◆ gotoRead()

void IoInterfaceFile::gotoRead ( )
protected

Change from writing to reading mode.

Definition at line 426 of file iointerfacefile.cpp.

◆ gotoWrite()

void IoInterfaceFile::gotoWrite ( )
protected

Change from reading to writing mode.

Definition at line 437 of file iointerfacefile.cpp.

◆ insertData()

XsResultValue IoInterfaceFile::insertData ( XsFilePos  start,
const XsByteArray data 
)
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.

Parameters
startThe offset in the file to write the first byte
dataThe data to insert in the file
Returns
XRV_OK if the data was inserted successfully

Reimplemented from IoInterface.

Definition at line 456 of file iointerfacefile.cpp.

◆ isOpen()

bool IoInterfaceFile::isOpen ( ) const
overridevirtual

Return whether the file is open or not.

Returns
true if the file is open

Implements IoInterface.

Definition at line 816 of file iointerfacefile.cpp.

◆ isReadOnly()

bool IoInterfaceFile::isReadOnly ( ) const
virtual

Return whether the file is read-only or not.

Returns
true if the file is read-only

Reimplemented from IoInterface.

Definition at line 824 of file iointerfacefile.cpp.

◆ open()

XsResultValue IoInterfaceFile::open ( const XsString filename,
bool  createNew,
bool  readOnly 
)
virtual

Open a file.

Parameters
filenameThe name of the file to open
createNewWhen true, the file will be created if it doesn't exist yet
readOnlyWhen true, the file will be marked as read only for IoInterfaceFile, preventing accidental writes to the file.
Returns
XRV_OK if the file was opened successfully
See also
createFile
Test:
does this work for non-existing files? Or do we need a check and create?

Reimplemented from IoInterface.

Definition at line 535 of file iointerfacefile.cpp.

◆ readData()

XsResultValue IoInterfaceFile::readData ( XsFilePos  maxLength,
XsByteArray data 
)
overridevirtual

Read at most maxLength bytes from the device into data.

Parameters
maxLengthThe 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.
dataA buffer that will contain the read data.
Returns
XRV_OK if all data was read successfully, XRV_TIMEOUT if some data was read, but not maxLength, XRV_TIMEOUTNODATA if no data was read at all.
Note
This function reads exactly the number of bytes as requested from the file unless the end of file boundary is encountered.

Implements IoInterface.

Definition at line 598 of file iointerfacefile.cpp.

◆ readDataBlocks()

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.

Parameters
blockCountThe number of blocks to read.
dataA buffer for the data that was read from the file
Returns
XRV_OK if the data was read successfully

Definition at line 634 of file iointerfacefile.cpp.

◆ readTerminatedData()

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.

◆ reserve()

XsResultValue IoInterfaceFile::reserve ( XsFilePos  minSize)

Make sure the file is at least minSize bytes big.

Parameters
minSizeThe minimum file size required
Returns
XRV_OK if the reserve succeeded

The file will not be truncated, any added bytes will be filled with '\0' characters

Definition at line 834 of file iointerfacefile.cpp.

◆ setReadPosition()

XsResultValue IoInterfaceFile::setReadPosition ( XsFilePos  pos)
virtual

Set the new absolute read position.

The read position is checked against the file size first.

Parameters
posThe new read position
Returns
XRV_OK if the read position was updated successfully

Reimplemented from IoInterface.

Definition at line 701 of file iointerfacefile.cpp.

◆ setWritePosition()

XsResultValue IoInterfaceFile::setWritePosition ( XsFilePos  pos = -1)
virtual

Set the new absolute write position.

The write position is checked against the file size first.

Parameters
posThe new write position
Returns
XRV_OK if the write position was updated successfully

Reimplemented from IoInterface.

Definition at line 721 of file iointerfacefile.cpp.

◆ writeData()

XsResultValue IoInterfaceFile::writeData ( const XsByteArray data,
XsFilePos written = nullptr 
)
overridevirtual

Write the data contained in data to the device.

Parameters
dataThe data to write to the device.
writtenAn optional XsFilePos value that will receive the number of bytes that were actually written.
Returns
XRV_OK if the data was written successfully
Note
The function writes the given data to the file at the current write position.

Implements IoInterface.

Definition at line 751 of file iointerfacefile.cpp.

◆ XSENS_DISABLE_COPY()

IoInterfaceFile::XSENS_DISABLE_COPY ( IoInterfaceFile  )

Member Data Documentation

◆ m_fileBlockSize

const XsFilePos IoInterfaceFile::m_fileBlockSize = 4096
static

The default file block size.

Definition at line 136 of file iointerfacefile.h.

◆ m_filename

XsString IoInterfaceFile::m_filename
protected

Contains the name of the file that was last successfully opened.

Definition at line 88 of file iointerfacefile.h.

◆ m_fileSize

XsFilePos IoInterfaceFile::m_fileSize
protected

Contains the size of the file.

Definition at line 80 of file iointerfacefile.h.

◆ m_handle

XsFile* IoInterfaceFile::m_handle
protected

The file handle, also indicates if the file is open or not.

Definition at line 78 of file iointerfacefile.h.

◆ m_lastResult

XsResultValue IoInterfaceFile::m_lastResult
mutableprotected

The last result of an operation.

Definition at line 86 of file iointerfacefile.h.

◆ m_reading

bool IoInterfaceFile::m_reading
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.

◆ m_readOnly

bool IoInterfaceFile::m_readOnly
protected

Indicates if the file was opened in read-only mode.

Definition at line 96 of file iointerfacefile.h.

◆ m_readPos

XsFilePos IoInterfaceFile::m_readPos
protected

The last read position in the file.

Definition at line 82 of file iointerfacefile.h.

◆ m_writePos

XsFilePos IoInterfaceFile::m_writePos
protected

The last write position in the file.

Definition at line 84 of file iointerfacefile.h.


The documentation for this class was generated from the following files:


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:21