distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
File.hpp
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_DISTORTOS_FILESYSTEM_FILE_HPP_
13 #define INCLUDE_DISTORTOS_FILESYSTEM_FILE_HPP_
14 
15 #include <sys/stat.h>
16 
17 #include <utility>
18 
19 namespace distortos
20 {
21 
28 class File
29 {
30 public:
31 
33  enum class Whence
34  {
36  beginning,
38  current,
40  end,
41  };
42 
49  virtual ~File() = default;
50 
65  virtual int close() = 0;
66 
77  virtual std::pair<int, off_t> getPosition() = 0;
78 
87  virtual std::pair<int, off_t> getSize() = 0;
88 
101  virtual int getStatus(struct stat& status) = 0;
102 
114  virtual std::pair<int, bool> isATerminal() = 0;
115 
131  virtual void lock() = 0;
132 
148  virtual std::pair<int, size_t> read(void* buffer, size_t size) = 0;
149 
160  virtual int rewind() = 0;
161 
178  virtual std::pair<int, off_t> seek(Whence whence, off_t offset) = 0;
179 
190  virtual int synchronize() = 0;
191 
202  virtual void unlock() = 0;
203 
220  virtual std::pair<int, size_t> write(const void* buffer, size_t size) = 0;
221 
222  File() = default;
223  File(const File&) = delete;
224  File& operator=(const File&) = delete;
225 };
226 
227 } // namespace distortos
228 
229 #endif // INCLUDE_DISTORTOS_FILESYSTEM_FILE_HPP_
virtual int getStatus(struct stat &status)=0
Returns status of file.
virtual std::pair< int, off_t > seek(Whence whence, off_t offset)=0
Moves file offset.
Whence
seek() mode of operation
Definition: File.hpp:33
virtual int rewind()=0
Resets current file offset.
Definition: File.hpp:28
virtual void lock()=0
Locks the file for exclusive use by current thread.
set file offset to provided argument, similar to SEEK_SET
virtual std::pair< int, off_t > getSize()=0
Returns size of file.
virtual std::pair< int, size_t > read(void *buffer, size_t size)=0
Reads data from file.
virtual int synchronize()=0
Synchronizes state of a file, ensuring all cached writes are finished.
virtual std::pair< int, size_t > write(const void *buffer, size_t size)=0
Writes data to file.
set file offset to the size of the file plus provided argument, similar to SEEK_END
Top-level namespace of distortos project.
Definition: buttons.hpp:33
virtual ~File()=default
File's destructor.
virtual void unlock()=0
Unlocks the file which was previously locked by current thread.
set file offset to its current value plus provided argument, similar to SEEK_CUR
virtual int close()=0
Closes file.
virtual std::pair< int, off_t > getPosition()=0
Returns current file offset.
virtual std::pair< int, bool > isATerminal()=0
Tells whether the file is a terminal.