-
Notifications
You must be signed in to change notification settings - Fork 7
/
syscallhandler.h
58 lines (47 loc) · 1.85 KB
/
syscallhandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2016 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef USERSPACE_TOUCHPAD_SYSCALLHANDLER_H_
#define USERSPACE_TOUCHPAD_SYSCALLHANDLER_H_
#include <fcntl.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
class SyscallHandler {
/* A class to wrap raw syscall access when using them in this module
*
* This class wraps the basic low-level system calls you would make to
* raw file descriptors when interacting with devices on the OS. The
* intention is to allow for us to mock these functions away for improved
* testing, otherwise it's very difficult to write unit tests for
* classes that use open(), read(), ioctl(), etc.
*
* All functions directly mirror the standard syscalls
*/
public:
virtual int open(const char* pathname, int flags) const {
return ::open(pathname, flags);
}
virtual ssize_t write(int fd, const void *buf, size_t count) const {
return ::write(fd, buf, count);
}
virtual ssize_t read(int fd, void *buf, size_t count) const {
return ::read(fd, buf, count);
}
virtual int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) const {
return ::select(nfds, readfds, writefds, exceptfds, timeout);
}
virtual int ioctl(int fd, uint64_t request_code) const {
return ::ioctl(fd, request_code);
}
virtual int ioctl(int fd, uint64_t request_code, uint64_t arg1) const {
return ::ioctl(fd, request_code, arg1);
}
virtual int ioctl(int fd, uint64_t request_code,
struct uinput_setup *arg1) const {
return ::ioctl(fd, request_code, arg1);
}
};
#endif // USERSPACE_TOUCHPAD_SYSCALLHANDLER_H_