| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/devfsdatasource.h`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "core/idatasource.h"cxx . . $ `<file>/src/core/idatasource.h`/ |
| 7 | #include <fcntl.h> |
| 8 | #include <filesystem> |
| 9 | #include <functional> |
| 10 | #include <spdlog/spdlog.h> |
| 11 | #include <string> |
| 12 | #include <unistd.h> |
| 13 | #include <utility> |
| 14 | |
| 15 | template<typename T> |
| 16 | class DevFSDataSourcecxx . . $ DevFSDataSource# : public IDataSourcecxx . . $ IDataSource#<T> |
| 17 | { |
| 18 | public: |
| 19 | DevFSDataSourcecxx . . $ DevFSDataSource#`DevFSDataSource<T>`(119b0f6ac260da3c).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &path, |
| 20 | stdcxx . . $ std/::functioncxx . . $ std/function#<T(int)> &&reader) noexcept |
| 21 | : path_cxx . . $ DevFSDataSource#path_.(path.stringcxx . . $ std/filesystem/__cxx11/path#string(219584694fe2b248).()) |
| 22 | , reader_cxx . . $ DevFSDataSource#reader_.(stdcxx . . $ std/::movecxx . . $ std/move(88304b602929f6f4).(reader)) |
| 23 | { |
| 24 | fd_cxx . . $ DevFSDataSource#fd_. = open(path.c_strcxx . . $ std/filesystem/__cxx11/path#c_str(ba32b354807b2b81).(), O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!); |
| 25 | if (fd_cxx . . $ DevFSDataSource#fd_. < 0) |
| 26 | SPDLOG_DEBUGcxx . . $ spdlog/source_loc#("Cannot open {}", path.c_str()); |
| 27 | } |
| 28 | |
| 29 | ~cxx . . $ DevFSDataSource#`~DevFSDataSource<T>`(49f6e7a06ebc5aa8).DevFSDataSource() override |
| 30 | { |
| 31 | if (fd_cxx . . $ DevFSDataSource#fd_. > 0) |
| 32 | close(fd_cxx . . $ DevFSDataSource#fd_.); |
| 33 | } |
| 34 | |
| 35 | stdcxx . . $ std/::stringcxx . . $ std/string# sourcecxx . . $ DevFSDataSource#source(219584694fe2b248).() const override |
| 36 | { |
| 37 | return path_cxx . . $ DevFSDataSource#path_.; |
| 38 | } |
| 39 | |
| 40 | bool readcxx . . $ DevFSDataSource#read(e5bfd7b2d24a2428).(T &data) override |
| 41 | { |
| 42 | data = reader_cxx . . $ DevFSDataSource#reader_.(fd_cxx . . $ DevFSDataSource#fd_.); |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | stdcxx . . $ std/::stringcxx . . $ std/string# const path_cxx . . $ DevFSDataSource#path_.; |
| 48 | stdcxx . . $ std/::functioncxx . . $ std/function#<T(int)> const reader_cxx . . $ DevFSDataSource#reader_.; |
| 49 | int fd_cxx . . $ DevFSDataSource#fd_.; |
| 50 | }; |