• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <string.h>
2 #include <iostream>
3 #include <stdexcept>
4 
5 #include <xf86drm.h>
6 #include <xf86drmMode.h>
7 
8 #include <kms++/kms++.h>
9 
10 using namespace std;
11 
12 namespace kms
13 {
14 
DrmPropObject(Card & card,uint32_t object_type)15 DrmPropObject::DrmPropObject(Card& card, uint32_t object_type)
16 	: DrmObject(card, object_type)
17 {
18 }
19 
DrmPropObject(Card & card,uint32_t id,uint32_t object_type,uint32_t idx)20 DrmPropObject::DrmPropObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx)
21 	: DrmObject(card, id, object_type, idx)
22 {
23 	refresh_props();
24 }
25 
~DrmPropObject()26 DrmPropObject::~DrmPropObject()
27 {
28 
29 }
30 
refresh_props()31 void DrmPropObject::refresh_props()
32 {
33 	auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type());
34 
35 	if (props == nullptr)
36 		return;
37 
38 	for (unsigned i = 0; i < props->count_props; ++i) {
39 		uint32_t prop_id = props->props[i];
40 		uint64_t prop_value = props->prop_values[i];
41 
42 		m_prop_values[prop_id] = prop_value;
43 	}
44 
45 	drmModeFreeObjectProperties(props);
46 }
47 
get_prop(const string & name) const48 Property* DrmPropObject::get_prop(const string& name) const
49 {
50 	for (auto pair : m_prop_values) {
51 		auto prop = card().get_prop(pair.first);
52 
53 		if (name == prop->name())
54 			return prop;
55 	}
56 
57 	throw invalid_argument(string("property ") + name + " not found");
58 }
59 
get_prop_value(uint32_t id) const60 uint64_t DrmPropObject::get_prop_value(uint32_t id) const
61 {
62 	return m_prop_values.at(id);
63 }
64 
get_prop_value(const string & name) const65 uint64_t DrmPropObject::get_prop_value(const string& name) const
66 {
67 	for (auto pair : m_prop_values) {
68 		auto prop = card().get_prop(pair.first);
69 		if (name == prop->name())
70 			return m_prop_values.at(prop->id());
71 	}
72 
73 	throw invalid_argument("property not found: " + name);
74 }
75 
get_prop_value_as_blob(const string & name) const76 unique_ptr<Blob> DrmPropObject::get_prop_value_as_blob(const string& name) const
77 {
78 	uint32_t blob_id = (uint32_t)get_prop_value(name);
79 
80 	return unique_ptr<Blob>(new Blob(card(), blob_id));
81 }
82 
set_prop_value(uint32_t id,uint64_t value)83 int DrmPropObject::set_prop_value(uint32_t id, uint64_t value)
84 {
85 	return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value);
86 }
87 
set_prop_value(const string & name,uint64_t value)88 int DrmPropObject::set_prop_value(const string &name, uint64_t value)
89 {
90 	Property* prop = get_prop(name);
91 
92 	if (prop == nullptr)
93 		throw invalid_argument("property not found: " + name);
94 
95 	return set_prop_value(prop->id(), value);
96 }
97 
98 }
99