MRPT  1.9.9
iointerface.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef IOINTERFACE_H
10 #define IOINTERFACE_H
11 
12 #include "xcommunicationconfig.h"
13 #include <xsens/xsplatform.h>
14 #include <xsens/xsmessage.h>
15 #include <xsens/xstime.h>
16 #include <xsens/xsfilepos.h>
17 #include <xsens/xsbytearray.h>
18 #include <xsens/xsresultvalue.h>
19 
20 #include <stdlib.h>
21 
22 //! The default size of the serial read buffer in bytes
23 #define XS_DEFAULT_READ_BUFFER_SIZE (XS_MAXMSGLEN * 8)
24 //! The default size of the serial write buffer in bytes
25 #define XS_DEFAULT_WRITE_BUFFER_SIZE XS_MAXMSGLEN
26 
27 #ifdef _MSC_VER
28 #define XS_MAX_FILENAME_LENGTH 512
29 #else
30 #define XS_MAX_FILENAME_LENGTH PATH_MAX
31 #endif
32 
33 #ifndef _WIN32
34 typedef int32_t XsIoHandle;
35 #else
36 #define XsIoHandle HANDLE
37 #endif
38 #define XsFileHandle FILE
39 
40 struct XsPortInfo;
41 
43 {
44  public:
45  /*! \brief Destructor */
46  virtual ~IoInterface() {}
47  /*! \brief Close the connection to the device.
48  \returns XRV_OK if the connection was closed successfully
49  */
50  virtual XsResultValue close(void) = 0;
51 
52  /*! \brief Flush all data in the buffers to and from the device
53  \returns XRV_OK if the data was flushed successfully
54  */
55  virtual XsResultValue flushData(void) = 0;
56 
57  /*! \brief Returns true if the object has a connection to a device
58  \returns true if the object has a connection to a device
59  */
60  virtual bool isOpen(void) const = 0;
61 
62  /*! \brief Returns the last result value produced by this interface
63  \returns The last result value produced by this interface.
64  */
65  virtual XsResultValue getLastResult(void) const = 0;
66 
67  /*! \brief Write the data contained in \a data to the device
68  \param data The data to write to the device.
69  \param written An optional %XsSize value that will receive the number of
70  bytes that were
71  actually written.
72  \returns XRV_OK if the data was written successfully
73  */
74  virtual XsResultValue writeData(
75  const XsByteArray& data, XsSize* written = nullptr) = 0;
76 
77  /*! \brief Read at most \a maxLength bytes from the device into \a data
78  \param maxLength The maximum number of bytes to read. Depending on the
79  device type and timeout
80  settings, the function may return with less than this number of bytes
81  read.
82  \param data A buffer that will contain the read data.
83  \returns XRV_OK if all data was read successfully, XRV_TIMEOUT if some
84  data was read, but not
85  \a maxLength, XRV_TIMEOUTNODATA if no data was read at all.
86  */
88 
89  // SerialInterface overridable functions
90  virtual XsResultValue open(
91  const XsPortInfo& portInfo,
93  uint32_t writeBufSize = XS_DEFAULT_WRITE_BUFFER_SIZE);
94  virtual XsResultValue setTimeout(uint32_t ms);
96  virtual void cancelIo(void) const;
97 
98  // IOInterfaceFile overridable functions
99  virtual XsResultValue appendData(const XsByteArray& bdata);
100  virtual XsResultValue closeAndDelete(void);
101  virtual XsResultValue create(const XsString& filename);
103  virtual XsResultValue find(const XsByteArray& needleV, XsFilePos& pos);
104  virtual XsFilePos getFileSize(void) const;
105  virtual XsResultValue getName(XsString& filename) const;
106  virtual XsFilePos getReadPosition(void) const;
107  virtual XsFilePos getWritePosition(void) const;
109  virtual bool isReadOnly(void) const;
110  virtual XsResultValue open(
111  const XsString& filename, bool createNew, bool readOnly);
113  virtual XsResultValue setWritePosition(XsFilePos pos = -1);
114 
116  protected:
117  /*! \brief Constructor */
119 };
120 #endif // file guard
virtual bool isOpen(void) const =0
Returns true if the object has a connection to a device.
virtual void cancelIo(void) const
Cancel any pending io requests.
Definition: iointerface.cpp:74
virtual XsResultValue writeData(const XsByteArray &data, XsSize *written=nullptr)=0
Write the data contained in data to the device.
struct XsByteArray XsByteArray
Definition: xsbytearray.h:25
virtual XsResultValue setWritePosition(XsFilePos pos=-1)
Set the new absolute write position.
virtual XsResultValue deleteData(XsFilePos start, XsSize length)
Delete the given data from the file.
Definition: iointerface.cpp:91
virtual bool isReadOnly(void) const
Return whether the file is readonly or not.
virtual XsResultValue closeAndDelete(void)
Close the file and delete it.
Definition: iointerface.cpp:83
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
virtual XsResultValue setReadPosition(XsFilePos pos)
Set the new absolute read position.
#define XS_DEFAULT_WRITE_BUFFER_SIZE
The default size of the serial write buffer in bytes.
Definition: iointerface.h:25
virtual XsFilePos getReadPosition(void) const
Return the current read position.
virtual XsResultValue getLastResult(void) const =0
Returns the last result value produced by this interface.
IoInterface()
Constructor.
Definition: iointerface.h:118
virtual XsResultValue flushData(void)=0
Flush all data in the buffers to and from the device.
virtual XsResultValue close(void)=0
Close the connection to the device.
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:27
__int64 XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:34
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.
Definition: iointerface.cpp:53
virtual XsResultValue setTimeout(uint32_t ms)
Set the default timeout value to use in blocking operations.
Definition: iointerface.cpp:61
virtual XsResultValue appendData(const XsByteArray &bdata)
Write data to the end of the file.
Definition: iointerface.cpp:77
virtual XsResultValue waitForData(XsSize maxLength, XsByteArray &data)
Wait for data to arrive or a timeout to occur.
Definition: iointerface.cpp:67
virtual XsFilePos getWritePosition(void) const
Return the current write position.
#define XSENS_DISABLE_COPY(className)
Add this macro to the start of a class definition to prevent automatic creation of copy functions...
virtual XsResultValue find(const XsByteArray &needleV, XsFilePos &pos)
Find a string of bytes in the file.
Definition: iointerface.cpp:98
virtual XsResultValue getName(XsString &filename) const
Retrieve the filename that was last successfully opened.
virtual ~IoInterface()
Destructor.
Definition: iointerface.h:46
__int32 int32_t
Definition: rptypes.h:46
An abstract IO interface.
Definition: iointerface.h:42
GLuint GLsizei GLsizei * length
Definition: glext.h:4064
virtual XsResultValue create(const XsString &filename)
Create an empty file.
Definition: iointerface.cpp:85
GLsizei maxLength
Definition: glext.h:4932
GLuint start
Definition: glext.h:3528
struct XsString XsString
Definition: xsstring.h:34
virtual XsResultValue readData(XsSize maxLength, XsByteArray &data)=0
Read at most maxLength bytes from the device into data.
#define XsIoHandle
The type that is used for low-level identification of an open I/O device.
Definition: iointerface.h:36
unsigned __int32 uint32_t
Definition: rptypes.h:47
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
#define XS_DEFAULT_READ_BUFFER_SIZE
The default size of the serial read buffer in bytes.
Definition: iointerface.h:23
virtual XsResultValue insertData(XsFilePos start, const XsByteArray &data)
Insert the given data into the file.
virtual XsFilePos getFileSize(void) const
Return the size of the file.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020