F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
File.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Posix/File.hpp
3 // \brief posix implementation for Os::File, header and test definitions
4 // ======================================================================
5 #include <Os/File.hpp>
6 #ifndef OS_POSIX_FILE_HPP
7 #define OS_POSIX_FILE_HPP
8 
9 namespace Os {
10 namespace Posix {
11 namespace File {
12 
15 struct PosixFileHandle : public FileHandle {
17  static constexpr PlatformIntType ERROR_RETURN_VALUE = -1;
18 
21 };
22 
29 class PosixFile : public FileInterface {
30  public:
33  PosixFile() = default;
34 
36  PosixFile(const PosixFile& other);
37 
39  PosixFile& operator=(const PosixFile& other);
40 
43  ~PosixFile() override = default;
44 
45  // ------------------------------------
46  // Functions overrides
47  // ------------------------------------
48 
65  Os::FileInterface::Status open(const char *path, Mode mode, OverwriteType overwrite) override;
66 
72  void close() override;
73 
80  Status size(FwSignedSizeType &size_result) override;
81 
88  Status position(FwSignedSizeType &position_result) override;
89 
102  Status preallocate(FwSignedSizeType offset, FwSignedSizeType length) override;
103 
113  Status seek(FwSignedSizeType offset, SeekType seekType) override;
114 
122  Status flush() override;
123 
142  Status read(U8 *buffer, FwSignedSizeType &size, WaitType wait) override;
143 
162  Status write(const U8 *buffer, FwSignedSizeType &size, WaitType wait) override;
163 
171  FileHandle *getHandle() override;
172 
173 
174  private:
176  PosixFileHandle m_handle;
177 };
178 } // namespace File
179 } // namespace Posix
180 } // namespace Os
181 
182 #endif // OS_POSIX_FILE_HPP
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSignedSizeType FwSignedSizeType
Definition: FpConfig.h:25
posix implementation of Os::File
Definition: File.hpp:29
Status position(FwSignedSizeType &position_result) override
get file pointer position of the currently open file
Definition: File.cpp:121
void close() override
close the file, if not opened then do nothing
Definition: File.cpp:90
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
Definition: File.cpp:180
Status preallocate(FwSignedSizeType offset, FwSignedSizeType length) override
pre-allocate file storage
Definition: File.cpp:133
Status read(U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
Definition: File.cpp:201
Status write(const U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
Definition: File.cpp:237
FileHandle * getHandle() override
returns the raw file handle
Definition: File.cpp:270
PosixFile()=default
constructor
Status size(FwSignedSizeType &size_result) override
get size of currently open file
Definition: File.cpp:98
Status flush() override
flush file contents to storage
Definition: File.cpp:192
PosixFile & operator=(const PosixFile &other)
assignment operator that copies the internal representation
Definition: File.cpp:51
~PosixFile() override=default
destructor
Os::FileInterface::Status open(const char *path, Mode mode, OverwriteType overwrite) override
open file with supplied path and mode
Definition: File.cpp:58
base implementation of FileHandle
Definition: File.hpp:14
PlatformIntType m_file_descriptor
Posix file descriptor.
Definition: File.hpp:20
static constexpr PlatformIntType INVALID_FILE_DESCRIPTOR
Definition: File.hpp:16
static constexpr PlatformIntType ERROR_RETURN_VALUE
Definition: File.hpp:17