7 #ifndef __LIBCAMERA_INTERNAL_FILE_H__ 8 #define __LIBCAMERA_INTERNAL_FILE_H__ 12 #include <sys/types.h> 15 #include <libcamera/span.h> 34 File(
const std::string &name);
38 const std::string &
fileName()
const {
return name_; }
43 bool isOpen()
const {
return fd_ != -1; }
47 int error()
const {
return error_; }
51 off_t
seek(off_t pos);
53 ssize_t
read(
const Span<uint8_t> &data);
54 ssize_t
write(
const Span<const uint8_t> &data);
56 Span<uint8_t>
map(off_t offset = 0, ssize_t size = -1,
58 bool unmap(uint8_t *addr);
60 static bool exists(
const std::string &name);
72 std::map<void *, size_t> maps_;
Utilities to help constructing class interfaces.
OpenMode
Mode in which a file is opened.
Definition: file.h:27
The file is not open.
Definition: file.h:28
MapFlag
Flags for the File::map() function.
Definition: file.h:22
off_t seek(off_t pos)
Set the read or write position.
Definition: file.cpp:264
The file is open for writing.
Definition: file.h:30
The file is open for reading.
Definition: file.h:29
bool unmap(uint8_t *addr)
Unmap a region mapped with map()
Definition: file.cpp:421
Top-level libcamera namespace.
Definition: bound_method.h:15
File()
Construct a File without an associated name.
Definition: file.cpp:86
void close()
Close the file.
Definition: file.cpp:200
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Interface for I/O operations on files.
Definition: file.h:19
const std::string & fileName() const
Retrieve the file name.
Definition: file.h:38
OpenMode openMode() const
Retrieve the file open mode.
Definition: file.h:44
No option (used as default value)
Definition: file.h:23
The file is open for reading and writing.
Definition: file.h:31
bool isOpen() const
Check if the file is open.
Definition: file.h:43
Span< uint8_t > map(off_t offset=0, ssize_t size=-1, MapFlag flags=MapNoOption)
Map a region of the file in the process memory.
Definition: file.cpp:374
void setFileName(const std::string &name)
Set the name of the file.
Definition: file.cpp:118
~File()
Destroy a File instance.
Definition: file.cpp:97
ssize_t read(const Span< uint8_t > &data)
Read data from the file.
Definition: file.cpp:291
ssize_t size() const
Retrieve the file size.
Definition: file.cpp:230
ssize_t write(const Span< const uint8_t > &data)
Write data to the file.
Definition: file.cpp:329
bool open(OpenMode mode)
Open the file in the given mode.
Definition: file.cpp:159
The memory region is mapped as private, changes are not reflected in the file constents.
Definition: file.h:24
int error() const
Retrieve the file error status.
Definition: file.h:47
off_t pos() const
Return current read or write position.
Definition: file.cpp:250
bool exists() const
Check if the file specified by fileName() exists.
Definition: file.cpp:141