Public Types | Public Member Functions | Protected Member Functions | List of all members
IoInterface Class Referenceabstract

An abstract IO interface. More...

#include <iointerface.h>

Inheritance diagram for IoInterface:
Inheritance graph
[legend]

Public Types

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...
 

Public Member Functions

virtual XsResultValue appendData (const XsByteArray &bdata)
 Write data to the end of the file. More...
 
virtual void cancelIo (void) const
 Cancel any pending io requests. More...
 
virtual XsResultValue close (void)=0
 Close the connection to the device. More...
 
virtual XsResultValue closeAndDelete (void)
 Close the file and delete it. More...
 
virtual XsResultValue create (const XsString &filename)
 Create an empty file. More...
 
virtual XsResultValue deleteData (XsFilePos start, XsFilePos length)
 Delete the given data from the file. More...
 
virtual XsResultValue find (const XsByteArray &needleV, XsFilePos &pos)
 Find a string of bytes in the file. More...
 
virtual XsResultValue flushData (void)=0
 Flush all data in the buffers to and from the device. More...
 
virtual XsFilePos getFileSize (void) const
 Return the size of the file. More...
 
virtual XsResultValue getLastResult (void) const =0
 Returns the last result value produced by this interface. More...
 
virtual XsResultValue getName (XsString &filename) const
 Retrieve the filename that was last successfully opened. More...
 
virtual XsFilePos getReadPosition (void) const
 Return the current read position. More...
 
virtual XsFilePos getWritePosition (void) const
 Return the current write position. More...
 
virtual XsResultValue insertData (XsFilePos start, const XsByteArray &data)
 Insert the given data into the file. More...
 
virtual bool isOpen (void) const =0
 Returns true if the object has a connection to a device. More...
 
virtual bool isReadOnly (void) const
 Return whether the file is read-only or not. 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 open (const XsString &filename, bool createNew, bool readOnly)
 Open a file. More...
 
virtual XsResultValue readData (XsFilePos maxLength, XsByteArray &data)=0
 Read at most maxLength bytes from the device into data. More...
 
virtual XsResultValue setReadPosition (XsFilePos pos)
 Set the new absolute read position. More...
 
virtual XsResultValue setTimeout (uint32_t ms)
 Set the default timeout value to use in blocking operations. More...
 
virtual XsResultValue setWritePosition (XsFilePos pos=-1)
 Set the new absolute write position. More...
 
virtual XsResultValue waitForData (XsFilePos maxLength, XsByteArray &data)
 Wait for data to arrive or a timeout to occur. More...
 
virtual XsResultValue writeData (const XsByteArray &data, XsFilePos *written=nullptr)=0
 Write the data contained in data to the device. More...
 
virtual ~IoInterface ()
 Destructor. More...
 

Protected Member Functions

 IoInterface ()
 Constructor. More...
 
 XSENS_DISABLE_COPY (IoInterface)
 

Detailed Description

An abstract IO interface.

An IoInterface provides a generic interface for dealing with an interface device such as a file, a com port or a USB port.

Note
The class is not thread safe.

Definition at line 86 of file iointerface.h.

Member Enumeration Documentation

◆ PortOptions

Options for flow control and stopbits which must be used when opening a port.

Enumerator
PO_NoFlowControl 
PO_RtsCtsFlowControl 
PO_DtrDsrFlowControl 
PO_XonXoffFlowControl 
PO_OneStopBit 
PO_TwoStopBits 
PO_XsensDefaults 

Definition at line 130 of file iointerface.h.

Constructor & Destructor Documentation

◆ ~IoInterface()

virtual IoInterface::~IoInterface ( )
inlinevirtual

Destructor.

Definition at line 90 of file iointerface.h.

◆ IoInterface()

IoInterface::IoInterface ( )
inlineprotected

Constructor.

Definition at line 164 of file iointerface.h.

Member Function Documentation

◆ appendData()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 121 of file iointerface.cpp.

◆ cancelIo()

void IoInterface::cancelIo ( void  ) const
virtual

Cancel any pending io requests.

Reimplemented in SerialInterface.

Definition at line 114 of file iointerface.cpp.

◆ close()

virtual XsResultValue IoInterface::close ( void  )
pure virtual

Close the connection to the device.

Returns
XRV_OK if the connection was closed successfully

Implemented in SerialInterface, UsbInterface, and IoInterfaceFile.

◆ closeAndDelete()

XsResultValue IoInterface::closeAndDelete ( void  )
virtual

Close the file and delete it.

Returns
XRV_OK if the file was closed and deleted successfully

Reimplemented in IoInterfaceFile.

Definition at line 127 of file iointerface.cpp.

