1 #pragma once 2 #include <linux/gpio.h> 3 4 #include <cstddef> 5 6 namespace gpioplus 7 { 8 namespace internal 9 { 10 11 /** @class Sys 12 * @brief Overridable direct syscall interface 13 */ 14 class Sys 15 { 16 public: 17 virtual ~Sys() = default; 18 19 virtual int open(const char* pathname, int flags) const = 0; 20 virtual int dup(int oldfd) const = 0; 21 virtual int close(int fd) const = 0; 22 virtual int read(int fd, void* buf, size_t count) const = 0; 23 virtual int fcntl_setfl(int fd, int flags) const = 0; 24 virtual int fcntl_getfl(int fd) const = 0; 25 26 virtual int gpiohandle_get_line_values( 27 int fd, struct gpiohandle_data* data) const = 0; 28 virtual int gpiohandle_set_line_values( 29 int fd, struct gpiohandle_data* data) const = 0; 30 virtual int gpio_get_chipinfo(int fd, struct gpiochip_info* info) const = 0; 31 virtual int gpio_get_lineinfo(int fd, struct gpioline_info* info) const = 0; 32 virtual int gpio_get_linehandle( 33 int fd, struct gpiohandle_request* request) const = 0; 34 virtual int gpio_get_lineevent(int fd, 35 struct gpioevent_request* request) const = 0; 36 }; 37 38 /** @class SysImpl 39 * @brief syscall concrete implementation 40 * @details Passes through all calls to the normal linux syscalls 41 */ 42 class SysImpl : public Sys 43 { 44 public: 45 int open(const char* pathname, int flags) const override; 46 int dup(int oldfd) const override; 47 int close(int fd) const override; 48 int read(int fd, void* buf, size_t count) const override; 49 int fcntl_setfl(int fd, int flags) const override; 50 int fcntl_getfl(int fd) const override; 51 52 int gpiohandle_get_line_values(int fd, 53 struct gpiohandle_data* data) const override; 54 int gpiohandle_set_line_values(int fd, 55 struct gpiohandle_data* data) const override; 56 int gpio_get_chipinfo(int fd, struct gpiochip_info* info) const override; 57 int gpio_get_lineinfo(int fd, struct gpioline_info* info) const override; 58 int gpio_get_linehandle(int fd, 59 struct gpiohandle_request* request) const override; 60 int gpio_get_lineevent(int fd, 61 struct gpioevent_request* request) const override; 62 }; 63 64 /** @brief Default instantiation of sys */ 65 extern SysImpl sys_impl; 66 67 } // namespace internal 68 } // namespace gpioplus 69