F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
File.hpp
Go to the documentation of this file.
1#ifndef _File_hpp_
2#define _File_hpp_
3
4#include <FpConfig.hpp>
5
6namespace Os {
7
8 // This class encapsulates a very simple file interface that has the most often-used features
9
10 class File {
11 public:
12
13 typedef enum {
21 } Mode;
22
23 typedef enum {
32 } Status;
33
34 File();
35 virtual ~File();
37 Status open(const char* fileName, Mode mode);
38 Status open(const char* fileName, Mode mode, bool include_excl);
39 bool isOpen();
40 Status seek(NATIVE_INT_TYPE offset, bool absolute = true);
41 Status flush();
42 Status read(void * buffer, NATIVE_INT_TYPE &size, bool waitForFull = true);
44 // size is modified to actual read size
45 Status write(const void * buffer, NATIVE_INT_TYPE &size, bool waitForDone = true);
46 Status bulkWrite(const void * buffer, NATIVE_UINT_TYPE &totalSize, NATIVE_INT_TYPE chunkSize);
47
48 void close();
49
51 const char* getLastErrorString();
52 Status calculateCRC32(U32 &crc);
53
54 static Status niceCRC32(U32 &crc, const char* fileName);
55
56 private:
57
58 NATIVE_INT_TYPE m_fd;
59 Mode m_mode;
60 NATIVE_INT_TYPE m_lastError;
61
62 };
63
64}
65
66#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
C++-compatible configuration header for fprime configuration.
File()
Constructor.
Definition File.cpp:8
bool isOpen()
check if file descriptor is open or not.
Definition File.cpp:20
static Status niceCRC32(U32 &crc, const char *fileName)
Calculates CRC32 of file, not burdening FS.
void close()
close file
Definition File.cpp:36
@ DOESNT_EXIST
File doesn't exist (for read)
Definition File.hpp:25
@ NOT_OPENED
file hasn't been opened yet
Definition File.hpp:29
@ BAD_SIZE
Invalid size parameter.
Definition File.hpp:28
@ OTHER_ERROR
A catch-all for other errors. Have to look in implementation-specific code.
Definition File.hpp:31
@ FILE_EXISTS
file already exist (for CREATE with O_EXCL enabled)
Definition File.hpp:30
@ NO_PERMISSION
No permission to read/write file.
Definition File.hpp:27
@ OP_OK
Operation was successful.
Definition File.hpp:24
@ NO_SPACE
No space left.
Definition File.hpp:26
Status write(const void *buffer, NATIVE_INT_TYPE &size, bool waitForDone=true)
write size; will return amount written or errno
Definition File.cpp:32
const char * getLastErrorString()
get a string of the last error (typically from strerror)
Definition File.cpp:42
Status seek(NATIVE_INT_TYPE offset, bool absolute=true)
seek to location. If absolute = true, absolute from beginning of file
Definition File.cpp:24
Status prealloc(NATIVE_INT_TYPE offset, NATIVE_INT_TYPE len)
Definition File.cpp:118
Status flush()
flush data to disk. No-op on systems that do not support.
Definition File.cpp:382
@ OPEN_SYNC_DIRECT_WRITE
Open file for writing, bypassing all caching. Requires data alignment.
Definition File.hpp:18
@ OPEN_APPEND
Open file for appending.
Definition File.hpp:20
@ OPEN_WRITE
Open file for writing.
Definition File.hpp:16
@ OPEN_NO_MODE
File mode not yet selected.
Definition File.hpp:14
@ OPEN_SYNC_WRITE
Open file for writing; writes don't return until data is on disk.
Definition File.hpp:17
@ OPEN_CREATE
Open file for writing and truncates file if it exists, ie same flags as creat()
Definition File.hpp:19
@ OPEN_READ
Open file for reading.
Definition File.hpp:15
NATIVE_INT_TYPE getLastError()
read back last error code (typically errno)
Definition File.cpp:38
Status open(const char *fileName, Mode mode)
open file. Writing creates file if it doesn't exist
Definition File.cpp:12
virtual ~File()
Destructor. Will close file if still open.
Definition File.cpp:10
Status bulkWrite(const void *buffer, NATIVE_UINT_TYPE &totalSize, NATIVE_INT_TYPE chunkSize)
write size; will return amount written or errno
Definition File.cpp:316
Status read(void *buffer, NATIVE_INT_TYPE &size, bool waitForFull=true)
waitForFull = true to wait for all bytes to be read
Definition File.cpp:28
Status calculateCRC32(U32 &crc)
calculates the CRC32 of the file
Definition File.cpp:420
Definition File.cpp:6