13 #include <sys/types.h> 15 #include <libcamera/base/private.h> 19 #include <libcamera/base/span.h> 38 ReadWrite = ReadOnly | WriteOnly,
43 File(
const std::string &name);
47 const std::string &
fileName()
const {
return name_; }
52 bool isOpen()
const {
return fd_.isValid(); }
56 int error()
const {
return error_; }
60 off_t
seek(off_t pos);
62 ssize_t
read(
const Span<uint8_t> &data);
63 ssize_t
write(
const Span<const uint8_t> &data);
65 Span<uint8_t>
map(off_t offset = 0, ssize_t size = -1,
67 bool unmap(uint8_t *addr);
69 static bool exists(
const std::string &name);
81 std::map<void *, size_t> maps_;
Utilities to help constructing class interfaces.
MapFlag
Flags for the File::map() function.
Definition: file.h:27
off_t seek(off_t pos)
Set the read or write position.
Definition: file.cpp:277
File descriptor wrapper that owns a file descriptor.
Span< uint8_t > map(off_t offset=0, ssize_t size=-1, MapFlags flags=MapFlag::NoOption)
Map a region of the file in the process memory.
Definition: file.cpp:387
bool unmap(uint8_t *addr)
Unmap a region mapped with map()
Definition: file.cpp:434
Top-level libcamera namespace.
Definition: backtrace.h:17
File()
Construct a File without an associated name.
Definition: file.cpp:97
void close()
Close the file.
Definition: file.cpp:214
OpenModeFlag
Mode in which a file is opened.
Definition: file.h:34
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Interface for I/O operations on files.
Definition: file.h:24
const std::string & fileName() const
Retrieve the file name.
Definition: file.h:47
OpenMode openMode() const
Retrieve the file open mode.
Definition: file.h:53
unique_ptr-like wrapper for a file descriptor
Definition: unique_fd.h:17
bool isOpen() const
Check if the file is open.
Definition: file.h:52
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
Enable bitwise operations on the enum enumeration.
void setFileName(const std::string &name)
Set the name of the file.
Definition: file.cpp:129
~File()
Destroy a File instance.
Definition: file.cpp:108
ssize_t read(const Span< uint8_t > &data)
Read data from the file.
Definition: file.cpp:304
Type-safe container for enum-based bitfields.
Definition: flags.h:15
ssize_t size() const
Retrieve the file size.
Definition: file.cpp:243
ssize_t write(const Span< const uint8_t > &data)
Write data to the file.
Definition: file.cpp:342
bool open(OpenMode mode)
Open the file in the given mode.
Definition: file.cpp:173
int error() const
Retrieve the file error status.
Definition: file.h:56
off_t pos() const
Return current read or write position.
Definition: file.cpp:263
bool exists() const
Check if the file specified by fileName() exists.
Definition: file.cpp:152