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 #ifdef TGT_OS_TYPE_VXWORKS
37  // Adding this pound-if-define code to allow building VxWorks for POSIX.
38  // Better than the alternative of copying this entire file to the VxWorks repo
39  // and removing this line.
40  PosixFile(const PosixFile& other) = delete;
41 #else
42  PosixFile(const PosixFile& other);
43 #endif
44 
46 #ifdef TGT_OS_TYPE_VXWORKS
47  // Adding this pound-if-define code to allow building VxWorks for POSIX.
48  // Better than the alternative of copying this entire file to the VxWorks repo
49  // and removing this line.
50  PosixFile& operator=(const PosixFile& other) = delete;
51 #else
52  PosixFile& operator=(const PosixFile& other);
53 #endif
54 
57  ~PosixFile() override = default;
58 
59  // ------------------------------------
60  // Functions overrides
61  // ------------------------------------
62 
79  Os::FileInterface::Status open(const char* path, Mode mode, OverwriteType overwrite) override;
80 
86  void close() override;
87 
94  Status size(FwSignedSizeType& size_result) override;
95 
102  Status position(FwSignedSizeType& position_result) override;
103 
116  Status preallocate(FwSignedSizeType offset, FwSignedSizeType length) override;
117 
127  Status seek(FwSignedSizeType offset, SeekType seekType) override;
128 
136  Status flush() override;
137 
156  Status read(U8* buffer, FwSignedSizeType& size, WaitType wait) override;
157 
176  Status write(const U8* buffer, FwSignedSizeType& size, WaitType wait) override;
177 
185  FileHandle* getHandle() override;
186 
187  private:
189  PosixFileHandle m_handle;
190 };
191 } // namespace File
192 } // namespace Posix
193 } // namespace Os
194 
195 #endif // OS_POSIX_FILE_HPP
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSignedSizeType FwSignedSizeType
Definition: FpConfig.h:30
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:130
void close() override
close the file, if not opened then do nothing
Definition: File.cpp:99
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
Definition: File.cpp:190
Status preallocate(FwSignedSizeType offset, FwSignedSizeType length) override
pre-allocate file storage
Definition: File.cpp:142
Status read(U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
Definition: File.cpp:212
Status write(const U8 *buffer, FwSignedSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
Definition: File.cpp:248
FileHandle * getHandle() override
returns the raw file handle
Definition: File.cpp:285
PosixFile()=default
constructor
Status size(FwSignedSizeType &size_result) override
get size of currently open file
Definition: File.cpp:107
Status flush() override
flush file contents to storage
Definition: File.cpp:203
PosixFile & operator=(const PosixFile &other)
assignment operator that copies the internal representation
Definition: File.cpp:56
~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:64
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