fsfw/src/fsfw_hal/linux/UnixFileGuard.h

31 lines
760 B
C
Raw Normal View History

2021-07-13 19:19:25 +02:00
#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_
#define LINUX_UTILITY_UNIXFILEGUARD_H_
#include <fcntl.h>
2022-08-16 12:48:22 +02:00
#include <fsfw/returnvalues/returnvalue.h>
2021-07-13 19:19:25 +02:00
#include <unistd.h>
2022-02-02 10:29:30 +01:00
#include <string>
2021-07-13 19:19:25 +02:00
class UnixFileGuard {
2022-02-02 10:29:30 +01:00
public:
static constexpr int READ_WRITE_FLAG = O_RDWR;
static constexpr int READ_ONLY_FLAG = O_RDONLY;
static constexpr int NON_BLOCKING_IO_FLAG = O_NONBLOCK;
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
static constexpr ReturnValue_t OPEN_FILE_FAILED = 1;
2021-07-13 19:19:25 +02:00
UnixFileGuard(const std::string& device, int* fileDescriptor, int flags,
2022-02-02 10:29:30 +01:00
std::string diagnosticPrefix = "");
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
virtual ~UnixFileGuard();
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
ReturnValue_t getOpenResult() const;
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
private:
int* fileDescriptor = nullptr;
2022-08-15 20:28:16 +02:00
ReturnValue_t openStatus = returnvalue::OK;
2022-02-02 10:29:30 +01:00
};
2021-07-13 19:19:25 +02:00
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */