1 #include <xf86drm.h>
2 #include <xf86drmMode.h>
3
4 #include <kms++/kms++.h>
5
6 using namespace std;
7
8 namespace kms
9 {
10
11 struct PropertyPriv
12 {
13 drmModePropertyPtr drm_prop;
14 };
15
Property(Card & card,uint32_t id)16 Property::Property(Card& card, uint32_t id)
17 : DrmObject(card, id, DRM_MODE_OBJECT_PROPERTY)
18 {
19 m_priv = new PropertyPriv();
20 m_priv->drm_prop = drmModeGetProperty(card.fd(), id);
21 m_name = m_priv->drm_prop->name;
22
23 PropertyType t;
24 drmModePropertyPtr p = m_priv->drm_prop;
25 if (drm_property_type_is(p, DRM_MODE_PROP_BITMASK))
26 t = PropertyType::Bitmask;
27 else if (drm_property_type_is(p, DRM_MODE_PROP_BLOB))
28 t = PropertyType::Blob;
29 else if (drm_property_type_is(p, DRM_MODE_PROP_ENUM))
30 t = PropertyType::Enum;
31 else if (drm_property_type_is(p, DRM_MODE_PROP_OBJECT))
32 t = PropertyType::Object;
33 else if (drm_property_type_is(p, DRM_MODE_PROP_RANGE))
34 t = PropertyType::Range;
35 else if (drm_property_type_is(p, DRM_MODE_PROP_SIGNED_RANGE))
36 t = PropertyType::SignedRange;
37 else
38 throw invalid_argument("Invalid property type");
39
40 m_type = t;
41 }
42
~Property()43 Property::~Property()
44 {
45 drmModeFreeProperty(m_priv->drm_prop);
46 delete m_priv;
47 }
48
name() const49 const string& Property::name() const
50 {
51 return m_name;
52 }
53
is_immutable() const54 bool Property::is_immutable() const
55 {
56 return m_priv->drm_prop->flags & DRM_MODE_PROP_IMMUTABLE;
57 }
58
is_pending() const59 bool Property::is_pending() const
60 {
61 return m_priv->drm_prop->flags & DRM_MODE_PROP_PENDING;
62 }
63
get_values() const64 vector<uint64_t> Property::get_values() const
65 {
66 drmModePropertyPtr p = m_priv->drm_prop;
67 return vector<uint64_t>(p->values, p->values + p->count_values);
68 }
69
get_enums() const70 map<uint64_t, string> Property::get_enums() const
71 {
72 drmModePropertyPtr p = m_priv->drm_prop;
73
74 map<uint64_t, string> map;
75
76 for (int i = 0; i < p->count_enums; ++i)
77 map[p->enums[i].value] = string(p->enums[i].name);
78
79 return map;
80 }
81
get_blob_ids() const82 vector<uint32_t> Property::get_blob_ids() const
83 {
84 drmModePropertyPtr p = m_priv->drm_prop;
85 return vector<uint32_t>(p->blob_ids, p->blob_ids + p->count_blobs);
86 }
87 }
88