The low-level file communication class.
Definition at line 23 of file iointerfacefile.h.
#include <xSens_MT4/xcommunication/include/xsens/iointerfacefile.h>
Public Member Functions | |
IoInterfaceFile () | |
~IoInterfaceFile () | |
XsResultValue | close (void) |
Close the file, overrides IoInterface::close(). More... | |
XsResultValue | closeFile (void) |
Close the file. More... | |
XsResultValue | flushData (void) |
Flush all data in the buffers to and from the device. More... | |
bool | isOpen (void) const |
Return whether the file is open or not. More... | |
XsResultValue | getLastResult (void) const |
Return the result code of the last operation. More... | |
XsResultValue | writeData (const XsByteArray &data, XsSize *written=NULL) |
Write the data contained in data to the device. More... | |
XsResultValue | readData (XsSize maxLength, XsByteArray &data) |
Read at most maxLength bytes from the device into data. More... | |
XsResultValue | readTerminatedData (XsSize maxLength, unsigned char terminator, XsByteArray &bdata) |
Read data from the file and put it into the data buffer. More... | |
XsResultValue | appendData (const XsByteArray &bdata) |
Write data to the end of the file. More... | |
XsResultValue | closeAndDelete (void) |
Close the file and delete it. More... | |
XsResultValue | create (const XsString &filename) |
Create an empty file. More... | |
XsResultValue | deleteData (XsFilePos start, XsSize 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... | |
XsFilePos | getFileSize (void) const |
Return the size of the file. More... | |
XsTimeStamp | getFileDate (void) const |
Return the creation date of the file. More... | |
XsResultValue | getName (XsString &filename) const |
Retrieve the filename that was last successfully opened. More... | |
XsFilePos | getReadPosition (void) const |
Return the current read position. More... | |
XsFilePos | getWritePosition (void) const |
Return the current write position. More... | |
XsResultValue | insertData (XsFilePos start, const XsByteArray &data) |
Insert the given data into the file. More... | |
bool | isReadOnly (void) const |
Return whether the file is readonly or not. More... | |
XsResultValue | open (const XsString &filename, bool createNew, bool readOnly) |
Open a file. More... | |
XsResultValue | setReadPosition (XsFilePos pos) |
Set the new absolute read position. More... | |
XsResultValue | setWritePosition (XsFilePos pos=-1) |
Set the new absolute write position. More... | |
virtual XsResultValue | open (const XsPortInfo &portInfo, uint32_t readBufSize=XS_DEFAULT_READ_BUFFER_SIZE, uint32_t writeBufSize=XS_DEFAULT_WRITE_BUFFER_SIZE) |
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 (XsSize maxLength, XsByteArray &data) |
Wait for data to arrive or a timeout to occur. More... | |
virtual void | cancelIo (void) const |
Cancel any pending io requests. More... | |
Protected Member Functions | |
void | gotoRead (void) |
Change from writing to reading mode. More... | |
void | gotoWrite (void) |
Change from reading to writing mode. More... | |
Protected Attributes | |
XsFileHandle * | m_handle |
The file handlem, also indicates if the file is open or not. More... | |
XsFilePos | m_fileSize |
Contains the size of the file. More... | |
XsFilePos | m_readPos |
The last read position in the file. More... | |
XsFilePos | m_writePos |
The last write position in the file. More... | |
XsResultValue | m_lastResult |
The last result of an operation. More... | |
XsString | m_filename |
Contains the name of the file that was last successfully opened. 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... | |
IoInterfaceFile::IoInterfaceFile | ( | ) |
Default constructor, initializes all members to their default values.
Definition at line 59 of file iointerfacefile.cpp.
References m_fileSize, m_handle, m_lastResult, m_reading, m_readOnly, m_readPos, m_writePos, and XRV_OK.
IoInterfaceFile::~IoInterfaceFile | ( | ) |
|
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 86 of file iointerfacefile.cpp.
References FSEEK_R, FTELL, m_fileSize, m_handle, m_lastResult, m_reading, m_readOnly, m_writePos, void(), XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.
Cancel any pending io requests.
Reimplemented in SerialInterface.
Definition at line 72 of file iointerface.cpp.
|
virtual |
Close the file, overrides IoInterface::close().
Implements IoInterface.
Definition at line 112 of file iointerfacefile.cpp.
References closeFile().
|
virtual |
Close the file and delete it.
Reimplemented from IoInterface.
Definition at line 145 of file iointerfacefile.cpp.
References mrpt::system::os::fclose(), m_filename, m_fileSize, m_handle, m_lastResult, m_reading, m_readOnly, m_readPos, m_writePos, XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.
XsResultValue IoInterfaceFile::closeFile | ( | void | ) |
Close the file.
Definition at line 120 of file iointerfacefile.cpp.
References mrpt::system::os::fclose(), m_fileSize, m_handle, m_lastResult, m_reading, m_readOnly, m_readPos, m_writePos, and XRV_OK.
Referenced by close(), and ~IoInterfaceFile().
|
virtual |
Create an empty file.
filename | The desired (path+)name of the file |
Reimplemented from IoInterface.
Definition at line 187 of file iointerfacefile.cpp.
References mrpt::system::os::fclose(), mrpt::system::os::fopen(), m_filename, m_fileSize, m_handle, m_lastResult, m_reading, m_readOnly, m_readPos, m_writePos, XRV_ALREADYOPEN, XRV_INVALIDPARAM, XRV_OK, XRV_OUTPUTCANNOTBEOPENED, and XS_MAX_FILENAME_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.
start | The offset of the first byte to delete |
length | The total number of bytes to delete |
Reimplemented from IoInterface.
Definition at line 245 of file iointerfacefile.cpp.
References FSEEK, gotoWrite(), m_fileSize, m_handle, m_lastResult, m_readOnly, m_writePos, XRV_BUSY, XRV_ERROR, XRV_INVALIDINSTANCE, XRV_INVALIDPARAM, XRV_NOFILEOPEN, XRV_OK, XRV_OUTOFMEMORY, and XRV_READONLY.
|
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 328 of file iointerfacefile.cpp.
References FSEEK, gotoRead(), m_handle, m_lastResult, m_readPos, XRV_ENDOFFILE, XRV_NOFILEOPEN, and XRV_OK.
|
virtual |
Flush all data in the buffers to and from the device.
Implements IoInterface.
Definition at line 417 of file iointerfacefile.cpp.
References m_handle, m_lastResult, and XRV_OK.
XsTimeStamp IoInterfaceFile::getFileDate | ( | void | ) | const |
Return the creation date of the file.
Definition at line 400 of file iointerfacefile.cpp.
References _stat, and m_filename.
Return the size of the file.
Reimplemented from IoInterface.
Definition at line 392 of file iointerfacefile.cpp.
References m_fileSize.
|
virtual |
Return the result code of the last operation.
Implements IoInterface.
Definition at line 803 of file iointerfacefile.cpp.
References m_lastResult.
|
virtual |
Retrieve the filename that was last successfully opened.
filename | The XsString which will contain the filename. |
Reimplemented from IoInterface.
Definition at line 429 of file iointerfacefile.cpp.
References m_filename, m_lastResult, and XRV_OK.
Return the current read position.
Reimplemented from IoInterface.
Definition at line 787 of file iointerfacefile.cpp.
References m_readPos.
Return the current write position.
Reimplemented from IoInterface.
Definition at line 795 of file iointerfacefile.cpp.
References m_writePos.
Change from writing to reading mode.
Definition at line 436 of file iointerfacefile.cpp.
References FSEEK, m_handle, m_reading, and m_readPos.
Referenced by find(), readData(), and readTerminatedData().
Change from reading to writing mode.
Definition at line 447 of file iointerfacefile.cpp.
References FSEEK, m_handle, m_reading, and m_writePos.
Referenced by deleteData(), insertData(), and writeData().
|
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 466 of file iointerfacefile.cpp.
References FSEEK, gotoWrite(), m_fileSize, m_handle, m_lastResult, m_readOnly, m_writePos, XRV_NOFILEOPEN, XRV_OK, XRV_OUTOFMEMORY, and XRV_READONLY.
|
virtual |
Return whether the file is open or not.
Implements IoInterface.
Definition at line 811 of file iointerfacefile.cpp.
References m_handle.
Referenced by isReadOnly().
|
virtual |
Return whether the file is readonly or not.
Reimplemented from IoInterface.
Definition at line 819 of file iointerfacefile.cpp.
References isOpen(), and m_readOnly.
|
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 543 of file iointerfacefile.cpp.
References mrpt::system::os::fclose(), mrpt::system::os::fopen(), FSEEK, FSEEK_R, FTELL, m_filename, m_fileSize, m_handle, m_lastResult, m_reading, m_readOnly, m_readPos, m_writePos, XRV_ALREADYOPEN, XRV_INPUTCANNOTBEOPENED, XRV_INVALIDPARAM, XRV_OK, and XS_MAX_FILENAME_LENGTH.
|
virtualinherited |
Open a communication channel to the given port info.
If the baudrate in portInfo is set to XBR_Invalid, the baud rate is automatically detected if possible.
portInfo | The details of the port that should be opened. Depending on the type of interface, parts of this parameter may be ignored. |
readBufSize | The size of the read buffer in bytes (if appliccable to the device) |
writeBufSize | The size of the write buffer in bytes (if appliccable to the device) |
Reimplemented in SerialInterface, and UsbInterface.
Definition at line 52 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
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 616 of file iointerfacefile.cpp.
References gotoRead(), m_handle, m_lastResult, m_readPos, XRV_ENDOFFILE, XRV_NOFILEOPEN, and XRV_OK.
XsResultValue IoInterfaceFile::readTerminatedData | ( | XsSize | maxLength, |
unsigned char | terminator, | ||
XsByteArray & | bdata | ||
) |
Read data from the file and put it into the data buffer.
This function reads upp 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.
maxLength | The amount of data that will be read. |
terminator | A character that will end the read operation if encountered. |
bdata | A buffer that will store the read data. |
Definition at line 655 of file iointerfacefile.cpp.
References gotoRead(), m_handle, m_lastResult, m_readPos, XRV_ENDOFFILE, XRV_NOFILEOPEN, and XRV_OK.
|
virtual |
Set the new absolute read position.
The read position is checked against the filesize first.
pos | The new read position |
Reimplemented from IoInterface.
Definition at line 700 of file iointerfacefile.cpp.
References FSEEK, m_handle, m_lastResult, m_reading, m_readPos, XRV_NOFILEOPEN, and XRV_OK.
|
virtualinherited |
Set the default timeout value to use in blocking operations.
This function sets the value of m_timeout. There is no infinity value. The value 0 means that all blocking operations now become polling (non-blocking) operations. If the value is set to or from 0, the low-level serial port settings may be changed in addition to the m_timeout value.
ms | The new timeout in milliseconds |
Reimplemented in SerialInterface, UsbInterface, and StreamInterface.
Definition at line 59 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Set the new absolute write position.
The write position is checked against the filesize first.
pos | The new write position |
Reimplemented from IoInterface.
Definition at line 720 of file iointerfacefile.cpp.
References FSEEK, FSEEK_R, FTELL, m_handle, m_lastResult, m_reading, m_readOnly, m_writePos, XRV_NOFILEOPEN, XRV_OK, and XRV_READONLY.
|
virtualinherited |
Wait for data to arrive or a timeout to occur.
The function waits until maxLength
data is available or until a timeout occurs. The function returns success if data is available or XsResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.
maxLength | The maximum number of bytes to read before returning |
data | The buffer to put the read data in. |
Reimplemented in SerialInterface.
Definition at line 65 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Write the data contained in data to the device.
data | The data to write to the device. |
written | An optional XsSize value that will receive the number of bytes that were actually written. |
Implements IoInterface.
Definition at line 750 of file iointerfacefile.cpp.
References gotoWrite(), m_fileSize, m_handle, m_lastResult, m_readOnly, m_writePos, XRV_ERROR, XRV_INSUFFICIENTSPACE, XRV_NOFILEOPEN, XRV_OK, XRV_OUTOFMEMORY, and XRV_READONLY.
|
protected |
Contains the name of the file that was last successfully opened.
Definition at line 39 of file iointerfacefile.h.
Referenced by closeAndDelete(), create(), getFileDate(), getName(), and open().
|
protected |
Contains the size of the file.
Definition at line 31 of file iointerfacefile.h.
Referenced by appendData(), closeAndDelete(), closeFile(), create(), deleteData(), getFileSize(), insertData(), IoInterfaceFile(), open(), and writeData().
|
protected |
The file handlem, also indicates if the file is open or not.
Definition at line 29 of file iointerfacefile.h.
Referenced by appendData(), closeAndDelete(), closeFile(), create(), deleteData(), find(), flushData(), gotoRead(), gotoWrite(), insertData(), IoInterfaceFile(), isOpen(), open(), readData(), readTerminatedData(), setReadPosition(), setWritePosition(), and writeData().
|
mutableprotected |
The last result of an operation.
Definition at line 37 of file iointerfacefile.h.
Referenced by appendData(), closeAndDelete(), closeFile(), create(), deleteData(), find(), flushData(), getLastResult(), getName(), insertData(), IoInterfaceFile(), open(), readData(), readTerminatedData(), setReadPosition(), setWritePosition(), and writeData().
|
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 45 of file iointerfacefile.h.
Referenced by appendData(), closeAndDelete(), closeFile(), create(), gotoRead(), gotoWrite(), IoInterfaceFile(), open(), setReadPosition(), and setWritePosition().
|
protected |
Indicates if the file was opened in read-only mode.
Definition at line 47 of file iointerfacefile.h.
Referenced by appendData(), closeAndDelete(), closeFile(), create(), deleteData(), insertData(), IoInterfaceFile(), isReadOnly(), open(), setWritePosition(), and writeData().
|
protected |
The last read position in the file.
Definition at line 33 of file iointerfacefile.h.
Referenced by closeAndDelete(), closeFile(), create(), find(), getReadPosition(), gotoRead(), IoInterfaceFile(), open(), readData(), readTerminatedData(), and setReadPosition().
|
protected |
The last write position in the file.
Definition at line 35 of file iointerfacefile.h.
Referenced by appendData(), closeAndDelete(), closeFile(), create(), deleteData(), getWritePosition(), gotoWrite(), insertData(), IoInterfaceFile(), open(), setWritePosition(), and writeData().
Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019 |