2021-07-13 19:19:25 +02:00
|
|
|
#ifndef LINUX_UTILITY_UNIXFILEGUARD_H_
|
|
|
|
#define LINUX_UTILITY_UNIXFILEGUARD_H_
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2022-02-02 10:29:30 +01:00
|
|
|
#include <fsfw/returnvalues/HasReturnvaluesIF.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
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
UnixFileGuard(std::string device, int* fileDescriptor, int flags,
|
|
|
|
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;
|
|
|
|
ReturnValue_t openStatus = HasReturnvaluesIF::RETURN_OK;
|
|
|
|
};
|
2021-07-13 19:19:25 +02:00
|
|
|
|
|
|
|
#endif /* LINUX_UTILITY_UNIXFILEGUARD_H_ */
|