blob: 6bb0a3ac009e38da294dae79d14a2bf476ff4690 (
plain) (
blame)
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
|
/* SPDX-License-Identifier: MIT */
#include "drm++/drm.hpp"
#include "drm++/helper.hpp"
#include "drm++/ioctl.hpp"
#include <stdexcept>
#include <drm.h>
#include <unistd.h>
using namespace drm;
Device::Device(int fd) : m_fd(fd) {
if (this->m_fd < 0) {
throw std::invalid_argument("invalid file descriptor");
}
drm_auth args{
};
ioctl::perform(this->m_fd, DRM_IOCTL_GET_MAGIC, args);
this->m_magic = args.magic;
}
void Device::acquireMaster() const {
ioctl::perform(this->m_fd, DRM_IOCTL_SET_MASTER);
}
void Device::releaseMaster() const {
ioctl::perform(this->m_fd, DRM_IOCTL_DROP_MASTER);
}
void Device::authenticate(u32 magic) const {
drm_auth args{
.magic = magic
};
ioctl::perform(this->m_fd, DRM_IOCTL_AUTH_MAGIC, args);
}
void Device::destruct() noexcept {
if (this->m_fd < 0) {
return;
}
::close(this->m_fd);
this->m_fd = -1;
}
|