◆ create()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 132 of file iointerface.cpp.

◆ deleteData()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 138 of file iointerface.cpp.

◆ find()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 145 of file iointerface.cpp.

◆ flushData()

virtual XsResultValue IoInterface::flushData ( void  )
pure virtual

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

Returns
XRV_OK if the data was flushed successfully

Implemented in SerialInterface, UsbInterface, and IoInterfaceFile.

◆ getFileSize()

XsFilePos IoInterface::getFileSize ( void  ) const
virtual

Return the size of the file.

Returns
The size of the file.

Reimplemented in IoInterfaceFile.

Definition at line 152 of file iointerface.cpp.

◆ getLastResult()

virtual XsResultValue IoInterface::getLastResult ( void  ) const
pure virtual

Returns the last result value produced by this interface.

Returns
The last result value produced by this interface.

Implemented in SerialInterface, UsbInterface, and IoInterfaceFile.

◆ getName()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 157 of file iointerface.cpp.

◆ getReadPosition()

XsFilePos IoInterface::getReadPosition ( void  ) const
virtual

Return the current read position.

Returns
The current read position.

Reimplemented in IoInterfaceFile.

Definition at line 163 of file iointerface.cpp.

◆ getWritePosition()

XsFilePos IoInterface::getWritePosition ( void  ) const
virtual

Return the current write position.

Returns
The current write position.

Reimplemented in IoInterfaceFile.

Definition at line 168 of file iointerface.cpp.

◆ insertData()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 173 of file iointerface.cpp.

◆ isOpen()

virtual bool IoInterface::isOpen ( void  ) const
pure virtual

Returns true if the object has a connection to a device.

Returns
true if the object has a connection to a device

Implemented in SerialInterface, UsbInterface, and IoInterfaceFile.

◆ isReadOnly()

bool IoInterface::isReadOnly ( void  ) const
virtual

Return whether the file is read-only or not.

Returns
true if the file is read-only

Reimplemented in IoInterfaceFile.

Definition at line 180 of file iointerface.cpp.

◆ open() [1/2]

XsResultValue IoInterface::open ( const XsPortInfo portInfo,
XsFilePos  readBufSize = XS_DEFAULT_READ_BUFFER_SIZE,
XsFilePos  writeBufSize = XS_DEFAULT_WRITE_BUFFER_SIZE,
PortOptions  options = PO_XsensDefaults 
)
virtual

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.

Parameters
portInfoThe details of the port that should be opened. Depending on the type of interface, parts of this parameter may be ignored.
readBufSizeThe size of the read buffer in bytes (if appliccable to the device)
writeBufSizeThe size of the write buffer in bytes (if appliccable to the device)
optionsThe options to enable (flow control, stop bits)
Returns
XRV_OK if the device was opened successfully

Reimplemented in SerialInterface, and UsbInterface.

Definition at line 96 of file iointerface.cpp.

◆ open() [2/2]

XsResultValue IoInterface::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

Reimplemented in IoInterfaceFile.

Definition at line 185 of file iointerface.cpp.

◆ readData()

virtual XsResultValue IoInterface::readData ( XsFilePos  maxLength,
XsByteArray data 
)
pure virtual

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.

Implemented in SerialInterface, UsbInterface, and IoInterfaceFile.

◆ setReadPosition()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 193 of file iointerface.cpp.

◆ setTimeout()

XsResultValue IoInterface::setTimeout ( uint32_t  ms)
virtual

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.

Parameters
msThe new timeout in milliseconds
Returns
XRV_OK if the function succeeded

Reimplemented in StreamInterface, SerialInterface, and UsbInterface.

Definition at line 101 of file iointerface.cpp.

◆ setWritePosition()

XsResultValue IoInterface::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 in IoInterfaceFile.

Definition at line 199 of file iointerface.cpp.

◆ waitForData()

XsResultValue IoInterface::waitForData ( XsFilePos  maxLength,
XsByteArray data 
)
virtual

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.

Parameters
maxLengthThe maximum number of bytes to read before returning
dataThe buffer to put the read data in.
Returns
XRV_OK if maxLength bytes were read, XRV_TIMEOUT if less was read, XRV_TIMEOUTNODATA if nothing was read

Reimplemented in SerialInterface.

Definition at line 107 of file iointerface.cpp.

◆ writeData()

virtual XsResultValue IoInterface::writeData ( const XsByteArray data,
XsFilePos written = nullptr 
)
pure virtual

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

Implemented in IoInterfaceFile, UsbInterface, and SerialInterface.

◆ XSENS_DISABLE_COPY()

IoInterface::XSENS_DISABLE_COPY ( IoInterface  )
protected

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