summaryrefslogtreecommitdiff
path: root/libkms++/drmobject.cpp
blob: 175ee169ccf630236aafc864ca73a1a1cefa86f3 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <string.h>
#include <iostream>
#include <stdexcept>

#include <xf86drm.h>
#include <xf86drmMode.h>

#include "kms++.h"

using namespace std;

namespace kms
{

DrmObject::DrmObject(Card& card, uint32_t object_type)
	:m_card(card), m_id(-1), m_object_type(object_type)
{
}

DrmObject::DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx)
	:m_card(card), m_id(id), m_object_type(object_type), m_idx(idx)
{
	refresh_props();
}

DrmObject::~DrmObject()
{

}

void DrmObject::refresh_props()
{
	auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type());

	if (props == nullptr)
		return;

	for (unsigned i = 0; i < props->count_props; ++i) {
		uint32_t prop_id = props->props[i];
		uint64_t prop_value = props->prop_values[i];

		m_prop_values[prop_id] = prop_value;
	}

	drmModeFreeObjectProperties(props);
}

void DrmObject::print_props() const
{
	for (auto it = m_prop_values.begin(); it != m_prop_values.end(); ++it) {
		cout << "\t" << card().get_prop(it->first)->name() <<
			" = " << it->second << endl;
	}
}

uint64_t DrmObject::get_prop_value(uint32_t id) const
{
	return m_prop_values.at(id);
}

uint64_t DrmObject::get_prop_value(const string& name) const
{
	for (auto pair : m_prop_values) {
		auto prop = card().get_prop(pair.first);
		if (name == prop->name())
			return m_prop_values.at(prop->id());
	}

	throw invalid_argument(string(name) + ": property not found");
}

void DrmObject::set_id(uint32_t id)
{
	m_id = id;
}
}