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
|
/* SPDX-License-Identifier: MIT */
#include "drm++/ioctl.hpp"
#include <format>
#include <string>
#include <errno.h>
using namespace drm::ioctl;
Exception::Exception(int fd, unsigned long op)
: m_fd(fd), m_op(op), m_syserrno(errno) {
switch (errno) {
case EBADF:
m_code = Error::BadFileDescriptor;
break;
case EINVAL:
case ENOTTY:
m_code = Error::InvalidArgument;
break;
case ENOTSUP:
m_code = Error::NotSupported;
break;
default:
m_code = Error::Other;
}
}
std::string Exception::readable() {
switch (this->m_code) {
case Error::BadFileDescriptor:
return std::format(
"ioctl({}, {}) failed: Invalid file descriptor",
this->m_fd, this->m_op
);
case Error::InvalidArgument:
return std::format(
"ioctl({}, {}) failed: Invalid argument (errno {})",
this->m_fd, this->m_op, this->m_syserrno
);
case Error::NotSupported:
return std::format(
"ioctl({}, {}) failed: Operation not supported",
this->m_fd, this->m_op
);
case Error::Other:
return std::format(
"ioctl({}, {}) failed: Unknown error (errno {})",
this->m_fd, this->m_op, this->m_syserrno
);
}
}
Exception::~Exception() = default;
|