Main MRPT website > C++ reference for MRPT 1.5.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-2017, 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 
42 struct IoInterface {
43 public:
44  /*! \brief Destructor */
45  virtual ~IoInterface() {}
46 
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 bytes that were
70  actually written.
71  \returns XRV_OK if the data was written successfully
72  */
73  virtual XsResultValue writeData(const XsByteArray& data, XsSize* written = NULL) = 0;
74 
75  /*! \brief Read at most \a maxLength bytes from the device into \a data
76  \param maxLength The maximum number of bytes to read. Depending on the device type and timeout
77  settings, the function may return with less than this number of bytes read.
78  \param data A buffer that will contain the read data.
79  \returns XRV_OK if all data was read successfully, XRV_TIMEOUT if some data was read, but not
80  \a maxLength, XRV_TIMEOUTNODATA if no data was read at all.
81  */
83 
84  // SerialInterface overridable functions
85  virtual XsResultValue open(const XsPortInfo& portInfo, uint32_t readBufSize = XS_DEFAULT_READ_BUFFER_SIZE, uint32_t writeBufSize = XS_DEFAULT_WRITE_BUFFER_SIZE);
86  virtual XsResultValue setTimeout (uint32_t ms);
88  virtual void cancelIo(void) const;
89 
90  // IOInterfaceFile overridable functions
91  virtual XsResultValue appendData(const XsByteArray& bdata);
92  virtual XsResultValue closeAndDelete(void);
93  virtual XsResultValue create(const XsString& filename);
95  virtual XsResultValue find(const XsByteArray& needleV, XsFilePos& pos);
96  virtual XsFilePos getFileSize(void) const;
97  virtual XsResultValue getName(XsString& filename) const;
98  virtual XsFilePos getReadPosition(void) const;
99  virtual XsFilePos getWritePosition(void) const;
101  virtual bool isReadOnly(void) const;
102  virtual XsResultValue open(const XsString& filename, bool createNew, bool readOnly);
104  virtual XsResultValue setWritePosition(XsFilePos pos = -1);
105 
107 protected:
108  /*! \brief Constructor */
110  {}
111 };
112 #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:72
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:96
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:85
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:17
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:109
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:26
__int64 XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:33
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:52
virtual XsResultValue setTimeout(uint32_t ms)
Set the default timeout value to use in blocking operations.
Definition: iointerface.cpp:59
virtual XsResultValue appendData(const XsByteArray &bdata)
Write data to the end of the file.
Definition: iointerface.cpp:79
virtual XsResultValue waitForData(XsSize maxLength, XsByteArray &data)
Wait for data to arrive or a timeout to occur.
Definition: iointerface.cpp:65
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.
virtual XsResultValue getName(XsString &filename) const
Retrieve the filename that was last successfully opened.
virtual ~IoInterface()
Destructor.
Definition: iointerface.h:45
__int32 int32_t
Definition: rptypes.h:48
An abstract IO interface.
Definition: iointerface.h:42
GLuint GLsizei GLsizei * length
Definition: glext.h:3900
virtual XsResultValue create(const XsString &filename)
Create an empty file.
Definition: iointerface.cpp:90
virtual XsResultValue writeData(const XsByteArray &data, XsSize *written=NULL)=0
Write the data contained in data to the device.
GLsizei maxLength
Definition: glext.h:4504
GLuint start
Definition: glext.h:3512
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:49
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
#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.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020