iointerfacefile.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #include "iointerfacefile.h"
66 
67 #include <errno.h>
68 #ifndef _WIN32
69  #include <unistd.h> // close
70  #include <sys/ioctl.h> // ioctl
71  #include <fcntl.h> // open, O_RDWR
72  #include <string.h> // strcpy
73  #include <sys/param.h>
74  #include <sys/stat.h>
75  #include <stdarg.h>
76 #else
77  #include <winbase.h>
78  #include <sys/stat.h>
79  #include <io.h>
80 #endif
81 
82 #include <xstypes/xsdeviceid.h>
83 
84 #ifndef _CRT_SECURE_NO_DEPRECATE
85  #define _CRT_SECURE_NO_DEPRECATE
86  #ifdef _WIN32
87  #pragma warning(disable:4996)
88  #endif
89 #endif
90 
94  : m_handle(NULL)
95  , m_fileSize(0)
96  , m_readPos(0)
97  , m_writePos(0)
98  , m_lastResult(XRV_OK)
99  , m_reading(true)
100  , m_readOnly(false)
101 {
102 }
103 
107 {
108  try
109  {
110  closeFile();
111  }
112  catch (...)
113  {
114  }
115 }
116 
124 {
125  if (!m_handle)
126  return m_lastResult = XRV_NOFILEOPEN;
127  if (m_readOnly)
128  return m_lastResult = XRV_READONLY;
129  if (!bdata.size())
130  return m_lastResult = XRV_OK;
131 
132  if (m_reading || m_writePos != m_fileSize)
133  {
134  m_reading = false;
135  m_handle->seek_r(0);
136  }
137  m_handle->write(bdata.data(), 1, (XsFilePos) bdata.size());
138  m_writePos = m_handle->tell();
140 
141  return (m_lastResult = XRV_OK);
142 }
143 
145 
149 {
150  return closeFile();
151 }
152 
157 {
158  if (m_handle)
159  {
160  m_handle->flush();
161  m_handle->close();
162 
163  delete m_handle;
164  m_handle = NULL;
165  }
166 
167  m_readPos = 0;
168  m_writePos = 0;
169  m_reading = true;
170  m_fileSize = 0;
171  m_readOnly = false;
172 
173  return m_lastResult = XRV_OK;
174 }
175 
180 {
181  if (m_handle)
182  {
183  m_handle->flush();
184  m_handle->close();
185 
186  if (m_readOnly)
188  else
189  m_lastResult = XsFile::erase(m_filename);
190 
191  delete m_handle;
192  m_handle = NULL;
193  }
194  else
196 
197  m_readPos = 0;
198  m_writePos = 0;
199  m_reading = true;
200  m_fileSize = 0;
201  m_readOnly = false;
202 
203  return m_lastResult;
204 }
205 
211 {
212  if (m_handle)
213  return m_lastResult = XRV_ALREADYOPEN;
214 
215  m_handle = new XsFile();
216  m_lastResult = m_handle->create(filename, false);
217  if (m_lastResult != XRV_OK)
218  {
219  delete m_handle;
220  m_handle = NULL;
221  return m_lastResult;
222  }
223 
224  m_lastResult = XsFile::fullPath(filename, m_filename);
225 
226  if (m_lastResult != XRV_OK)
227  {
228  m_handle->close();
229  XsFile::erase(m_filename);
230  delete m_handle;
231  m_handle = NULL;
232 
234  }
235 
236  m_readPos = 0;
237  m_writePos = 0;
238  m_fileSize = 0;
239  m_reading = true;
240  m_readOnly = false;
241  return m_lastResult = XRV_OK;
242 }
243 
254 {
255  if (!m_handle)
256  return m_lastResult = XRV_NOFILEOPEN;
257  if (m_readOnly)
258  return m_lastResult = XRV_READONLY;
259 
260  gotoWrite();
261 
262  XsFilePos wPos = start;
263  XsFilePos rPos = wPos + length;
264 
265  XsFilePos read1;
266  XsFilePos endPos = (start + (XsFilePos) length);
267  if (endPos < m_fileSize)
268  {
269  XsFilePos remaining = m_fileSize - endPos;
270  char buffer[m_fileBlockSize];
271 
272  // copy data
273  m_handle->seek(rPos);
274 
275  while (remaining > 0)
276  {
277  if (remaining >= m_fileBlockSize)
278  read1 = m_handle->read(buffer, 1, m_fileBlockSize);
279  else
280  read1 = m_handle->read(buffer, 1, remaining);
281 
282  remaining -= read1;
283  rPos += read1;
284 
285  // write block to the correct position
286  m_handle->seek(wPos);
287  wPos += m_handle->write(buffer, 1, read1);
288  m_handle->seek(rPos);
289  }
290  m_fileSize -= length;
291  }
292  else
293  m_fileSize = start;
294 
295  XsResultValue truncateResult = m_handle->truncate(m_fileSize);
296 
297  m_writePos = start;
298  m_handle->seek(wPos);
299 
300  return m_lastResult = truncateResult;
301 }
302 
313 {
314  if (!m_handle)
315  return m_lastResult = XRV_NOFILEOPEN;
316 
317  XsFilePos needleLength = (XsFilePos) needleV.size();
318 
319  pos = 0;
320  if (needleLength == 0)
321  return m_lastResult = XRV_OK;
322 
323  const char* needle = (const char*) needleV.data();
324 
325  gotoRead();
326 
327  char buffer[m_fileBlockSize];
328  XsFilePos bufferPos, needlePos = 0;
329  XsFilePos readBytes;
330  if (m_readPos & 0x1FF) // read a block of data
331  readBytes = m_handle->read(buffer, 1, (m_fileBlockSize - (m_readPos & (m_fileBlockSize - 1))));
332  else
333  readBytes = m_handle->read(buffer, 1, m_fileBlockSize); // read a block of data
334 
335  while (readBytes > 0)
336  {
337  m_readPos += readBytes;
338  bufferPos = 0;
339 
340  while (bufferPos < readBytes && needlePos < needleLength)
341  {
342  if (buffer[bufferPos] == needle[needlePos])
343  {
344  // found a byte
345  ++needlePos;
346  }
347  else
348  {
349  if (needlePos > 0)
350  needlePos = 0;
351  else if (buffer[bufferPos] == needle[0])
352  {
353  // found a byte
354  needlePos = 1;
355  }
356  }
357  ++bufferPos;
358  }
359  if (needlePos < needleLength)
360  readBytes = m_handle->read(buffer, 1, m_fileBlockSize); // read next block
361  else
362  {
363  m_readPos = (m_readPos + bufferPos - readBytes) - needleLength;
364  pos = m_readPos;
365  m_handle->seek(m_readPos);
366  return m_lastResult = XRV_OK;
367  }
368  }
369  return m_lastResult = XRV_ENDOFFILE;
370 }
371 
376 {
377  return m_fileSize;
378 }
379 
384 {
385 #ifdef _WIN32
386  struct _stat stats;
387  if (_wstat(m_filename.toStdWString().c_str(), &stats) == 0)
388 #else
389  struct stat stats;
390  if (stat(m_filename.c_str(), &stats) == 0)
391 #endif
392  {
393  XsTimeStamp t = XsTimeStamp((int64_t)stats.st_mtime * 1000);
394  return t;
395  }
396  return XsTimeStamp();
397 }
398 
401 {
402  m_handle->flush();
403 
404  return m_lastResult = XRV_OK;
405 }
406 
413 {
414  filename = m_filename;
415  return m_lastResult = XRV_OK;
416 }
417 
421 {
422  return m_filename;
423 }
424 
427 {
428  if (m_reading)
429  return;
430 
431  m_handle->flush();
432  m_handle->seek(m_readPos);
433  m_reading = true;
434 }
435 
438 {
439  if (!m_reading)
440  return;
441 
442  m_handle->flush();
443  m_handle->seek(m_writePos);
444  m_reading = false;
445 }
446 
457 {
458  if (!m_handle)
459  return m_lastResult = XRV_NOFILEOPEN;
460  if (m_readOnly)
461  return m_lastResult = XRV_READONLY;
462 
463  gotoWrite();
464 
465  XsFilePos length = (XsFilePos) data.size();
466  XsFilePos rPos = start;
467  XsFilePos wPos = rPos + length;
468 
469  XsFilePos read1, read2;
470  XsFilePos remaining = m_fileSize - start;
472  char* bufferRoot = (char*) malloc((XsSize)(bsize * 2));
473  if (!bufferRoot)
474  return XRV_OUTOFMEMORY;
475  char* buffer1 = bufferRoot;
476  char* buffer2 = bufferRoot + bsize;
477  char* btemp;
478 
479  // copy data
480  m_handle->seek(rPos);
481 
482  if (data.size() == 0)
483  return m_lastResult = XRV_OK;
484 
485  if (remaining >= bsize)
486  read1 = m_handle->read(buffer1, 1, bsize);
487  else
488  read1 = m_handle->read(buffer1, 1, remaining);
489 
490  remaining -= read1;
491  rPos += read1;
492 
493  while (remaining > 0)
494  {
495  // move data to correct buffer
496  read2 = read1;
497  btemp = buffer1;
498  buffer1 = buffer2;
499  buffer2 = btemp;
500 
501  // read next block
502  if (remaining >= bsize)
503  read1 = m_handle->read(buffer1, 1, bsize);
504  else
505  read1 = m_handle->read(buffer1, 1, remaining);
506 
507  remaining -= read1;
508  rPos += read1;
509 
510  // write block to the correct position
511  m_handle->seek(wPos);
512  wPos += m_handle->write(buffer2, 1, read2);
513  m_handle->seek(rPos);
514  }
515 
516  m_handle->seek(wPos);
517  /* wPos += */ m_handle->write(buffer1, 1, read1);
518 
519  m_handle->seek(start);
520  m_writePos = start + m_handle->write(data.data(), 1, length);
521  m_fileSize += length;
522 
523  free(bufferRoot);
524  return m_lastResult = XRV_OK;
525 }
526 
535 XsResultValue IoInterfaceFile::open(const XsString& filename, bool createNew, bool readOnly)
536 {
537  if (m_handle)
538  return m_lastResult = XRV_ALREADYOPEN;
539 
540  m_handle = new XsFile();
541 
543  m_readOnly = readOnly;
544  XsResultValue localResult = m_handle->open(filename, readOnly);
545 
546  if (localResult != XRV_OK)
547  {
548  if (createNew)
549  localResult = m_handle->create(filename, false);
550  else
551  {
552  // final attempt: open it forced readonly
553  localResult = m_handle->open(filename, false);
554  m_readOnly = true;
555  }
556  }
557  if (localResult != XRV_OK)
558  {
559  delete m_handle;
560  m_handle = NULL;
561  return m_lastResult = XRV_INPUTCANNOTBEOPENED; // overrides a possible OUTPUTCANNOTBEOPENED
562  }
563 
564  bool fail = false;
565 #ifdef _WIN32
566  wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
567  if (_wfullpath(fullpath, filename.toStdWString().c_str(), XS_MAX_FILENAME_LENGTH) == NULL)
568  fail = true;
569 #else
570  // use the same trick again.
571  char fullpath[XS_MAX_FILENAME_LENGTH * 2];
572  if (realpath(filename.c_str(), fullpath) == NULL)
573  fail = true;
574 #endif
575  m_filename = XsString(fullpath);
576 
577  if (fail)
578  {
579  m_handle->close();
580  delete m_handle;
581  m_handle = NULL;
583  }
584 
585  m_readPos = 0;
586  m_writePos = 0;
587  m_reading = true;
588  m_handle->seek_r(0);
589  m_fileSize = m_handle->tell();
590  m_handle->seek(0);
591  return (m_lastResult = XRV_OK);
592 }
593 
599 {
600  if (!m_handle)
601  return m_lastResult = XRV_NOFILEOPEN;
602 
603  if (maxLength == 0)
604  {
605  data.clear();
606  return m_lastResult = XRV_OK;
607  }
608 
610 
611  gotoRead();
612  data.setSize((XsSize) maxLength);
613 
614  length = m_handle->read(data.data(), 1, maxLength);
615  if (m_handle->eof() && length <= 0)
616  {
617  data.clear();
618  return (m_lastResult = XRV_ENDOFFILE);
619  }
620 
621  m_readPos += length;
622  if (length < maxLength)
623  data.pop_back((XsSize)(maxLength - length));
624  return m_lastResult = XRV_OK;
625 }
626 
635 {
636  XsFilePos realign = (m_readPos & (m_fileBlockSize - 1));
637  if (realign)
638  blockCount = m_fileBlockSize * blockCount + m_fileBlockSize - realign;
639  else
640  blockCount *= m_fileBlockSize;
641  if (blockCount == 0)
642  return XRV_OK;
643  return readData(blockCount, data);
644 }
645 
656 XsResultValue IoInterfaceFile::readTerminatedData(XsFilePos maxLength, unsigned char terminator, XsByteArray& bdata)
657 {
658  if (!m_handle)
659  return m_lastResult = XRV_NOFILEOPEN;
660 
661  if (maxLength == 0)
662  {
663  bdata.clear();
664  return m_lastResult = XRV_OK;
665  }
666 
667  bdata.setSize((XsSize) maxLength);
668  char* data = (char*) bdata.data();
669 
671  int readChar;
672 
673  gotoRead();
674 
675  length = 0;
676  readChar = m_handle->getc();
677 
678  while (!m_handle->eof() && !m_handle->error())
679  {
680  data[length] = (char) readChar;
681  ++length;
682  ++m_readPos;
683 
684  if (length >= maxLength)
685  return m_lastResult = XRV_OK;
686  if ((unsigned char) readChar == terminator)
687  {
688  bdata.pop_back((XsSize)(maxLength - length));
689  return m_lastResult = XRV_OK;
690  }
691  }
692  bdata.pop_back((XsSize)(maxLength - length));
693  return m_lastResult = XRV_ENDOFFILE;
694 }
695 
702 {
703  if (!m_handle)
704  return m_lastResult = XRV_NOFILEOPEN;
705 
706  if (m_readPos != pos)
707  {
708  m_readPos = pos;
709  if (m_reading)
710  m_handle->seek(m_readPos);
711  }
712 
713  return m_lastResult = XRV_OK;
714 }
715 
722 {
723  if (!m_handle)
724  return m_lastResult = XRV_NOFILEOPEN;
725  if (m_readOnly)
726  return m_lastResult = XRV_READONLY;
727 
728  if (pos == -1)
729  {
730  if (m_reading)
731  m_reading = false;
732  m_handle->seek_r(0);
733  m_writePos = m_handle->tell();
734  }
735  else
736  {
737  if (m_writePos != pos)
738  {
739  m_writePos = pos;
740  if (!m_reading)
741  m_handle->seek(m_writePos);
742  }
743  }
744 
745  return m_lastResult = XRV_OK;
746 }
747 
752 {
753  if (!m_handle)
754  return m_lastResult = XRV_NOFILEOPEN;
755  if (m_readOnly)
756  return m_lastResult = XRV_READONLY;
757 
758  XsFilePos length = (XsFilePos) data.size();
759  if (length == 0)
760  return m_lastResult = XRV_OK;
761 
762  gotoWrite();
763  XsFilePos writeRes = m_handle->write(data.data(), 1, length);
764  if (writeRes == (XsFilePos)EOF || writeRes < length)
765  {
766  int err = errno;
767  switch (err)
768  {
769  case 0:
770  break;
771  case ENOSPC:
773  case ENOMEM:
774  return m_lastResult = XRV_OUTOFMEMORY;
775  default:
776  return m_lastResult = XRV_ERROR;
777  }
778  }
779  m_writePos += writeRes;
780  if (written)
781  *written = writeRes;
782 
783  if (m_writePos > m_fileSize)
785 
786  return m_lastResult = XRV_OK;
787 }
788 
793 {
794  return m_readPos;
795 }
796 
801 {
802  return m_writePos;
803 }
804 
809 {
810  return m_lastResult;
811 }
812 
817 {
818  return m_handle != NULL;
819 }
820 
825 {
826  return !isOpen() || m_readOnly;
827 }
828 
835 {
836  if (isReadOnly())
837  return XRV_READONLY;
838 
839  if (minSize <= m_fileSize)
840  return XRV_OK;
841 
842  auto rv = m_handle->resize(minSize);
843  if (rv != XRV_OK)
844  return rv;
845 
846  m_fileSize = minSize;
847  return XRV_OK;
848 }
849 
856 {
857 #ifdef XSENS_WINDOWS
858  return FlushFileBuffers((HANDLE)_get_osfhandle(_fileno(m_handle->handle()))) ? XRV_OK : XRV_ERROR;
859 #else
860  return XRV_OK;
861 #endif
862 }
IoInterfaceFile::flushFileBuffers
XsResultValue flushFileBuffers()
Flushes the buffers of a specified file and causes all buffered data to be written to a file.
Definition: iointerfacefile.cpp:855
XsString
struct XsString XsString
Definition: xsstring.h:87
IoInterfaceFile::setWritePosition
XsResultValue setWritePosition(XsFilePos pos=-1)
Set the new absolute write position.
Definition: iointerfacefile.cpp:721
IoInterfaceFile::gotoWrite
void gotoWrite()
Change from reading to writing mode.
Definition: iointerfacefile.cpp:437
IoInterfaceFile::open
XsResultValue open(const XsString &filename, bool createNew, bool readOnly)
Open a file.
Definition: iointerfacefile.cpp:535
XsByteArray
A list of uint8_t values.
IoInterfaceFile::getFileName
XsString getFileName() const
Return the filename that was last successfully opened.
Definition: iointerfacefile.cpp:420
IoInterfaceFile::isReadOnly
bool isReadOnly() const
Return whether the file is read-only or not.
Definition: iointerfacefile.cpp:824
IoInterfaceFile::getName
XsResultValue getName(XsString &filename) const
Retrieve the filename that was last successfully opened.
Definition: iointerfacefile.cpp:412
IoInterfaceFile::flushData
XsResultValue flushData() override
Flush all data in the buffers to and from the device.
Definition: iointerfacefile.cpp:400
io.h
IoInterfaceFile::m_lastResult
XsResultValue m_lastResult
The last result of an operation.
Definition: iointerfacefile.h:86
IoInterfaceFile::appendData
XsResultValue appendData(const XsByteArray &bdata)
Write data to the end of the file.
Definition: iointerfacefile.cpp:123
IoInterfaceFile::m_writePos
XsFilePos m_writePos
The last write position in the file.
Definition: iointerfacefile.h:84
XRV_ENDOFFILE
@ XRV_ENDOFFILE
270: End of file is reached
Definition: xsresultvalue.h:140
IoInterfaceFile::getFileDate
XsTimeStamp getFileDate() const
Return the creation date of the file.
Definition: iointerfacefile.cpp:383
IoInterfaceFile::insertData
XsResultValue insertData(XsFilePos start, const XsByteArray &data)
Insert the given data into the file.
Definition: iointerfacefile.cpp:456
XRV_ALREADYOPEN
@ XRV_ALREADYOPEN
269: An I/O device is already opened with this object
Definition: xsresultvalue.h:139
XRV_NOFILEOPEN
@ XRV_NOFILEOPEN
287: No file opened for reading/writing
Definition: xsresultvalue.h:158
IoInterfaceFile::deleteData
XsResultValue deleteData(XsFilePos start, XsFilePos length)
Delete the given data from the file.
Definition: iointerfacefile.cpp:253
XRV_ERROR
@ XRV_ERROR
256: A generic error occurred
Definition: xsresultvalue.h:126
IoInterfaceFile::gotoRead
void gotoRead()
Change from writing to reading mode.
Definition: iointerfacefile.cpp:426
IoInterfaceFile::getReadPosition
XsFilePos getReadPosition() const
Return the current read position.
Definition: iointerfacefile.cpp:792
data
data
IoInterfaceFile::m_handle
XsFile * m_handle
The file handle, also indicates if the file is open or not.
Definition: iointerfacefile.h:78
XRV_OK
@ XRV_OK
0: Operation was performed successfully
Definition: xsresultvalue.h:85
IoInterfaceFile::m_readPos
XsFilePos m_readPos
The last read position in the file.
Definition: iointerfacefile.h:82
IoInterfaceFile::setReadPosition
XsResultValue setReadPosition(XsFilePos pos)
Set the new absolute read position.
Definition: iointerfacefile.cpp:701
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
IoInterfaceFile::m_fileBlockSize
static const XsFilePos m_fileBlockSize
The default file block size.
Definition: iointerfacefile.h:136
XRV_OUTOFMEMORY
@ XRV_OUTOFMEMORY
261: No internal memory available
Definition: xsresultvalue.h:131
IoInterfaceFile::getFileSize
XsFilePos getFileSize() const
Return the size of the file.
Definition: iointerfacefile.cpp:375
IoInterfaceFile::readDataBlocks
XsResultValue readDataBlocks(XsFilePos blockCount, XsByteArray &data)
This function will read blocks of data aligned to m_fileBlockSize.
Definition: iointerfacefile.cpp:634
IoInterfaceFile::~IoInterfaceFile
~IoInterfaceFile()
Definition: iointerfacefile.cpp:106
IoInterfaceFile::reserve
XsResultValue reserve(XsFilePos minSize)
Make sure the file is at least minSize bytes big.
Definition: iointerfacefile.cpp:834
IoInterfaceFile::closeFile
XsResultValue closeFile()
Close the file.
Definition: iointerfacefile.cpp:156
IoInterfaceFile::getWritePosition
XsFilePos getWritePosition() const
Return the current write position.
Definition: iointerfacefile.cpp:800
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
XRV_INPUTCANNOTBEOPENED
@ XRV_INPUTCANNOTBEOPENED
267: The specified i/o device can not be opened
Definition: xsresultvalue.h:137
IoInterfaceFile::m_readOnly
bool m_readOnly
Indicates if the file was opened in read-only mode.
Definition: iointerfacefile.h:96
xsdeviceid.h
XsFile
struct XsFile XsFile
Definition: xsfile.h:326
IoInterfaceFile::m_filename
XsString m_filename
Contains the name of the file that was last successfully opened.
Definition: iointerfacefile.h:88
IoInterfaceFile::find
XsResultValue find(const XsByteArray &data, XsFilePos &pos)
Find a string of bytes in the file.
Definition: iointerfacefile.cpp:312
IoInterfaceFile::IoInterfaceFile
IoInterfaceFile()
Definition: iointerfacefile.cpp:93
IoInterfaceFile::readTerminatedData
XsResultValue readTerminatedData(XsFilePos maxLength, unsigned char terminator, XsByteArray &bdata)
Read data from the file and put it into the data buffer.
Definition: iointerfacefile.cpp:656
start
ROSCPP_DECL void start()
IoInterfaceFile::getLastResult
XsResultValue getLastResult() const override
Return the result code of the last operation.
Definition: iointerfacefile.cpp:808
IoInterfaceFile::close
XsResultValue close() override
Close the file, overrides IoInterface::close().
Definition: iointerfacefile.cpp:148
iointerfacefile.h
XRV_READONLY
@ XRV_READONLY
273: Tried to change a read-only value
Definition: xsresultvalue.h:143
length
TF2SIMD_FORCE_INLINE tf2Scalar length(const Quaternion &q)
IoInterfaceFile::writeData
XsResultValue writeData(const XsByteArray &data, XsFilePos *written=nullptr) override
Write the data contained in data to the device.
Definition: iointerfacefile.cpp:751
IoInterfaceFile::m_fileSize
XsFilePos m_fileSize
Contains the size of the file.
Definition: iointerfacefile.h:80
IoInterfaceFile::isOpen
bool isOpen() const override
Return whether the file is open or not.
Definition: iointerfacefile.cpp:816
IoInterfaceFile::m_reading
bool m_reading
Indicates whether the last operation was a read or write operation.
Definition: iointerfacefile.h:94
IoInterfaceFile::readData
XsResultValue readData(XsFilePos maxLength, XsByteArray &data) override
Read at most maxLength bytes from the device into data.
Definition: iointerfacefile.cpp:598
XsFilePos
int64_t XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:102
XsString
A 0-terminated managed string of characters.
XsTimeStamp
struct XsTimeStamp XsTimeStamp
Definition: xstimestamp.h:458
IoInterfaceFile::create
XsResultValue create(const XsString &filename)
Create an empty file.
Definition: iointerfacefile.cpp:210
XsTimeStamp
This class contains method to set, retrieve and compare timestamps.
Definition: xstimestamp.h:115
XRV_INSUFFICIENTSPACE
@ XRV_INSUFFICIENTSPACE
266: Insufficient buffer space available
Definition: xsresultvalue.h:136
XS_MAX_FILENAME_LENGTH
#define XS_MAX_FILENAME_LENGTH
Definition: xsfile.h:78
XRV_INVALIDPARAM
@ XRV_INVALIDPARAM
33: An invalid parameter is supplied
Definition: xsresultvalue.h:105
IoInterfaceFile::closeAndDelete
XsResultValue closeAndDelete()
Close the file and delete it.
Definition: iointerfacefile.cpp:179


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